Using MSB Java SDK for registration 83/10083/1
authorGuangrong Fu <fu.guangrong@zte.com.cn>
Sat, 2 Sep 2017 10:31:37 +0000 (18:31 +0800)
committerGuangrong Fu <fu.guangrong@zte.com.cn>
Sat, 2 Sep 2017 10:31:37 +0000 (18:31 +0800)
Use the MSB Java SDK for service registration

Change-Id: I4f74deb1db23c79fadfbb6ae44ac716af9e79725
Issue-ID: HOLMES-48
Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn>
rulemgt/pom.xml
rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java

index 5033e8b..9a9daf1 100644 (file)
     <packaging>jar</packaging>
 
     <dependencies>
+        <dependency>
+            <groupId>org.onap.msb.java-sdk</groupId>
+            <artifactId>msb-java-sdk</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.reflections</groupId>
             <artifactId>reflections</artifactId>
index 8dc697c..0aeb584 100644 (file)
 
 package org.onap.holmes.rulemgt;
 
+import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;
+
 import io.dropwizard.setup.Environment;
-import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
 import lombok.extern.slf4j.Slf4j;
-import org.onap.holmes.common.dropwizard.ioc.bundle.IOCApplication;
-import org.onap.holmes.common.api.entity.ServiceRegisterEntity;
 import org.onap.holmes.common.config.MicroServiceConfig;
+import org.onap.holmes.common.dropwizard.ioc.bundle.IOCApplication;
+import org.onap.holmes.common.exception.CorrelationException;
 import org.onap.holmes.common.utils.MSBRegisterUtil;
+import org.onap.holmes.rulemgt.resources.RuleMgtResources;
+import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
+import org.onap.msb.sdk.discovery.entity.Node;
 
 @Slf4j
-public class RuleActiveApp extends IOCApplication< RuleAppConfig > {
+public class RuleActiveApp extends IOCApplication<RuleAppConfig> {
 
-    public static void main( String[] args ) throws Exception {
-       new RuleActiveApp().run( args );
+    public static void main(String[] args) throws Exception {
+        new RuleActiveApp().run(args);
     }
-        
+
     @Override
     public String getName() {
         return "Holmes Rule Management ActiveApp APP ";
@@ -40,22 +46,27 @@ public class RuleActiveApp extends IOCApplication< RuleAppConfig > {
     public void run(RuleAppConfig configuration, Environment environment) throws Exception {
         super.run(configuration, environment);
 
+        environment.jersey().register(new RuleMgtResources());
         try {
-            new MSBRegisterUtil().register(initServiceEntity());
-        } catch (IOException e) {
-            log.warn("Micro service registry httpclient close failure",e);
+            new MSBRegisterUtil().register2Msb(createMicroServiceInfo());
+        } catch (CorrelationException e) {
+            log.warn(e.getMessage(), e);
         }
-
     }
 
-    private ServiceRegisterEntity initServiceEntity() {
-        ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity();
-        serviceRegisterEntity.setServiceName("holmes-rule-mgmt");
-        serviceRegisterEntity.setProtocol("REST");
-        serviceRegisterEntity.setVersion("v1");
-        serviceRegisterEntity.setUrl("/onapapi/holmes-rule-mgmt/v1");
-        serviceRegisterEntity.setSingleNode(MicroServiceConfig.getServiceIp(), "9101", 0);
-        serviceRegisterEntity.setVisualRange("1|0");
-        return serviceRegisterEntity;
+    private MicroServiceInfo createMicroServiceInfo() {
+        MicroServiceInfo msinfo = new MicroServiceInfo();
+        msinfo.setServiceName("holmes-rule-mgmt");
+        msinfo.setVersion("v1");
+        msinfo.setUrl("/onapapi/holmes-rule-mgmt/v1");
+        msinfo.setProtocol("REST");
+        msinfo.setVisualRange("0|1");
+        Set<Node> nodes = new HashSet<>();
+        Node node = new Node();
+        node.setIp(MicroServiceConfig.getServiceIp());
+        node.setPort("9101");
+        nodes.add(node);
+        msinfo.setNodes(nodes);
+        return msinfo;
     }
 }