2 * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.vfc.nfvo.emsdriver.northbound.service;
18 import io.dropwizard.Application;
19 import io.dropwizard.jetty.HttpConnectorFactory;
20 import io.dropwizard.server.DefaultServerFactory;
21 import io.dropwizard.setup.Bootstrap;
22 import io.dropwizard.setup.Environment;
24 import java.net.InetAddress;
25 import java.net.UnknownHostException;
26 import java.util.ArrayList;
27 import java.util.List;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.onap.vfc.nfvo.emsdriver.serviceregister.MsbConfiguration;
32 import org.onap.vfc.nfvo.emsdriver.serviceregister.MsbRestServiceProxy;
33 import org.onap.vfc.nfvo.emsdriver.serviceregister.model.MsbRegisterVo;
34 import org.onap.vfc.nfvo.emsdriver.serviceregister.model.ServiceNodeVo;
36 public class EmsDriverApplication extends Application<EmsDriverConfiguration> {
38 protected static Log log = LogFactory.getLog(EmsDriverApplication.class);
40 public static void main(String[] args) throws Exception {
41 new EmsDriverApplication().run(args);
45 public String getName() {
50 public void initialize(Bootstrap<EmsDriverConfiguration> bootstrap) {
55 public void run(EmsDriverConfiguration configuration,Environment environment) {
56 // register CommandResource
57 environment.jersey().register(new CommandResource());
60 MsbConfiguration.setMsbAddress(configuration.getMsbAddress());
62 this.msbRegisteEmsDriverService(configuration);
65 private void msbRegisteEmsDriverService(EmsDriverConfiguration configuration) {
66 DefaultServerFactory defaultServerFactory = (DefaultServerFactory)configuration.getServerFactory();
67 HttpConnectorFactory connector = (HttpConnectorFactory)defaultServerFactory.getAdminConnectors().get(0);
68 MsbRegisterVo registerVo = new MsbRegisterVo();
69 ServiceNodeVo serviceNode = new ServiceNodeVo();
72 ip = InetAddress.getLocalHost().getHostAddress();
73 } catch (UnknownHostException e) {
74 log.error("Unable to get host ip: " + e.getMessage());
77 ip = connector.getBindHost();
79 serviceNode.setIp(ip);
80 serviceNode.setPort(String.valueOf(connector.getPort()));
81 serviceNode.setTtl(0);
83 List<ServiceNodeVo> nodeList = new ArrayList<ServiceNodeVo>();
84 nodeList.add(serviceNode);
85 registerVo.setServiceName("emsdriver");
86 registerVo.setUrl("/api/emsdriver/v1");
87 registerVo.setNodes(nodeList);
89 MsbRestServiceProxy.registerService(registerVo);
90 log.info("register monitor-umc service to msb finished.");