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.apache.activemq.broker.BrokerService;
32 import org.onap.aai.dbmap.AAIGraph;
33 import org.onap.aai.exceptions.AAIException;
34 import org.onap.aai.introspection.ModelInjestor;
35 import org.onap.aai.logging.ErrorLogHelper;
36 import org.onap.aai.logging.LogFormatTools;
37 import org.onap.aai.logging.LoggingContext;
38 import org.onap.aai.logging.LoggingContext.StatusCode;
40 import com.att.eelf.configuration.EELFLogger;
41 import com.att.eelf.configuration.EELFManager;
43 public class AAIAppServletContextListener implements ServletContextListener {
45 private static final String MICRO_SVC="aai-traversal";
46 private static final String ACTIVEMQ_TCP_URL = "tcp://localhost:61446";
47 private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIAppServletContextListener.class.getName());
48 private BrokerService broker = new BrokerService();
53 * @param arg0 the ServletContextEvent
55 public void contextDestroyed(ServletContextEvent arg0) {
61 * @param arg0 the ServletContextEvent
63 public void contextInitialized(ServletContextEvent arg0) {
64 System.setProperty("org.onap.aai.serverStarted", "false");
65 System.setProperty("aai.service.name", "traversal");
67 LoggingContext.save();
68 LoggingContext.component("init");
69 LoggingContext.partnerName("NA");
70 LoggingContext.targetEntity(MICRO_SVC);
71 LoggingContext.requestId(UUID.randomUUID().toString());
72 LoggingContext.serviceName(MICRO_SVC);
73 LoggingContext.targetServiceName("contextInitialized");
74 LoggingContext.statusCode(StatusCode.COMPLETE);
75 LOGGER.info("AAI Server initialization started...");
77 LOGGER.info("Loading aaiconfig.properties");
80 LOGGER.info("Loading error.properties");
81 ErrorLogHelper.loadProperties();
83 LOGGER.info("Loading graph database");
85 AAIGraph.getInstance();
86 ModelInjestor.getInstance();
88 // Jsm internal broker for aai events
89 broker = new BrokerService();
90 broker.addConnector(ACTIVEMQ_TCP_URL);
91 broker.setPersistent(false);
92 broker.setUseJmx(false);
93 broker.setSchedulerSupport(false);
96 LOGGER.info("A&AI Server initialization succcessful.");
97 System.setProperty("activemq.tcp.url", ACTIVEMQ_TCP_URL);
98 System.setProperty("org.onap.aai.serverStarted", "true");
100 Runtime.getRuntime().addShutdownHook(new Thread() {
102 LOGGER.info("AAIGraph shutting down");
103 AAIGraph.getInstance().graphShutdown();
104 LOGGER.info("AAIGraph shutdown");
107 } catch (Exception e) {
108 LOGGER.error("Issue closing broker " + LogFormatTools.getStackTop(e));
110 System.out.println("Shutdown hook triggered.");
114 } catch (AAIException e) {
115 ErrorLogHelper.logException(e);
116 throw new RuntimeException("AAIException caught while initializing A&AI server", e);
117 } catch (IOException e) {
118 ErrorLogHelper.logError("AAI_4000", e.getMessage());
119 throw new RuntimeException("IOException caught while initializing A&AI server", e);
120 } catch (Exception e) {
121 LOGGER.error("Unknown failure while initializing A&AI Server" + LogFormatTools.getStackTop(e));
122 throw new RuntimeException("Unknown failure while initializing A&AI server", e);
125 LOGGER.info("Graph-Query MicroService Started");
126 LOGGER.debug("Graph-Query MicroService Started");
127 LoggingContext.restore();