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.
63 static void resetQueue(String subid, String ip) {
64 delivery.resetQueue(nodeConfigManager.getSpoolDir(subid, ip));
68 * Start the data router.
70 * <p>The location of the node configuration file can be set using the org.onap.dmaap.datarouter.node.properties
71 * system property. By default, it is "/opt/app/datartr/etc/node.properties".
73 public static void main(String[] args) throws Exception {
74 nodeMainLogger.info("NODE0001 Data Router Node Starting");
76 nodeConfigManager = NodeConfigManager.getInstance();
77 nodeMainLogger.info("NODE0002 I am " + nodeConfigManager.getMyName());
78 (new WaitForConfig(nodeConfigManager)).waitForConfig();
79 delivery = new Delivery(nodeConfigManager);
80 new LogManager(nodeConfigManager);
82 Server server = new Server();
85 HttpConfiguration httpConfiguration = new HttpConfiguration();
86 httpConfiguration.setRequestHeaderSize(2048);
89 try (ServerConnector httpServerConnector = new ServerConnector(server,
90 new HttpConnectionFactory(httpConfiguration))) {
91 httpServerConnector.setPort(nodeConfigManager.getHttpPort());
92 httpServerConnector.setIdleTimeout(2000);
94 // HTTPS configuration
95 SslContextFactory sslContextFactory = new SslContextFactory();
96 sslContextFactory.setKeyStoreType(nodeConfigManager.getKSType());
97 sslContextFactory.setKeyStorePath(nodeConfigManager.getKSFile());
98 sslContextFactory.setKeyStorePassword(nodeConfigManager.getKSPass());
99 sslContextFactory.setKeyManagerPassword(nodeConfigManager.getKPass());
101 //SP-6: Fixes for SDV scan to exclude/remove DES/3DES
102 // ciphers are taken care by upgrading jdk in descriptor.xml
103 sslContextFactory.setExcludeCipherSuites(
104 "SSL_RSA_WITH_DES_CBC_SHA",
105 "SSL_DHE_RSA_WITH_DES_CBC_SHA",
106 "SSL_DHE_DSS_WITH_DES_CBC_SHA",
107 "SSL_RSA_EXPORT_WITH_RC4_40_MD5",
108 "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
109 "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
110 "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"
113 sslContextFactory.addExcludeProtocols("SSLv3");
114 sslContextFactory.setIncludeProtocols(nodeConfigManager.getEnabledprotocols());
115 nodeMainLogger.info("NODE00004 Unsupported protocols node server:-"
116 + String.join(",", sslContextFactory.getExcludeProtocols()));
117 nodeMainLogger.info("NODE00004 Supported protocols node server:-"
118 + String.join(",", sslContextFactory.getIncludeProtocols()));
119 nodeMainLogger.info("NODE00004 Unsupported ciphers node server:-"
120 + String.join(",", sslContextFactory.getExcludeCipherSuites()));
122 HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
123 httpsConfiguration.setRequestHeaderSize(8192);
125 SecureRequestCustomizer secureRequestCustomizer = new SecureRequestCustomizer();
126 secureRequestCustomizer.setStsMaxAge(2000);
127 secureRequestCustomizer.setStsIncludeSubDomains(true);
128 httpsConfiguration.addCustomizer(secureRequestCustomizer);
131 try (ServerConnector httpsServerConnector = new ServerConnector(server,
132 new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
133 new HttpConnectionFactory(httpsConfiguration))) {
135 httpsServerConnector.setPort(nodeConfigManager.getHttpsPort());
136 httpsServerConnector.setIdleTimeout(3600000);
137 httpsServerConnector.setAcceptQueueSize(2);
140 ServletContextHandler servletContextHandler = new ServletContextHandler(0);
141 servletContextHandler.setContextPath("/");
142 servletContextHandler.addServlet(new ServletHolder(new NodeServlet(delivery)), "/*");
144 //CADI Filter activation check
145 if (nodeConfigManager.getCadiEnabled()) {
146 enableCadi(servletContextHandler);
149 server.setHandler(servletContextHandler);
150 server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector});
156 nodeMainLogger.info("NODE00006 Node Server started-" + server.getState());
157 } catch (Exception e) {
158 nodeMainLogger.info("NODE00006 Jetty failed to start. Reporting will we unavailable: " + e.getMessage(), e);
161 nodeMainLogger.info("NODE00007 Node Server joined - " + server.getState());
164 private static void enableCadi(ServletContextHandler servletContextHandler) throws ServletException {
165 Properties cadiProperties = new Properties();
167 Inner obj = new NodeMain().new Inner();
168 InputStream in = obj.getCadiProps();
169 cadiProperties.load(in);
170 } catch (IOException e1) {
172 .error("NODE00005 Exception in NodeMain.Main() loading CADI properties " + e1.getMessage(), e1);
174 cadiProperties.setProperty("aaf_locate_url", nodeConfigManager.getAafURL());
175 nodeMainLogger.info("NODE00005 aaf_url set to - " + cadiProperties.getProperty("aaf_url"));
177 PropAccess access = new PropAccess(cadiProperties);
178 servletContextHandler.addFilter(new FilterHolder(new DRNodeCadiFilter(true, access)), "/*", EnumSet
179 .of(DispatcherType.REQUEST));
182 private static class WaitForConfig implements Runnable {
184 private NodeConfigManager localNodeConfigManager;
186 WaitForConfig(NodeConfigManager ncm) {
187 this.localNodeConfigManager = ncm;
190 public synchronized void run() {
194 synchronized void waitForConfig() {
195 localNodeConfigManager.registerConfigTask(this);
196 while (!localNodeConfigManager.isConfigured()) {
197 nodeMainLogger.info("NODE0003 Waiting for Node Configuration");
200 } catch (Exception exception) {
202 .error("NodeMain: waitForConfig exception. Exception Message:- " + exception.toString(),
206 localNodeConfigManager.deregisterConfigTask(this);
207 nodeMainLogger.info("NODE0004 Node Configuration Data Received");
213 InputStream getCadiProps() {
214 InputStream in = null;
216 in = getClass().getClassLoader().getResourceAsStream("drNodeCadi.properties");
217 } catch (Exception e) {
218 nodeMainLogger.error("Exception in Inner.getCadiProps() method ", e);