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.cloud.CloudConfigIdentityMapper;
31 import org.openecomp.mso.logger.MessageEnum;
32 import org.openecomp.mso.logger.MsoLogger;
35 * This class will attempt to initialize Cloud Config when part of a web application.
41 public class CloudConfigInitializer implements ServletContextListener
44 private CloudConfigFactory cloudConfigFactory=new CloudConfigFactory();
46 public CloudConfigInitializer () {
50 public void contextDestroyed(ServletContextEvent event) {
56 public void contextInitialized(ServletContextEvent event)
59 // Note - this logger may be before or after MSO Logging configuration applied
60 MsoLogger initLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL);
62 // Look first in the init-parameters
63 String msoPropConfigParam = event.getServletContext().getInitParameter("mso.cloud_config.configuration");
65 String[] configFileSplit = msoPropConfigParam.split(",");
66 for (String msoPropConfig:configFileSplit) {
67 String[] msoPropDecoded = msoPropConfig.split("=");
70 cloudConfigFactory.initializeCloudConfig(msoPropDecoded[0], Integer.valueOf(msoPropDecoded[1]));
71 initLogger.info(MessageEnum.RA_CONFIG_LOAD, msoPropDecoded[0], "", "");
72 initLogger.debug("Mso properties successfully loaded:"+msoPropDecoded[0]+"(Timer(mins):"+Integer.valueOf(msoPropDecoded[1]));
73 } catch (NumberFormatException ne) {
74 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 // Second, obtain class name that will register all mappings
79 String msoMapperClassParam = event.getServletContext().getInitParameter("mso.cloud_config.mapper.class");
80 if (msoMapperClassParam != null) {
81 Class<?> mapperClass = Class.forName(msoMapperClassParam);
82 if (CloudConfigIdentityMapper.class.isAssignableFrom(mapperClass)) {
83 ((CloudConfigIdentityMapper)mapperClass.newInstance()).registerAllMappings();
84 initLogger.info(MessageEnum.RA_CONFIG_LOAD,msoMapperClassParam+"(Openstack authentication mapper class)","","");
86 initLogger.info(MessageEnum.RA_CONFIG_LOAD,msoMapperClassParam+"(Openstack authentication mapper class not an implementation of CloudConfigIdentityMapper)","","");
89 initLogger.info(MessageEnum.RA_CONFIG_LOAD,"Openstack authentication mapper class not specified in web.xml (ONLY core authentication mechanisms will be loaded)","","");
94 initLogger.error(MessageEnum.RA_CONFIG_EXC, "Unknown. MSO Properties failed to initialize completely", "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception - MSO Properties failed to initialize completely", e);