2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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=========================================================
20 package org.onap.aai.util;
22 import java.io.IOException;
23 import java.util.UUID;
24 import javax.servlet.ServletContextEvent;
25 import javax.servlet.ServletContextListener;
27 import org.onap.aai.dbmap.AAIGraph;
28 import org.onap.aai.exceptions.AAIException;
29 import org.onap.aai.introspection.ModelInjestor;
30 import org.onap.aai.logging.ErrorLogHelper;
31 import org.onap.aai.logging.LogFormatTools;
32 import org.onap.aai.logging.LoggingContext;
33 import org.onap.aai.logging.LoggingContext.StatusCode;
35 import com.att.eelf.configuration.EELFLogger;
36 import com.att.eelf.configuration.EELFManager;
38 public class AAIAppServletContextListener implements ServletContextListener {
40 private static final String MICRO_SVC="aai-traversal";
41 private static final String ACTIVEMQ_TCP_URL = "tcp://localhost:61446";
42 private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIAppServletContextListener.class.getName());
47 * @param arg0 the ServletContextEvent
49 public void contextDestroyed(ServletContextEvent arg0) {
55 * @param arg0 the ServletContextEvent
57 public void contextInitialized(ServletContextEvent arg0) {
58 System.setProperty("org.onap.aai.serverStarted", "false");
59 System.setProperty("aai.service.name", "traversal");
61 LoggingContext.save();
62 LoggingContext.component("init");
63 LoggingContext.partnerName("NA");
64 LoggingContext.targetEntity(MICRO_SVC);
65 LoggingContext.requestId(UUID.randomUUID().toString());
66 LoggingContext.serviceName(MICRO_SVC);
67 LoggingContext.targetServiceName("contextInitialized");
68 LoggingContext.statusCode(StatusCode.COMPLETE);
69 LOGGER.info("AAI Server initialization started...");
71 LOGGER.info("Loading aaiconfig.properties");
74 LOGGER.info("Loading error.properties");
75 ErrorLogHelper.loadProperties();
77 LOGGER.info("Loading graph database");
79 AAIGraph.getInstance();
80 ModelInjestor.getInstance();
82 LOGGER.info("A&AI Server initialization succcessful.");
83 System.setProperty("activemq.tcp.url", ACTIVEMQ_TCP_URL);
84 System.setProperty("org.onap.aai.serverStarted", "true");
86 Runtime.getRuntime().addShutdownHook(new Thread() {
88 LOGGER.info("AAIGraph shutting down");
89 AAIGraph.getInstance().graphShutdown();
90 LOGGER.info("AAIGraph shutdown");
91 System.out.println("Shutdown hook triggered.");
95 } catch (AAIException e) {
96 ErrorLogHelper.logException(e);
97 throw new RuntimeException("AAIException caught while initializing A&AI server", e);
98 } catch (IOException e) {
99 ErrorLogHelper.logError("AAI_4000", e.getMessage());
100 throw new RuntimeException("IOException caught while initializing A&AI server", e);
101 } catch (Exception e) {
102 LOGGER.error("Unknown failure while initializing A&AI Server" + LogFormatTools.getStackTop(e));
103 throw new RuntimeException("Unknown failure while initializing A&AI server", e);
106 LOGGER.info("Graph-Query MicroService Started");
107 LOGGER.debug("Graph-Query MicroService Started");
108 LoggingContext.restore();