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.
26 func SvcReg(confPath string) (string, error) {
27 conf, err := GetConf(confPath)
29 log.Println(err.Error())
33 appInstanceId := conf.AppInstanceId
34 serviceInfos := conf.ServiceInfoPosts
35 mepServerIP := conf.MepServerIP
36 mepServerPORT := conf.MepServerPORT
37 url := "http://" + mepServerIP + ":" + mepServerPORT + "/mep/mec_service_mgmt/v1/applications/" + appInstanceId + "/services"
39 for _, serviceInfo := range serviceInfos {
40 data, e := json.Marshal(serviceInfo)
42 log.Println("Failed to marshal service info to object")
46 for i := 1; i <= 5; i++ { // if register failed, then retry five times
47 _, err := RegisterToMep(string(data), url)
49 log.Println("Failed to register to mep, appInstanceId is" + appInstanceId + ", serviceName is " + serviceInfo.SerName)
51 log.Println("Register mep main to mep success, appInstanceId is" + appInstanceId + ", serviceName is " + serviceInfo.SerName)
54 log.Println("Failed to register mep main to mep, will retry 5 times, retry interval is 30 s, already retry " + strconv.Itoa(i) + " time")
55 time.Sleep(30 * time.Second) // register failed , 30 seconds after try again