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;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import org.eclipse.jetty.http.HttpVersion;
30 import org.eclipse.jetty.server.*;
31 import org.eclipse.jetty.servlet.FilterHolder;
32 import org.eclipse.jetty.servlet.ServletContextHandler;
33 import org.eclipse.jetty.servlet.ServletHolder;
34 import org.eclipse.jetty.util.ssl.SslContextFactory;
35 import org.onap.aaf.cadi.PropAccess;
37 import javax.servlet.DispatcherType;
38 import java.io.IOException;
39 import java.io.InputStream;
40 import java.util.EnumSet;
41 import java.util.Properties;
44 * The main starting point for the Data Router node
46 public class NodeMain {
51 private static EELFLogger nodeMainLogger = EELFManager.getInstance().getLogger(NodeMain.class);
54 InputStream getCadiProps() {
55 InputStream in = null;
57 in = getClass().getClassLoader().getResourceAsStream("drNodeCadi.properties");
58 } catch (Exception e) {
59 nodeMainLogger.error("Exception in Inner.getCadiProps() method " + e.getMessage());
65 private static class WaitForConfig implements Runnable {
67 private NodeConfigManager localNodeConfigManager;
69 WaitForConfig(NodeConfigManager ncm) {
70 this.localNodeConfigManager = ncm;
73 public synchronized void run() {
77 synchronized void waitForConfig() {
78 localNodeConfigManager.registerConfigTask(this);
79 while (!localNodeConfigManager.isConfigured()) {
80 nodeMainLogger.info("NODE0003 Waiting for Node Configuration");
83 } catch (Exception exception) {
85 .error("NodeMain: waitForConfig exception. Exception Message:- " + exception.toString(),
89 localNodeConfigManager.deregisterConfigTask(this);
90 nodeMainLogger.info("NODE0004 Node Configuration Data Received");
94 private static Delivery delivery;
95 private static NodeConfigManager nodeConfigManager;
98 * Reset the retry timer for a subscription
100 static void resetQueue(String subid, String ip) {
101 delivery.resetQueue(nodeConfigManager.getSpoolDir(subid, ip));
105 * Start the data router.
107 * The location of the node configuration file can be set using the org.onap.dmaap.datarouter.node.properties system
108 * property. By default, it is "/opt/app/datartr/etc/node.properties".
110 public static void main(String[] args) throws Exception {
111 nodeMainLogger.info("NODE0001 Data Router Node Starting");
112 IsFrom.setDNSCache();
113 nodeConfigManager = NodeConfigManager.getInstance();
114 nodeMainLogger.info("NODE0002 I am " + nodeConfigManager.getMyName());
115 (new WaitForConfig(nodeConfigManager)).waitForConfig();
116 delivery = new Delivery(nodeConfigManager);
117 new LogManager(nodeConfigManager);
119 Server server = new Server();
121 // HTTP configuration
122 HttpConfiguration httpConfiguration = new HttpConfiguration();
123 httpConfiguration.setRequestHeaderSize(2048);
126 try (ServerConnector httpServerConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration))) {
127 httpServerConnector.setPort(nodeConfigManager.getHttpPort());
128 httpServerConnector.setIdleTimeout(2000);
130 // HTTPS configuration
131 SslContextFactory sslContextFactory = new SslContextFactory();
132 sslContextFactory.setKeyStoreType(nodeConfigManager.getKSType());
133 sslContextFactory.setKeyStorePath(nodeConfigManager.getKSFile());
134 sslContextFactory.setKeyStorePassword(nodeConfigManager.getKSPass());
135 sslContextFactory.setKeyManagerPassword(nodeConfigManager.getKPass());
137 //SP-6 : Fixes for SDV scan to exclude/remove DES/3DES ciphers are taken care by upgrading jdk in descriptor.xml
138 sslContextFactory.setExcludeCipherSuites(
139 "SSL_RSA_WITH_DES_CBC_SHA",
140 "SSL_DHE_RSA_WITH_DES_CBC_SHA",
141 "SSL_DHE_DSS_WITH_DES_CBC_SHA",
142 "SSL_RSA_EXPORT_WITH_RC4_40_MD5",
143 "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
144 "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
145 "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"
148 sslContextFactory.addExcludeProtocols("SSLv3");
149 sslContextFactory.setIncludeProtocols(nodeConfigManager.getEnabledprotocols());
150 nodeMainLogger.info("NODE00004 Unsupported protocols node server:-" + String.join(",", sslContextFactory.getExcludeProtocols()));
151 nodeMainLogger.info("NODE00004 Supported protocols node server:-" + String.join(",", sslContextFactory.getIncludeProtocols()));
152 nodeMainLogger.info("NODE00004 Unsupported ciphers node server:-" + String.join(",", sslContextFactory.getExcludeCipherSuites()));
154 HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
155 httpsConfiguration.setRequestHeaderSize(8192);
157 SecureRequestCustomizer secureRequestCustomizer = new SecureRequestCustomizer();
158 secureRequestCustomizer.setStsMaxAge(2000);
159 secureRequestCustomizer.setStsIncludeSubDomains(true);
160 httpsConfiguration.addCustomizer(secureRequestCustomizer);
163 try (ServerConnector httpsServerConnector = new ServerConnector(server,
164 new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
165 new HttpConnectionFactory(httpsConfiguration))) {
167 httpsServerConnector.setPort(nodeConfigManager.getHttpsPort());
168 httpsServerConnector.setIdleTimeout(3600000);
169 httpsServerConnector.setAcceptQueueSize(2);
172 ServletContextHandler servletContextHandler = new ServletContextHandler(0);
173 servletContextHandler.setContextPath("/");
174 servletContextHandler.addServlet(new ServletHolder(new NodeServlet(delivery)), "/*");
176 //CADI Filter activation check
177 if (nodeConfigManager.getCadiEnabeld()) {
178 Properties cadiProperties = new Properties();
180 Inner obj = new NodeMain().new Inner();
181 InputStream in = obj.getCadiProps();
182 cadiProperties.load(in);
183 } catch (IOException e1) {
184 nodeMainLogger.error("NODE00005 Exception in NodeMain.Main() loading CADI properties " + e1.getMessage());
186 cadiProperties.setProperty("aaf_locate_url", nodeConfigManager.getAafURL());
187 nodeMainLogger.info("NODE00005 aaf_url set to - " + cadiProperties.getProperty("aaf_url"));
189 PropAccess access = new PropAccess(cadiProperties);
190 servletContextHandler.addFilter(new FilterHolder(new DRNodeCadiFilter(true, access)), "/*", EnumSet.of(DispatcherType.REQUEST));
193 server.setHandler(servletContextHandler);
194 server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector});
200 nodeMainLogger.info("NODE00006 Node Server started-" + server.getState());
201 } catch (Exception e) {
202 nodeMainLogger.info("NODE00006 Jetty failed to start. Reporting will we unavailable", e.getMessage());
205 nodeMainLogger.info("NODE00007 Node Server joined - " + server.getState());