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 java.util.Arrays;
27 import org.apache.log4j.Logger;
28 import org.eclipse.jetty.http.HttpVersion;
29 import org.eclipse.jetty.server.Connector;
30 import org.eclipse.jetty.server.HttpConfiguration;
31 import org.eclipse.jetty.server.HttpConnectionFactory;
32 import org.eclipse.jetty.server.SecureRequestCustomizer;
33 import org.eclipse.jetty.server.Server;
34 import org.eclipse.jetty.server.ServerConnector;
35 import org.eclipse.jetty.server.SslConnectionFactory;
36 import org.eclipse.jetty.servlet.ServletContextHandler;
37 import org.eclipse.jetty.servlet.ServletHolder;
38 import org.eclipse.jetty.util.ssl.SslContextFactory;
41 * The main starting point for the Data Router node
43 public class NodeMain {
48 private static Logger nodeMainLogger = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeMain");
50 private static class WaitForConfig implements Runnable {
52 private NodeConfigManager localNodeConfigManager;
54 WaitForConfig(NodeConfigManager ncm) {
55 this.localNodeConfigManager = ncm;
58 public synchronized void run() {
62 synchronized void waitForConfig() {
63 localNodeConfigManager.registerConfigTask(this);
64 while (!localNodeConfigManager.isConfigured()) {
65 nodeMainLogger.info("NODE0003 Waiting for Node Configuration");
68 } catch (Exception exception) {
70 .debug("NodeMain: waitForConfig exception. Exception Message:- " + exception.toString(),
74 localNodeConfigManager.deregisterConfigTask(this);
75 nodeMainLogger.info("NODE0004 Node Configuration Data Received");
79 private static Delivery delivery;
80 private static NodeConfigManager nodeConfigManager;
83 * Reset the retry timer for a subscription
85 static void resetQueue(String subid, String ip) {
86 delivery.resetQueue(nodeConfigManager.getSpoolDir(subid, ip));
90 * Start the data router.
92 * The location of the node configuration file can be set using the org.onap.dmaap.datarouter.node.ConfigFile system
93 * property. By default, it is "etc/node.properties".
95 public static void main(String[] args) throws Exception {
96 nodeMainLogger.info("NODE0001 Data Router Node Starting");
98 nodeConfigManager = NodeConfigManager.getInstance();
99 nodeMainLogger.info("NODE0002 I am " + nodeConfigManager.getMyName());
100 (new WaitForConfig(nodeConfigManager)).waitForConfig();
101 delivery = new Delivery(nodeConfigManager);
102 new LogManager(nodeConfigManager);
103 Server server = new Server();
104 // HTTP configuration
105 HttpConfiguration httpConfiguration = new HttpConfiguration();
106 httpConfiguration.setRequestHeaderSize(2048);
109 ServletContextHandler ctxt;
110 try (ServerConnector httpServerConnector = new ServerConnector(server,
111 new HttpConnectionFactory(httpConfiguration))) {
112 httpServerConnector.setPort(nodeConfigManager.getHttpPort());
113 httpServerConnector.setIdleTimeout(2000);
115 // HTTPS configuration
116 SslContextFactory sslContextFactory = new SslContextFactory();
117 sslContextFactory.setKeyStoreType(nodeConfigManager.getKSType());
118 sslContextFactory.setKeyStorePath(nodeConfigManager.getKSFile());
119 sslContextFactory.setKeyStorePassword(nodeConfigManager.getKSPass());
120 sslContextFactory.setKeyManagerPassword(nodeConfigManager.getKPass());
121 /* Skip SSLv3 Fixes */
122 sslContextFactory.addExcludeProtocols("SSLv3");
123 nodeMainLogger.info("Excluded protocols node-" + Arrays.toString(sslContextFactory.getExcludeProtocols()));
124 /* End of SSLv3 Fixes */
126 HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
127 httpsConfiguration.setRequestHeaderSize(8192);
129 SecureRequestCustomizer secureRequestCustomizer = new SecureRequestCustomizer();
130 secureRequestCustomizer.setStsMaxAge(2000);
131 secureRequestCustomizer.setStsIncludeSubDomains(true);
132 httpsConfiguration.addCustomizer(secureRequestCustomizer);
135 try (ServerConnector httpsServerConnector = new ServerConnector(server,
136 new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
137 new HttpConnectionFactory(httpsConfiguration))) {
138 httpsServerConnector.setPort(nodeConfigManager.getHttpsPort());
139 httpsServerConnector.setIdleTimeout(500000);
140 httpsServerConnector.setAcceptQueueSize(2);
142 server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector});
145 ctxt = new ServletContextHandler(0);
146 ctxt.setContextPath("/");
147 server.setHandler(ctxt);
148 ctxt.addServlet(new ServletHolder(new NodeServlet(delivery)), "/*");
149 nodeMainLogger.info("NODE0005 Data Router Node Activating Service");