Initialize the App and Config Class
[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 io.dropwizard.setup.Environment;\r
20 import java.io.IOException;\r
21 import lombok.extern.slf4j.Slf4j;\r
22 import org.onap.holmes.common.api.entity.ServiceRegisterEntity;\r
23 import org.onap.holmes.common.config.MicroServiceConfig;\r
24 import org.onap.holmes.common.dropwizard.ioc.bundle.IOCApplication;\r
25 import org.onap.holmes.common.utils.MSBRegisterUtil;\r
26 \r
27 @Slf4j\r
28 public class DmaapDsaActiveApp  extends IOCApplication<DmaapDsaConfig> {\r
29     public static void main(String[] args) throws Exception {\r
30         new DmaapDsaActiveApp().run(args);\r
31     }\r
32 \r
33     @Override\r
34     public void run(DmaapDsaConfig configuration, Environment environment) throws Exception {\r
35         super.run(configuration, environment);\r
36 \r
37         try {\r
38             new MSBRegisterUtil().register(initServiceEntity());\r
39         } catch (IOException e) {\r
40             log.warn("Micro service registry httpclient close failure", e);\r
41         }\r
42     }\r
43 \r
44     private ServiceRegisterEntity initServiceEntity() {\r
45         ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity();\r
46         serviceRegisterEntity.setServiceName("holmes-dmaap-dsa");\r
47         serviceRegisterEntity.setProtocol("REST");\r
48         serviceRegisterEntity.setVersion("v1");\r
49         serviceRegisterEntity.setUrl("/onapapi/holmes-dmaap-dsa/v1/");\r
50         serviceRegisterEntity.setSingleNode(MicroServiceConfig.getServiceIp(), "9103", 0);\r
51         serviceRegisterEntity.setVisualRange("1|0");\r
52         return serviceRegisterEntity;\r
53     }\r
54 }\r