[DMAAP-BC] Consolidate bus controller repos
[dmaap/buscontroller.git] / dmaap-bc / 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 static com.att.eelf.configuration.Configuration.MDC_ALERT_SEVERITY;
23 import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID;
24 import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
25 import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
26 import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
27 import static com.att.eelf.configuration.Configuration.MDC_TARGET_ENTITY;
28
29 import java.net.InetAddress;
30 import java.util.Properties;
31 import java.util.UUID;
32 import org.onap.dmaap.dbcapi.authentication.ApiPerms;
33 import org.onap.dmaap.dbcapi.authentication.ApiPolicy;
34 import org.onap.dmaap.dbcapi.database.DatabaseClass;
35 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
36 import org.onap.dmaap.dbcapi.model.Dmaap;
37 import org.onap.dmaap.dbcapi.util.DmaapConfig;
38 import org.onap.dmaap.dbcapi.util.Singleton;
39 import org.slf4j.MDC;
40
41 public class Main extends BaseLoggingClass {
42
43     private static String provFQDN;
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) {
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                 errorLogger.error("Error while getting hostname or address", e);
66         }
67         MDC.put(MDC_INSTANCE_UUID, UUID.randomUUID().toString());
68         MDC.put(MDC_ALERT_SEVERITY, "0");
69         MDC.put(MDC_TARGET_ENTITY, "DCAE");
70
71         appLogger.info("Started.");
72         Properties parameters = DmaapConfig.getConfig();
73         setProvFQDN( parameters.getProperty("ProvFQDN", "ProvFQDN.notset.com"));
74
75                 // for fresh installs, we may come up with no dmaap name so need to have a way for Controller to talk to us
76                 Singleton<Dmaap> dmaapholder = DatabaseClass.getDmaap();
77                 String name = dmaapholder.get().getDmaapName();
78                 ApiPolicy apiPolicy = new ApiPolicy();
79                 if ( apiPolicy.isPermissionClassSet() && (name == null || name.isEmpty())) {
80                         ApiPerms p = new ApiPerms();
81                         p.setBootMap();
82                 }
83
84         try {
85                 new JettyServer(parameters);
86         } catch (Exception e) {
87             errorLogger.error("Unable to start Jetty " + DmaapConfig.getConfigFileName(), e);
88             System.exit(1);
89         }
90
91     }
92
93 }