Clean the config files.
[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.ThirdpatySdncManager;
23 import org.onap.aai.esr.resource.VimManager;
24 import org.onap.aai.esr.resource.VnfmManager;
25 import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 import io.dropwizard.Application;
30 import io.dropwizard.setup.Environment;
31
32 public class ExtsysApp extends Application<ExtsysAppConfiguration> {
33
34   private static final Logger LOGGER = LoggerFactory.getLogger(ExtsysApp.class);
35   
36   public static void main(String[] args) throws Exception {
37     new ExtsysApp().run(args);
38   }
39
40   @Override
41   public String getName() {
42     return "ONAP-ESR";
43   }
44
45   @Override
46   public void run(ExtsysAppConfiguration configuration, Environment environment) {
47     LOGGER.info("Start to initialize esr.");
48     MsbConfig.setMsbServerAddr(configuration.getMsbServerAddr());
49     MsbConfig.setMsbDiscoveryIp(configuration.getMsbDiscoveryIp());
50     MsbConfig.setMsbDiscoveryPort(configuration.getMsbDiscoveryPort());
51     environment.jersey().register(new EmsManager());
52     environment.jersey().register(new ThirdpatySdncManager());
53     environment.jersey().register(new VimManager());
54     environment.jersey().register(new VnfmManager());
55     
56     if (configuration.getRegistByHand().endsWith("true")){
57       String MSB_IP=configuration.getMsbDiscoveryIp();
58       Integer MSB_Port= Integer.valueOf(configuration.getMsbDiscoveryPort());
59       MSBServiceClient msbClient = new MSBServiceClient(MSB_IP, MSB_Port);
60       MsbHelper helper = new MsbHelper(msbClient);
61       try {
62         helper.registerMsb();
63       } catch (Exception e) {
64         LOGGER.error("Register esr-server to msb by java-sdk failed", e);
65       }
66     }
67     LOGGER.info("Initialize extsys finished.");
68   }
69
70 }