1 /*******************************************************************************
2 * ============LICENSE_START==================================================
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
11 * * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 ******************************************************************************/
24 package org.onap.dmaap.datarouter.node;
26 import static java.lang.System.exit;
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;
36 * The main starting point for the Data Router node.
38 public class NodeRunner {
40 private static final EELFLogger nodeMainLogger = EELFManager.getInstance().getLogger(NodeRunner.class);
42 private NodeRunner() {
46 * Start the data router.
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".
51 public static void main(String[] args) {
52 nodeMainLogger.debug("NODE0001 Data Router Node Starting");
54 NodeConfigManager nodeConfigManager = NodeConfigManager.getInstance();
55 nodeMainLogger.debug("NODE0002 I am {}", nodeConfigManager.getMyName());
56 (new WaitForConfig(nodeConfigManager)).waitForConfig();
57 new LogManager(nodeConfigManager);
59 Server server = NodeServer.getServerInstance(nodeConfigManager);
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());
67 nodeMainLogger.debug("NODE0007 Node Server joined");
70 private static class WaitForConfig implements Runnable {
72 private final NodeConfigManager localNodeConfigManager;
74 WaitForConfig(NodeConfigManager ncm) {
75 this.localNodeConfigManager = ncm;
78 public synchronized void run() {
82 synchronized void waitForConfig() {
83 localNodeConfigManager.registerConfigTask(this);
84 while (!localNodeConfigManager.isConfigured()) {
85 nodeMainLogger.debug("NODE0003 Waiting for Node Configuration");
88 } catch (Exception exception) {
89 nodeMainLogger.error("NodeMain: waitForConfig exception. Exception Message:- "
90 + exception, exception);
93 localNodeConfigManager.deregisterConfigTask(this);
94 nodeMainLogger.debug("NODE0004 Node Configuration Data Received");