1ada42896d78e684db3ef9adcafc010805cdf995
[dmaap/dbcapi.git] / src / main / java / org / onap / dmaap / dbcapi / server / Main.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dmaap
4  * ================================================================================
5  * Copyright (C) 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
21 package org.onap.dmaap.dbcapi.server;
22 import java.net.InetAddress;
23 import java.util.Properties;
24 import java.util.UUID;
25
26 import org.onap.dmaap.dbcapi.aaf.authentication.ApiPerms;
27 import org.onap.dmaap.dbcapi.aaf.database.DatabaseClass;
28 import org.onap.dmaap.dbcapi.logging.*;
29 import org.onap.dmaap.dbcapi.model.Dmaap;
30 import org.onap.dmaap.dbcapi.util.DmaapConfig;
31 import org.onap.dmaap.dbcapi.util.Singleton;
32
33 import static com.att.eelf.configuration.Configuration.*;
34
35 import org.slf4j.MDC;
36
37 public class Main extends BaseLoggingClass {
38
39         
40     private Properties parameters;
41     private static String provFQDN;
42
43     public static String getProvFQDN() {
44                 return provFQDN;
45         }
46         public void setProvFQDN(String provFQDN) {
47                 Main.provFQDN = provFQDN;
48         }
49         private Main() {
50     }
51     public static void main(String[] args) throws Exception {
52         (new Main()).main();
53     }
54
55     private void main()  {
56     
57         MDC.clear();
58
59         MDC.put(MDC_SERVICE_INSTANCE_ID, "");
60         try {
61             MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
62             MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
63         } catch (Exception e) {
64             e.printStackTrace();
65         }
66         MDC.put(MDC_INSTANCE_UUID, UUID.randomUUID().toString());
67         MDC.put(MDC_ALERT_SEVERITY, "0");
68
69
70         MDC.put(MDC_TARGET_ENTITY, "DCAE");
71
72
73 /*
74         String msg = "This is a sample {} message to demo EELF logging.";
75     
76         appLogger.info( msg, "appLogger.info");
77
78         auditLogger.auditEvent( msg, "auditLogger.auditEvent");
79         errorLogger.error(DmaapbcLogMessageEnum.MESSAGE_SAMPLE_NOARGS);
80         errorLogger.error(DmaapbcLogMessageEnum.MESSAGE_SAMPLE_ONE_ARG, "errorLogger.error");
81         errorLogger.error(DmaapbcLogMessageEnum.MESSAGE_SAMPLE_TWO_ARGS, new Date().toString(), "errorLogger.error" );
82         metricsLogger.metricsEvent( msg, "metricsLogger.metricsEvent" );
83         debugLogger.debug( msg, "debugLogger.debug");
84         
85         //String log = System.getProperty( "log4j.configuration");
86         //if ( log.isEmpty() ) {
87         //      log = "log4j.properties";
88         //}
89         //PropertyConfigurator.configure( log );
90          * 
91          */
92         appLogger.info("Started.");
93         parameters = DmaapConfig.getConfig();
94         setProvFQDN( parameters.getProperty("ProvFQDN", "ProvFQDN.notset.com"));
95                 
96                 
97                 // for fresh installs, we may come up with no dmaap name so need to have a way for Controller to talk to us
98                 Singleton<Dmaap> dmaapholder = DatabaseClass.getDmaap();
99                 String name = dmaapholder.get().getDmaapName();
100                 if ( name == null || name.isEmpty()) {
101                         ApiPerms p = new ApiPerms();
102                         p.setBootMap();
103                 }
104
105         
106         try {
107                 new JettyServer( parameters );
108         } catch (Exception e) {
109             errorLogger.error("Unable to start Jetty " + DmaapConfig.getConfigFileName(), e);
110             System.exit(1);
111         }
112
113     }
114
115 }