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 ******************************************************************************/
25 package org.onap.dmaap.datarouter.provisioning;
27 import java.security.*;
30 import org.apache.log4j.Logger;
31 import org.eclipse.jetty.http.HttpVersion;
32 import org.eclipse.jetty.server.Connector;
33 import org.eclipse.jetty.server.Handler;
34 import org.eclipse.jetty.server.HttpConfiguration;
35 import org.eclipse.jetty.server.HttpConnectionFactory;
36 import org.eclipse.jetty.server.NCSARequestLog;
37 import org.eclipse.jetty.server.Server;
38 import org.eclipse.jetty.server.ServerConnector;
39 import org.eclipse.jetty.server.handler.ContextHandlerCollection;
40 import org.eclipse.jetty.server.handler.DefaultHandler;
41 import org.eclipse.jetty.server.handler.HandlerCollection;
42 import org.eclipse.jetty.server.handler.RequestLogHandler;
43 import org.eclipse.jetty.server.SslConnectionFactory;
44 import org.eclipse.jetty.util.ssl.SslContextFactory;
45 import org.eclipse.jetty.servlet.FilterHolder;
46 import org.eclipse.jetty.servlet.ServletContextHandler;
47 import org.eclipse.jetty.servlet.ServletHolder;
48 import org.eclipse.jetty.util.thread.QueuedThreadPool;
49 import org.onap.dmaap.datarouter.provisioning.utils.DB;
50 import org.onap.dmaap.datarouter.provisioning.utils.LogfileLoader;
51 import org.onap.dmaap.datarouter.provisioning.utils.PurgeLogDirTask;
52 import org.onap.dmaap.datarouter.provisioning.utils.ThrottleFilter;
54 import javax.servlet.DispatcherType;
58 * A main class which may be used to start the provisioning server with an "embedded" Jetty server.
59 * Configuration is done via the properties file <i>provserver.properties</i>, which should be in the CLASSPATH.
60 * The provisioning server may also be packaged with a web.xml and started as a traditional webapp.
63 * Most of the work of the provisioning server is carried out within the eight servlets (configured below)
64 * that are used to handle each of the eight types of requests the server may receive.
65 * In addition, there are background threads started to perform other tasks:
68 * <li>One background Thread runs the {@link LogfileLoader} in order to process incoming logfiles.
69 * This Thread is created as a side effect of the first successful POST to the /internal/logs/ servlet.</li>
70 * <li>One background Thread runs the {@link SynchronizerTask} which is used to periodically
71 * synchronize the database between active and standby servers.</li>
72 * <li>One background Thread runs the {@link Poker} which is used to notify the nodes whenever
73 * provisioning data changes.</li>
74 * <li>One task is run once a day to run {@link PurgeLogDirTask} which purges older logs from the
75 * /opt/app/datartr/logs directory.</li>
78 * The provisioning server is stopped by issuing a GET to the URL http://127.0.0.1/internal/halt
79 * using <i>curl</i> or some other such tool.
83 * @version $Id: Main.java,v 1.12 2014/03/12 19:45:41 eby Exp $
87 * The truststore to use if none is specified
89 public static final String DEFAULT_TRUSTSTORE = "/opt/java/jdk/jdk180/jre/lib/security/cacerts";
90 public static final String KEYSTORE_TYPE_PROPERTY = "org.onap.dmaap.datarouter.provserver.keystore.type";
91 public static final String KEYSTORE_PATH_PROPERTY = "org.onap.dmaap.datarouter.provserver.keystore.path";
92 public static final String KEYSTORE_PASSWORD_PROPERTY = "org.onap.dmaap.datarouter.provserver.keystore.password";
93 public static final String TRUSTSTORE_PATH_PROPERTY = "org.onap.dmaap.datarouter.provserver.truststore.path";
94 public static final String TRUSTSTORE_PASSWORD_PROPERTY = "org.onap.dmaap.datarouter.provserver.truststore.password";
97 * The one and only {@link Server} instance in this JVM
99 private static Server server;
102 * Starts the Data Router Provisioning server.
104 * @param args not used
105 * @throws Exception if Jetty has a problem starting
107 public static void main(String[] args) throws Exception {
108 Security.setProperty("networkaddress.cache.ttl", "4");
109 Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");
111 // Check DB is accessible and contains the expected tables
112 if (!checkDatabase(logger))
115 logger.info("PROV0000 **** AT&T Data Router Provisioning Server starting....");
118 Properties p = (new DB()).getProperties();
119 int http_port = Integer.parseInt(p.getProperty("org.onap.dmaap.datarouter.provserver.http.port", "8080"));
120 int https_port = Integer.parseInt(p.getProperty("org.onap.dmaap.datarouter.provserver.https.port", "8443"));
123 HttpConfiguration http_config = new HttpConfiguration();
124 http_config.setSecureScheme("https");
125 http_config.setSecurePort(https_port);
126 http_config.setOutputBufferSize(32768);
127 http_config.setRequestHeaderSize(2048);
128 http_config.setIdleTimeout(300000);
129 http_config.setSendServerVersion(true);
130 http_config.setSendDateHeader(false);
132 ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config));
133 http.setPort(http_port);
134 http.setAcceptQueueSize(2);
137 HttpConfiguration https_config = new HttpConfiguration(http_config);
138 https_config.setRequestHeaderSize(8192);
141 SslContextFactory sslContextFactory = new SslContextFactory();
142 sslContextFactory.setKeyStorePath(p.getProperty(KEYSTORE_PATH_PROPERTY));
143 sslContextFactory.setKeyStorePassword(p.getProperty(KEYSTORE_PASSWORD_PROPERTY));
144 sslContextFactory.setKeyManagerPassword(p.getProperty("org.onap.dmaap.datarouter.provserver.keymanager.password"));
146 ServerConnector https = new ServerConnector(server,
147 new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()),
148 new HttpConnectionFactory(https_config));
149 https.setPort(https_port);
150 https.setIdleTimeout(30000);
151 https.setAcceptQueueSize(2);
154 /* Skip SSLv3 Fixes */
155 sslContextFactory.addExcludeProtocols("SSLv3");
156 logger.info("Excluded protocols prov-" + sslContextFactory.getExcludeProtocols());
157 /* End of SSLv3 Fixes */
159 sslContextFactory.setKeyStoreType(p.getProperty(KEYSTORE_TYPE_PROPERTY, "jks"));
160 sslContextFactory.setKeyStorePath(p.getProperty(KEYSTORE_PATH_PROPERTY));
161 sslContextFactory.setKeyStorePassword(p.getProperty(KEYSTORE_PASSWORD_PROPERTY));
162 sslContextFactory.setKeyManagerPassword(p.getProperty("org.onap.dmaap.datarouter.provserver.keymanager.password"));
163 String ts = p.getProperty(TRUSTSTORE_PATH_PROPERTY);
164 if (ts != null && ts.length() > 0) {
165 System.out.println("@@ TS -> " + ts);
166 sslContextFactory.setTrustStorePath(ts);
167 sslContextFactory.setTrustStorePassword(p.getProperty(TRUSTSTORE_PASSWORD_PROPERTY));
169 sslContextFactory.setTrustStorePath(DEFAULT_TRUSTSTORE);
170 sslContextFactory.setTrustStorePassword("changeit");
172 sslContextFactory.setTrustStorePath("/opt/app/datartr/self_signed/cacerts.jks");
173 sslContextFactory.setTrustStorePassword("changeit");
174 sslContextFactory.setWantClientAuth(true);
176 // Servlet and Filter configuration
177 ServletContextHandler ctxt = new ServletContextHandler(0);
178 ctxt.setContextPath("/");
179 ctxt.addServlet(new ServletHolder(new FeedServlet()), "/feed/*");
180 ctxt.addServlet(new ServletHolder(new FeedLogServlet()), "/feedlog/*");
181 ctxt.addServlet(new ServletHolder(new PublishServlet()), "/publish/*");
182 ctxt.addServlet(new ServletHolder(new SubscribeServlet()), "/subscribe/*");
183 ctxt.addServlet(new ServletHolder(new StatisticsServlet()), "/statistics/*");
184 ctxt.addServlet(new ServletHolder(new SubLogServlet()), "/sublog/*");
185 ctxt.addServlet(new ServletHolder(new GroupServlet()), "/group/*"); //Provision groups - Rally US708115 -1610
186 ctxt.addServlet(new ServletHolder(new SubscriptionServlet()), "/subs/*");
187 ctxt.addServlet(new ServletHolder(new InternalServlet()), "/internal/*");
188 ctxt.addServlet(new ServletHolder(new RouteServlet()), "/internal/route/*");
189 ctxt.addServlet(new ServletHolder(new DRFeedsServlet()), "/");
190 ctxt.addFilter(new FilterHolder(new ThrottleFilter()), "/publish/*", EnumSet.of(DispatcherType.REQUEST));
192 ContextHandlerCollection contexts = new ContextHandlerCollection();
193 contexts.addHandler(ctxt);
195 // Request log configuration
196 NCSARequestLog nrl = new NCSARequestLog();
197 nrl.setFilename(p.getProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir") + "/request.log.yyyy_mm_dd");
198 nrl.setFilenameDateFormat("yyyyMMdd");
199 nrl.setRetainDays(90);
201 nrl.setExtended(false);
202 nrl.setLogCookies(false);
203 nrl.setLogTimeZone("GMT");
205 RequestLogHandler reqlog = new RequestLogHandler();
206 reqlog.setRequestLog(nrl);
208 // Server's Handler collection
209 HandlerCollection hc = new HandlerCollection();
210 hc.setHandlers(new Handler[]{contexts, new DefaultHandler()});
211 hc.addHandler(reqlog);
213 // Server's thread pool
214 QueuedThreadPool queuedThreadPool = new QueuedThreadPool();
215 queuedThreadPool.setMinThreads(10);
216 queuedThreadPool.setMaxThreads(200);
217 queuedThreadPool.setDetailedDump(false);
219 // Daemon to clean up the log directory on a daily basis
220 Timer rolex = new Timer();
221 rolex.scheduleAtFixedRate(new PurgeLogDirTask(), 0, 86400000L); // run once per day
223 // Start LogfileLoader
224 LogfileLoader.getLoader();
227 server = new Server(queuedThreadPool);
229 ServerConnector serverConnector = new ServerConnector(server,
230 new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()),
231 new HttpConnectionFactory(https_config));
232 serverConnector.setPort(https_port);
233 serverConnector.setIdleTimeout(500000);
235 server.setConnectors(new Connector[]{http, https});
236 server.setHandler(hc);
237 server.setStopAtShutdown(true);
238 server.setStopTimeout(5000);
240 server.setDumpAfterStart(false);
241 server.setDumpBeforeStop(false);
245 logger.info("PROV0001 **** AT&T Data Router Provisioning Server halted.");
248 private static boolean checkDatabase(Logger logger) {
250 return db.runRetroFits();
254 * Stop the Jetty server.
256 static void shutdown() {
262 } catch (Exception e) {