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.
18 import com.fasterxml.jackson.annotation.JsonInclude;
19 import io.dropwizard.Application;
20 import io.dropwizard.assets.AssetsBundle;
21 import io.dropwizard.server.SimpleServerFactory;
22 import io.dropwizard.setup.Bootstrap;
23 import io.dropwizard.setup.Environment;
24 import io.swagger.jaxrs.config.BeanConfig;
25 import io.swagger.jaxrs.listing.ApiListingResource;
26 import org.onap.sfc.utils.SfcConst;
27 import org.onap.sfc.health.ConsoleHealthCheck;
28 import org.onap.sfc.resources.DriverResource;
29 import org.onap.sfc.service.ConfigInfo;
30 import org.onap.sfc.resources.MsbServiceRegister;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class SfcDriver extends Application<SfcDriverConfig> {
36 private static final Logger LOGGER = LoggerFactory.getLogger(SfcDriver.class);
38 public static void main(String[] args) throws Exception {
39 new SfcDriver().run(args);
43 public String getName() {
44 return SfcConst.SERVICE_NAME;
48 public void initialize(Bootstrap<SfcDriverConfig> bootstrap) {
49 bootstrap.addBundle(new AssetsBundle("/iui", "/", "index.html", "iui"));
50 bootstrap.addBundle(new AssetsBundle("/api-doc", "/api-doc", "index.html", "api-doc"));
54 public void run(SfcDriverConfig configuration,
55 Environment environment) {
56 final DriverResource driverResource = new DriverResource();
57 final ConsoleHealthCheck healthCheck =
58 new ConsoleHealthCheck(configuration.getTemplate());
59 environment.healthChecks().register("template", healthCheck);
60 environment.jersey().register(driverResource);
61 ConfigInfo.setConfig(configuration);
64 initSwaggerConfig(environment, configuration);
68 private void initSwaggerConfig(Environment environment, SfcDriverConfig configuration) {
69 environment.jersey().register(new ApiListingResource());
70 environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
72 BeanConfig config = new BeanConfig();
73 config.setTitle(" Console Service rest API");
74 config.setVersion("1.0.0");
75 config.setResourcePackage("org.openo.sfc.resources");
76 //swagger rest api basepath
77 SimpleServerFactory simpleServerFactory = (SimpleServerFactory) configuration.getServerFactory();
78 String basePath = simpleServerFactory.getApplicationContextPath();
80 basePath = basePath.endsWith("/") ? basePath : (new StringBuilder()).append(basePath).append('/').toString();
81 basePath = basePath + "service";
82 LOGGER.info("getApplicationContextPath: " + basePath);
83 config.setBasePath(basePath);
87 private void registerService()
89 Thread msbRegisterThread = new Thread(new MsbServiceRegister());
90 msbRegisterThread.setName("Register Service 2 MSB");
91 msbRegisterThread.start();