summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHuabing Zhao <zhaohuabing@gmail.com>2018-08-06 07:39:19 +0000
committerGerrit Code Review <gerrit@onap.org>2018-08-06 07:39:19 +0000
commit7898ba2e11e4dfab3e55cf320f2a34dc83068079 (patch)
tree2008325e9a197e2cb6c524b18613b5eec805ee1f
parentfd5a73ed626884d37dff38ed2410bf7f3c4782d2 (diff)
parentce890da0e79c26ad6f31f86956f690efee0106da (diff)
Merge "get published services from msb"
-rw-r--r--msb2pilot/src/msb2pilot/models/config.go5
-rw-r--r--msb2pilot/src/msb2pilot/msb/msb.go59
2 files changed, 62 insertions, 2 deletions
diff --git a/msb2pilot/src/msb2pilot/models/config.go b/msb2pilot/src/msb2pilot/models/config.go
index 8dd2d3c..5773cf4 100644
--- a/msb2pilot/src/msb2pilot/models/config.go
+++ b/msb2pilot/src/msb2pilot/models/config.go
@@ -12,6 +12,7 @@
package models
const (
- EnvConsulAddress = "ConsulAddress" //http://localhost:8500
- EnvK8sAddress = "K8sAddress"
+ EnvConsulAddress = "ConsulAddress" //http://localhost:8500
+ EnvK8sAddress = "K8sAddress"
+ EnvMsbAddress = "MsbAddress"
)
diff --git a/msb2pilot/src/msb2pilot/msb/msb.go b/msb2pilot/src/msb2pilot/msb/msb.go
new file mode 100644
index 0000000..9d5754a
--- /dev/null
+++ b/msb2pilot/src/msb2pilot/msb/msb.go
@@ -0,0 +1,59 @@
+/**
+ * Copyright (c) 2018 ZTE Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * ZTE - initial Project
+ */
+package msb
+
+import (
+ "encoding/json"
+ "io/ioutil"
+ "msb2pilot/log"
+ "msb2pilot/models"
+ "net/http"
+ "os"
+)
+
+var (
+ msbAddr = "http://localhost:9081"
+)
+
+func getBaseUrl() string {
+ baseUrl := os.Getenv(models.EnvMsbAddress)
+ if baseUrl == "" {
+ baseUrl = msbAddr
+ }
+
+ return baseUrl
+}
+
+func GetAllPublishServices() []*models.PublishService {
+ url := getBaseUrl() + "/api/msdiscover/v1/publishservicelist"
+ res, err := http.Get(url)
+
+ if err != nil {
+ log.Log.Error("fail to get public address", url, err)
+ return nil
+ }
+
+ b, err := ioutil.ReadAll(res.Body)
+ if err != nil {
+ log.Log.Error("fail to read response", err)
+ return nil
+ }
+
+ result := make([]*models.PublishService, 0)
+ err = json.Unmarshal(b, &result)
+ if err != nil {
+ log.Log.Error("fail to unmarshal publish address", err)
+ return nil
+ }
+
+ return result
+}