Modify the Service Addr Query Logic
[holmes/dsa.git] / dmaap-dsa / src / main / java / org / onap / holmes / dsa / dmaap / DmaapDsaActiveApp.java
1 /*\r
2  * Copyright 2017 ZTE Corporation.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 package org.onap.holmes.dsa.dmaap;\r
18 \r
19 import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;\r
20 \r
21 import io.dropwizard.setup.Environment;\r
22 import java.util.HashSet;\r
23 import java.util.Set;\r
24 import lombok.extern.slf4j.Slf4j;\r
25 import org.onap.holmes.common.config.MicroServiceConfig;\r
26 import org.onap.holmes.common.dropwizard.ioc.bundle.IOCApplication;\r
27 import org.onap.holmes.common.exception.CorrelationException;\r
28 import org.onap.holmes.common.utils.MSBRegisterUtil;\r
29 import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;\r
30 import org.onap.msb.sdk.discovery.entity.Node;\r
31 \r
32 @Slf4j\r
33 public class DmaapDsaActiveApp  extends IOCApplication<DmaapDsaConfig> {\r
34     public static void main(String[] args) throws Exception {\r
35         new DmaapDsaActiveApp().run(args);\r
36     }\r
37 \r
38     @Override\r
39     public void run(DmaapDsaConfig configuration, Environment environment) throws Exception {\r
40         super.run(configuration, environment);\r
41         try {\r
42             new MSBRegisterUtil().register2Msb(createMicroServiceInfo());\r
43         } catch (CorrelationException e) {\r
44             log.warn(e.getMessage(), e);\r
45         }\r
46     }\r
47 \r
48     private MicroServiceInfo createMicroServiceInfo() {\r
49         String[] serviceAddrInfo = MicroServiceConfig.getMicroServiceIpAndPort();\r
50         MicroServiceInfo msinfo = new MicroServiceInfo();\r
51         msinfo.setServiceName("holmes-dmaap-dsa");\r
52         msinfo.setVersion("v1");\r
53         msinfo.setUrl("/api/holmes-dmaap-dsa/v1/");\r
54         msinfo.setProtocol("REST");\r
55         msinfo.setVisualRange("0|1");\r
56         Set<Node> nodes = new HashSet<>();\r
57         Node node = new Node();\r
58         node.setIp(serviceAddrInfo[0]);\r
59         node.setPort(serviceAddrInfo[1]);\r
60         nodes.add(node);\r
61         msinfo.setNodes(nodes);\r
62         return msinfo;\r
63     }\r
64 }\r