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 Server server = new Server();
103 // HTTP configuration
104 HttpConfiguration httpConfiguration = new HttpConfiguration();
105 httpConfiguration.setRequestHeaderSize(2048);
108 ServletContextHandler ctxt;
109 try (ServerConnector httpServerConnector = new ServerConnector(server,
110 new HttpConnectionFactory(httpConfiguration))) {
111 httpServerConnector.setPort(nodeConfigManager.getHttpPort());
112 httpServerConnector.setIdleTimeout(2000);
114 // HTTPS configuration
115 SslContextFactory sslContextFactory = new SslContextFactory();
116 sslContextFactory.setKeyStoreType(nodeConfigManager.getKSType());
117 sslContextFactory.setKeyStorePath(nodeConfigManager.getKSFile());
118 sslContextFactory.setKeyStorePassword(nodeConfigManager.getKSPass());
119 sslContextFactory.setKeyManagerPassword(nodeConfigManager.getKPass());
120 /* Skip SSLv3 Fixes */
121 sslContextFactory.addExcludeProtocols("SSLv3");
122 nodeMainLogger.info("Excluded protocols node-" + Arrays.toString(sslContextFactory.getExcludeProtocols()));
123 /* End of SSLv3 Fixes */
125 HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
126 httpsConfiguration.setRequestHeaderSize(8192);
128 SecureRequestCustomizer secureRequestCustomizer = new SecureRequestCustomizer();
129 secureRequestCustomizer.setStsMaxAge(2000);
130 secureRequestCustomizer.setStsIncludeSubDomains(true);
131 httpsConfiguration.addCustomizer(secureRequestCustomizer);
134 try (ServerConnector httpsServerConnector = new ServerConnector(server,
135 new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
136 new HttpConnectionFactory(httpsConfiguration))) {
137 httpsServerConnector.setPort(nodeConfigManager.getHttpsPort());
138 httpsServerConnector.setIdleTimeout(500000);
139 httpsServerConnector.setAcceptQueueSize(2);
141 server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector});
144 ctxt = new ServletContextHandler(0);
145 ctxt.setContextPath("/");
146 server.setHandler(ctxt);
147 ctxt.addServlet(new ServletHolder(new NodeServlet()), "/*");
148 nodeMainLogger.info("NODE0005 Data Router Node Activating Service");