2e1ae6f127d910fe300b44c35061758ee3a247fc
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / ExtsysApp.java
1 /**
2  * Copyright 2016-2017 ZTE Corporation.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.aai.esr;
17
18
19 import org.onap.aai.esr.common.MsbConfig;
20 import org.onap.aai.esr.externalservice.msb.MsbHelper;
21 import org.onap.aai.esr.resource.EmsManager;
22 import org.onap.aai.esr.resource.ServiceTest;
23 import org.onap.aai.esr.resource.ThirdpatySdncManager;
24 import org.onap.aai.esr.resource.VimManager;
25 import org.onap.aai.esr.resource.VnfmManager;
26 import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import io.dropwizard.Application;
31 import io.dropwizard.setup.Environment;
32
33 public class ExtsysApp extends Application<ExtsysAppConfiguration> {
34
35   private static final Logger LOGGER = LoggerFactory.getLogger(ExtsysApp.class);
36   
37   public static void main(String[] args) throws Exception {
38     new ExtsysApp().run(args);
39   }
40
41   @Override
42   public String getName() {
43     return "ONAP-ESR";
44   }
45
46   @Override
47   public void run(ExtsysAppConfiguration configuration, Environment environment) {
48     LOGGER.info("Start to initialize esr.");
49     MsbConfig.setMsbServerAddr(configuration.getMsbServerAddr());
50     MsbConfig.setMsbDiscoveryIp(configuration.getMsbDiscoveryIp());
51     MsbConfig.setMsbDiscoveryPort(configuration.getMsbDiscoveryPort());
52     environment.jersey().register(new EmsManager());
53     environment.jersey().register(new ThirdpatySdncManager());
54     environment.jersey().register(new VimManager());
55     environment.jersey().register(new VnfmManager());
56     environment.jersey().register(new ServiceTest());
57     if (configuration.getRegistByHand().equals("true")){
58       String MSB_IP=configuration.getMsbDiscoveryIp();
59       Integer MSB_Port= Integer.valueOf(configuration.getMsbDiscoveryPort());
60       MSBServiceClient msbClient = new MSBServiceClient(MSB_IP, MSB_Port);
61       MsbHelper helper = new MsbHelper(msbClient);
62       try {
63         helper.registerMsb();
64         LOGGER.info("Register esr-server to msb by java-sdk finished");
65       } catch (Exception e) {
66         LOGGER.error("Register esr-server to msb by java-sdk failed", e);
67       }
68     }
69     LOGGER.info("Initialize extsys finished.");
70   }
71
72 }