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 org.apache.log4j.Logger;
27 import org.eclipse.jetty.http.HttpVersion;
28 import org.eclipse.jetty.server.*;
29 import org.eclipse.jetty.servlet.FilterHolder;
30 import org.eclipse.jetty.servlet.ServletContextHandler;
31 import org.eclipse.jetty.servlet.ServletHolder;
32 import org.eclipse.jetty.util.ssl.SslContextFactory;
33 import org.onap.aaf.cadi.PropAccess;
35 import javax.servlet.DispatcherType;
36 import java.io.IOException;
37 import java.io.InputStream;
38 import java.util.EnumSet;
39 import java.util.Properties;
42 * The main starting point for the Data Router node
44 public class NodeMain {
49 private static Logger nodeMainLogger = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeMain");
52 InputStream getCadiProps() {
53 InputStream in = null;
55 in = getClass().getClassLoader().getResourceAsStream("drNodeCadi.properties");
56 } catch (Exception e) {
57 nodeMainLogger.error("Exception in Inner.getCadiProps() method " + e.getMessage());
63 private static class WaitForConfig implements Runnable {
65 private NodeConfigManager localNodeConfigManager;
67 WaitForConfig(NodeConfigManager ncm) {
68 this.localNodeConfigManager = ncm;
71 public synchronized void run() {
75 synchronized void waitForConfig() {
76 localNodeConfigManager.registerConfigTask(this);
77 while (!localNodeConfigManager.isConfigured()) {
78 nodeMainLogger.info("NODE0003 Waiting for Node Configuration");
81 } catch (Exception exception) {
83 .debug("NodeMain: waitForConfig exception. Exception Message:- " + exception.toString(),
87 localNodeConfigManager.deregisterConfigTask(this);
88 nodeMainLogger.info("NODE0004 Node Configuration Data Received");
92 private static Delivery delivery;
93 private static NodeConfigManager nodeConfigManager;
96 * Reset the retry timer for a subscription
98 static void resetQueue(String subid, String ip) {
99 delivery.resetQueue(nodeConfigManager.getSpoolDir(subid, ip));
103 * Start the data router.
105 * The location of the node configuration file can be set using the org.onap.dmaap.datarouter.node.properties system
106 * property. By default, it is "/opt/app/datartr/etc/node.properties".
108 public static void main(String[] args) throws Exception {
109 nodeMainLogger.info("NODE0001 Data Router Node Starting");
110 IsFrom.setDNSCache();
111 nodeConfigManager = NodeConfigManager.getInstance();
112 nodeMainLogger.info("NODE0002 I am " + nodeConfigManager.getMyName());
113 (new WaitForConfig(nodeConfigManager)).waitForConfig();
114 delivery = new Delivery(nodeConfigManager);
115 new LogManager(nodeConfigManager);
117 Server server = new Server();
119 // HTTP configuration
120 HttpConfiguration httpConfiguration = new HttpConfiguration();
121 httpConfiguration.setRequestHeaderSize(2048);
124 try (ServerConnector httpServerConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration))) {
125 httpServerConnector.setPort(nodeConfigManager.getHttpPort());
126 httpServerConnector.setIdleTimeout(2000);
128 // HTTPS configuration
129 SslContextFactory sslContextFactory = new SslContextFactory();
130 sslContextFactory.setKeyStoreType(nodeConfigManager.getKSType());
131 sslContextFactory.setKeyStorePath(nodeConfigManager.getKSFile());
132 sslContextFactory.setKeyStorePassword(nodeConfigManager.getKSPass());
133 sslContextFactory.setKeyManagerPassword(nodeConfigManager.getKPass());
135 //SP-6 : Fixes for SDV scan to exclude/remove DES/3DES ciphers are taken care by upgrading jdk in descriptor.xml
136 sslContextFactory.setExcludeCipherSuites(
137 "SSL_RSA_WITH_DES_CBC_SHA",
138 "SSL_DHE_RSA_WITH_DES_CBC_SHA",
139 "SSL_DHE_DSS_WITH_DES_CBC_SHA",
140 "SSL_RSA_EXPORT_WITH_RC4_40_MD5",
141 "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
142 "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
143 "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"
146 sslContextFactory.addExcludeProtocols("SSLv3");
147 sslContextFactory.setIncludeProtocols(nodeConfigManager.getEnabledprotocols());
148 nodeMainLogger.info("NODE00004 Unsupported protocols node server:-" + String.join(",", sslContextFactory.getExcludeProtocols()));
149 nodeMainLogger.info("NODE00004 Supported protocols node server:-" + String.join(",", sslContextFactory.getIncludeProtocols()));
150 nodeMainLogger.info("NODE00004 Unsupported ciphers node server:-" + String.join(",", sslContextFactory.getExcludeCipherSuites()));
152 HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
153 httpsConfiguration.setRequestHeaderSize(8192);
155 SecureRequestCustomizer secureRequestCustomizer = new SecureRequestCustomizer();
156 secureRequestCustomizer.setStsMaxAge(2000);
157 secureRequestCustomizer.setStsIncludeSubDomains(true);
158 httpsConfiguration.addCustomizer(secureRequestCustomizer);
161 try (ServerConnector httpsServerConnector = new ServerConnector(server,
162 new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
163 new HttpConnectionFactory(httpsConfiguration))) {
165 httpsServerConnector.setPort(nodeConfigManager.getHttpsPort());
166 httpsServerConnector.setIdleTimeout(3600000);
167 httpsServerConnector.setAcceptQueueSize(2);
170 ServletContextHandler servletContextHandler = new ServletContextHandler(0);
171 servletContextHandler.setContextPath("/");
172 servletContextHandler.addServlet(new ServletHolder(new NodeServlet(delivery)), "/*");
174 //CADI Filter activation check
175 if (nodeConfigManager.getCadiEnabeld()) {
176 Properties cadiProperties = new Properties();
178 Inner obj = new NodeMain().new Inner();
179 InputStream in = obj.getCadiProps();
180 cadiProperties.load(in);
181 } catch (IOException e1) {
182 nodeMainLogger.error("NODE00005 Exception in NodeMain.Main() loading CADI properties " + e1.getMessage());
184 cadiProperties.setProperty("aaf_locate_url", nodeConfigManager.getAafURL());
185 nodeMainLogger.info("NODE00005 aaf_url set to - " + cadiProperties.getProperty("aaf_url"));
187 PropAccess access = new PropAccess(cadiProperties);
188 servletContextHandler.addFilter(new FilterHolder(new DRNodeCadiFilter(true, access)), "/*", EnumSet.of(DispatcherType.REQUEST));
191 server.setHandler(servletContextHandler);
192 server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector});
198 nodeMainLogger.info("NODE00006 Node Server started-" + server.getState());
199 } catch (Exception e) {
200 nodeMainLogger.info("NODE00006 Jetty failed to start. Reporting will we unavailable", e);
203 nodeMainLogger.info("NODE00007 Node Server joined - " + server.getState());