TOSCA-159 Add serviceIp property which is used to config catalog microservice ipaddress
authorsunqi310 <sun.qi310@zte.com.cn>
Fri, 28 Oct 2016 08:46:24 +0000 (16:46 +0800)
committersunqi310 <sun.qi310@zte.com.cn>
Fri, 28 Oct 2016 08:55:18 +0000 (16:55 +0800)
Change-Id: I9faac688747ba9e55cd545716ef927214a24d403
Issue-id: TOSCA-158
Signed-off-by: sunqi310 <sun.qi310@zte.com.cn>
catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/CatalogAppConfiguration.java
catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/ServiceRegistrer.java
catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/MicroserviceBusConsumer.java
catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/ServiceRegisterEntity.java
catalog-core/distribution/catalog-standalone/src/main/assembly/conf/catalog.yml

index 1093990..b320487 100644 (file)
@@ -47,6 +47,9 @@ public class CatalogAppConfiguration extends Configuration {
   @NotEmpty
   private String httpServerPath;
 
+  @Valid
+  private String serviceIp;
+  
   @Valid
   @NotNull
   private DataSourceFactory database = new DataSourceFactory();
@@ -128,5 +131,15 @@ public class CatalogAppConfiguration extends Configuration {
   public void setHttpServerPath(String httpServerPath) {
     this.httpServerPath = httpServerPath;
   }
+  
+  @JsonProperty
+  public String getServiceIp() {
+    return serviceIp;
+  }
+
+  @JsonProperty
+  public void setServiceIp(String serviceIp) {
+    this.serviceIp = serviceIp;
+  }
 
 }
index b81a656..1e2be58 100644 (file)
@@ -15,6 +15,7 @@
  */
 package org.openo.commontosca.catalog.common;
 
+import org.openo.commontosca.catalog.common.Config;
 import org.openo.commontosca.catalog.externalservice.msb.MicroserviceBusConsumer;
 import org.openo.commontosca.catalog.externalservice.msb.ServiceRegisterEntity;
 import org.slf4j.Logger;
@@ -81,7 +82,7 @@ public class ServiceRegistrer implements Runnable {
     catalogEntity.setProtocol("REST");
     catalogEntity.setVersion("v1");
     catalogEntity.setUrl("/openoapi/catalog/v1");
-    catalogEntity.setSingleNode(null, "8200", 0);
+    catalogEntity.setSingleNode(Config.getConfigration().getServiceIp(), "8200", 0);
     catalogEntity.setVisualRange("1");
     serviceEntityList.add(catalogEntity);
     ServiceRegisterEntity httpServiceEntity = new ServiceRegisterEntity();
@@ -89,7 +90,7 @@ public class ServiceRegistrer implements Runnable {
     httpServiceEntity.setProtocol("REST");
     httpServiceEntity.setVersion("v1");
     httpServiceEntity.setUrl("/");
-    httpServiceEntity.setSingleNode(null, "8201", 0);
+    httpServiceEntity.setSingleNode(Config.getConfigration().getServiceIp(), "8201", 0);
     httpServiceEntity.setVisualRange("1");
     serviceEntityList.add(httpServiceEntity);
   }
index 3c964b2..33e1700 100644 (file)
@@ -17,6 +17,7 @@ package org.openo.commontosca.catalog.externalservice.msb;
 
 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
 import org.glassfish.jersey.client.ClientConfig;
+import org.openo.commontosca.catalog.db.util.CatalogDbUtil;
 import org.openo.commontosca.catalog.common.Config;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -32,6 +33,7 @@ public class MicroserviceBusConsumer {
    */
   public static boolean registerService(ServiceRegisterEntity entity) {
     ClientConfig config = new ClientConfig();
+    LOG.info("microservice register body:" + CatalogDbUtil.objectToString(entity));
     try {
       MicroserviceBusRest resourceserviceproxy =
           ConsumerFactory.createConsumer(Config.getConfigration().getMsbServerAddr(), config,
index acf8ab6..7732437 100644 (file)
@@ -44,7 +44,11 @@ public class ServiceRegisterEntity {
    */
   public void setSingleNode(String ip, String port, int ttl) {
     ServiceNode node = new ServiceNode();
-    node.setIp(ip);
+    if (ip != null && ip.length() > 0) {
+      node.setIp(ip);
+    } else {
+      node.setIp(null);
+    }
     node.setPort(port);
     node.setTtl(ttl);
     nodes.add(node);
index c445917..7bb6a5f 100644 (file)
@@ -17,7 +17,8 @@
 template: Hello, %s!
 
 defaultName: ${DW_DEFAULT_NAME:-Stranger}
-
+# the micro service ip
+serviceIp: 
 msbServerAddr: http://127.0.0.1:80
 
 httpServerAddr: http://127.0.0.1:8201