Fix datarouter-prov server issue
[dmaap/datarouter.git] / datarouter-node / src / main / java / org / onap / dmaap / datarouter / node / NodeMain.java
1 /*******************************************************************************
2  * ============LICENSE_START==================================================
3  * * org.onap.dmaap
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
10  * *
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * *
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====================================================
19  * *
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  * *
22  ******************************************************************************/
23
24 package org.onap.dmaap.datarouter.node;
25
26 import org.eclipse.jetty.http.HttpVersion;
27 import org.eclipse.jetty.servlet.*;
28 import org.eclipse.jetty.util.ssl.*;
29 import org.eclipse.jetty.server.*;
30 import org.apache.log4j.Logger;
31
32 /**
33  * The main starting point for the Data Router node
34  */
35 public class NodeMain {
36     private NodeMain() {
37     }
38
39     private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeMain");
40
41     private static class wfconfig implements Runnable {
42         private NodeConfigManager ncm;
43
44         wfconfig(NodeConfigManager ncm) {
45             this.ncm = ncm;
46         }
47
48         public synchronized void run() {
49             notify();
50         }
51
52         synchronized void waitforconfig() {
53             ncm.registerConfigTask(this);
54             while (!ncm.isConfigured()) {
55                 logger.info("NODE0003 Waiting for Node Configuration");
56                 try {
57                     wait();
58                 } catch (Exception e) {
59                     logger.debug("NodeMain: waitforconfig exception");
60                 }
61             }
62             ncm.deregisterConfigTask(this);
63             logger.info("NODE0004 Node Configuration Data Received");
64         }
65     }
66
67     private static Delivery d;
68     private static NodeConfigManager ncm;
69
70     /**
71      * Reset the retry timer for a subscription
72      */
73     static void resetQueue(String subid, String ip) {
74         d.resetQueue(ncm.getSpoolDir(subid, ip));
75     }
76
77     /**
78      * Start the data router.
79      * <p>
80      * The location of the node configuration file can be set using the
81      * org.onap.dmaap.datarouter.node.ConfigFile system property.  By
82      * default, it is "etc/node.properties".
83      */
84     public static void main(String[] args) throws Exception {
85         logger.info("NODE0001 Data Router Node Starting");
86         IsFrom.setDNSCache();
87         ncm = NodeConfigManager.getInstance();
88         logger.info("NODE0002 I am " + ncm.getMyName());
89         (new wfconfig(ncm)).waitforconfig();
90         d = new Delivery(ncm);
91         LogManager lm = new LogManager(ncm);
92         Server server = new Server();
93
94         // HTTP configuration
95         HttpConfiguration httpConfiguration = new HttpConfiguration();
96         httpConfiguration.setIdleTimeout(2000);
97         httpConfiguration.setRequestHeaderSize(2048);
98
99         // HTTP connector
100         ServerConnector httpServerConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration));
101         httpServerConnector.setPort(ncm.getHttpPort());
102
103         // HTTPS configuration
104         SslContextFactory sslContextFactory = new SslContextFactory();
105         sslContextFactory.setKeyStoreType(ncm.getKSType());
106         sslContextFactory.setKeyStorePath(ncm.getKSFile());
107         sslContextFactory.setKeyStorePassword(ncm.getKSPass());
108         sslContextFactory.setKeyManagerPassword(ncm.getKPass());
109         /* Skip SSLv3 Fixes */
110         sslContextFactory.addExcludeProtocols("SSLv3");
111         logger.info("Excluded protocols node-" + sslContextFactory.getExcludeProtocols());
112         /* End of SSLv3 Fixes */
113
114         HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
115         httpsConfiguration.setRequestHeaderSize(8192);
116
117         SecureRequestCustomizer secureRequestCustomizer = new SecureRequestCustomizer();
118         secureRequestCustomizer.setStsMaxAge(2000);
119         secureRequestCustomizer.setStsIncludeSubDomains(true);
120         httpsConfiguration.addCustomizer(secureRequestCustomizer);
121
122         // HTTPS connector
123         ServerConnector httpsServerConnector = new ServerConnector(server,
124                 new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()),
125                 new HttpConnectionFactory(httpsConfiguration));
126         httpsServerConnector.setPort(ncm.getHttpsPort());
127         httpsServerConnector.setIdleTimeout(500000);
128         httpsServerConnector.setAcceptQueueSize(2);
129
130         server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector});
131         ServletContextHandler ctxt = new ServletContextHandler(0);
132         ctxt.setContextPath("/");
133         server.setHandler(ctxt);
134         ctxt.addServlet(new ServletHolder(new NodeServlet()), "/*");
135         logger.info("NODE0005 Data Router Node Activating Service");
136         server.start();
137         server.join();
138     }
139 }