2 * Copyright 2016 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;
18 import com.fasterxml.jackson.annotation.JsonInclude;
19 import io.dropwizard.Application;
20 import io.dropwizard.assets.AssetsBundle;
21 import io.dropwizard.db.DataSourceFactory;
22 import io.dropwizard.hibernate.HibernateBundle;
23 import io.dropwizard.server.SimpleServerFactory;
24 import io.dropwizard.setup.Bootstrap;
25 import io.dropwizard.setup.Environment;
26 import io.swagger.jaxrs.config.BeanConfig;
27 import io.swagger.jaxrs.listing.ApiListingResource;
29 import org.glassfish.jersey.media.multipart.MultiPartFeature;
30 import org.onap.aai.esr.common.Config;
31 import org.onap.aai.esr.common.ServiceRegistrer;
32 import org.onap.aai.esr.dao.DaoManager;
33 import org.onap.aai.esr.entity.db.BaseData;
34 import org.onap.aai.esr.entity.db.EmsData;
35 import org.onap.aai.esr.entity.db.SdncData;
36 import org.onap.aai.esr.entity.db.VimData;
37 import org.onap.aai.esr.entity.db.VnfmData;
38 import org.onap.aai.esr.hibernate.HibernateBundleAgent;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 public class ExtsysApp extends Application<ExtsysAppConfiguration> {
44 private static final Logger LOGGER = LoggerFactory.getLogger(ExtsysApp.class);
46 public static void main(String[] args) throws Exception {
47 new ExtsysApp().run(args);
51 public String getName() {
55 private final HibernateBundleAgent bundle = new HibernateBundleAgent();
58 public void initialize(Bootstrap<ExtsysAppConfiguration> bootstrap) {
59 bootstrap.addBundle(new AssetsBundle("/api-doc", "/api-doc", "index.html", "api-doc"));
63 private void initService() {
64 Thread registerExtsysService = new Thread(new ServiceRegistrer());
65 registerExtsysService.setName("register extsys service to Microservice Bus");
66 registerExtsysService.start();
69 private void initDb(Bootstrap<ExtsysAppConfiguration> bootstrap) {
70 bootstrap.addBundle(bundle);
74 public void run(ExtsysAppConfiguration configuration, Environment environment) {
75 LOGGER.info("Start to initialize extsys.");
76 environment.jersey().packages("org.onap.aai.esr.resource");
77 environment.jersey().register(MultiPartFeature.class);
78 initSwaggerConfig(environment, configuration);
79 Config.setConfigration(configuration);
81 LOGGER.info("Initialize extsys finished.");
85 * initialize swagger configuration.
87 * @param environment environment information
88 * @param configuration configuration
90 private void initSwaggerConfig(Environment environment, ExtsysAppConfiguration configuration) {
91 environment.jersey().register(new ApiListingResource());
92 environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
94 BeanConfig config = new BeanConfig();
95 config.setTitle("Open-o ExtSys Service rest API");
96 config.setVersion("1.0.0");
97 config.setResourcePackage("org.onap.aai.esr.resource");
98 // set rest api basepath in swagger
99 SimpleServerFactory simpleServerFactory =
100 (SimpleServerFactory) configuration.getServerFactory();
101 String basePath = simpleServerFactory.getApplicationContextPath();
102 String rootPath = simpleServerFactory.getJerseyRootPath();
103 rootPath = rootPath.substring(0, rootPath.indexOf("/*"));
104 basePath = basePath.equals("/") ? rootPath
105 : (new StringBuilder()).append(basePath).append(rootPath).toString();
106 config.setBasePath(basePath);
107 config.setScan(true);