Register the Service Using MSB SDK
[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.io.IOException;\r
23 import java.util.HashSet;\r
24 import java.util.Set;\r
25 import lombok.extern.slf4j.Slf4j;\r
26 import org.onap.holmes.common.api.entity.ServiceRegisterEntity;\r
27 import org.onap.holmes.common.config.MicroServiceConfig;\r
28 import org.onap.holmes.common.dropwizard.ioc.bundle.IOCApplication;\r
29 import org.onap.holmes.common.exception.CorrelationException;\r
30 import org.onap.holmes.common.utils.MSBRegisterUtil;\r
31 import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;\r
32 import org.onap.msb.sdk.discovery.entity.Node;\r
33 \r
34 @Slf4j\r
35 public class DmaapDsaActiveApp  extends IOCApplication<DmaapDsaConfig> {\r
36     public static void main(String[] args) throws Exception {\r
37         new DmaapDsaActiveApp().run(args);\r
38     }\r
39 \r
40     @Override\r
41     public void run(DmaapDsaConfig configuration, Environment environment) throws Exception {\r
42         super.run(configuration, environment);\r
43         try {\r
44             new MSBRegisterUtil().register2Msb(createMicroServiceInfo());\r
45         } catch (CorrelationException e) {\r
46             log.warn(e.getMessage(), e);\r
47         }\r
48     }\r
49 \r
50     private MicroServiceInfo createMicroServiceInfo() {\r
51         String[] serviceAddrInfo = MicroServiceConfig.getServiceAddrInfo();\r
52         MicroServiceInfo msinfo = new MicroServiceInfo();\r
53         msinfo.setServiceName("holmes-dmaap-dsa");\r
54         msinfo.setVersion("v1");\r
55         msinfo.setUrl("/api/holmes-dmaap-dsa/v1/");\r
56         msinfo.setProtocol("REST");\r
57         msinfo.setVisualRange("0|1");\r
58         Set<Node> nodes = new HashSet<>();\r
59         Node node = new Node();\r
60         node.setIp(serviceAddrInfo[0]);\r
61         node.setPort(serviceAddrInfo[1]);\r
62         nodes.add(node);\r
63         msinfo.setNodes(nodes);\r
64         return msinfo;\r
65     }\r
66 }\r