remove the policy and security issue dependencies
[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 http_config = new HttpConfiguration();
96         http_config.setIdleTimeout(2000);
97         http_config.setRequestHeaderSize(2048);
98
99         ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config));
100         http.setPort(ncm.getHttpPort());
101
102         // HTTPS configuration
103         SslContextFactory sslContextFactory = new SslContextFactory();
104         sslContextFactory.setKeyStoreType(ncm.getKSType());
105         sslContextFactory.setKeyStorePath(ncm.getKSFile());
106         sslContextFactory.setKeyStorePassword(ncm.getKSPass());
107         sslContextFactory.setKeyManagerPassword(ncm.getKPass());
108
109         HttpConfiguration https_config = new HttpConfiguration(http_config);
110         https_config.setRequestHeaderSize(8192);
111
112         ServerConnector https = new ServerConnector(server,
113                 new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()),
114                 new HttpConnectionFactory(https_config));
115         https.setPort(ncm.getHttpsPort());
116         https.setIdleTimeout(500000);
117         https.setAcceptQueueSize(2);
118
119         /* Skip SSLv3 Fixes */
120         sslContextFactory.addExcludeProtocols("SSLv3");
121         logger.info("Excluded protocols node-" + sslContextFactory.getExcludeProtocols());
122         /* End of SSLv3 Fixes */
123
124         server.setConnectors(new Connector[]{http, https});
125         ServletContextHandler ctxt = new ServletContextHandler(0);
126         ctxt.setContextPath("/");
127         server.setHandler(ctxt);
128         ctxt.addServlet(new ServletHolder(new NodeServlet()), "/*");
129         logger.info("NODE0005 Data Router Node Activating Service");
130         server.start();
131         server.join();
132     }
133 }