2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.util;
25 import java.io.IOException;
26 import java.util.UUID;
27 import javax.servlet.ServletContextEvent;
28 import javax.servlet.ServletContextListener;
30 import org.onap.aai.dbmap.AAIGraph;
31 import org.onap.aai.exceptions.AAIException;
32 import org.onap.aai.introspection.ModelInjestor;
33 import org.onap.aai.logging.ErrorLogHelper;
34 import org.onap.aai.logging.LogFormatTools;
35 import org.onap.aai.logging.LoggingContext;
36 import org.onap.aai.logging.LoggingContext.StatusCode;
38 import com.att.eelf.configuration.EELFLogger;
39 import com.att.eelf.configuration.EELFManager;
41 public class AAIAppServletContextListener implements ServletContextListener {
43 private static final String MICRO_SVC="aai-traversal";
44 private static final String ACTIVEMQ_TCP_URL = "tcp://localhost:61446";
45 private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIAppServletContextListener.class.getName());
50 * @param arg0 the ServletContextEvent
52 public void contextDestroyed(ServletContextEvent arg0) {
58 * @param arg0 the ServletContextEvent
60 public void contextInitialized(ServletContextEvent arg0) {
61 System.setProperty("org.onap.aai.serverStarted", "false");
62 System.setProperty("aai.service.name", "traversal");
64 LoggingContext.save();
65 LoggingContext.component("init");
66 LoggingContext.partnerName("NA");
67 LoggingContext.targetEntity(MICRO_SVC);
68 LoggingContext.requestId(UUID.randomUUID().toString());
69 LoggingContext.serviceName(MICRO_SVC);
70 LoggingContext.targetServiceName("contextInitialized");
71 LoggingContext.statusCode(StatusCode.COMPLETE);
72 LOGGER.info("AAI Server initialization started...");
74 LOGGER.info("Loading aaiconfig.properties");
77 LOGGER.info("Loading error.properties");
78 ErrorLogHelper.loadProperties();
80 LOGGER.info("Loading graph database");
82 AAIGraph.getInstance();
83 ModelInjestor.getInstance();
85 LOGGER.info("A&AI Server initialization succcessful.");
86 System.setProperty("activemq.tcp.url", ACTIVEMQ_TCP_URL);
87 System.setProperty("org.onap.aai.serverStarted", "true");
89 Runtime.getRuntime().addShutdownHook(new Thread() {
91 LOGGER.info("AAIGraph shutting down");
92 AAIGraph.getInstance().graphShutdown();
93 LOGGER.info("AAIGraph shutdown");
94 System.out.println("Shutdown hook triggered.");
98 } catch (AAIException e) {
99 ErrorLogHelper.logException(e);
100 throw new RuntimeException("AAIException caught while initializing A&AI server", e);
101 } catch (IOException e) {
102 ErrorLogHelper.logError("AAI_4000", e.getMessage());
103 throw new RuntimeException("IOException caught while initializing A&AI server", e);
104 } catch (Exception e) {
105 LOGGER.error("Unknown failure while initializing A&AI Server" + LogFormatTools.getStackTop(e));
106 throw new RuntimeException("Unknown failure while initializing A&AI server", e);
109 LOGGER.info("Graph-Query MicroService Started");
110 LOGGER.debug("Graph-Query MicroService Started");
111 LoggingContext.restore();