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.io.IOException;
29 import java.io.InputStream;
30 import java.util.EnumSet;
31 import java.util.Properties;
32 import javax.servlet.DispatcherType;
33 import javax.servlet.ServletException;
34 import org.eclipse.jetty.http.HttpVersion;
35 import org.eclipse.jetty.server.Connector;
36 import org.eclipse.jetty.server.HttpConfiguration;
37 import org.eclipse.jetty.server.HttpConnectionFactory;
38 import org.eclipse.jetty.server.SecureRequestCustomizer;
39 import org.eclipse.jetty.server.Server;
40 import org.eclipse.jetty.server.ServerConnector;
41 import org.eclipse.jetty.server.SslConnectionFactory;
42 import org.eclipse.jetty.servlet.FilterHolder;
43 import org.eclipse.jetty.servlet.ServletContextHandler;
44 import org.eclipse.jetty.servlet.ServletHolder;
45 import org.eclipse.jetty.util.ssl.SslContextFactory;
46 import org.onap.aaf.cadi.PropAccess;
49 * The main starting point for the Data Router node.
51 public class NodeMain {
53 private static EELFLogger nodeMainLogger = EELFManager.getInstance().getLogger(NodeMain.class);
54 private static Delivery delivery;
55 private static NodeConfigManager nodeConfigManager;
61 * Reset the retry timer for a subscription.
64 static void resetQueue(String subid, String ip) {
65 delivery.resetQueue(nodeConfigManager.getSpoolDir(subid, ip));
69 * Start the data router.
71 * <p>The location of the node configuration file can be set using the org.onap.dmaap.datarouter.node.properties
72 * system property. By default, it is "/opt/app/datartr/etc/node.properties".
74 public static void main(String[] args) throws Exception {
75 nodeMainLogger.debug("NODE0001 Data Router Node Starting");
77 nodeConfigManager = NodeConfigManager.getInstance();
78 nodeMainLogger.debug("NODE0002 I am " + nodeConfigManager.getMyName());
79 (new WaitForConfig(nodeConfigManager)).waitForConfig();
80 delivery = new Delivery(nodeConfigManager);
81 new LogManager(nodeConfigManager);
83 Server server = new Server();
86 HttpConfiguration httpConfiguration = new HttpConfiguration();
87 httpConfiguration.setRequestHeaderSize(2048);
90 try (ServerConnector httpServerConnector = new ServerConnector(server,
91 new HttpConnectionFactory(httpConfiguration))) {
92 httpServerConnector.setPort(nodeConfigManager.getHttpPort());
93 httpServerConnector.setIdleTimeout(2000);
95 // HTTPS configuration
96 SslContextFactory sslContextFactory = new SslContextFactory();
97 sslContextFactory.setKeyStoreType(nodeConfigManager.getKSType());
98 sslContextFactory.setKeyStorePath(nodeConfigManager.getKSFile());
99 sslContextFactory.setKeyStorePassword(nodeConfigManager.getKSPass());
100 sslContextFactory.setKeyManagerPassword(nodeConfigManager.getKPass());
102 //SP-6: Fixes for SDV scan to exclude/remove DES/3DES
103 // ciphers are taken care by upgrading jdk in descriptor.xml
104 sslContextFactory.setExcludeCipherSuites(
105 "SSL_RSA_WITH_DES_CBC_SHA",
106 "SSL_DHE_RSA_WITH_DES_CBC_SHA",
107 "SSL_DHE_DSS_WITH_DES_CBC_SHA",
108 "SSL_RSA_EXPORT_WITH_RC4_40_MD5",
109 "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
110 "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
111 "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"
114 sslContextFactory.addExcludeProtocols("SSLv3");
115 sslContextFactory.setIncludeProtocols(nodeConfigManager.getEnabledprotocols());
116 nodeMainLogger.debug("NODE00004 Unsupported protocols node server:-"
117 + String.join(",", sslContextFactory.getExcludeProtocols()));
118 nodeMainLogger.debug("NODE00004 Supported protocols node server:-"
119 + String.join(",", sslContextFactory.getIncludeProtocols()));
120 nodeMainLogger.debug("NODE00004 Unsupported ciphers node server:-"
121 + String.join(",", sslContextFactory.getExcludeCipherSuites()));
123 HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
124 httpsConfiguration.setRequestHeaderSize(8192);
126 SecureRequestCustomizer secureRequestCustomizer = new SecureRequestCustomizer();
127 secureRequestCustomizer.setStsMaxAge(2000);
128 secureRequestCustomizer.setStsIncludeSubDomains(true);
129 httpsConfiguration.addCustomizer(secureRequestCustomizer);
132 try (ServerConnector httpsServerConnector = new ServerConnector(server,
133 new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
134 new HttpConnectionFactory(httpsConfiguration))) {
136 httpsServerConnector.setPort(nodeConfigManager.getHttpsPort());
137 httpsServerConnector.setIdleTimeout(3600000);
138 httpsServerConnector.setAcceptQueueSize(2);
141 ServletContextHandler servletContextHandler = new ServletContextHandler(0);
142 servletContextHandler.setContextPath("/");
143 servletContextHandler.addServlet(new ServletHolder(new NodeServlet(delivery)), "/*");
145 //CADI Filter activation check
146 if (nodeConfigManager.getCadiEnabled()) {
147 enableCadi(servletContextHandler);
150 server.setHandler(servletContextHandler);
151 server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector});
157 nodeMainLogger.debug("NODE00006 Node Server started-" + server.getState());
158 } catch (Exception e) {
159 nodeMainLogger.error("NODE00006 Jetty failed to start. Reporting will we unavailable: "
160 + e.getMessage(), e);
163 nodeMainLogger.debug("NODE00007 Node Server joined - " + server.getState());
166 private static void enableCadi(ServletContextHandler servletContextHandler) throws ServletException {
167 Properties cadiProperties = new Properties();
169 Inner obj = new NodeMain().new Inner();
170 InputStream in = obj.getCadiProps();
171 cadiProperties.load(in);
172 } catch (IOException e1) {
174 .error("NODE00005 Exception in NodeMain.Main() loading CADI properties " + e1.getMessage(), e1);
176 cadiProperties.setProperty("aaf_locate_url", nodeConfigManager.getAafURL());
177 nodeMainLogger.debug("NODE00005 aaf_url set to - " + cadiProperties.getProperty("aaf_url"));
179 PropAccess access = new PropAccess(cadiProperties);
180 servletContextHandler.addFilter(new FilterHolder(new DRNodeCadiFilter(true, access)), "/*", EnumSet
181 .of(DispatcherType.REQUEST));
184 private static class WaitForConfig implements Runnable {
186 private NodeConfigManager localNodeConfigManager;
188 WaitForConfig(NodeConfigManager ncm) {
189 this.localNodeConfigManager = ncm;
192 public synchronized void run() {
196 synchronized void waitForConfig() {
197 localNodeConfigManager.registerConfigTask(this);
198 while (!localNodeConfigManager.isConfigured()) {
199 nodeMainLogger.debug("NODE0003 Waiting for Node Configuration");
202 } catch (Exception exception) {
204 .error("NodeMain: waitForConfig exception. Exception Message:- " + exception.toString(),
208 localNodeConfigManager.deregisterConfigTask(this);
209 nodeMainLogger.debug("NODE0004 Node Configuration Data Received");
215 InputStream getCadiProps() {
216 InputStream in = null;
218 in = getClass().getClassLoader().getResourceAsStream("drNodeCadi.properties");
219 } catch (Exception e) {
220 nodeMainLogger.error("Exception in Inner.getCadiProps() method ", e);