Revert "Support SIP TLS"
[sdc.git] / catalog-fe / src / main / java / org / openecomp / sdc / fe / listen / FEAppContextListener.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.sdc.fe.listen;
21
22 import java.util.concurrent.ExecutorService;
23 import java.util.concurrent.Executors;
24 import javax.servlet.ServletContextEvent;
25 import javax.servlet.ServletContextListener;
26 import org.openecomp.sdc.common.api.Constants;
27 import org.openecomp.sdc.common.impl.ExternalConfiguration;
28 import org.openecomp.sdc.common.listener.AppContextListener;
29 import org.openecomp.sdc.common.log.wrappers.Logger;
30 import org.openecomp.sdc.fe.config.ConfigurationManager;
31 import org.openecomp.sdc.fe.impl.HealthCheckService;
32 import org.openecomp.sdc.fe.impl.PluginStatusBL;
33 import org.openecomp.sdc.fe.monitoring.FeMonitoringService;
34
35 public class FEAppContextListener extends AppContextListener implements ServletContextListener {
36
37     private static final int HEALTH_CHECHK_INTERVALE = 5;
38     private static final int PROBE_INTERVALE = 15;
39     private static Logger log = Logger.getLogger(FEAppContextListener.class.getName());
40
41     public void contextInitialized(ServletContextEvent context) {
42         super.contextInitialized(context);
43         ConfigurationManager configurationManager = new ConfigurationManager(ExternalConfiguration.getConfigurationSource());
44         log.debug("loading configuration from configDir:{} appName:{}", ExternalConfiguration.getConfigDir(), ExternalConfiguration.getAppName());
45         context.getServletContext().setAttribute(Constants.CONFIGURATION_MANAGER_ATTR, configurationManager);
46         PluginStatusBL pbl = new PluginStatusBL();
47         context.getServletContext().setAttribute(Constants.PLUGIN_BL_COMPONENT, pbl);
48         // Health Check service
49         HealthCheckService hcs = new HealthCheckService(context.getServletContext());
50         hcs.start(configurationManager.getConfiguration().getHealthCheckIntervalInSeconds(HEALTH_CHECHK_INTERVALE));
51         context.getServletContext().setAttribute(Constants.HEALTH_CHECK_SERVICE_ATTR, hcs);
52         // Monitoring service
53         FeMonitoringService fms = new FeMonitoringService(context.getServletContext());
54         fms.start(configurationManager.getConfiguration().getSystemMonitoring().getProbeIntervalInSeconds(PROBE_INTERVALE));
55         if (configurationManager.getConfiguration() == null) {
56             log.debug("ERROR: configuration was not properly loaded");
57             return;
58         }
59         ExecutorService executorPool = Executors.newFixedThreadPool(configurationManager.getConfiguration().getThreadpoolSize());
60         context.getServletContext().setAttribute(Constants.THREAD_EXECUTOR_ATTR, executorPool);
61         log.debug("After executing {}", this.getClass());
62     }
63
64     public void contextDestroyed(ServletContextEvent context) {
65         ExecutorService executorPool = (ExecutorService) context.getServletContext().getAttribute(Constants.THREAD_EXECUTOR_ATTR);
66         if (executorPool != null) {
67             executorPool.shutdown();
68         }
69         super.contextDestroyed(context);
70     }
71 }