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 com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import java.util.EnumSet;
29 import javax.servlet.DispatcherType;
30 import org.eclipse.jetty.http.HttpVersion;
31 import org.eclipse.jetty.server.Connector;
32 import org.eclipse.jetty.server.HttpConfiguration;
33 import org.eclipse.jetty.server.HttpConnectionFactory;
34 import org.eclipse.jetty.server.SecureRequestCustomizer;
35 import org.eclipse.jetty.server.Server;
36 import org.eclipse.jetty.server.ServerConnector;
37 import org.eclipse.jetty.server.SslConnectionFactory;
38 import org.eclipse.jetty.servlet.FilterHolder;
39 import org.eclipse.jetty.servlet.ServletContextHandler;
40 import org.eclipse.jetty.servlet.ServletHolder;
41 import org.eclipse.jetty.util.ssl.SslContextFactory;
44 * The main starting point for the Data Router node.
46 public class NodeMain {
48 private static EELFLogger nodeMainLogger = EELFManager.getInstance().getLogger(NodeMain.class);
49 private static Delivery delivery;
50 private static NodeConfigManager nodeConfigManager;
56 * Reset the retry timer for a subscription.
59 static void resetQueue(String subid, String ip) {
60 delivery.resetQueue(nodeConfigManager.getSpoolDir(subid, ip));
64 * Start the data router.
66 * <p>The location of the node configuration file can be set using the org.onap.dmaap.datarouter.node.properties
67 * system property. By default, it is "/opt/app/datartr/etc/node.properties".
69 public static void main(String[] args) throws Exception {
70 nodeMainLogger.debug("NODE0001 Data Router Node Starting");
72 nodeConfigManager = NodeConfigManager.getInstance();
73 nodeMainLogger.debug("NODE0002 I am " + nodeConfigManager.getMyName());
74 (new WaitForConfig(nodeConfigManager)).waitForConfig();
75 delivery = new Delivery(nodeConfigManager);
76 new LogManager(nodeConfigManager);
78 Server server = new Server();
81 HttpConfiguration httpConfiguration = new HttpConfiguration();
82 httpConfiguration.setRequestHeaderSize(2048);
85 try (ServerConnector httpServerConnector = new ServerConnector(server,
86 new HttpConnectionFactory(httpConfiguration))) {
87 httpServerConnector.setPort(nodeConfigManager.getHttpPort());
88 httpServerConnector.setIdleTimeout(2000);
90 // HTTPS configuration
91 SslContextFactory sslContextFactory = new SslContextFactory();
92 sslContextFactory.setKeyStoreType(nodeConfigManager.getKSType());
93 sslContextFactory.setKeyStorePath(nodeConfigManager.getKSFile());
94 sslContextFactory.setKeyStorePassword(nodeConfigManager.getKSPass());
95 sslContextFactory.setKeyManagerPassword(nodeConfigManager.getKPass());
97 //SP-6: Fixes for SDV scan to exclude/remove DES/3DES
98 // ciphers are taken care by upgrading jdk in descriptor.xml
99 sslContextFactory.setExcludeCipherSuites(
100 "SSL_RSA_WITH_DES_CBC_SHA",
101 "SSL_DHE_RSA_WITH_DES_CBC_SHA",
102 "SSL_DHE_DSS_WITH_DES_CBC_SHA",
103 "SSL_RSA_EXPORT_WITH_RC4_40_MD5",
104 "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
105 "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
106 "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"
109 sslContextFactory.addExcludeProtocols("SSLv3");
110 sslContextFactory.setIncludeProtocols(nodeConfigManager.getEnabledprotocols());
111 nodeMainLogger.debug("NODE00004 Unsupported protocols node server:-"
112 + String.join(",", sslContextFactory.getExcludeProtocols()));
113 nodeMainLogger.debug("NODE00004 Supported protocols node server:-"
114 + String.join(",", sslContextFactory.getIncludeProtocols()));
115 nodeMainLogger.debug("NODE00004 Unsupported ciphers node server:-"
116 + String.join(",", sslContextFactory.getExcludeCipherSuites()));
118 HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
119 httpsConfiguration.setRequestHeaderSize(8192);
121 SecureRequestCustomizer secureRequestCustomizer = new SecureRequestCustomizer();
122 secureRequestCustomizer.setStsMaxAge(2000);
123 secureRequestCustomizer.setStsIncludeSubDomains(true);
124 httpsConfiguration.addCustomizer(secureRequestCustomizer);
127 try (ServerConnector httpsServerConnector = new ServerConnector(server,
128 new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
129 new HttpConnectionFactory(httpsConfiguration))) {
131 httpsServerConnector.setPort(nodeConfigManager.getHttpsPort());
132 httpsServerConnector.setIdleTimeout(3600000);
133 httpsServerConnector.setAcceptQueueSize(2);
136 ServletContextHandler servletContextHandler = new ServletContextHandler(0);
137 servletContextHandler.setContextPath("/");
138 servletContextHandler.addServlet(new ServletHolder(new NodeServlet(delivery)), "/*");
140 //CADI Filter activation check
141 if (nodeConfigManager.getCadiEnabled()) {
142 servletContextHandler.addFilter(new FilterHolder(new DRNodeCadiFilter(true,
143 nodeConfigManager.getNodeAafPropsUtils().getPropAccess())), "/*", EnumSet.of(DispatcherType.REQUEST));
146 server.setHandler(servletContextHandler);
147 server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector});
153 nodeMainLogger.debug("NODE00006 Node Server started-" + server.getState());
154 } catch (Exception e) {
155 nodeMainLogger.error("NODE00006 Jetty failed to start. Reporting will we unavailable: "
156 + e.getMessage(), e);
159 nodeMainLogger.debug("NODE00007 Node Server joined - " + server.getState());
162 private static class WaitForConfig implements Runnable {
164 private NodeConfigManager localNodeConfigManager;
166 WaitForConfig(NodeConfigManager ncm) {
167 this.localNodeConfigManager = ncm;
170 public synchronized void run() {
174 synchronized void waitForConfig() {
175 localNodeConfigManager.registerConfigTask(this);
176 while (!localNodeConfigManager.isConfigured()) {
177 nodeMainLogger.debug("NODE0003 Waiting for Node Configuration");
180 } catch (Exception exception) {
181 nodeMainLogger.error("NodeMain: waitForConfig exception. Exception Message:- "
182 + exception.toString(), exception);
185 localNodeConfigManager.deregisterConfigTask(this);
186 nodeMainLogger.debug("NODE0004 Node Configuration Data Received");