datarouter-node clean code - remove tabs
[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
25 package org.onap.dmaap.datarouter.node;
26
27 import org.eclipse.jetty.servlet.*;
28 import org.eclipse.jetty.util.ssl.*;
29 import org.eclipse.jetty.server.*;
30 import org.eclipse.jetty.server.nio.*;
31 import org.eclipse.jetty.server.ssl.*;
32 import org.apache.log4j.Logger;
33
34 /**
35  * The main starting point for the Data Router node
36  */
37 public class NodeMain {
38     private NodeMain() {
39     }
40
41     private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeMain");
42
43     private static class wfconfig implements Runnable {
44         private NodeConfigManager ncm;
45
46         public wfconfig(NodeConfigManager ncm) {
47             this.ncm = ncm;
48         }
49
50         public synchronized void run() {
51             notify();
52         }
53
54         public synchronized void waitforconfig() {
55             ncm.registerConfigTask(this);
56             while (!ncm.isConfigured()) {
57                 logger.info("NODE0003 Waiting for Node Configuration");
58                 try {
59                     wait();
60                 } catch (Exception e) {
61                 }
62             }
63             ncm.deregisterConfigTask(this);
64             logger.info("NODE0004 Node Configuration Data Received");
65         }
66     }
67
68     private static Delivery d;
69     private static NodeConfigManager ncm;
70
71     /**
72      * Reset the retry timer for a subscription
73      */
74     public static void resetQueue(String subid, String ip) {
75         d.resetQueue(ncm.getSpoolDir(subid, ip));
76     }
77
78     /**
79      * Start the data router.
80      * <p>
81      * The location of the node configuration file can be set using the
82      * org.onap.dmaap.datarouter.node.ConfigFile system property.  By
83      * default, it is "etc/node.properties".
84      */
85     public static void main(String[] args) throws Exception {
86         logger.info("NODE0001 Data Router Node Starting");
87         IsFrom.setDNSCache();
88         ncm = NodeConfigManager.getInstance();
89         logger.info("NODE0002 I am " + ncm.getMyName());
90         (new wfconfig(ncm)).waitforconfig();
91         d = new Delivery(ncm);
92         LogManager lm = new LogManager(ncm);
93         Server server = new Server();
94         SelectChannelConnector http = new SelectChannelConnector();
95         http.setPort(ncm.getHttpPort());
96         http.setMaxIdleTime(2000);
97         http.setRequestHeaderSize(2048);
98         SslSelectChannelConnector https = new SslSelectChannelConnector();
99         https.setPort(ncm.getHttpsPort());
100         https.setMaxIdleTime(30000);
101         https.setRequestHeaderSize(8192);
102         SslContextFactory cf = https.getSslContextFactory();
103
104         /**Skip SSLv3 Fixes*/
105         cf.addExcludeProtocols("SSLv3");
106         logger.info("Excluded protocols node-" + cf.getExcludeProtocols());
107         /**End of SSLv3 Fixes*/
108
109         cf.setKeyStoreType(ncm.getKSType());
110         cf.setKeyStorePath(ncm.getKSFile());
111         cf.setKeyStorePassword(ncm.getKSPass());
112         cf.setKeyManagerPassword(ncm.getKPass());
113         server.setConnectors(new Connector[]{http, https});
114         ServletContextHandler ctxt = new ServletContextHandler(0);
115         ctxt.setContextPath("/");
116         server.setHandler(ctxt);
117         ctxt.addServlet(new ServletHolder(new NodeServlet()), "/*");
118         logger.info("NODE0005 Data Router Node Activating Service");
119         server.start();
120         server.join();
121     }
122 }