Merge "Added docs directory and index file for traversal"
[aai/traversal.git] / aai-traversal / src / main / java / org / onap / aai / util / AAIAppServletContextListener.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  *
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.util;
23
24 import java.io.IOException;
25
26 import javax.servlet.ServletContextEvent;
27 import javax.servlet.ServletContextListener;
28
29 //import org.apache.activemq.broker.BrokerService;
30
31 import org.onap.aai.dbmap.AAIGraph;
32 import org.onap.aai.exceptions.AAIException;
33 import org.onap.aai.introspection.ModelInjestor;
34 import org.onap.aai.logging.ErrorLogHelper;
35 import com.att.eelf.configuration.EELFLogger;
36 import com.att.eelf.configuration.EELFManager;
37
38 public class AAIAppServletContextListener implements ServletContextListener {
39
40         private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIAppServletContextListener.class.getName());     
41         
42         //private BrokerService broker = new BrokerService();
43
44         /**
45          * Destroys Context
46          * 
47          * @param arg0 the ServletContextEvent
48          */
49         public void contextDestroyed(ServletContextEvent arg0) {                
50                 LOGGER.info("AAIGraph shutting down");
51                 AAIGraph.getInstance().graphShutdown();
52                 LOGGER.info("AAIGraph shutdown");
53
54                 //try {
55                         ////broker.stop();
56                 //} catch (Exception e) {
57                         //// TODO Auto-generated catch block
58                         //e.printStackTrace();
59                 //}
60         }
61
62         /**
63          * Initializes Context
64          * 
65          * @param arg0 the ServletContextEvent
66          */
67         public void contextInitialized(ServletContextEvent arg0) {
68                 System.setProperty("org.onap.aai.serverStarted", "false");
69                 LOGGER.info("***AAI Server initialization started...");
70
71                 try {
72                         LOGGER.info("Loading aaiconfig.properties");
73                         AAIConfig.init();
74
75                         LOGGER.info("Loading error.properties");
76                         ErrorLogHelper.loadProperties();
77
78                         LOGGER.info("Loading graph database");
79
80                         AAIGraph.getInstance();
81                         ModelInjestor.getInstance();
82
83                         // Jsm internal broker for aai events
84                         //broker = new BrokerService();
85                         //broker.addConnector("tcp://localhost:61446");
86                         //broker.setPersistent(false);
87                         //broker.setUseJmx(false);
88                         //broker.setSchedulerSupport(false);
89                         //broker.start();
90
91                         LOGGER.info("AAI Server initialization succcessful.");
92                         System.setProperty("org.onap.aai.serverStarted", "true");
93
94                 } catch (AAIException e) {
95                         ErrorLogHelper.logException(e);
96                         throw new RuntimeException("AAIException caught while initializing AAI server", e);
97                 } catch (IOException e) {
98                         ErrorLogHelper.logError("AAI_4000", e.getMessage());
99                         throw new RuntimeException("IOException caught while initializing AAI server", e);
100                 } catch (Exception e) {
101                         LOGGER.error("Unknown failure while initializing AAI Server", e);
102                         throw new RuntimeException("Unknown failure while initializing AAI server", e);
103                 }
104
105                 LOGGER.info("Graph-Query MicroService Started");
106                 LOGGER.error("Graph-Query MicroService Started");
107                 LOGGER.debug("Graph-Query MicroService Started");
108
109         }
110 }