Update the license for 2017-2018 license
[aai/traversal.git] / aai-traversal / src / main / java / org / onap / aai / TraversalApp.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 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 package org.onap.aai;
21
22 import com.att.eelf.configuration.EELFLogger;
23 import com.att.eelf.configuration.EELFManager;
24 import org.onap.aai.config.PropertyPasswordConfiguration;
25 import org.onap.aai.dbmap.AAIGraph;
26 import org.onap.aai.exceptions.AAIException;
27 import org.onap.aai.introspection.ModelInjestor;
28 import org.onap.aai.logging.LoggingContext;
29 import org.onap.aai.util.AAIConfig;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.boot.SpringApplication;
32 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
33 import org.springframework.boot.autoconfigure.SpringBootApplication;
34 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
35 import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
36 import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
37 import org.springframework.context.annotation.ComponentScan;
38 import org.springframework.core.env.Environment;
39
40 import javax.annotation.PostConstruct;
41 import javax.annotation.PreDestroy;
42 import java.util.UUID;
43
44 @SpringBootApplication
45 // Component Scan provides a way to look for spring beans
46 // It only searches beans in the following packages
47 // Any method annotated with @Bean annotation or any class
48 // with @Component, @Configuration, @Service will be picked up
49 @ComponentScan(basePackages = {
50                 "org.onap.aai.config",
51                 "org.onap.aai.web",
52                 "org.onap.aai.tasks",
53                 "org.onap.aai.rest",
54                 "com.att.ajsc.common"
55 })
56 @EnableAutoConfiguration(exclude = {
57                 DataSourceAutoConfiguration.class,
58                 DataSourceTransactionManagerAutoConfiguration.class,
59                 HibernateJpaAutoConfiguration.class
60 })
61 public class TraversalApp {
62
63         private static final EELFLogger logger = EELFManager.getInstance().getLogger(TraversalApp.class.getName());
64
65         private static final String APP_NAME = "aai-traversal";
66
67         @Autowired
68         private Environment env;
69
70         @PostConstruct
71         private void init() throws AAIException {
72                 System.setProperty("org.onap.aai.serverStarted", "false");
73                 setDefaultProps();
74
75                 LoggingContext.save();
76                 LoggingContext.component("init");
77                 LoggingContext.partnerName("NA");
78                 LoggingContext.targetEntity(APP_NAME);
79                 LoggingContext.requestId(UUID.randomUUID().toString());
80                 LoggingContext.serviceName(APP_NAME);
81                 LoggingContext.targetServiceName("contextInitialized");
82
83                 logger.info("AAI Server initialization started...");
84
85                 // Setting this property to allow for encoded slash (/) in the path parameter
86                 // This is only needed for tomcat keeping this as temporary
87                 System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
88
89             logger.info("Starting AAIGraph connections and the ModelInjestor");
90
91             if(env.acceptsProfiles(Profiles.TWO_WAY_SSL) && env.acceptsProfiles(Profiles.ONE_WAY_SSL)){
92                 logger.warn("You have seriously misconfigured your application");
93             }
94
95                 AAIConfig.init();
96                 ModelInjestor.getInstance();
97                 AAIGraph.getInstance();
98         }
99
100         @PreDestroy
101         public void cleanup(){
102                 logger.info("Shutting down both realtime and cached connections");
103                 AAIGraph.getInstance().graphShutdown();
104         }
105
106         public static void main(String[] args) {
107
108             setDefaultProps();
109                 SpringApplication app = new SpringApplication(TraversalApp.class);
110                 app.setRegisterShutdownHook(true);
111                 app.addInitializers(new PropertyPasswordConfiguration());
112                 Environment env = app.run(args).getEnvironment();
113
114                 logger.info(
115                                 "Application '{}' is running on {}!" ,
116                                 env.getProperty("spring.application.name"),
117                                 env.getProperty("server.port")
118                 );
119
120                 logger.info("Traversal MicroService Started");
121                 logger.error("Traversal MicroService Started");
122                 logger.debug("Traversal MicroService Started");
123                 System.out.println("Traversal Microservice Started");
124         }
125
126         public static void setDefaultProps(){
127
128                 if (System.getProperty("file.separator") == null) {
129                         System.setProperty("file.separator", "/");
130                 }
131
132                 String currentDirectory = System.getProperty("user.dir");
133
134                 if (System.getProperty("AJSC_HOME") == null) {
135                         System.setProperty("AJSC_HOME", ".");
136                 }
137
138                 if(currentDirectory.contains(APP_NAME)){
139                         if (System.getProperty("BUNDLECONFIG_DIR") == null) {
140                                 System.setProperty("BUNDLECONFIG_DIR", "src/main/resources");
141                         }
142                 } else {
143                         if (System.getProperty("BUNDLECONFIG_DIR") == null) {
144                                 System.setProperty("BUNDLECONFIG_DIR", "aai-traversal/src/main/resources");
145                         }
146                 }
147
148         }
149 }