[DMAAP-DR] Remove AAF/TLS phase 1
[dmaap/datarouter.git] / datarouter-node / src / main / java / org / onap / dmaap / datarouter / node / NodeRunner.java
1 /*******************************************************************************
2  * ============LICENSE_START==================================================
3  * * org.onap.dmaap
4  * * ===========================================================================
5  * * Copyright © 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  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  * *
22  ******************************************************************************/
23
24 package org.onap.dmaap.datarouter.node;
25
26 import static java.lang.System.exit;
27
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import org.eclipse.jetty.server.Server;
31
32 /**
33  * The main starting point for the Data Router node.
34  */
35 public class NodeRunner {
36
37     private static final EELFLogger nodeMainLogger = EELFManager.getInstance().getLogger(NodeRunner.class);
38
39     private NodeRunner() {
40     }
41
42     /**
43      * Start the data router.
44      *
45      * <p>The location of the node configuration file can be set using the org.onap.dmaap.datarouter.node.properties
46      * system property. By default, it is "/opt/app/datartr/etc/node.properties".
47      */
48     public static void main(String[] args) {
49         nodeMainLogger.debug("NODE0001 Data Router Node Starting");
50         IsFrom.setDNSCache();
51         NodeConfigManager nodeConfigManager = NodeConfigManager.getInstance();
52         nodeMainLogger.debug("NODE0002 I am " + nodeConfigManager.getMyName());
53         (new WaitForConfig(nodeConfigManager)).waitForConfig();
54         new LogManager(nodeConfigManager);
55         try {
56             Server server = NodeServer.getServerInstance(nodeConfigManager);
57             server.start();
58             server.join();
59             nodeMainLogger.debug("NODE0006 Node Server started-" + server.getState());
60         } catch (Exception e) {
61             nodeMainLogger.error("NODE0006 Jetty failed to start. Reporting will we be unavailable: "
62                                          + e.getMessage(), e);
63             exit(1);
64         }
65         nodeMainLogger.debug("NODE0007 Node Server joined");
66     }
67
68     private static class WaitForConfig implements Runnable {
69
70         private final NodeConfigManager localNodeConfigManager;
71
72         WaitForConfig(NodeConfigManager ncm) {
73             this.localNodeConfigManager = ncm;
74         }
75
76         public synchronized void run() {
77             notifyAll();
78         }
79
80         synchronized void waitForConfig() {
81             localNodeConfigManager.registerConfigTask(this);
82             while (!localNodeConfigManager.isConfigured()) {
83                 nodeMainLogger.debug("NODE0003 Waiting for Node Configuration");
84                 try {
85                     wait();
86                 } catch (Exception exception) {
87                     nodeMainLogger.error("NodeMain: waitForConfig exception. Exception Message:- "
88                         + exception, exception);
89                 }
90             }
91             localNodeConfigManager.deregisterConfigTask(this);
92             nodeMainLogger.debug("NODE0004 Node Configuration Data Received");
93         }
94     }
95 }