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