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