update link to upper-constraints.txt
[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 import org.onap.dmaap.datarouter.node.log.LogManager;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 /**
36  * The main starting point for the Data Router node.
37  */
38 public class NodeRunner {
39
40     private static final EELFLogger nodeMainLogger = EELFManager.getInstance().getLogger(NodeRunner.class);
41
42     private NodeRunner() {
43     }
44
45     /**
46      * Start the data router.
47      *
48      * <p>The location of the node configuration file can be set using the org.onap.dmaap.datarouter.node.properties
49      * system property. By default, it is "/opt/app/datartr/etc/node.properties".
50      */
51     public static void main(String[] args) {
52         nodeMainLogger.debug("NODE0001 Data Router Node Starting");
53         IsFrom.setDNSCache();
54         NodeConfigManager nodeConfigManager = NodeConfigManager.getInstance();
55         nodeMainLogger.debug("NODE0002 I am {}", nodeConfigManager.getMyName());
56         (new WaitForConfig(nodeConfigManager)).waitForConfig();
57         new LogManager(nodeConfigManager);
58         try {
59             Server server = NodeServer.getServerInstance(nodeConfigManager);
60             server.start();
61             server.join();
62             nodeMainLogger.debug("NODE0006 Node Server started-" + server.getState());
63         } catch (Exception e) {
64             nodeMainLogger.error("NODE0006 Jetty failed to start. Reporting will we be unavailable: {}", e.getMessage());
65             exit(1);
66         }
67         nodeMainLogger.debug("NODE0007 Node Server joined");
68     }
69
70     private static class WaitForConfig implements Runnable {
71
72         private final NodeConfigManager localNodeConfigManager;
73
74         WaitForConfig(NodeConfigManager ncm) {
75             this.localNodeConfigManager = ncm;
76         }
77
78         public synchronized void run() {
79             notifyAll();
80         }
81
82         synchronized void waitForConfig() {
83             localNodeConfigManager.registerConfigTask(this);
84             while (!localNodeConfigManager.isConfigured()) {
85                 nodeMainLogger.debug("NODE0003 Waiting for Node Configuration");
86                 try {
87                     wait();
88                 } catch (Exception exception) {
89                     nodeMainLogger.error("NodeMain: waitForConfig exception. Exception Message:- "
90                         + exception, exception);
91                 }
92             }
93             localNodeConfigManager.deregisterConfigTask(this);
94             nodeMainLogger.debug("NODE0004 Node Configuration Data Received");
95         }
96     }
97 }