aboutsummaryrefslogtreecommitdiffstats
path: root/aai-resources/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java
diff options
context:
space:
mode:
Diffstat (limited to 'aai-resources/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java')
-rw-r--r--aai-resources/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java56
1 files changed, 48 insertions, 8 deletions
diff --git a/aai-resources/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java b/aai-resources/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java
index 58dc29b..e3e2d97 100644
--- a/aai-resources/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java
+++ b/aai-resources/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java
@@ -22,31 +22,37 @@
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.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 org.onap.aai.migration.MigrationControllerInternal;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
public class AAIAppServletContextListener implements ServletContextListener {
+ private static final String ACTIVEMQ_TCP_URL = "tcp://localhost:61447";
+
private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIAppServletContextListener.class.getName());
+ private BrokerService broker = new BrokerService();
+
/**
* Destroys Context
- *
+ *
* @param arg0 the ServletContextEvent
*/
- public void contextDestroyed(ServletContextEvent arg0) {
- LOGGER.info("AAIGraph shutting down");
- AAIGraph.getInstance().graphShutdown();
- LOGGER.info("AAIGraph shutdown");
+ public void contextDestroyed(ServletContextEvent arg0) {
}
/**
@@ -56,8 +62,18 @@ 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", "resources");
+
+ LoggingContext.save();
+ LoggingContext.component("init");
+ LoggingContext.partnerName("NA");
+ LoggingContext.targetEntity("aai-resources");
+ LoggingContext.requestId(UUID.randomUUID().toString());
+ LoggingContext.serviceName("aai-resources");
+ LoggingContext.targetServiceName("contextInitialized");
+ LoggingContext.statusCode(StatusCode.COMPLETE);
+ LOGGER.info("AAI Server initialization started...");
try {
LOGGER.info("Loading aaiconfig.properties");
AAIConfig.init();
@@ -70,12 +86,36 @@ public class AAIAppServletContextListener implements ServletContextListener {
AAIGraph.getInstance();
ModelInjestor.getInstance();
+ // Jsm internal broker for aai events
+ 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");
if ("true".equals(AAIConfig.get("aai.run.migrations", "false"))) {
MigrationControllerInternal migrations = new MigrationControllerInternal();
migrations.run(new String[]{"--commit"});
}
+
+ 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 A&AI server", e);
@@ -83,12 +123,12 @@ public class AAIAppServletContextListener implements ServletContextListener {
ErrorLogHelper.logError("AAI_4000", e.getMessage());
throw new RuntimeException("IOException caught while initializing A&AI server", e);
} catch (Exception e) {
- LOGGER.error("Unknown failure while initializing A&AI 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("Resources MicroService Started");
- LOGGER.error("Resources MicroService Started");
LOGGER.debug("Resources MicroService Started");
+ LoggingContext.restore();
}
}