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