aboutsummaryrefslogtreecommitdiffstats
path: root/aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java
diff options
context:
space:
mode:
Diffstat (limited to 'aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java')
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java84
1 files changed, 52 insertions, 32 deletions
diff --git a/aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java b/aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java
index 49a77d8..86fefdd 100644
--- a/aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java
+++ b/aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,27 +19,33 @@
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
+
package org.onap.aai.util;
import java.io.IOException;
-
+import java.util.UUID;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
-//import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.BrokerService;
import org.onap.aai.dbmap.AAIGraph;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.ModelInjestor;
import org.onap.aai.logging.ErrorLogHelper;
+import org.onap.aai.logging.LogFormatTools;
+import org.onap.aai.logging.LoggingContext;
+import org.onap.aai.logging.LoggingContext.StatusCode;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
public class AAIAppServletContextListener implements ServletContextListener {
+ private static final String MICRO_SVC="aai-traversal";
+ private static final String ACTIVEMQ_TCP_URL = "tcp://localhost:61446";
private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIAppServletContextListener.class.getName());
-
- //private BrokerService broker = new BrokerService();
+ private BrokerService broker = new BrokerService();
/**
* Destroys Context
@@ -47,16 +53,6 @@ public class AAIAppServletContextListener implements ServletContextListener {
* @param arg0 the ServletContextEvent
*/
public void contextDestroyed(ServletContextEvent arg0) {
- LOGGER.info("AAIGraph shutting down");
- AAIGraph.getInstance().graphShutdown();
- LOGGER.info("AAIGraph shutdown");
-
- //try {
- ////broker.stop();
- //} catch (Exception e) {
- //// TODO Auto-generated catch block
- //e.printStackTrace();
- //}
}
/**
@@ -66,8 +62,17 @@ public class AAIAppServletContextListener implements ServletContextListener {
*/
public void contextInitialized(ServletContextEvent arg0) {
System.setProperty("org.onap.aai.serverStarted", "false");
- LOGGER.info("***AAI Server initialization started...");
-
+ System.setProperty("aai.service.name", "traversal");
+
+ LoggingContext.save();
+ LoggingContext.component("init");
+ LoggingContext.partnerName("NA");
+ LoggingContext.targetEntity(MICRO_SVC);
+ LoggingContext.requestId(UUID.randomUUID().toString());
+ LoggingContext.serviceName(MICRO_SVC);
+ LoggingContext.targetServiceName("contextInitialized");
+ LoggingContext.statusCode(StatusCode.COMPLETE);
+ LOGGER.info("AAI Server initialization started...");
try {
LOGGER.info("Loading aaiconfig.properties");
AAIConfig.init();
@@ -81,30 +86,45 @@ public class AAIAppServletContextListener implements ServletContextListener {
ModelInjestor.getInstance();
// Jsm internal broker for aai events
- //broker = new BrokerService();
- //broker.addConnector("tcp://localhost:61446");
- //broker.setPersistent(false);
- //broker.setUseJmx(false);
- //broker.setSchedulerSupport(false);
- //broker.start();
-
- LOGGER.info("AAI Server initialization succcessful.");
+ broker = new BrokerService();
+ broker.addConnector(ACTIVEMQ_TCP_URL);
+ broker.setPersistent(false);
+ broker.setUseJmx(false);
+ broker.setSchedulerSupport(false);
+ broker.start();
+
+ LOGGER.info("A&AI Server initialization succcessful.");
+ System.setProperty("activemq.tcp.url", ACTIVEMQ_TCP_URL);
System.setProperty("org.onap.aai.serverStarted", "true");
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ LOGGER.info("AAIGraph shutting down");
+ AAIGraph.getInstance().graphShutdown();
+ LOGGER.info("AAIGraph shutdown");
+ try {
+ broker.stop();
+ } catch (Exception e) {
+ LOGGER.error("Issue closing broker " + LogFormatTools.getStackTop(e));
+ }
+ System.out.println("Shutdown hook triggered.");
+ }
+ });
+
} catch (AAIException e) {
ErrorLogHelper.logException(e);
- throw new RuntimeException("AAIException caught while initializing AAI server", e);
+ throw new RuntimeException("AAIException caught while initializing A&AI server", e);
} catch (IOException e) {
ErrorLogHelper.logError("AAI_4000", e.getMessage());
- throw new RuntimeException("IOException caught while initializing AAI server", e);
+ throw new RuntimeException("IOException caught while initializing A&AI server", e);
} catch (Exception e) {
- LOGGER.error("Unknown failure while initializing AAI Server", e);
- throw new RuntimeException("Unknown failure while initializing AAI server", e);
+ LOGGER.error("Unknown failure while initializing A&AI Server" + LogFormatTools.getStackTop(e));
+ throw new RuntimeException("Unknown failure while initializing A&AI server", e);
}
LOGGER.info("Graph-Query MicroService Started");
- LOGGER.error("Graph-Query MicroService Started");
LOGGER.debug("Graph-Query MicroService Started");
+ LoggingContext.restore();
}
}