Remove the database related code in ESR.
[aai/esr-server.git] / esr-core / 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 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;
28
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.entity.aai.BaseData;
33 import org.onap.aai.esr.entity.aai.EmsData;
34 import org.onap.aai.esr.entity.aai.SdncData;
35 import org.onap.aai.esr.entity.aai.VimData;
36 import org.onap.aai.esr.entity.aai.VnfmData;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40 public class ExtsysApp extends Application<ExtsysAppConfiguration> {
41
42   private static final Logger LOGGER = LoggerFactory.getLogger(ExtsysApp.class);
43
44   public static void main(String[] args) throws Exception {
45     new ExtsysApp().run(args);
46   }
47
48   @Override
49   public String getName() {
50     return "ONAP-ESR";
51   }
52
53
54   @Override
55   public void initialize(Bootstrap<ExtsysAppConfiguration> bootstrap) {
56     bootstrap.addBundle(new AssetsBundle("/api-doc", "/api-doc", "index.html", "api-doc"));
57   }
58
59   private void initService() {
60     Thread registerExtsysService = new Thread(new ServiceRegistrer());
61     registerExtsysService.setName("register extsys service to Microservice Bus");
62     registerExtsysService.start();
63   }
64
65
66   @Override
67   public void run(ExtsysAppConfiguration configuration, Environment environment) {
68     LOGGER.info("Start to initialize extsys.");    
69     environment.jersey().packages("org.onap.aai.esr.resource");
70     environment.jersey().register(MultiPartFeature.class);
71     initSwaggerConfig(environment, configuration);
72     Config.setConfigration(configuration);
73     initService();
74     LOGGER.info("Initialize extsys finished.");
75   }
76
77   /**
78    * initialize swagger configuration.
79    * 
80    * @param environment environment information
81    * @param configuration configuration
82    */
83   private void initSwaggerConfig(Environment environment, ExtsysAppConfiguration configuration) {
84     environment.jersey().register(new ApiListingResource());
85     environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
86
87     BeanConfig config = new BeanConfig();
88     config.setTitle("Open-o ExtSys Service rest API");
89     config.setVersion("1.0.0");
90     config.setResourcePackage("org.onap.aai.esr.resource");
91     // set rest api basepath in swagger
92     SimpleServerFactory simpleServerFactory =
93         (SimpleServerFactory) configuration.getServerFactory();
94     String basePath = simpleServerFactory.getApplicationContextPath();
95     String rootPath = simpleServerFactory.getJerseyRootPath();
96     rootPath = rootPath.substring(0, rootPath.indexOf("/*"));
97     basePath = basePath.equals("/") ? rootPath
98         : (new StringBuilder()).append(basePath).append(rootPath).toString();
99     config.setBasePath(basePath);
100     config.setScan(true);
101   }
102
103 }