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;
33 import java.io.FileInputStream;
34 import java.io.IOException;
35 import java.util.Properties;
36 import java.util.Timer;
37 import org.eclipse.jetty.server.Server;
38 import org.onap.dmaap.datarouter.provisioning.utils.AafPropsUtils;
39 import org.onap.dmaap.datarouter.provisioning.utils.LogfileLoader;
40 import org.onap.dmaap.datarouter.provisioning.utils.Poker;
41 import org.onap.dmaap.datarouter.provisioning.utils.ProvDbUtils;
42 import org.onap.dmaap.datarouter.provisioning.utils.PurgeLogDirTask;
43 import org.onap.dmaap.datarouter.provisioning.utils.SynchronizerTask;
47 * A main class which may be used to start the provisioning server with an "embedded" Jetty server. Configuration is
48 * done via the properties file <i>provserver.properties</i>, which should be in the CLASSPATH. The provisioning server
49 * may also be packaged with a web.xml and started as a traditional webapp.
52 * Most of the work of the provisioning server is carried out within the eight servlets (configured below) that are used
53 * to handle each of the eight types of requests the server may receive. In addition, there are background threads
54 * started to perform other tasks:
57 * <li>One background Thread runs the {@link LogfileLoader} in order to process incoming logfiles.
58 * This Thread is created as a side effect of the first successful POST to the /internal/logs/ servlet.</li>
59 * <li>One background Thread runs the {@link SynchronizerTask} which is used to periodically
60 * synchronize the database between active and standby servers.</li>
61 * <li>One background Thread runs the {@link Poker} which is used to notify the nodes whenever
62 * provisioning data changes.</li>
63 * <li>One task is run once a day to run {@link PurgeLogDirTask} which purges older logs from the
64 * /opt/app/datartr/logs directory.</li>
67 * The provisioning server is stopped by issuing a GET to the URL http://127.0.0.1/internal/halt using <i>curl</i> or
68 * some other such tool.
72 * @version $Id: Main.java,v 1.12 2014/03/12 19:45:41 eby Exp $
74 public class ProvRunner {
76 public static final EELFLogger intlogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.provisioning.internal");
78 private static Server provServer;
79 private static AafPropsUtils aafPropsUtils;
80 private static Properties provProperties;
81 private static Boolean tlsEnabled;
84 * Starts the Data Router Provisioning server.
86 * @param args not used
88 public static void main(String[] args) {
89 // Check DB is accessible and contains the expected tables
90 if (!ProvDbUtils.getInstance().initProvDB()) {
91 intlogger.error("Data Router Provisioning database init failure. Exiting.");
94 if (Boolean.TRUE.equals(getTlsEnabled())) {
95 // Set up AAF properties
97 aafPropsUtils = new AafPropsUtils(new File(getProvProperties().getProperty(
98 "org.onap.dmaap.datarouter.provserver.aafprops.path",
99 "/opt/app/osaaf/local/org.onap.dmaap-dr.props")));
100 } catch (IOException e) {
101 intlogger.error("NODE0314 Failed to load AAF props. Exiting", e);
105 // Daemon to clean up the log directory on a daily basis
106 Timer rolex = new Timer();
107 rolex.scheduleAtFixedRate(new PurgeLogDirTask(), 0, 86400000L); // run once per day
110 // Create and start the Jetty server
111 provServer = ProvServer.getServerInstance();
112 intlogger.info("PROV0000 **** DMaaP Data Router Provisioning Server starting....");
114 provServer.dumpStdErr();
116 intlogger.info("PROV0000 **** DMaaP Data Router Provisioning Server started: " + provServer.getState());
117 } catch (Exception e) {
119 "PROV0010 **** DMaaP Data Router Provisioning Server failed to start. Exiting: " + e.getMessage(), e);
122 // Start LogfileLoader
123 LogfileLoader.getLoader();
127 * Stop the Jetty server.
129 static void shutdown() {
135 } catch (Exception e) {
136 intlogger.error("Exception in Main.shutdown(): " + e.getMessage(), e);
141 public static Properties getProvProperties() {
142 if (provProperties == null) {
143 try (FileInputStream props = new FileInputStream(getProperty(
144 "org.onap.dmaap.datarouter.provserver.properties",
145 "/opt/app/datartr/etc/provserver.properties"))) {
146 provProperties = new Properties();
147 provProperties.load(props);
148 } catch (IOException e) {
149 intlogger.error("Failed to load PROV properties: " + e.getMessage(), e);
153 return provProperties;
156 public static AafPropsUtils getAafPropsUtils() {
157 return aafPropsUtils;
160 public static Boolean getTlsEnabled() {
161 if (tlsEnabled == null) {
162 tlsEnabled = Boolean.parseBoolean(getProvProperties()
163 .getProperty("org.onap.dmaap.datarouter.provserver.tlsenabled", "true"));