2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.openstack.utils;
25 import javax.servlet.ServletContextEvent;
26 import javax.servlet.ServletContextListener;
27 import javax.servlet.annotation.WebListener;
29 import org.openecomp.mso.cloud.CloudConfigFactory;
30 import org.openecomp.mso.logger.MessageEnum;
31 import org.openecomp.mso.logger.MsoLogger;
34 * This class will attempt to initialize Cloud Config when part of a web application.
40 public class CloudConfigInitializer implements ServletContextListener
43 private CloudConfigFactory cloudConfigFactory=new CloudConfigFactory();
45 public CloudConfigInitializer () {
49 public void contextDestroyed(ServletContextEvent event) {
55 public void contextInitialized(ServletContextEvent event)
58 // Note - this logger may be before or after MSO Logging configuration applied
59 MsoLogger initLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL);
61 // Look first in the init-parameters
62 String msoPropConfigParam = event.getServletContext().getInitParameter("mso.cloud_config.configuration");
64 String[] configFileSplit = msoPropConfigParam.split(",");
65 for (String msoPropConfig:configFileSplit) {
66 String[] msoPropDecoded = msoPropConfig.split("=");
69 cloudConfigFactory.initializeCloudConfig(msoPropDecoded[0], Integer.valueOf(msoPropDecoded[1]));
70 initLogger.info(MessageEnum.RA_CONFIG_LOAD, msoPropDecoded[0], "", "");
71 initLogger.debug("Mso properties successfully loaded:"+msoPropDecoded[0]+"(Timer(mins):"+Integer.valueOf(msoPropDecoded[1]));
72 } catch (NumberFormatException ne) {
73 initLogger.error(MessageEnum.RA_CONFIG_EXC, msoPropDecoded[0] + ". MSO Properties failed due to conversion error (in web.xml file)", "", "", MsoLogger.ErrorCode.DataError, "MSO Properties failed due to conversion error (in web.xml file)", ne);
78 initLogger.error(MessageEnum.RA_CONFIG_EXC, "Unknown. MSO Properties failed to initialize completely", "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception - MSO Properties failed to initialize completely", e);