2 * Copyright 2016-2018 ZTE Corporation.
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.aai.esr;
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.PnfManager;
23 import org.onap.aai.esr.resource.ServiceTest;
24 import org.onap.aai.esr.resource.ThirdpartySdncManager;
25 import org.onap.aai.esr.resource.VimManager;
26 import org.onap.aai.esr.resource.VnfmManager;
27 import org.onap.aai.esr.resource.NfvoManager;
28 import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import io.dropwizard.Application;
32 import io.dropwizard.server.SimpleServerFactory;
33 import io.dropwizard.setup.Environment;
34 import io.swagger.jaxrs.config.BeanConfig;
35 import io.swagger.jaxrs.listing.ApiListingResource;
37 import com.fasterxml.jackson.annotation.JsonInclude;
39 public class ExtsysApp extends Application<ExtsysAppConfiguration> {
41 private static final Logger LOGGER = LoggerFactory.getLogger(ExtsysApp.class);
43 public static void main(String[] args) throws Exception {
44 new ExtsysApp().run(args);
48 public String getName() {
53 public void run(ExtsysAppConfiguration configuration, Environment environment) {
54 LOGGER.info("Start to initialize esr.");
55 MsbConfig.setMsbServerAddr(configuration.getMsbServerAddr());
56 MsbConfig.setMsbDiscoveryIp(configuration.getMsbDiscoveryIp());
57 MsbConfig.setMsbDiscoveryPort(configuration.getMsbDiscoveryPort());
58 environment.jersey().register(new EmsManager());
59 environment.jersey().register(new ThirdpartySdncManager());
60 environment.jersey().register(new VimManager());
61 environment.jersey().register(new VnfmManager());
62 environment.jersey().register(new NfvoManager());
63 environment.jersey().register(new PnfManager());
64 environment.jersey().register(new ServiceTest());
65 initSwaggerConfig(environment, configuration);
66 if ("false".equals(configuration.getRegistByHand())) {
67 String MSB_IP = configuration.getMsbDiscoveryIp();
68 Integer MSB_Port = Integer.valueOf(configuration.getMsbDiscoveryPort());
69 MSBServiceClient msbClient = new MSBServiceClient(MSB_IP, MSB_Port);
70 MsbHelper helper = new MsbHelper(msbClient);
73 LOGGER.info("Register esr-server to msb by java-sdk finished");
74 } catch (Exception e) {
75 LOGGER.error("Register esr-server to msb by java-sdk failed", e);
78 LOGGER.info("Initialize extsys finished.");
82 * initialize swagger configuration.
84 * @param environment environment information
85 * @param configuration catalogue configuration
87 private void initSwaggerConfig(Environment environment, ExtsysAppConfiguration configuration) {
88 environment.jersey().register(new ApiListingResource());
89 environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
91 BeanConfig config = new BeanConfig();
92 config.setTitle("ONAP ESR Service rest API");
93 config.setVersion("1.0.0");
94 config.setResourcePackage("org.onap.aai.esr.resource");
95 // set rest api basepath in swagger
96 SimpleServerFactory simpleServerFactory =
97 (SimpleServerFactory) configuration.getServerFactory();
98 String basePath = simpleServerFactory.getApplicationContextPath();
99 String rootPath = simpleServerFactory.getJerseyRootPath().get();
100 rootPath = rootPath.substring(0, rootPath.indexOf("/*"));
102 basePath.equals("/") ? rootPath : (new StringBuilder()).append(basePath)
103 .append(rootPath).toString();
104 LOGGER.info("getApplicationContextPath: " + basePath);
105 config.setBasePath(basePath);
106 config.setScan(true);