import javax.validation.constraints.NotNull;
import org.onap.policy.common.capabilities.Lockable;
import org.onap.policy.common.im.AllSeemsWellException;
+import org.onap.policy.common.im.IntegrityMonitorException;
import org.onap.policy.common.im.StateChangeNotifier;
+import org.onap.policy.common.im.StateManagementException;
import org.onap.policy.common.utils.services.OrderedService;
/**
* will take a value of coldstandby.
*
* @param resourceName resource name
- * @throws Exception exception
+ * @throws StateManagementException exception
*/
- void disableFailed(String resourceName) throws Exception;
+ void disableFailed(String resourceName) throws StateManagementException;
/**
* This method moves the X.731 Operational State for this resource into a value of disabled and
* the Availability Status to a value of failed. As a consequence the Standby Status value will
* take a value of coldstandby.
*
- * @throws Exception exception
+ * @throws StateManagementException exception
*/
- void disableFailed() throws Exception;
+ void disableFailed() throws StateManagementException;
/**
* This method moves the X.731 Standby Status for this resource from hotstandby to
* value is null, it will move to providingservice assuming the Operational State is enabled and
* Administrative State is unlocked.
*
- * @throws Exception exception
+ * @throws IntegrityMonitorException exception
*/
- void promote() throws Exception;
+ void promote() throws IntegrityMonitorException;
/**
* This method moves the X.731 Standby Status for this resource from providingservice to
* hotstandby. If the current value is null, it will move to hotstandby assuming the Operational
* State is enabled and Administrative State is unlocked. Else, it will move to coldstandby
*
- * @throws Exception exception
+ * @throws StateManagementException exception
*/
- void demote() throws Exception;
+ void demote() throws StateManagementException;
/**
* Returns the resourceName associated with this instance of the
* Only call promote if it is not already in the right state. Don't worry about
* synching the lower level topic endpoint states. That is done by the
* refreshStateAudit.
- * Note that we need to fetch the session list from 'mostRecentPrimary'
- * at this point -- soon, 'mostRecentPrimary' will be set to this host.
*/
- //this.sessions = mostRecentPrimary.getSessions();
stateManagementFeature.promote();
}
} catch (Exception e) {
* current host.
*/
UUID key = oldHost.uuid;
- for (int count = new Random().nextInt(rb.testServers.size() - 1); count >= 0; count -= 1) {
+ /*
+ * Disabling sonar, because this Random() is not used for security purposes.
+ */
+ int randomStart = new Random().nextInt(rb.testServers.size() - 1); // NOSONAR
+ for (int count = randomStart; count >= 0; count -= 1) {
key = rb.testServers.higherKey(key);
if (key == null) {
// wrap to the beginning of the list
// add any additional servlets
for (ServerPoolApi feature : ServerPoolApi.impl.getList()) {
- Collection<Class<?>> classes = feature.servletClasses();
- if (classes != null) {
- for (Class<?> clazz : classes) {
- restServer.addServletClass(null, clazz.getName());
- }
+ for (Class<?> clazz : feature.servletClasses()) {
+ restServer.addServletClass(null, clazz.getName());
}
}
package org.onap.policy.drools.serverpool;
import java.util.Collection;
+import java.util.Collections;
import org.onap.policy.common.utils.services.OrderedService;
import org.onap.policy.common.utils.services.OrderedServiceImpl;
* @return a Collection of classes implementing REST methods
*/
public default Collection<Class<?>> servletClasses() {
- return null;
+ return Collections.emptyList();
}
/**
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
private List<CountDownLatch> restoreBucketDroolsSessions() {
List<CountDownLatch> sessionLatches = new LinkedList<>();
for (Map.Entry<String, ReceiverSessionBucketData> entry : sessionData.entrySet()) {
- String sessionName = entry.getKey();
- ReceiverSessionBucketData rsbd = entry.getValue();
+ restoreBucketDroolsSession(sessionLatches, entry);
+ }
+ return sessionLatches;
+ }
- PolicySession policySession = detmPolicySession(sessionName);
- if (policySession == null) {
- logger.error(RESTORE_BUCKET_ERROR
- + "Can't find PolicySession{}", sessionName);
- continue;
- }
+ private void restoreBucketDroolsSession(List<CountDownLatch> sessionLatches,
+ Entry<String, ReceiverSessionBucketData> entry) {
- final Map<?, ?> droolsObjects = deserializeMap(sessionName, rsbd, policySession);
- if (droolsObjects == null) {
- continue;
- }
+ String sessionName = entry.getKey();
+ ReceiverSessionBucketData rsbd = entry.getValue();
- // if we reach this point, we have decoded the persistent data
+ PolicySession policySession = detmPolicySession(sessionName);
+ if (policySession == null) {
+ logger.error(RESTORE_BUCKET_ERROR
+ + "Can't find PolicySession{}", sessionName);
+ return;
+ }
- // signal when restore is complete
- final CountDownLatch sessionLatch = new CountDownLatch(1);
+ final Map<?, ?> droolsObjects = deserializeMap(sessionName, rsbd, policySession);
+ if (droolsObjects == null) {
+ return;
+ }
- // 'KieSession' object
- final KieSession kieSession = policySession.getKieSession();
+ // if we reach this point, we have decoded the persistent data
- // run the following within the Drools session thread
- DroolsRunnable insertDroolsObjects = () -> {
- try {
- // insert all of the Drools objects into the session
- for (Object droolsObj : droolsObjects.keySet()) {
- kieSession.insert(droolsObj);
- }
- } finally {
- // signal completion
- sessionLatch.countDown();
+ // signal when restore is complete
+ final CountDownLatch sessionLatch = new CountDownLatch(1);
+
+ // 'KieSession' object
+ final KieSession kieSession = policySession.getKieSession();
+
+ // run the following within the Drools session thread
+ DroolsRunnable insertDroolsObjects = () -> {
+ try {
+ // insert all of the Drools objects into the session
+ for (Object droolsObj : droolsObjects.keySet()) {
+ kieSession.insert(droolsObj);
}
- };
- kieSession.insert(insertDroolsObjects);
+ } finally {
+ // signal completion
+ sessionLatch.countDown();
+ }
+ };
+ kieSession.insert(insertDroolsObjects);
- // add this to the set of 'CountDownLatch's we are waiting for
- sessionLatches.add(sessionLatch);
- }
- return sessionLatches;
+ // add this to the set of 'CountDownLatch's we are waiting for
+ sessionLatches.add(sessionLatch);
}
private PolicySession detmPolicySession(String sessionName) {
* Each 'AdapterImpl' instance has it's own class object, making it a
* singleton. There is only a single 'Adapter' class object, and all
* 'AdapterImpl' classes are derived from it.
+ *
+ * Sonar thinks this field isn't used. However, it's value is actually
+ * retrieved via Whitebox, below. Thus it is marked "protected" instead
+ * of "private" to avoid the sonar complaint.
*/
- private static AdapterImpl adapter = null;
+ protected static AdapterImpl adapter = null;
// this is the adapter index
private int index;
boolean rval = false;
ClassLoader myClassLoader = AdapterImpl.class.getClassLoader();
for (Object o : objects) {
- Class clazz = o.getClass();
+ Class<?> clazz = o.getClass();
ClassLoader objClassLoader = clazz.getClassLoader();
try {
* @param persistenceProperties Used for DB access
* @throws Exception passed in by the audit
*/
- abstract void invoke(Properties persistenceProperties) throws Exception;
+ abstract void invoke(Properties persistenceProperties) throws IntegrityMonitorException;
}
public static class IntegrityMonitorRestServer implements Startable {
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.onap.policy.common.im.IntegrityMonitorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @param properties properties to be passed to the audit
*/
@Override
- public void invoke(Properties properties) throws IOException, InterruptedException {
+ public void invoke(Properties properties) throws IntegrityMonitorException {
logger.debug("Running 'RepositoryAudit.invoke'");
InvokeData data = new InvokeData();
return;
}
- // Run audit for first nexus repository
- logger.debug("Running read-only audit on first nexus repository: repository");
- runAudit(data);
+ try {
+ // Run audit for first nexus repository
+ logger.debug("Running read-only audit on first nexus repository: repository");
+ runAudit(data);
- // set of indices for supported nexus repos (ex: repository2 -> 2)
- // TreeSet is used to maintain order so repos can be audited in numerical order
- TreeSet<Integer> repoIndices = countAdditionalNexusRepos();
- logger.debug("Additional nexus repositories: {}", repoIndices);
+ // set of indices for supported nexus repos (ex: repository2 -> 2)
+ // TreeSet is used to maintain order so repos can be audited in numerical
+ // order
+ TreeSet<Integer> repoIndices = countAdditionalNexusRepos();
+ logger.debug("Additional nexus repositories: {}", repoIndices);
- // Run audit for remaining 'numNexusRepos' repositories
- for (int index : repoIndices) {
- logger.debug("Running read-only audit on nexus repository = repository{}", index);
+ // Run audit for remaining 'numNexusRepos' repositories
+ for (int index : repoIndices) {
+ logger.debug("Running read-only audit on nexus repository = repository{}", index);
- data = new InvokeData(index);
- data.initIsActive();
+ data = new InvokeData(index);
+ data.initIsActive();
- if (data.isActive) {
- runAudit(data);
+ if (data.isActive) {
+ runAudit(data);
+ }
}
+
+ } catch (IOException e) {
+ throw new IntegrityMonitorException(e);
+
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new IntegrityMonitorException(e);
}
}
import java.io.IOException;
import java.util.Properties;
import org.onap.policy.common.im.AllSeemsWellException;
+import org.onap.policy.common.im.IntegrityMonitorException;
import org.onap.policy.common.im.StateChangeNotifier;
import org.onap.policy.common.im.StateManagement;
+import org.onap.policy.common.im.StateManagementException;
import org.onap.policy.drools.core.PolicySessionFeatureApi;
import org.onap.policy.drools.features.PolicyEngineFeatureApi;
import org.onap.policy.drools.utils.PropertyUtil;
* {@inheritDoc}.
*/
@Override
- public void disableFailed(String resourceName) throws Exception {
+ public void disableFailed(String resourceName) throws StateManagementException {
stateManagement.disableFailed(resourceName);
}
* {@inheritDoc}.
*/
@Override
- public void disableFailed() throws Exception {
+ public void disableFailed() throws StateManagementException {
stateManagement.disableFailed();
}
* {@inheritDoc}.
*/
@Override
- public void promote() throws Exception {
+ public void promote() throws IntegrityMonitorException {
stateManagement.promote();
}
* {@inheritDoc}.
*/
@Override
- public void demote() throws Exception {
+ public void demote() throws StateManagementException {
stateManagement.demote();
}
import java.io.File;
import java.io.FileInputStream;
-import java.io.IOException;
import java.util.Properties;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.common.im.IntegrityMonitorException;
import org.onap.policy.common.im.StateManagement;
import org.onap.policy.drools.core.PolicySessionFeatureApi;
import org.onap.policy.drools.statemanagement.DbAudit;
repositoryAudit.invoke(fsmProperties);
//Should not throw an IOException in Linux Foundation env
- assertTrue(true);
- } catch (IOException e) {
+
+ } catch (IntegrityMonitorException e) {
//Note: this catch is here because in a local environment mvn will not run in
//in the temp directory
logger.debug("testSubsytemTest RepositoryAudit IOException", e);
- } catch (InterruptedException e) {
- assertTrue(false);
- logger.debug("testSubsytemTest RepositoryAudit InterruptedException", e);
}
/* ****************Db Audit Test. ************** */
logger.debug("\n\ntestStateManagementOperation: DB Audit\n\n");
- try {
- DbAudit dbAudit = (DbAudit) DbAudit.getInstance();
- dbAudit.invoke(fsmProperties);
-
- assertTrue(true);
- } catch (Exception e) {
- assertTrue(false);
- logger.debug("testSubsytemTest DbAudit exception", e);
- }
+ DbAudit dbAudit = (DbAudit) DbAudit.getInstance();
+ dbAudit.invoke(fsmProperties);
/* ************IntegrityMonitorRestManager Test. ************ */
logger.debug("\n\ntestStateManagementOperation: IntegrityMonitorRestManager\n\n");
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.onap.policy.common.utils.services.FeatureApiUtils;
import org.onap.policy.drools.controller.internal.MavenDroolsController;
import org.onap.policy.drools.controller.internal.NullDroolsController;
import org.onap.policy.drools.features.DroolsControllerFeatureApi;
/* new drools controller */
- DroolsController controller = null;
- for (DroolsControllerFeatureApi feature: getProviders()) {
- try {
- controller = feature.beforeInstance(properties,
- newGroupId, newArtifactId, newVersion,
+ DroolsController controller = applyBeforeInstance(properties, newGroupId, newArtifactId, newVersion,
decoderConfigurations, encoderConfigurations);
- if (controller != null) {
- logger.info("feature {} ({}) beforeInstance() has intercepted drools controller {}:{}:{}",
- feature.getName(), feature.getSequenceNumber(),
- newGroupId, newArtifactId, newVersion);
- break;
- }
- } catch (RuntimeException r) {
- logger.error("feature {} ({}) beforeInstance() of drools controller {}:{}:{} failed",
- feature.getName(), feature.getSequenceNumber(),
- newGroupId, newArtifactId, newVersion, r);
- }
- }
if (controller == null) {
controller = new MavenDroolsController(newGroupId, newArtifactId, newVersion, decoderConfigurations,
droolsControllers.put(controllerId, controller);
}
+ final DroolsController controllerFinal = controller;
+
+ FeatureApiUtils.apply(getProviders(),
+ feature -> feature.afterInstance(controllerFinal, properties),
+ (feature, ex) -> logger.error("feature {} ({}) afterInstance() of drools controller {}:{}:{} failed",
+ feature.getName(), feature.getSequenceNumber(),
+ newGroupId, newArtifactId, newVersion, ex));
+
+ return controller;
+ }
+
+ private DroolsController applyBeforeInstance(Properties properties, String newGroupId, String newArtifactId,
+ String newVersion, List<TopicCoderFilterConfiguration> decoderConfigurations,
+ List<TopicCoderFilterConfiguration> encoderConfigurations) {
+ DroolsController controller = null;
for (DroolsControllerFeatureApi feature: getProviders()) {
try {
- feature.afterInstance(controller, properties);
+ controller = feature.beforeInstance(properties,
+ newGroupId, newArtifactId, newVersion,
+ decoderConfigurations, encoderConfigurations);
+ if (controller != null) {
+ logger.info("feature {} ({}) beforeInstance() has intercepted drools controller {}:{}:{}",
+ feature.getName(), feature.getSequenceNumber(),
+ newGroupId, newArtifactId, newVersion);
+ break;
+ }
} catch (RuntimeException r) {
- logger.error("feature {} ({}) afterInstance() of drools controller {}:{}:{} failed",
+ logger.error("feature {} ({}) beforeInstance() of drools controller {}:{}:{} failed",
feature.getName(), feature.getSequenceNumber(),
newGroupId, newArtifactId, newVersion, r);
}
}
-
return controller;
}
/* 5. Open the engine for dynamic configuration */
PolicyEngineConstants.getManager().open();
- logger.info(String.format(MessageConstants.START_SUCCESS_MSG, MessageConstants.POLICY_DROOLS_PDP));
+ if (logger.isInfoEnabled()) {
+ logger.info(String.format(MessageConstants.START_SUCCESS_MSG, MessageConstants.POLICY_DROOLS_PDP));
+ }
}
private static void setSystemProperties() {