2 * Copyright 2020 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
27 func SvcReg(confPath string) (string, error) {
31 conf, err := GetConf(confPath)
33 log.Println(err.Error())
37 appInstanceId := conf.AppInstanceId
38 serviceInfos := conf.ServiceInfoPosts
39 gwRoutes := conf.MepGWROUTES
42 sslMode := os.Getenv("APP_SSL_MODE")
43 //if ssl mode is enabled, then config tls
45 gwPORT = conf.HttpGWPORT
48 gwPORT = conf.HttpsGWPORT
52 url := urlProto + gwIP + ":" + gwPORT + gwRoutes + "/mep/mec_service_mgmt/v1/applications/" + appInstanceId + "/services"
53 log.Println("Register url is" + url)
55 for _, serviceInfo := range serviceInfos {
56 data, e := json.Marshal(serviceInfo)
58 log.Println("Failed to marshal service info to object")
62 for i := 1; i <= 5; i++ { // if register failed, then retry five times
63 _, err := RegisterToMep(string(data), url)
65 log.Println("Failed to register to mep, appInstanceId is" + appInstanceId + ", serviceName is " + serviceInfo.SerName)
67 log.Println("Register mep main to mep success, appInstanceId is" + appInstanceId + ", serviceName is " + serviceInfo.SerName)
70 log.Println("Failed to register mep main to mep, will retry 5 times, retry interval is 30 s, already retry " + strconv.Itoa(i) + " time")
71 time.Sleep(30 * time.Second) // register failed , 30 seconds after try again