diff options
author | mmis <michael.morris@ericsson.com> | 2018-07-19 13:21:08 +0100 |
---|---|---|
committer | mmis <michael.morris@ericsson.com> | 2018-07-25 09:14:33 +0100 |
commit | 64f53ef14f5a9ea98208fd2b835bfb01fda9a5f9 (patch) | |
tree | 60afa251c126287a85c89e0b1dc7fd5d1a766439 /feature-state-management/src/main/java | |
parent | e8f1b7235f8338fbb9eba28d8cff29d3d6adf6e7 (diff) |
Copy policy-endpoints from drools-pdp to common
Removed policy-endpoints, and 3 classes from policy-core. Replaced
refenences to the deleted classes with references to the corresponding
classes in policy-common
Issue-ID: POLICY-967
Change-Id: I547cde4894424b8f40b7ddd4e2342ebb729cb588
Signed-off-by: mmis <michael.morris@ericsson.com>
Diffstat (limited to 'feature-state-management/src/main/java')
2 files changed, 460 insertions, 467 deletions
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPDPIntegrityMonitor.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPDPIntegrityMonitor.java index 83d4f040..8fdd3a4d 100644 --- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPDPIntegrityMonitor.java +++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPDPIntegrityMonitor.java @@ -21,426 +21,413 @@ package org.onap.policy.drools.statemanagement; import java.io.IOException; -import java.util.ArrayList; import java.util.List; import java.util.Properties; + +import org.onap.policy.common.capabilities.Startable; +import org.onap.policy.common.endpoints.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.http.server.impl.IndexedHttpServletServerFactory; import org.onap.policy.common.im.IntegrityMonitor; import org.onap.policy.common.im.IntegrityMonitorException; -import org.onap.policy.drools.http.server.HttpServletServer; -import org.onap.policy.drools.properties.Startable; import org.onap.policy.drools.utils.PropertyUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * This class extends 'IntegrityMonitor' for use in the 'Drools PDP' - * virtual machine. The included audits are 'Database' and 'Repository'. + * This class extends 'IntegrityMonitor' for use in the 'Drools PDP' virtual machine. The included + * audits are 'Database' and 'Repository'. */ -public class DroolsPDPIntegrityMonitor extends IntegrityMonitor -{ - - private static final String INVALID_PROPERTY_VALUE = "init: property {} does not have the expected value of {}"; - -// get an instance of logger - private static final Logger logger = LoggerFactory.getLogger(DroolsPDPIntegrityMonitor.class); - - // static global instance - private static DroolsPDPIntegrityMonitor im = null; - - // list of audits to run - private static AuditBase[] audits = - new AuditBase[]{DbAudit.getInstance(), RepositoryAudit.getInstance()}; - - private static Properties subsystemTestProperties = null; - - private static final String PROPERTIES_NAME = "feature-state-management.properties"; - - /** - * Constructor - pass arguments to superclass, but remember properties - * @param resourceName unique name of this Integrity Monitor - * @param url the JMX URL of the MBean server - * @param properties properties used locally, as well as by - * 'IntegrityMonitor' - * @throws IntegrityMonitorException (passed from superclass) - */ - private DroolsPDPIntegrityMonitor(String resourceName, - Properties consolidatedProperties - ) throws IntegrityMonitorException { - super(resourceName, consolidatedProperties); - } - - private static void missingProperty(String prop) throws IntegrityMonitorException{ - String msg = "init: missing IntegrityMonitor property: ".concat(prop); - logger.error(msg); - throw new IntegrityMonitorException(msg); - } - - private static void logPropertyValue(String prop, String val){ - if(logger.isInfoEnabled()){ - String msg = "\n\n init: property: " + prop + " = " + val + "\n"; - logger.info(msg); - } - } - - /** - * Static initialization -- create Drools Integrity Monitor, and - * an HTTP server to handle REST 'test' requests - * @throws StateManagementPropertiesException - * @throws IntegrityMonitorException - */ - public static DroolsPDPIntegrityMonitor init(String configDir) throws IntegrityMonitorException - { - - logger.info("init: Entering and invoking PropertyUtil.getProperties() on '{}'", configDir); - - // read in properties - Properties stateManagementProperties = getProperties(configDir); - - // fetch and verify definitions of some properties, adding defaults where - // appropriate - // (the 'IntegrityMonitor' constructor does some additional verification) - - checkPropError(stateManagementProperties, StateManagementProperties.TEST_HOST); - checkPropError(stateManagementProperties, StateManagementProperties.TEST_PORT); - - addDefaultPropError(stateManagementProperties, - StateManagementProperties.TEST_SERVICES, - StateManagementProperties.TEST_SERVICES_DEFAULT); - - addDefaultPropError(stateManagementProperties, - StateManagementProperties.TEST_REST_CLASSES, - StateManagementProperties.TEST_REST_CLASSES_DEFAULT); - - addDefaultPropWarn(stateManagementProperties, - StateManagementProperties.TEST_MANAGED, - StateManagementProperties.TEST_MANAGED_DEFAULT); - - addDefaultPropWarn(stateManagementProperties, - StateManagementProperties.TEST_SWAGGER, - StateManagementProperties.TEST_SWAGGER_DEFAULT); - - checkPropError(stateManagementProperties, StateManagementProperties.RESOURCE_NAME); - checkPropError(stateManagementProperties, StateManagementProperties.FP_MONITOR_INTERVAL); - checkPropError(stateManagementProperties, StateManagementProperties.FAILED_COUNTER_THRESHOLD); - checkPropError(stateManagementProperties, StateManagementProperties.TEST_TRANS_INTERVAL); - checkPropError(stateManagementProperties, StateManagementProperties.WRITE_FPC_INTERVAL); - checkPropError(stateManagementProperties, StateManagementProperties.SITE_NAME); - checkPropError(stateManagementProperties, StateManagementProperties.NODE_TYPE); - checkPropError(stateManagementProperties, StateManagementProperties.DEPENDENCY_GROUPS); - checkPropError(stateManagementProperties, StateManagementProperties.DB_DRIVER); - checkPropError(stateManagementProperties, StateManagementProperties.DB_URL); - checkPropError(stateManagementProperties, StateManagementProperties.DB_USER); - checkPropError(stateManagementProperties, StateManagementProperties.DB_PWD); - - String testHost = stateManagementProperties.getProperty(StateManagementProperties.TEST_HOST); - String testPort = stateManagementProperties.getProperty(StateManagementProperties.TEST_PORT); - String resourceName = stateManagementProperties.getProperty(StateManagementProperties.RESOURCE_NAME); - - subsystemTestProperties = stateManagementProperties; - - // Now that we've validated the properties, create Drools Integrity Monitor - // with these properties. - im = makeMonitor(resourceName, stateManagementProperties); - logger.info("init: New DroolsPDPIntegrityMonitor instantiated, resourceName = ", resourceName); - - // create http server - makeRestServer(testHost, testPort, stateManagementProperties); - logger.info("init: Exiting and returning DroolsPDPIntegrityMonitor"); - - return im; - } - - /** - * Makes an Integrity Monitor. - * @param resourceName unique name of this Integrity Monitor - * @param properties properties used to configure the Integrity Monitor - * @return - * @throws IntegrityMonitorException - */ - private static DroolsPDPIntegrityMonitor makeMonitor(String resourceName, Properties properties) - throws IntegrityMonitorException { - - try { - return new DroolsPDPIntegrityMonitor(resourceName, properties); - - } catch (Exception e) { - throw new IntegrityMonitorException(e); - } - } - - /** - * Makes a rest server for the Integrity Monitor. - * @param testHost host name - * @param testPort port - * @param properties properties used to configure the rest server - * @throws IntegrityMonitorException - */ - private static void makeRestServer(String testHost, String testPort, Properties properties) - throws IntegrityMonitorException { - - try { - logger.info("init: Starting HTTP server, addr= {}", testHost+":"+testPort); - - IntegrityMonitorRestServer server = new IntegrityMonitorRestServer(); - server.init(properties); - - } catch (Exception e) { - logger.error("init: Caught Exception attempting to start server on testPort= {} message:", - testPort, e); - throw new IntegrityMonitorException(e); - } - } - - /** - * Gets the properties from the property file. - * @param configDir directory containing the property file - * @return the properties - * @throws IntegrityMonitorException - */ - private static Properties getProperties(String configDir) throws IntegrityMonitorException { - try { - return PropertyUtil.getProperties(configDir + "/" + PROPERTIES_NAME); - - } catch (IOException e) { - throw new IntegrityMonitorException(e); - } - } - - /** - * Checks that a property is defined. - * @param props set of properties - * @param name name of the property to check - * @throws IntegrityMonitorException - */ - private static void checkPropError(Properties props, String name) throws IntegrityMonitorException { - String val = props.getProperty(name); - if(val == null) { - missingProperty(name); - } - - logPropertyValue(name, val); - } - - /** - * Checks a property's value to verify that it matches the expected value. - * If the property is not defined, then it is added to the property set, - * with the expected value. Logs an error if the property is defined, - * but does not have the expected value. - * @param props set of properties - * @param name name of the property to check - * @param expected expected/default value - */ - private static void addDefaultPropError(Properties props, String name, String expected) { - String val = props.getProperty(name); - if(val == null) { - props.setProperty(name, expected); - - } else if( ! val.equals(expected)) { - logger.error(INVALID_PROPERTY_VALUE, name, expected); - } - - logPropertyValue(name, val); - } - - /** - * Checks a property's value to verify that it matches the expected value. - * If the property is not defined, then it is added to the property set, - * with the expected value. Logs a warning if the property is defined, - * but does not have the expected value. - * @param props set of properties - * @param name name of the property to check - * @param expected expected/default value - */ - private static void addDefaultPropWarn(Properties props, String name, String dflt) { - String val = props.getProperty(name); - if(val == null) { - props.setProperty(name, dflt); - - } else if( ! val.equals(dflt)) { - logger.warn(INVALID_PROPERTY_VALUE, name, dflt); - } - - logPropertyValue(name, val); - } - - /** - * Run tests (audits) unique to Drools PDP VM (Database + Repository) - */ - @Override - public void subsystemTest() throws IntegrityMonitorException - { - logger.info("DroolsPDPIntegrityMonitor.subsystemTest called"); - - // clear all responses (non-null values indicate an error) - for (AuditBase audit : audits) - { - audit.setResponse(null); - } - - // invoke all of the audits - for (AuditBase audit : audits) - { - try - { - // invoke the audit (responses are stored within the audit object) - audit.invoke(subsystemTestProperties); - } - catch (Exception e) - { - logger.error("{} audit error", audit.getName(), e); - if (audit.getResponse() == null) - { - // if there is no current response, use the exception message - audit.setResponse(e.getMessage()); - } - } - } - - // will contain list of subsystems where the audit failed - String responseMsg = ""; - - // Loop through all of the audits, and see which ones have failed. - // NOTE: response information is stored within the audit objects - // themselves -- only one can run at a time. - for (AuditBase audit : audits) - { - String response = audit.getResponse(); - if (response != null) - { - // the audit has failed -- add subsystem and - // and 'responseValue' with the new information - responseMsg = responseMsg.concat("\n" + audit.getName() + ": " + response); - } - } - - if(!responseMsg.isEmpty()){ - throw new IntegrityMonitorException(responseMsg); - } - } - - /* ============================================================ */ - - /** - * This is the base class for audits invoked in 'subsystemTest' - */ - public abstract static class AuditBase - { - // name of the audit - protected String name; - - // non-null indicates the error response - protected String response; - - /** - * Constructor - initialize the name, and clear the initial response - * @param name name of the audit - */ - public AuditBase(String name) - { - this.name = name; - this.response = null; - } - - /** - * @return the name of this audit - */ - public String getName() - { - return name; - } - - /** - * @return the response String (non-null indicates the error message) - */ - public String getResponse() - { - return response; - } - - /** - * Set the response string to the specified value - * @param value the new value of the response string (null = no errors) - */ - public void setResponse(String value) - { - response = value; - } - - /** - * Abstract method to invoke the audit - * @param persistenceProperties Used for DB access - * @throws Exception passed in by the audit - */ - abstract void invoke(Properties persistenceProperties) throws Exception; - } - - public static class IntegrityMonitorRestServer implements Startable { - protected volatile HttpServletServer server = null; - protected volatile Properties integrityMonitorRestServerProperties = null; - - public void init(Properties props) { - this.integrityMonitorRestServerProperties = props; - this.start(); - } - - @Override - public boolean start() { - try { - List<HttpServletServer> servers = HttpServletServer.factory.build(integrityMonitorRestServerProperties); - - if (!servers.isEmpty()) { - server = servers.get(0); - - waitServerStart(); - } - } catch (Exception e) { - logger.error("Exception building servers", e); - return false; - } - - return true; - } - - private void waitServerStart() { - try { - server.waitedStart(5); - } catch (Exception e) { - logger.error("Exception waiting for servers to start: ", e); - } - } - - @Override - public boolean stop() { - try { - server.stop(); - } catch (Exception e) { - logger.error("Exception during stop", e); - } - - return true; - } - - @Override - public void shutdown() { - this.stop(); - } - - @Override - public synchronized boolean isAlive() { - return this.integrityMonitorRestServerProperties != null; - } - } - - public static DroolsPDPIntegrityMonitor getInstance() throws IntegrityMonitorException{ - if(logger.isDebugEnabled()){ - logger.debug("getInstance() called"); - } - if (im == null) { - String msg = "No DroolsPDPIntegrityMonitor instance exists." - + " Please use the method DroolsPDPIntegrityMonitor init(String configDir)"; - throw new IntegrityMonitorException(msg); - }else{ - return im; - } - } +public class DroolsPDPIntegrityMonitor extends IntegrityMonitor { + + private static final String INVALID_PROPERTY_VALUE = "init: property {} does not have the expected value of {}"; + + // get an instance of logger + private static final Logger logger = LoggerFactory.getLogger(DroolsPDPIntegrityMonitor.class); + + // static global instance + private static DroolsPDPIntegrityMonitor im = null; + + // list of audits to run + private static AuditBase[] audits = new AuditBase[] {DbAudit.getInstance(), RepositoryAudit.getInstance()}; + + private static Properties subsystemTestProperties = null; + + private static final String PROPERTIES_NAME = "feature-state-management.properties"; + + /** + * Constructor - pass arguments to superclass, but remember properties + * + * @param resourceName unique name of this Integrity Monitor + * @param url the JMX URL of the MBean server + * @param properties properties used locally, as well as by 'IntegrityMonitor' + * @throws IntegrityMonitorException (passed from superclass) + */ + private DroolsPDPIntegrityMonitor(String resourceName, Properties consolidatedProperties) + throws IntegrityMonitorException { + super(resourceName, consolidatedProperties); + } + + private static void missingProperty(String prop) throws IntegrityMonitorException { + String msg = "init: missing IntegrityMonitor property: ".concat(prop); + logger.error(msg); + throw new IntegrityMonitorException(msg); + } + + private static void logPropertyValue(String prop, String val) { + if (logger.isInfoEnabled()) { + String msg = "\n\n init: property: " + prop + " = " + val + "\n"; + logger.info(msg); + } + } + + /** + * Static initialization -- create Drools Integrity Monitor, and an HTTP server to handle REST + * 'test' requests + * + * @throws StateManagementPropertiesException + * @throws IntegrityMonitorException + */ + public static DroolsPDPIntegrityMonitor init(String configDir) throws IntegrityMonitorException { + + logger.info("init: Entering and invoking PropertyUtil.getProperties() on '{}'", configDir); + + // read in properties + Properties stateManagementProperties = getProperties(configDir); + + // fetch and verify definitions of some properties, adding defaults where + // appropriate + // (the 'IntegrityMonitor' constructor does some additional verification) + + checkPropError(stateManagementProperties, StateManagementProperties.TEST_HOST); + checkPropError(stateManagementProperties, StateManagementProperties.TEST_PORT); + + addDefaultPropError(stateManagementProperties, StateManagementProperties.TEST_SERVICES, + StateManagementProperties.TEST_SERVICES_DEFAULT); + + addDefaultPropError(stateManagementProperties, StateManagementProperties.TEST_REST_CLASSES, + StateManagementProperties.TEST_REST_CLASSES_DEFAULT); + + addDefaultPropWarn(stateManagementProperties, StateManagementProperties.TEST_MANAGED, + StateManagementProperties.TEST_MANAGED_DEFAULT); + + addDefaultPropWarn(stateManagementProperties, StateManagementProperties.TEST_SWAGGER, + StateManagementProperties.TEST_SWAGGER_DEFAULT); + + checkPropError(stateManagementProperties, StateManagementProperties.RESOURCE_NAME); + checkPropError(stateManagementProperties, StateManagementProperties.FP_MONITOR_INTERVAL); + checkPropError(stateManagementProperties, StateManagementProperties.FAILED_COUNTER_THRESHOLD); + checkPropError(stateManagementProperties, StateManagementProperties.TEST_TRANS_INTERVAL); + checkPropError(stateManagementProperties, StateManagementProperties.WRITE_FPC_INTERVAL); + checkPropError(stateManagementProperties, StateManagementProperties.SITE_NAME); + checkPropError(stateManagementProperties, StateManagementProperties.NODE_TYPE); + checkPropError(stateManagementProperties, StateManagementProperties.DEPENDENCY_GROUPS); + checkPropError(stateManagementProperties, StateManagementProperties.DB_DRIVER); + checkPropError(stateManagementProperties, StateManagementProperties.DB_URL); + checkPropError(stateManagementProperties, StateManagementProperties.DB_USER); + checkPropError(stateManagementProperties, StateManagementProperties.DB_PWD); + + String testHost = stateManagementProperties.getProperty(StateManagementProperties.TEST_HOST); + String testPort = stateManagementProperties.getProperty(StateManagementProperties.TEST_PORT); + String resourceName = stateManagementProperties.getProperty(StateManagementProperties.RESOURCE_NAME); + + subsystemTestProperties = stateManagementProperties; + + // Now that we've validated the properties, create Drools Integrity Monitor + // with these properties. + im = makeMonitor(resourceName, stateManagementProperties); + logger.info("init: New DroolsPDPIntegrityMonitor instantiated, resourceName = ", resourceName); + + // create http server + makeRestServer(testHost, testPort, stateManagementProperties); + logger.info("init: Exiting and returning DroolsPDPIntegrityMonitor"); + + return im; + } + + /** + * Makes an Integrity Monitor. + * + * @param resourceName unique name of this Integrity Monitor + * @param properties properties used to configure the Integrity Monitor + * @return + * @throws IntegrityMonitorException + */ + private static DroolsPDPIntegrityMonitor makeMonitor(String resourceName, Properties properties) + throws IntegrityMonitorException { + + try { + return new DroolsPDPIntegrityMonitor(resourceName, properties); + + } catch (Exception e) { + throw new IntegrityMonitorException(e); + } + } + + /** + * Makes a rest server for the Integrity Monitor. + * + * @param testHost host name + * @param testPort port + * @param properties properties used to configure the rest server + * @throws IntegrityMonitorException + */ + private static void makeRestServer(String testHost, String testPort, Properties properties) + throws IntegrityMonitorException { + + try { + logger.info("init: Starting HTTP server, addr= {}", testHost + ":" + testPort); + + IntegrityMonitorRestServer server = new IntegrityMonitorRestServer(); + server.init(properties); + + } catch (Exception e) { + logger.error("init: Caught Exception attempting to start server on testPort= {} message:", testPort, e); + throw new IntegrityMonitorException(e); + } + } + + /** + * Gets the properties from the property file. + * + * @param configDir directory containing the property file + * @return the properties + * @throws IntegrityMonitorException + */ + private static Properties getProperties(String configDir) throws IntegrityMonitorException { + try { + return PropertyUtil.getProperties(configDir + "/" + PROPERTIES_NAME); + + } catch (IOException e) { + throw new IntegrityMonitorException(e); + } + } + + /** + * Checks that a property is defined. + * + * @param props set of properties + * @param name name of the property to check + * @throws IntegrityMonitorException + */ + private static void checkPropError(Properties props, String name) throws IntegrityMonitorException { + String val = props.getProperty(name); + if (val == null) { + missingProperty(name); + } + + logPropertyValue(name, val); + } + + /** + * Checks a property's value to verify that it matches the expected value. If the property is + * not defined, then it is added to the property set, with the expected value. Logs an error if + * the property is defined, but does not have the expected value. + * + * @param props set of properties + * @param name name of the property to check + * @param expected expected/default value + */ + private static void addDefaultPropError(Properties props, String name, String expected) { + String val = props.getProperty(name); + if (val == null) { + props.setProperty(name, expected); + + } else if (!val.equals(expected)) { + logger.error(INVALID_PROPERTY_VALUE, name, expected); + } + + logPropertyValue(name, val); + } + + /** + * Checks a property's value to verify that it matches the expected value. If the property is + * not defined, then it is added to the property set, with the expected value. Logs a warning if + * the property is defined, but does not have the expected value. + * + * @param props set of properties + * @param name name of the property to check + * @param expected expected/default value + */ + private static void addDefaultPropWarn(Properties props, String name, String dflt) { + String val = props.getProperty(name); + if (val == null) { + props.setProperty(name, dflt); + + } else if (!val.equals(dflt)) { + logger.warn(INVALID_PROPERTY_VALUE, name, dflt); + } + + logPropertyValue(name, val); + } + + /** + * Run tests (audits) unique to Drools PDP VM (Database + Repository) + */ + @Override + public void subsystemTest() throws IntegrityMonitorException { + logger.info("DroolsPDPIntegrityMonitor.subsystemTest called"); + + // clear all responses (non-null values indicate an error) + for (AuditBase audit : audits) { + audit.setResponse(null); + } + + // invoke all of the audits + for (AuditBase audit : audits) { + try { + // invoke the audit (responses are stored within the audit object) + audit.invoke(subsystemTestProperties); + } catch (Exception e) { + logger.error("{} audit error", audit.getName(), e); + if (audit.getResponse() == null) { + // if there is no current response, use the exception message + audit.setResponse(e.getMessage()); + } + } + } + + // will contain list of subsystems where the audit failed + String responseMsg = ""; + + // Loop through all of the audits, and see which ones have failed. + // NOTE: response information is stored within the audit objects + // themselves -- only one can run at a time. + for (AuditBase audit : audits) { + String response = audit.getResponse(); + if (response != null) { + // the audit has failed -- add subsystem and + // and 'responseValue' with the new information + responseMsg = responseMsg.concat("\n" + audit.getName() + ": " + response); + } + } + + if (!responseMsg.isEmpty()) { + throw new IntegrityMonitorException(responseMsg); + } + } + + /* ============================================================ */ + + /** + * This is the base class for audits invoked in 'subsystemTest' + */ + public abstract static class AuditBase { + // name of the audit + protected String name; + + // non-null indicates the error response + protected String response; + + /** + * Constructor - initialize the name, and clear the initial response + * + * @param name name of the audit + */ + public AuditBase(String name) { + this.name = name; + this.response = null; + } + + /** + * @return the name of this audit + */ + public String getName() { + return name; + } + + /** + * @return the response String (non-null indicates the error message) + */ + public String getResponse() { + return response; + } + + /** + * Set the response string to the specified value + * + * @param value the new value of the response string (null = no errors) + */ + public void setResponse(String value) { + response = value; + } + + /** + * Abstract method to invoke the audit + * + * @param persistenceProperties Used for DB access + * @throws Exception passed in by the audit + */ + abstract void invoke(Properties persistenceProperties) throws Exception; + } + + public static class IntegrityMonitorRestServer implements Startable { + protected volatile HttpServletServer server = null; + protected volatile Properties integrityMonitorRestServerProperties = null; + + public void init(Properties props) { + this.integrityMonitorRestServerProperties = props; + this.start(); + } + + @Override + public boolean start() { + try { + List<HttpServletServer> servers = + IndexedHttpServletServerFactory.getInstance().build(integrityMonitorRestServerProperties); + + if (!servers.isEmpty()) { + server = servers.get(0); + + waitServerStart(); + } + } catch (Exception e) { + logger.error("Exception building servers", e); + return false; + } + + return true; + } + + private void waitServerStart() { + try { + server.waitedStart(5); + } catch (Exception e) { + logger.error("Exception waiting for servers to start: ", e); + } + } + + @Override + public boolean stop() { + try { + server.stop(); + } catch (Exception e) { + logger.error("Exception during stop", e); + } + + return true; + } + + @Override + public void shutdown() { + this.stop(); + } + + @Override + public synchronized boolean isAlive() { + return this.integrityMonitorRestServerProperties != null; + } + } + + public static DroolsPDPIntegrityMonitor getInstance() throws IntegrityMonitorException { + if (logger.isDebugEnabled()) { + logger.debug("getInstance() called"); + } + if (im == null) { + String msg = "No DroolsPDPIntegrityMonitor instance exists." + + " Please use the method DroolsPDPIntegrityMonitor init(String configDir)"; + throw new IntegrityMonitorException(msg); + } else { + return im; + } + } } diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementProperties.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementProperties.java index 192acc16..38356226 100644 --- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementProperties.java +++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementProperties.java @@ -22,65 +22,71 @@ package org.onap.policy.drools.statemanagement; import java.util.Properties; -import org.onap.policy.drools.properties.PolicyProperties; +import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class StateManagementProperties { - // get an instance of logger - private static final Logger logger = LoggerFactory.getLogger(StateManagementProperties.class); - - public static final String NODE_NAME = "resource.name"; - public static final String NODE_TYPE = "node_type"; - public static final String SITE_NAME = "site_name"; - - public static final String DB_DRIVER = "javax.persistence.jdbc.driver"; - public static final String DB_URL = "javax.persistence.jdbc.url"; - public static final String DB_USER = "javax.persistence.jdbc.user"; - public static final String DB_PWD = "javax.persistence.jdbc.password"; - - public static final String TEST_SERVICES = PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES; - public static final String TEST_SERVICES_DEFAULT = "TEST"; - public static final String TEST_HOST = TEST_SERVICES + "." + TEST_SERVICES_DEFAULT + PolicyProperties.PROPERTY_HTTP_HOST_SUFFIX; - public static final String TEST_PORT = TEST_SERVICES + "." + TEST_SERVICES_DEFAULT + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX; - public static final String TEST_REST_CLASSES = TEST_SERVICES + "." + TEST_SERVICES_DEFAULT + PolicyProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX; - public static final String TEST_REST_CLASSES_DEFAULT = IntegrityMonitorRestManager.class.getName(); - public static final String TEST_MANAGED = TEST_SERVICES + "." + TEST_SERVICES_DEFAULT + PolicyProperties.PROPERTY_MANAGED_SUFFIX; - public static final String TEST_MANAGED_DEFAULT = "false"; - public static final String TEST_SWAGGER = TEST_SERVICES + "." + TEST_SERVICES_DEFAULT + PolicyProperties.PROPERTY_HTTP_SWAGGER_SUFFIX; - public static final String TEST_SWAGGER_DEFAULT = "true"; - public static final String RESOURCE_NAME = "resource.name"; - public static final String FP_MONITOR_INTERVAL = "fp_monitor_interval"; - public static final String FAILED_COUNTER_THRESHOLD = "failed_counter_threshold"; - public static final String TEST_TRANS_INTERVAL = "test_trans_interval"; - public static final String WRITE_FPC_INTERVAL = "write_fpc_interval"; - public static final String DEPENDENCY_GROUPS = "dependency_groups"; - - private static Properties properties = null; + // get an instance of logger + private static final Logger logger = LoggerFactory.getLogger(StateManagementProperties.class); - private StateManagementProperties(){ - } - /* - * Initialize the parameter values from the feature-state-management.properties file values - * - * This is designed so that the Properties object is obtained from the feature-state-management.properties - * file and then is passed to this method to initialize the value of the parameters. - * This allows the flexibility of JUnit tests using getProperties(filename) to get the - * properties while runtime methods can use getPropertiesFromClassPath(filename). - * - */ - public static void initProperties (Properties prop){ - logger.info("StateManagementProperties.initProperties(Properties): entry"); - logger.info("\n\nStateManagementProperties.initProperties: Properties = \n{}\n\n", prop); - - properties = prop; - } + public static final String NODE_NAME = "resource.name"; + public static final String NODE_TYPE = "node_type"; + public static final String SITE_NAME = "site_name"; - public static String getProperty(String key){ - return properties.getProperty(key); - } - - public static Properties getProperties() { - return properties; - } + public static final String DB_DRIVER = "javax.persistence.jdbc.driver"; + public static final String DB_URL = "javax.persistence.jdbc.url"; + public static final String DB_USER = "javax.persistence.jdbc.user"; + public static final String DB_PWD = "javax.persistence.jdbc.password"; + + public static final String TEST_SERVICES = PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES; + public static final String TEST_SERVICES_DEFAULT = "TEST"; + public static final String TEST_HOST = + TEST_SERVICES + "." + TEST_SERVICES_DEFAULT + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX; + public static final String TEST_PORT = + TEST_SERVICES + "." + TEST_SERVICES_DEFAULT + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX; + public static final String TEST_REST_CLASSES = + TEST_SERVICES + "." + TEST_SERVICES_DEFAULT + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX; + public static final String TEST_REST_CLASSES_DEFAULT = IntegrityMonitorRestManager.class.getName(); + public static final String TEST_MANAGED = + TEST_SERVICES + "." + TEST_SERVICES_DEFAULT + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX; + public static final String TEST_MANAGED_DEFAULT = "false"; + public static final String TEST_SWAGGER = + TEST_SERVICES + "." + TEST_SERVICES_DEFAULT + PolicyEndPointProperties.PROPERTY_HTTP_SWAGGER_SUFFIX; + public static final String TEST_SWAGGER_DEFAULT = "true"; + public static final String RESOURCE_NAME = "resource.name"; + public static final String FP_MONITOR_INTERVAL = "fp_monitor_interval"; + public static final String FAILED_COUNTER_THRESHOLD = "failed_counter_threshold"; + public static final String TEST_TRANS_INTERVAL = "test_trans_interval"; + public static final String WRITE_FPC_INTERVAL = "write_fpc_interval"; + public static final String DEPENDENCY_GROUPS = "dependency_groups"; + + private static Properties properties = null; + + private StateManagementProperties() {} + + /* + * Initialize the parameter values from the feature-state-management.properties file values + * + * This is designed so that the Properties object is obtained from the + * feature-state-management.properties file and then is passed to this method to initialize the + * value of the parameters. This allows the flexibility of JUnit tests using + * getProperties(filename) to get the properties while runtime methods can use + * getPropertiesFromClassPath(filename). + * + */ + public static void initProperties(Properties prop) { + logger.info("StateManagementProperties.initProperties(Properties): entry"); + logger.info("\n\nStateManagementProperties.initProperties: Properties = \n{}\n\n", prop); + + properties = prop; + } + + public static String getProperty(String key) { + return properties.getProperty(key); + } + + public static Properties getProperties() { + return properties; + } } |