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 static java.lang.System.exit;
28 import static java.lang.System.getProperty;
30 import com.att.eelf.configuration.EELFLogger;
31 import com.att.eelf.configuration.EELFManager;
32 import java.io.FileInputStream;
33 import java.io.IOException;
34 import java.util.Properties;
35 import java.util.Timer;
36 import org.eclipse.jetty.server.Server;
37 import org.onap.dmaap.datarouter.provisioning.utils.LogfileLoader;
38 import org.onap.dmaap.datarouter.provisioning.utils.Poker;
39 import org.onap.dmaap.datarouter.provisioning.utils.ProvDbUtils;
40 import org.onap.dmaap.datarouter.provisioning.utils.ProvTlsManager;
41 import org.onap.dmaap.datarouter.provisioning.utils.PurgeLogDirTask;
42 import org.onap.dmaap.datarouter.provisioning.utils.SynchronizerTask;
46 * A main class which may be used to start the provisioning server with an "embedded" Jetty server. Configuration is
47 * done via the properties file <i>provserver.properties</i>, which should be in the CLASSPATH. The provisioning server
48 * may also be packaged with a web.xml and started as a traditional webapp.
51 * Most of the work of the provisioning server is carried out within the eight servlets (configured below) that are used
52 * to handle each of the eight types of requests the server may receive. In addition, there are background threads
53 * started to perform other tasks:
56 * <li>One background Thread runs the {@link LogfileLoader} in order to process incoming logfiles.
57 * This Thread is created as a side effect of the first successful POST to the /internal/logs/ servlet.</li>
58 * <li>One background Thread runs the {@link SynchronizerTask} which is used to periodically
59 * synchronize the database between active and standby servers.</li>
60 * <li>One background Thread runs the {@link Poker} which is used to notify the nodes whenever
61 * provisioning data changes.</li>
62 * <li>One task is run once a day to run {@link PurgeLogDirTask} which purges older logs from the
63 * /opt/app/datartr/logs directory.</li>
66 * The provisioning server is stopped by issuing a GET to the URL http://127.0.0.1/internal/halt using <i>curl</i> or
67 * some other such tool.
71 * @version $Id: Main.java,v 1.12 2014/03/12 19:45:41 eby Exp $
73 public class ProvRunner {
75 public static final EELFLogger intlogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.provisioning.internal");
77 private static Server provServer;
78 private static ProvTlsManager provTlsManager;
79 private static Properties provProperties;
80 private static Boolean tlsEnabled;
83 * Starts the Data Router Provisioning server.
85 * @param args not used
87 public static void main(String[] args) {
88 // Check DB is accessible and contains the expected tables
89 if (!ProvDbUtils.getInstance().initProvDB()) {
90 intlogger.error("Data Router Provisioning database init failure. Exiting.");
93 if (Boolean.TRUE.equals(getTlsEnabled())) {
96 provTlsManager = new ProvTlsManager(ProvRunner.getProvProperties(), true);
97 } catch (Exception e) {
98 intlogger.error("NODE0314 Failed to load TLS config. Exiting", e);
102 // Daemon to clean up the log directory on a daily basis
103 Timer rolex = new Timer();
104 rolex.scheduleAtFixedRate(new PurgeLogDirTask(), 0, 86400000L); // run once per day
107 // Create and start the Jetty server
108 provServer = ProvServer.getServerInstance();
109 intlogger.info("PROV0000 **** DMaaP Data Router Provisioning Server starting....");
111 provServer.dumpStdErr();
113 intlogger.info("PROV0000 **** DMaaP Data Router Provisioning Server started: " + provServer.getState());
114 } catch (Exception e) {
116 "PROV0010 **** DMaaP Data Router Provisioning Server failed to start. Exiting: " + e.getMessage(), e);
119 // Start LogfileLoader
120 LogfileLoader.getLoader();
124 * Stop the Jetty server.
126 static void shutdown() {
132 } catch (Exception e) {
133 intlogger.error("Exception in Main.shutdown(): " + e.getMessage(), e);
138 public static Properties getProvProperties() {
139 if (provProperties == null) {
140 try (FileInputStream props = new FileInputStream(getProperty(
141 "org.onap.dmaap.datarouter.provserver.properties",
142 "/opt/app/datartr/etc/provserver.properties"))) {
143 provProperties = new Properties();
144 provProperties.load(props);
145 } catch (IOException e) {
146 intlogger.error("Failed to load PROV properties: " + e.getMessage(), e);
150 return provProperties;
153 public static Boolean getTlsEnabled() {
154 if (tlsEnabled == null) {
155 tlsEnabled = Boolean.parseBoolean(getProvProperties()
156 .getProperty("org.onap.dmaap.datarouter.provserver.tlsenabled", "true"));
161 public static ProvTlsManager getProvTlsManager() {
162 return provTlsManager;