Register the Service Using MSB SDK 55/12855/1
authorGuangrong Fu <fu.guangrong@zte.com.cn>
Sat, 16 Sep 2017 07:07:47 +0000 (15:07 +0800)
committerGuangrong Fu <fu.guangrong@zte.com.cn>
Sat, 16 Sep 2017 07:07:47 +0000 (15:07 +0800)
Change-Id: I265a2da3f49656130d0226805782b458942a2451
Issue-ID: HOLMES-45
Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn>
dmaap-dsa/pom.xml
dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaap/DmaapDsaActiveApp.java
dmaap-dsa/src/main/java/org/onap/holmes/dsa/resources/HealthCheck.java [deleted file]
pom.xml

index df4d31e..414e271 100644 (file)
     <packaging>jar</packaging>
 
     <dependencies>
+        <dependency>
+            <groupId>org.onap.msb.java-sdk</groupId>
+            <artifactId>msb-java-sdk</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.onap.holmes.common</groupId>
             <artifactId>holmes-actions</artifactId>
index ab1e36b..55838ae 100644 (file)
 \r
 package org.onap.holmes.dsa.dmaap;\r
 \r
+import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;\r
+\r
 import io.dropwizard.setup.Environment;\r
 import java.io.IOException;\r
+import java.util.HashSet;\r
+import java.util.Set;\r
 import lombok.extern.slf4j.Slf4j;\r
 import org.onap.holmes.common.api.entity.ServiceRegisterEntity;\r
 import org.onap.holmes.common.config.MicroServiceConfig;\r
 import org.onap.holmes.common.dropwizard.ioc.bundle.IOCApplication;\r
+import org.onap.holmes.common.exception.CorrelationException;\r
 import org.onap.holmes.common.utils.MSBRegisterUtil;\r
+import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;\r
+import org.onap.msb.sdk.discovery.entity.Node;\r
 \r
 @Slf4j\r
 public class DmaapDsaActiveApp  extends IOCApplication<DmaapDsaConfig> {\r
@@ -33,22 +40,27 @@ public class DmaapDsaActiveApp  extends IOCApplication<DmaapDsaConfig> {
     @Override\r
     public void run(DmaapDsaConfig configuration, Environment environment) throws Exception {\r
         super.run(configuration, environment);\r
-\r
         try {\r
-            new MSBRegisterUtil().register(initServiceEntity());\r
-        } catch (IOException e) {\r
-            log.warn("Micro service registry httpclient close failure", e);\r
+            new MSBRegisterUtil().register2Msb(createMicroServiceInfo());\r
+        } catch (CorrelationException e) {\r
+            log.warn(e.getMessage(), e);\r
         }\r
     }\r
 \r
-    private ServiceRegisterEntity initServiceEntity() {\r
-        ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity();\r
-        serviceRegisterEntity.setServiceName("holmes-dmaap-dsa");\r
-        serviceRegisterEntity.setProtocol("REST");\r
-        serviceRegisterEntity.setVersion("v1");\r
-        serviceRegisterEntity.setUrl("/api/holmes-dmaap-dsa/v1/");\r
-        serviceRegisterEntity.setSingleNode(MicroServiceConfig.getServiceIp(), "9103", 0);\r
-        serviceRegisterEntity.setVisualRange("1|0");\r
-        return serviceRegisterEntity;\r
+    private MicroServiceInfo createMicroServiceInfo() {\r
+        String[] serviceAddrInfo = MicroServiceConfig.getServiceAddrInfo();\r
+        MicroServiceInfo msinfo = new MicroServiceInfo();\r
+        msinfo.setServiceName("holmes-dmaap-dsa");\r
+        msinfo.setVersion("v1");\r
+        msinfo.setUrl("/api/holmes-dmaap-dsa/v1/");\r
+        msinfo.setProtocol("REST");\r
+        msinfo.setVisualRange("0|1");\r
+        Set<Node> nodes = new HashSet<>();\r
+        Node node = new Node();\r
+        node.setIp(serviceAddrInfo[0]);\r
+        node.setPort(serviceAddrInfo[1]);\r
+        nodes.add(node);\r
+        msinfo.setNodes(nodes);\r
+        return msinfo;\r
     }\r
 }\r
diff --git a/dmaap-dsa/src/main/java/org/onap/holmes/dsa/resources/HealthCheck.java b/dmaap-dsa/src/main/java/org/onap/holmes/dsa/resources/HealthCheck.java
deleted file mode 100644 (file)
index 060a303..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2017 ZTE Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onap.holmes.dsa.resources;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.SwaggerDefinition;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
-
-@Service
-@SwaggerDefinition
-@Path("/healthcheck")
-@Api(tags = {"HealthCheck"})
-@Produces(MediaType.TEXT_PLAIN)
-@Slf4j
-public class HealthCheck {
-    @GET
-    @Produces(MediaType.TEXT_PLAIN)
-    @ApiOperation(value = "Interface for the health check of the data source adapter module for Holmes")
-    public boolean healthCheck(){
-        return true;
-    }
-}
diff --git a/pom.xml b/pom.xml
index ea275a5..d134703 100644 (file)
--- a/pom.xml
+++ b/pom.xml
     </properties>\r
     <dependencyManagement>\r
         <dependencies>\r
+            <dependency>\r
+                <groupId>org.onap.msb.java-sdk</groupId>\r
+                <artifactId>msb-java-sdk</artifactId>\r
+                <version>1.0.0-SNAPSHOT</version>\r
+            </dependency>\r
             <dependency>\r
                 <groupId>org.easymock</groupId>\r
                 <artifactId>easymock</artifactId>\r