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()
77 .getLogger("org.onap.dmaap.datarouter.provisioning.internal");
79 private static Server provServer;
80 private static AafPropsUtils aafPropsUtils;
81 private static Properties provProperties;
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 // Set up AAF properties
96 aafPropsUtils = new AafPropsUtils(new File(getProvProperties().getProperty(
97 "org.onap.dmaap.datarouter.provserver.aafprops.path",
98 "/opt/app/osaaf/local/org.onap.dmaap-dr.props")));
99 } catch (IOException e) {
100 intlogger.error("NODE0314 Failed to load AAF props. Exiting", e);
103 // Daemon to clean up the log directory on a daily basis
104 Timer rolex = new Timer();
105 rolex.scheduleAtFixedRate(new PurgeLogDirTask(), 0, 86400000L); // run once per day
108 // Create and start the Jetty server
109 provServer = ProvServer.getServerInstance();
110 intlogger.info("PROV0000 **** DMaaP Data Router Provisioning Server starting....");
112 provServer.dumpStdErr();
114 intlogger.info("PROV0000 **** DMaaP Data Router Provisioning Server started: " + provServer.getState());
115 } catch (Exception e) {
117 "PROV0010 **** DMaaP Data Router Provisioning Server failed to start. Exiting: " + e.getMessage(), e);
120 // Start LogfileLoader
121 LogfileLoader.getLoader();
125 * Stop the Jetty server.
127 static void shutdown() {
133 } catch (Exception e) {
134 intlogger.error("Exception in Main.shutdown(): " + e.getMessage(), e);
139 public static Properties getProvProperties() {
140 if (provProperties == null) {
142 provProperties = new Properties();
143 provProperties.load(new FileInputStream(getProperty(
144 "org.onap.dmaap.datarouter.provserver.properties",
145 "/opt/app/datartr/etc/provserver.properties")));
146 } catch (IOException e) {
147 intlogger.error("Failed to load PROV properties: " + e.getMessage(), e);
151 return provProperties;
154 public static AafPropsUtils getAafPropsUtils() {
155 return aafPropsUtils;