aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/ECOMPLoggingContext.java113
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java10
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java104
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/EelfLogger.java3
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger4J.java32
-rw-r--r--common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/SystemOutLogger.java3
-rw-r--r--integrity-audit/src/main/java/org/openecomp/policy/common/ia/DbAudit.java2
-rw-r--r--integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/AuditPeriodTest.java5
-rw-r--r--integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/DbAuditCompareEntriesTest.java5
-rw-r--r--integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/DbAuditTest.java5
-rw-r--r--integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/DbDAOTest.java10
-rw-r--r--integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/IntegrityAuditDesignationTest.java22
-rw-r--r--integrity-monitor/config/policyLogger.properties44
-rw-r--r--integrity-monitor/src/main/java/org/openecomp/policy/common/im/IntegrityMonitor.java176
-rw-r--r--integrity-monitor/src/main/java/org/openecomp/policy/common/im/StateManagement.java169
-rw-r--r--integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/IntegrityMonitorTest.java118
-rw-r--r--integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/StateManagementTest.java7
-rw-r--r--integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/StateTransitionTest.java6
18 files changed, 593 insertions, 241 deletions
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/ECOMPLoggingContext.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/ECOMPLoggingContext.java
index 71e75a11..e6e2b1ca 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/ECOMPLoggingContext.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/ECOMPLoggingContext.java
@@ -75,6 +75,10 @@ public class ECOMPLoggingContext {
private static final String THREAD_ID = "threadId";
private static final String SERVER_NAME = "serverName";
private static final String SERVICE_NAME = "serviceName";
+ private static final String PARTNER_NAME = "partnerName";
+ private static final String STATUS_CODE = "statusCode";
+ private static final String TARGET_ENTITY = "targetEntity";
+ private static final String TARGET_SERVICE_NAME = "targetServiceName";
private static final String INSTANCE_UUID = "instanceUuid";
private static final String SEVERITY = "severity";
private static final String SERVER_IP_ADDRESS = "serverIpAddress";
@@ -123,6 +127,11 @@ public class ECOMPLoggingContext {
MDC.clear();
baseContext.context.transferTo(context);
transactionStartTime = baseContext.transactionStartTime;
+ setServiceName("POLICY");
+ setPartnerName("USER");
+ setStatusCode("COMPLETE");
+ setTargetEntity("POLICY");
+ setTargetServiceName("PE Process");
}
/**
@@ -253,6 +262,70 @@ public class ECOMPLoggingContext {
}
/**
+ * Set the value for the data item with key "partnerName"
+ *
+ * @param id
+ */
+ public void setPartnerName(String name) {
+ context.put(PARTNER_NAME, name);
+ }
+ /**
+ * Get the value for the data item with key "partnerName"
+ * @return current value, or empty string if not set
+ */
+ public String getPartnerName() {
+ return context.get(PARTNER_NAME, "");
+ }
+
+ /**
+ * Set the value for the data item with key "statusCode"
+ *
+ * @param id
+ */
+ public void setStatusCode(String name) {
+ context.put(STATUS_CODE, name);
+ }
+ /**
+ * Get the value for the data item with key "statusCode"
+ * @return current value, or empty string if not set
+ */
+ public String getStatusCode() {
+ return context.get(STATUS_CODE, "");
+ }
+
+ /**
+ * Set the value for the data item with key "targetEntity"
+ *
+ * @param id
+ */
+ public void setTargetEntity(String name) {
+ context.put(TARGET_ENTITY, name);
+ }
+ /**
+ * Get the value for the data item with key "targetEntity"
+ * @return current value, or empty string if not set
+ */
+ public String getTargetEntity() {
+ return context.get(TARGET_ENTITY, "");
+ }
+
+ /**
+ * Set the value for the data item with key "targetServiceName"
+ *
+ * @param id
+ */
+ public void setTargetServiceName(String name) {
+ context.put(TARGET_SERVICE_NAME, name);
+ }
+ /**
+ * Get the value for the data item with key "targetServiceName"
+ * @return current value, or empty string if not set
+ */
+ public String getTargetServiceName() {
+ return context.get(TARGET_SERVICE_NAME, "");
+ }
+
+ /**
* Set the value for the data item with key "instanceUuid"
*
* @param id
@@ -433,17 +506,17 @@ public class ECOMPLoggingContext {
*/
public void setTransactionElapsedTime(Instant transactionEndTime) {
- long ns = Duration.between(transactionStartTime, transactionEndTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
+ long ns = Duration.between(transactionStartTime, transactionEndTime).toMillis();
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
- if(ns < 1){
- ns = Duration.between(transactionStartTime, transactionEndTime).toMillis();
- unit = " milliseconds";
- }
- context.put(TRANSACTION_ELAPSED_TIME, ns + unit);
+ //if(ns < 1){
+ //ns = Duration.between(transactionStartTime, transactionEndTime).toMillis();
+ //unit = " milliseconds";
+ //}
+ context.put(TRANSACTION_ELAPSED_TIME, ns); // + unit);
}
/**
@@ -506,17 +579,17 @@ public class ECOMPLoggingContext {
*/
public void setMetricElapsedTime(Instant metricEndTime) {
- long ns = Duration.between(metricStartTime, metricEndTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
+ long ns = Duration.between(metricStartTime, metricEndTime).toMillis();
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
- if(ns < 1){
- ns = Duration.between(metricStartTime, metricEndTime).toMillis();
- unit = " milliseconds";
- }
- context.put(METRIC_ELAPSED_TIME, ns + unit);
+ //if(ns < 1){
+ //ns = Duration.between(metricStartTime, metricEndTime).toMillis();
+ //unit = " milliseconds";
+ //}
+ context.put(METRIC_ELAPSED_TIME, ns); // + unit);
}
/**
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java
index a2a0b783..a839ea16 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/Configuration.java
@@ -43,6 +43,16 @@ public interface Configuration extends com.att.eelf.configuration.Configuration
*/
public String PARTNER_NAME = "PartnerName";
+ /**
+ * Target Entity
+ */
+ public String TARGET_ENTITY = "TargetEntity";
+
+ /**
+ * Target service name
+ */
+ public String TARGET_SERVICE_NAME = "TargetServiceName";
+
/**
* High level success or failure (COMPLETE or ERROR)
*/
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java
index 624ba580..ed03f9a9 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/eelf/PolicyLogger.java
@@ -125,7 +125,13 @@ public class PolicyLogger {
}
if(component != null && component.equalsIgnoreCase("DROOLS")){
+ MDC.put(TARGET_ENTITY, "POLICY");
+ MDC.put(TARGET_SERVICE_NAME, "drools evaluate rule");
return postMDCInfoForEvent(transId, new DroolsPDPMDCInfo());
+ } else {
+ // For Xacml
+ MDC.put(TARGET_ENTITY, "POLICY");
+ MDC.put(TARGET_SERVICE_NAME, "PE Process");
}
MDC.put(MDC_REMOTE_HOST, "");
@@ -140,16 +146,16 @@ public class PolicyLogger {
}
Instant startTime = Instant.now();
Instant endTime = Instant.now();
- long ns = Duration.between(startTime, endTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
-
- if(ns < 1){
- ns = Duration.between(startTime, endTime).toMillis();
- unit = " milliseconds";
- }
+ long ns = Duration.between(startTime, endTime).toMillis(); // use millisecond as default and remove unit from log
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
+
+ //if(ns < 1){
+ //ns = Duration.between(startTime, endTime).toMillis();
+ //unit = " milliseconds";
+ //}
MDC.put(MDC_INSTANCE_UUID, "");
MDC.put(MDC_ALERT_SEVERITY, "");
@@ -161,11 +167,11 @@ public class PolicyLogger {
//set default values for these required fields below, they can be overridden
formatedTime = sdf.format(Date.from(endTime));
MDC.put(END_TIME_STAMP, formatedTime);
- MDC.put(ELAPSED_TIME, ns + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
MDC.put(PARTNER_NAME, "N/A");
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
MDC.put(RESPONSE_CODE, "N/A");
MDC.put(RESPONSE_DESCRIPTION, "N/A");
@@ -203,16 +209,16 @@ public class PolicyLogger {
}
Instant startTime = Instant.now();
Instant endTime = Instant.now();
- long ns = Duration.between(startTime, endTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
+ long ns = Duration.between(startTime, endTime).toMillis(); // use millisecond as default and remove unit from log
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
- if(ns < 1){
- ns = Duration.between(startTime, endTime).toMillis();
- unit = " milliseconds";
- }
+ //if(ns < 1){
+ //ns = Duration.between(startTime, endTime).toMillis();
+ //unit = " milliseconds";
+ //}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+00:00");
@@ -222,7 +228,7 @@ public class PolicyLogger {
//set default values for these required fields below, they can be overridden
formatedTime = sdf.format(Date.from(endTime));
MDC.put(END_TIME_STAMP, formatedTime);
- MDC.put(ELAPSED_TIME, ns + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
return transId;
}
@@ -234,16 +240,16 @@ public class PolicyLogger {
Instant startTime = Instant.now();
Instant endTime = Instant.now();
- long ns = Duration.between(startTime, endTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
-
- if(ns < 1){
- ns = Duration.between(startTime, endTime).toMillis();
- unit = " milliseconds";
- }
+ long ns = Duration.between(startTime, endTime).toMillis();
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
+
+ //if(ns < 1){
+ //ns = Duration.between(startTime, endTime).toMillis();
+ //unit = " milliseconds";
+ //}
MDC.put(MDC_INSTANCE_UUID, "");
MDC.put(MDC_ALERT_SEVERITY, "");
@@ -255,11 +261,11 @@ public class PolicyLogger {
//set default values for these required fields below, they can be overridden
formatedTime = sdf.format(Date.from(endTime));
MDC.put(END_TIME_STAMP, formatedTime);
- MDC.put(ELAPSED_TIME, ns + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
MDC.put(PARTNER_NAME, "N/A");
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
MDC.put(RESPONSE_CODE, "N/A");
MDC.put(RESPONSE_DESCRIPTION, "N/A");
@@ -315,7 +321,7 @@ public class PolicyLogger {
}
MDC.put(MDC_INSTANCE_UUID, "");
MDC.put(MDC_ALERT_SEVERITY, "");
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
return transId;
@@ -634,7 +640,7 @@ public class PolicyLogger {
* @param arg0
*/
public static void audit(String className, Object arg0) {
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
MDC.put(CLASS_NAME, className);
auditLogger.info("" + arg0);
}
@@ -644,7 +650,7 @@ public class PolicyLogger {
* @param arg0
*/
public static void audit(Object arg0) {
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
MDC.put(CLASS_NAME, "");
auditLogger.info("" + arg0);
}
@@ -748,7 +754,7 @@ public class PolicyLogger {
*/
public static void recordAuditEventStart(String eventId) {
- MDC.put(STATUS_CODE, "N/A");
+ MDC.put(STATUS_CODE, "COMPLETE");
postMDCInfoForEvent(eventId);
if(eventTracker == null){
@@ -955,21 +961,21 @@ public class PolicyLogger {
MDC.put(RESPONSE_CODE, "N/A");
MDC.put(RESPONSE_DESCRIPTION, "N/A");
- long ns = Duration.between(startTime, endTime).getSeconds();
- String unit = " Seconds";
- if(ns == 1){
- unit = " Second";
- }
+ long ns = Duration.between(startTime, endTime).toMillis();
+ //String unit = " Seconds";
+ //if(ns == 1){
+ //unit = " Second";
+ //}
- if(ns < 1){
- ns = Duration.between(startTime, endTime).toMillis();
- unit = " milliseconds";
- }
+ //if(ns < 1){
+ //ns = Duration.between(startTime, endTime).toMillis();
+ //unit = " milliseconds";
+ //}
- MDC.put(ELAPSED_TIME, ns + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
auditLogger.info(MessageCodes.RULE_AUDIT_START_END_INFO,
- serviceName, rule, startTime.toString(), endTime.toString(), ns+unit, policyVersion);
+ serviceName, rule, startTime.toString(), endTime.toString(), Long.toString(ns), policyVersion);
//--- remove the record from the concurrentHashMap
if(eventTracker != null){
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/EelfLogger.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/EelfLogger.java
index 6e74b94c..31c17554 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/EelfLogger.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/EelfLogger.java
@@ -20,6 +20,7 @@
package org.openecomp.policy.common.logging.flexlogger;
+import java.io.Serializable;
import java.util.UUID;
import org.openecomp.policy.common.logging.eelf.MessageCodes;
@@ -33,7 +34,7 @@ import com.att.eelf.configuration.EELFLogger.Level;
*
*/
-public class EelfLogger implements Logger {
+public class EelfLogger implements Logger, Serializable {
private String className = "";
private String transId = UUID.randomUUID().toString();
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger4J.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger4J.java
index 02f95cf2..23cafb41 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger4J.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/Logger4J.java
@@ -20,6 +20,10 @@
package org.openecomp.policy.common.logging.flexlogger;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.util.UUID;
import org.apache.log4j.Logger;
@@ -34,7 +38,7 @@ import com.att.eelf.configuration.EELFLogger.Level;
* Logger4J implements all the methods of interface Logger by calling org.apache.log4j.Logger
*
*/
-public class Logger4J implements org.openecomp.policy.common.logging.flexlogger.Logger {
+public class Logger4J implements org.openecomp.policy.common.logging.flexlogger.Logger, Serializable {
private Logger log = null;
private String methodName = "";
@@ -451,4 +455,30 @@ public class Logger4J implements org.openecomp.policy.common.logging.flexlogger.
public void postMDCInfoForEvent(Object o){
log.info(o);
}
+
+ /* ============================================================ */
+
+ /*
+ * Support for 'Serializable' --
+ * the default rules don't work for the 'log' field
+ */
+
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ // write out 'methodName', 'className', 'transId' strings
+ out.writeObject(methodName);
+ out.writeObject(className);
+ out.writeObject(transId);
+ }
+
+ private void readObject(ObjectInputStream in)
+ throws IOException, ClassNotFoundException {
+
+ // read in 'methodName', 'className', 'transId' strings
+ methodName = (String)(in.readObject());
+ className = (String)(in.readObject());
+ transId = (String)(in.readObject());
+
+ // look up associated logger
+ log = Logger.getLogger(className);
+ }
}
diff --git a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/SystemOutLogger.java b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/SystemOutLogger.java
index 26f06640..91e16b97 100644
--- a/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/SystemOutLogger.java
+++ b/common-logging/src/main/java/org/openecomp/policy/common/logging/flexlogger/SystemOutLogger.java
@@ -20,6 +20,7 @@
package org.openecomp.policy.common.logging.flexlogger;
+import java.io.Serializable;
import java.util.UUID;
import org.openecomp.policy.common.logging.eelf.MessageCodes;
@@ -31,7 +32,7 @@ import com.att.eelf.configuration.EELFLogger.Level;
* SystemOutLogger implements all the methods of interface Logger by calling System.out.println
*
*/
-public class SystemOutLogger implements Logger {
+public class SystemOutLogger implements Logger, Serializable {
private String className = "";
private boolean isDebugEnabled = true;
diff --git a/integrity-audit/src/main/java/org/openecomp/policy/common/ia/DbAudit.java b/integrity-audit/src/main/java/org/openecomp/policy/common/ia/DbAudit.java
index 9af89998..b509d563 100644
--- a/integrity-audit/src/main/java/org/openecomp/policy/common/ia/DbAudit.java
+++ b/integrity-audit/src/main/java/org/openecomp/policy/common/ia/DbAudit.java
@@ -242,8 +242,6 @@ public class DbAudit {
}
// If misMatchedMap is not empty, retrieve the entries in each misMatched list and compare again
-
- //classNameSet = (HashSet<String>) misMatchedMap.keySet();
classNameSet = new HashSet<String>(misMatchedMap.keySet());
// We need to keep track of how long the audit is taking
startTime = System.currentTimeMillis();
diff --git a/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/AuditPeriodTest.java b/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/AuditPeriodTest.java
index 649b71f2..d0c64065 100644
--- a/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/AuditPeriodTest.java
+++ b/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/AuditPeriodTest.java
@@ -49,6 +49,11 @@ import org.openecomp.policy.common.ia.IntegrityAuditProperties;
import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
import org.openecomp.policy.common.logging.flexlogger.Logger;
+/*
+ * All JUnits are designed to run in the local development environment
+ * where they have write privileges and can execute time-sensitive
+ * tasks.
+ */
public class AuditPeriodTest {
private static Logger logger = FlexLogger.getLogger(AuditPeriodTest.class);
diff --git a/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/DbAuditCompareEntriesTest.java b/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/DbAuditCompareEntriesTest.java
index f109689d..5b3c7550 100644
--- a/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/DbAuditCompareEntriesTest.java
+++ b/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/DbAuditCompareEntriesTest.java
@@ -51,6 +51,11 @@ import org.openecomp.policy.common.ia.test.jpa.PersonTest;
import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
import org.openecomp.policy.common.logging.flexlogger.Logger;
+/*
+ * All JUnits are designed to run in the local development environment
+ * where they have write privileges and can execute time-sensitive
+ * tasks.
+ */
public class DbAuditCompareEntriesTest {
private static Logger logger = FlexLogger.getLogger(DbAuditCompareEntriesTest.class);
diff --git a/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/DbAuditTest.java b/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/DbAuditTest.java
index a84281dd..21e3bfab 100644
--- a/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/DbAuditTest.java
+++ b/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/DbAuditTest.java
@@ -55,6 +55,11 @@ import org.openecomp.policy.common.ia.jpa.IntegrityAuditEntity;
import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
import org.openecomp.policy.common.logging.flexlogger.Logger;
+/*
+ * All JUnits are designed to run in the local development environment
+ * where they have write privileges and can execute time-sensitive
+ * tasks.
+ */
public class DbAuditTest {
private static Logger logger = FlexLogger.getLogger(DbAuditTest.class);
diff --git a/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/DbDAOTest.java b/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/DbDAOTest.java
index 31fd0be6..351fe5f8 100644
--- a/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/DbDAOTest.java
+++ b/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/DbDAOTest.java
@@ -22,6 +22,11 @@ package org.openecomp.policy.common.ia.test;
import static org.junit.Assert.*;
+/*
+ * All JUnits are designed to run in the local development environment
+ * where they have write privileges and can execute time-sensitive
+ * tasks.
+ */
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
@@ -49,6 +54,11 @@ import org.openecomp.policy.common.ia.DbDaoTransactionException;
import org.openecomp.policy.common.ia.IntegrityAuditProperties;
import org.openecomp.policy.common.ia.jpa.IntegrityAuditEntity;
+/*
+ * All JUnits are designed to run in the local development environment
+ * where they have write privileges and can execute time-sensitive
+ * tasks.
+ */
public class DbDAOTest {
private static String persistenceUnit;
private static Properties properties;
diff --git a/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/IntegrityAuditDesignationTest.java b/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/IntegrityAuditDesignationTest.java
index 6eb5fa4e..69936bfe 100644
--- a/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/IntegrityAuditDesignationTest.java
+++ b/integrity-audit/src/test/java/org/openecomp/policy/common/ia/test/IntegrityAuditDesignationTest.java
@@ -51,6 +51,11 @@ import org.openecomp.policy.common.ia.IntegrityAuditProperties;
import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
import org.openecomp.policy.common.logging.flexlogger.Logger;
+/*
+ * All JUnits are designed to run in the local development environment
+ * where they have write privileges and can execute time-sensitive
+ * tasks.
+ */
public class IntegrityAuditDesignationTest {
private static Logger logger = FlexLogger.getLogger(IntegrityAuditDesignationTest.class);
@@ -58,7 +63,7 @@ public class IntegrityAuditDesignationTest {
/*
* Provides a little cushion for timing events.
*/
- private static int FUDGE_FACTOR = 5000;
+ private static int FUDGE_FACTOR = 15000;
private static String persistenceUnit;
private static Properties properties;
@@ -1028,29 +1033,31 @@ public class IntegrityAuditDesignationTest {
IntegrityAudit integrityAudit3 = new IntegrityAudit(resourceName3, persistenceUnit3, properties3);
// Start audit on pdp1
+ logger.info("testDesignatedNodeDead: Start audit on pdp1");
integrityAudit.startAuditThread();
- // Sleep long enough for pdp1 figure out that it should be auditing and start the audit.
- Thread.sleep(500);
-
// Start the auditing threads on other nodes.
+ logger.info("testDesignatedNodeDead: Start audit on pdp2");
integrityAudit2.startAuditThread();
+ logger.info("testDesignatedNodeDead: Start audit on pdp3");
integrityAudit3.startAuditThread();
- // Sleep long enough to ensure the other two audits have registered.
- Thread.sleep(500);
-
+
// Kill audit on pdp1
+ logger.info("testDesignatedNodeDead: Kill audit on pdp1");
integrityAudit.stopAuditThread();
// Sleep long enough for pdp1 to get stale and pdp2 to take over
+ logger.info("testDesignatedNodeDead: Sleep long enough for pdp1 to get stale and pdp2 to take over");
Thread.sleep(AuditThread.AUDIT_COMPLETION_INTERVAL + FUDGE_FACTOR);
// Start audit thread on pdp1 again.
+ logger.info("testDesignatedNodeDead: Start audit thread on pdp1 again.");
integrityAudit.startAuditThread();
// Sleep long enough for pdp2 to complete its audit and get stale, at
// which point pdp3 should take over
+ logger.info("testDesignatedNodeDead: Sleep long enough for pdp2 to complete its audit and get stale, at which point pdp3 should take over");
Thread.sleep((AuditThread.AUDIT_SIMULATION_SLEEP_INTERVAL * AuditThread.AUDIT_SIMULATION_ITERATIONS)
+ AuditThread.AUDIT_COMPLETION_INTERVAL + FUDGE_FACTOR);
@@ -1059,6 +1066,7 @@ public class IntegrityAuditDesignationTest {
integrityAudit3.stopAuditThread();
// Sleep long enough for pdp3 to get stale and pdp1 to take over
+ logger.info("testDesignatedNodeDead: Sleep long enough for pdp3 to get stale and pdp1 to take over");
Thread.sleep(AuditThread.AUDIT_COMPLETION_INTERVAL + FUDGE_FACTOR);
FileInputStream fstream = new FileInputStream(TEST_LOG);
diff --git a/integrity-monitor/config/policyLogger.properties b/integrity-monitor/config/policyLogger.properties
new file mode 100644
index 00000000..1e7187f2
--- /dev/null
+++ b/integrity-monitor/config/policyLogger.properties
@@ -0,0 +1,44 @@
+###
+# ============LICENSE_START=======================================================
+# Integrity Audit
+# ================================================================================
+# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
+
+################################### Set concurrentHashMap and timer info #######################
+#Timer initial delay and the delay between in milliseconds before task is to be execute.
+timer.delay.time=1000
+#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions.
+check.interval= 30000
+#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds.
+event.expired.time=86400
+#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed
+#to remove all expired records from this concurrentHashMap.
+concurrentHashMap.limit=5000
+#Size of the concurrentHashMap - when its size drops to this point, stop the Timer
+stop.check.point=2500
+################################### Set logging format #############################################
+# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println
+logger.type=EELF
+#################################### Set level for EELF or SYSTEMOUT logging ##################################
+# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all
+debugLogger.level=INFO
+# Set level for metrics file. Set OFF to disable; set ON to enable
+metricsLogger.level=ON
+# Set level for error file. Set OFF to disable; set ON to enable
+error.level=ON
+# Set level for audit file. Set OFF to disable; set ON to enable
+audit.level=ON
diff --git a/integrity-monitor/src/main/java/org/openecomp/policy/common/im/IntegrityMonitor.java b/integrity-monitor/src/main/java/org/openecomp/policy/common/im/IntegrityMonitor.java
index 6c575ab7..293bd11c 100644
--- a/integrity-monitor/src/main/java/org/openecomp/policy/common/im/IntegrityMonitor.java
+++ b/integrity-monitor/src/main/java/org/openecomp/policy/common/im/IntegrityMonitor.java
@@ -37,14 +37,15 @@ import javax.persistence.LockModeType;
import javax.persistence.Persistence;
import javax.persistence.Query;
-//import org.apache.log4j.Logger;
-
-import org.openecomp.policy.common.im.jmx.*;
import org.openecomp.policy.common.im.jpa.ForwardProgressEntity;
import org.openecomp.policy.common.im.jpa.ResourceRegistrationEntity;
import org.openecomp.policy.common.im.jpa.StateManagementEntity;
-import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
+import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
import org.openecomp.policy.common.logging.flexlogger.Logger;
+//import org.apache.log4j.Logger;
+import org.openecomp.policy.common.im.jmx.ComponentAdmin;
+import org.openecomp.policy.common.im.jmx.ComponentAdminMBean;
+import org.openecomp.policy.common.im.jmx.JmxAgentConnection;
/**
* IntegrityMonitor
@@ -309,7 +310,6 @@ public class IntegrityMonitor {
em.persist(rrx);
// flush to the DB
synchronized(IMFLUSHLOCK){
- em.flush();
et.commit();
}
@@ -442,59 +442,145 @@ public class IntegrityMonitor {
}
}
-
- private String stateCheck(String dep) {
+
+ /*
+ * This method checks the forward progress counter and the state of
+ * a dependency. If the dependency is unavailable or failed, an
+ * error message is created which is checked when evaluateSanity interface
+ * is called. If the error message is set then the evaluateSanity
+ * will return an error.
+ */
+ public String stateCheck(String dep) {
logger.debug("checking state of dependent resource: " + dep);
-
- // get state management entry for dependent resource
- StateManagementEntity stateManagementEntity = null;
+
String error_msg = null;
- try {
- // Start a transaction
- EntityTransaction et = em.getTransaction();
- et.begin();
+ ForwardProgressEntity forwardProgressEntity = null;
+ StateManagementEntity stateManagementEntity = null;
+
+ // Start a transaction
+ EntityTransaction et = em.getTransaction();
+ et.begin();
- // query if StateManagement entry exists for dependent resource
- Query query = em.createQuery("Select p from StateManagementEntity p where p.resourceName=:resource");
+ try{
+ Query query = em.createQuery("Select p from ForwardProgressEntity p where p.resourceName=:resource");
query.setParameter("resource", dep);
@SuppressWarnings("rawtypes")
- List smList = query.setLockMode(
- LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
- if (!smList.isEmpty()) {
- // exist
- stateManagementEntity = (StateManagementEntity) smList.get(0);
+ List fpList = query.setLockMode(
+ LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
+
+ if (!fpList.isEmpty()) {
+ // exists
+ forwardProgressEntity = (ForwardProgressEntity) fpList.get(0);
// refresh the object from DB in case cached data was returned
- em.refresh(stateManagementEntity);
- logger.debug("Found entry in StateManagementEntity table for dependent Resource=" + dep);
+ em.refresh(forwardProgressEntity);
+ logger.debug("Found entry in ForwardProgressEntity table for dependent Resource=" + dep);
} else {
- error_msg = dep + ": resource not found in state management entity database table";
+ error_msg = dep + ": resource not found in ForwardProgressEntity database table";
+ logger.debug(error_msg);
logger.error(error_msg);
}
-
synchronized(IMFLUSHLOCK){
et.commit();
}
- } catch (Exception e) {
+ }
+ catch(Exception ex){
// log an error
- error_msg = dep + ": StateManagementEntity DB read failed with exception: " + e;
+ error_msg = dep + ": ForwardProgressEntity DB operation failed with exception: " + ex;
+ logger.debug(error_msg);
logger.error(error_msg);
+ synchronized(IMFLUSHLOCK){
+ if(et.isActive()){
+ et.rollback();
+ }
+ }
+ }
+
+ if(error_msg==null){
+ // Start a transaction
+ et = em.getTransaction();
+ et.begin();
+ try {
+ // query if StateManagement entry exists for dependent resource
+ Query query = em.createQuery("Select p from StateManagementEntity p where p.resourceName=:resource");
+ query.setParameter("resource", dep);
+
+ @SuppressWarnings("rawtypes")
+ List smList = query.setLockMode(
+ LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
+ if (!smList.isEmpty()) {
+ // exist
+ stateManagementEntity = (StateManagementEntity) smList.get(0);
+ // refresh the object from DB in case cached data was returned
+ em.refresh(stateManagementEntity);
+ logger.debug("Found entry in StateManagementEntity table for dependent Resource=" + dep);
+ } else {
+ error_msg = dep + ": resource not found in state management entity database table";
+ logger.debug(error_msg);
+ logger.error(error_msg);
+ }
+
+ synchronized(IMFLUSHLOCK){
+ et.commit();
+ }
+ } catch (Exception e) {
+ // log an error
+ error_msg = dep + ": StateManagementEntity DB read failed with exception: " + e;
+ logger.debug(error_msg);
+ logger.error(error_msg);
+ synchronized(IMFLUSHLOCK){
+ if(et.isActive()){
+ et.rollback();
+ }
+ }
+ }
+ }
+
+ //verify that the ForwardProgress is current (check last_updated)
+ if(error_msg==null){
+ Date date = new Date();
+ long diffMs = date.getTime() - forwardProgressEntity.getLastUpdated().getTime();
+ logger.debug("IntegrityMonitor.stateCheck(): diffMs = " + diffMs);
+
+ //Threshold for a stale entry
+ long staleMs = failedCounterThreshold * monitorInterval * 1000;
+ logger.debug("IntegrityMonitor.stateCheck(): staleMs = " + staleMs);
+
+ if(diffMs > staleMs){
+ //ForwardProgress is stale. Disable it
+ try {
+ if(!stateManagementEntity.getOpState().equals(StateManagement.DISABLED)){
+ logger.debug("IntegrityMonitor.stateCheck(): Changing OpStat = disabled for " + dep);
+ stateManager.disableFailed(dep);
+ }
+ } catch (Exception e) {
+ String msg = "IntegrityMonitor.stateCheck(): Failed to diableFail dependent resource = " + dep
+ + "; " + e.getMessage();
+ logger.debug(msg);
+ logger.error(msg);
+ }
+ }
}
// check operation, admin and standby states of dependent resource
if (error_msg == null) {
if ((stateManager.getAdminState() != null) && stateManagementEntity.getAdminState().equals(StateManagement.LOCKED)) {
error_msg = dep + ": resource is administratively locked";
+ logger.debug(error_msg);
logger.error(error_msg);
} else if ((stateManager.getOpState() != null) && stateManagementEntity.getOpState().equals(StateManagement.DISABLED)) {
error_msg = dep + ": resource is operationally disabled";
+ logger.debug(error_msg);
logger.error(error_msg);
} else if ((stateManager.getStandbyStatus() != null) && stateManagementEntity.getStandbyStatus().equals(StateManagement.COLD_STANDBY)) {
error_msg = dep + ": resource is cold standby";
+ logger.debug(error_msg);
logger.error(error_msg);
}
}
+ String returnMsg = "IntegrityMonitor.stateCheck(): returned error_msg: " + error_msg;
+ logger.debug(returnMsg);
return error_msg;
}
@@ -551,6 +637,11 @@ public class IntegrityMonitor {
// log an error and continue
error_msg = dep + ": ForwardProgressEntity DB read failed with exception: " + e;
logger.error(error_msg);
+ synchronized(IMFLUSHLOCK){
+ if(et.isActive()){
+ et.rollback();
+ }
+ }
}
return error_msg;
@@ -563,11 +654,10 @@ public class IntegrityMonitor {
// get the JMX URL from the database
String jmxUrl = null;
+ // Start a transaction
+ EntityTransaction et = em.getTransaction();
+ et.begin();
try {
- // Start a transaction
- EntityTransaction et = em.getTransaction();
- et.begin();
-
// query if ResourceRegistration entry exists for resourceName
Query rquery = em.createQuery("Select r from ResourceRegistrationEntity r where r.resourceName=:rn");
rquery.setParameter("rn", dep);
@@ -595,6 +685,11 @@ public class IntegrityMonitor {
} catch (Exception e) {
error_msg = dep + ": ResourceRegistrationEntity DB read failed with exception: " + e;
logger.error(error_msg);
+ synchronized(IMFLUSHLOCK){
+ if(et.isActive()){
+ et.rollback();
+ }
+ }
}
@@ -876,7 +971,6 @@ public class IntegrityMonitor {
em.persist(fpx);
// flush to the DB and commit
synchronized(IMFLUSHLOCK){
- em.flush();
et.commit();
}
}
@@ -887,8 +981,10 @@ public class IntegrityMonitor {
}
} catch (Exception e) {
try {
- if (et.isActive()) {
- et.rollback();
+ synchronized(IMFLUSHLOCK){
+ if (et.isActive()) {
+ et.rollback();
+ }
}
} catch (Exception e1) {
// ignore
@@ -965,18 +1061,6 @@ public class IntegrityMonitor {
}
}
- /***********************
- // followers are a comma separated list of resource names
- if (prop.getProperty(IntegrityMonitorProperties.SS_FOLLOWERS) != null) {
- try {
- followers = prop.getProperty(IntegrityMonitorProperties.SS_FOLLOWERS).split(",");
- logger.debug("followers property = " + Arrays.toString(followers));
- } catch (Exception e) {
- logger.warn("Ignored invalid property: " + IntegrityMonitorProperties.SS_FOLLOWERS);
- }
- }
- **************************/
-
// dependency_groups are a semi-colon separated list of groups
// each group is a comma separated list of resource names
// For ex. dependency_groups = site_1.pap_1,site_1.pap_2 ; site_1.pdp_1, site_1.pdp_2
diff --git a/integrity-monitor/src/main/java/org/openecomp/policy/common/im/StateManagement.java b/integrity-monitor/src/main/java/org/openecomp/policy/common/im/StateManagement.java
index 14d35e1d..fd0f3d9f 100644
--- a/integrity-monitor/src/main/java/org/openecomp/policy/common/im/StateManagement.java
+++ b/integrity-monitor/src/main/java/org/openecomp/policy/common/im/StateManagement.java
@@ -129,16 +129,11 @@ public class StateManagement extends Observable {
logger.debug("Persist adminstrative state, resourceName = " + this.resourceName);
em.persist(sm);
synchronized(FLUSHLOCK){
- em.flush();
- if(et.isActive()){
- et.commit();
- }
+ et.commit();
}
} else {
synchronized(FLUSHLOCK){
- if(et.isActive()){
- et.commit();
- }
+ et.commit();
}
}
@@ -147,13 +142,13 @@ public class StateManagement extends Observable {
logger.debug("StateManagement: constructor end, resourceName: " + this.resourceName);
} catch(Exception ex) {
+ logger.error("StateManagement: constructor caught unexpected exception: " + ex);
+ ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
- et.commit();
+ et.rollback();
}
}
- ex.printStackTrace();
- logger.error("StateManagement: constructor caught unexpected exception: " + ex);
throw new Exception("StateManagement: Exception: " + ex.toString());
}
}
@@ -186,23 +181,20 @@ public class StateManagement extends Observable {
em.persist(sm);
synchronized(FLUSHLOCK){
- em.flush();
- if(et.isActive()){
- et.commit();
- }
+ et.commit();
}
setChanged();
notifyObservers(ADMIN_STATE);
logger.debug("StateManagement: initializeState() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
+ logger.error("StateManagement.initializeState() caught unexpected exception: " + ex);
+ ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
- et.commit();
+ et.rollback();
}
}
- ex.printStackTrace();
- logger.error("StateManagement.initializeState() caught unexpected exception: " + ex);
throw new Exception("StateManagement.initializeState() Exception: " + ex);
}
}
@@ -237,23 +229,20 @@ public class StateManagement extends Observable {
em.persist(sm);
synchronized(FLUSHLOCK){
- em.flush();
- if(et.isActive()){
- et.commit();
- }
+ et.commit();
}
setChanged();
notifyObservers(ADMIN_STATE);
logger.debug("StateManagement: lock() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
+ logger.error("StateManagement.lock() caught unexpected exception: " + ex);
+ ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
- et.commit();
+ et.rollback();
}
}
- ex.printStackTrace();
- logger.error("StateManagement.lock() caught unexpected exception: " + ex);
throw new Exception("StateManagement.lock() Exception: " + ex.toString());
}
}
@@ -287,23 +276,20 @@ public class StateManagement extends Observable {
em.persist(sm);
synchronized(FLUSHLOCK){
- em.flush();
- if(et.isActive()){
- et.commit();
- }
+ et.commit();
}
setChanged();
notifyObservers(ADMIN_STATE);
logger.debug("StateManagement: unlock() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
+ logger.error("StateManagement.unlock() caught unexpected exception: " + ex);
+ ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
- et.commit();
+ et.rollback();
}
}
- ex.printStackTrace();
- logger.error("StateManagement.unlock() caught unexpected exception: " + ex);
throw new Exception("StateManagement.unlock() Exception: " + ex);
}
}
@@ -338,23 +324,20 @@ public class StateManagement extends Observable {
em.persist(sm);
synchronized(FLUSHLOCK){
- em.flush();
- if(et.isActive()){
- et.commit();
- }
+ et.commit();
}
setChanged();
notifyObservers(OPERATION_STATE);
logger.debug("StateManagement enableNotFailed() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
+ logger.error("StateManagement.enableNotFailed() caught unexpected exception: " + ex);
+ ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
- et.commit();
+ et.rollback();
}
}
- ex.printStackTrace();
- logger.error("StateManagement.enableNotFailed() caught unexpected exception: " + ex);
throw new Exception("StateManagement.enableNotFailed() Exception: " + ex);
}
}
@@ -387,23 +370,20 @@ public class StateManagement extends Observable {
em.persist(sm);
synchronized(FLUSHLOCK){
- em.flush();
- if(et.isActive()){
- et.commit();
- }
+ et.commit();
}
setChanged();
notifyObservers(OPERATION_STATE);
logger.debug("StateManagement: disableFailed() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
+ logger.error("StateManagement.disableFailed() caught unexpected exception: " + ex);
+ ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
- et.commit();
+ et.rollback();
}
}
- ex.printStackTrace();
- logger.error("StateManagement.disableFailed() caught unexpected exception: " + ex);
throw new Exception("StateManagement.disableFailed() Exception: " + ex);
}
}
@@ -442,10 +422,7 @@ public class StateManagement extends Observable {
em.persist(sm);
synchronized(FLUSHLOCK){
- em.flush();
- if(et.isActive()){
- et.commit();
- }
+ et.commit();
}
setChanged();
notifyObservers(OPERATION_STATE);
@@ -453,13 +430,13 @@ public class StateManagement extends Observable {
logger.debug("StateManagement: disableFailed(otherResourceName) operation completed, resourceName = "
+ otherResourceName);
} catch(Exception ex) {
+ logger.error("StateManagement.disableFailed(otherResourceName) caught unexpected exception: " + ex);
+ ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
- et.commit();
+ et.rollback();
}
}
- ex.printStackTrace();
- logger.error("StateManagement.disableFailed(otherResourceName) caught unexpected exception: " + ex);
throw new Exception("StateManagement.disableFailed(otherResourceName) Exception: " + ex);
}
}
@@ -493,23 +470,20 @@ public class StateManagement extends Observable {
em.persist(sm);
synchronized(FLUSHLOCK){
- em.flush();
- if(et.isActive()){
- et.commit();
- }
+ et.commit();
}
setChanged();
notifyObservers(OPERATION_STATE);
logger.debug("StateManagement: disableDependency() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
+ logger.error("StateManagement.disableDependency() caught unexpected exception: " + ex);
+ ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
- et.commit();
+ et.rollback();
}
}
- ex.printStackTrace();
- logger.error("StateManagement.disableDependency() caught unexpected exception: " + ex);
throw new Exception("StateManagement.disableDependency() Exception: " + ex);
}
}
@@ -544,23 +518,20 @@ public class StateManagement extends Observable {
em.persist(sm);
synchronized(FLUSHLOCK){
- em.flush();
- if(et.isActive()){
- et.commit();
- }
+ et.commit();
}
setChanged();
notifyObservers(OPERATION_STATE);
logger.debug("StateManagement: enableNoDependency() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
+ logger.error("StateManagement.enableNoDependency() caught unexpected exception: " + ex);
+ ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
- et.commit();
+ et.rollback();
}
}
- ex.printStackTrace();
- logger.error("StateManagement.enableNoDependency() caught unexpected exception: " + ex);
throw new Exception("StateManagement.enableNoDependency() Exception: " + ex);
}
}
@@ -597,7 +568,6 @@ public class StateManagement extends Observable {
em.persist(sm);
synchronized(FLUSHLOCK){
- em.flush();
if(et.isActive()){
et.commit();
}
@@ -605,13 +575,13 @@ public class StateManagement extends Observable {
setChanged();
notifyObservers(STANDBY_STATUS);
}catch(Exception ex){
+ logger.error("StateManagement.promote() caught unexpected exception: " + ex);
+ ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
- et.commit();
+ et.rollback();
}
}
- ex.printStackTrace();
- logger.error("StateManagement.promote() caught unexpected exception: " + ex);
throw new Exception("StateManagement.promote() Exception: " + ex);
}
@@ -651,23 +621,20 @@ public class StateManagement extends Observable {
em.persist(sm);
synchronized(FLUSHLOCK){
- em.flush();
- if(et.isActive()){
- et.commit();
- }
+ et.commit();
}
setChanged();
notifyObservers(STANDBY_STATUS);
logger.debug("StateManagement: demote() operation completed, resourceName = " + this.resourceName);
} catch(Exception ex) {
+ logger.error("StateManagement.demote() caught unexpected exception: " + ex);
+ ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
- et.commit();
+ et.rollback();
}
}
- ex.printStackTrace();
- logger.error("StateManagement.demote() caught unexpected exception: " + ex);
throw new Exception("StateManagement.demote() Exception: " + ex);
}
}
@@ -710,22 +677,19 @@ public class StateManagement extends Observable {
em.persist(sm);
synchronized(FLUSHLOCK){
- em.flush();
- if(et.isActive()){
- et.commit();
- }
+ et.commit();
}
//We don't notify observers because this is assumed to be a remote resource
logger.debug("StateManagement: demote(otherResourceName) operation completed, resourceName = " + otherResourceName);
} catch(Exception ex) {
+ logger.error("StateManagement.demote(otherResourceName) caught unexpected exception: " + ex);
+ ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
- et.commit();
+ et.rollback();
}
}
- ex.printStackTrace();
- logger.error("StateManagement.demote(otherResourceName) caught unexpected exception: " + ex);
throw new Exception("StateManagement.demote(otherResourceName) Exception: " + ex);
}
}
@@ -914,6 +878,7 @@ public String getOpState()
String standbyStatus = null;
+ // The transaction is required for the LockModeType
EntityTransaction et = em.getTransaction();
if(!et.isActive()){
et.begin();
@@ -940,17 +905,19 @@ public String getOpState()
logger.error("getStandbyStatus: resourceName =" + otherResourceName
+ " not found in statemanagemententity table");
}
+ synchronized(FLUSHLOCK){
+ et.commit();
+ }
} catch (Exception e) {
- e.printStackTrace();
logger.error("getStandbyStatus: Caught Exception attempting to get statemanagemententity record, message='"
+ e.getMessage() + "'");
- }
- synchronized(FLUSHLOCK){
- if(et.isActive()){
- et.commit();
+ e.printStackTrace();
+ synchronized(FLUSHLOCK){
+ if(et.isActive()){
+ et.rollback();
+ }
}
}
-
if (logger.isDebugEnabled()) {
logger.debug("getStandbyStatus: Returning standbyStatus="
+ standbyStatus);
@@ -989,27 +956,21 @@ public String getOpState()
+ stateManagementEntity.getStandbyStatus());
em.remove(stateManagementEntity);
}
+ synchronized(FLUSHLOCK){
+ et.commit();
+ }
}catch(Exception ex){
+ logger.error("StateManagement.deleteAllStateManagementEntities() caught Exception: " + ex);
+ ex.printStackTrace();
synchronized(FLUSHLOCK){
if(et.isActive()){
- et.commit();
+ et.rollback();
}
}
- ex.printStackTrace();
- logger.error("StateManagement.deleteAllStateManagementEntities() caught Exception: " + ex);
}
-
- /*
- * End transaction.
- */
- synchronized(FLUSHLOCK){
- if(et.isActive()){
- et.commit();
- }
+ if(logger.isDebugEnabled()){
+ logger.info("deleteAllStateManagementEntities: Exiting");
}
-
- logger.info("deleteAllStateManagementEntities: Exiting");
-
}
}
diff --git a/integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/IntegrityMonitorTest.java b/integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/IntegrityMonitorTest.java
index 68a6cf2f..7375988e 100644
--- a/integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/IntegrityMonitorTest.java
+++ b/integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/IntegrityMonitorTest.java
@@ -53,6 +53,11 @@ import org.openecomp.policy.common.im.jpa.StateManagementEntity;
import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
import org.openecomp.policy.common.logging.flexlogger.Logger;
+/*
+ * All JUnits are designed to run in the local development environment
+ * where they have write privileges and can execute time-sensitive
+ * tasks.
+ */
public class IntegrityMonitorTest {
private static Logger logger = FlexLogger.getLogger(IntegrityMonitorTest.class);
private static Properties myProp;
@@ -103,6 +108,21 @@ public class IntegrityMonitorTest {
// clear jmx remote port setting
systemProps.remove("com.sun.management.jmxremote.port");
}
+
+ /*
+ * The following runs all tests and controls the order of execution. If you allow
+ * the tests to execute individually, you cannot predict the order and some
+ * conflicts occur.
+ */
+ @Ignore
+ @Test
+ public void runAllTests() throws Exception{
+ testSanityJmx();
+ testIM();
+ testSanityState();
+ testRefreshStateAudit();
+ testStateCheck();
+ }
/*
* The following test verifies the following test cases:
@@ -114,8 +134,6 @@ public class IntegrityMonitorTest {
* Unlock
* Unlock restart
*/
- @Ignore // Test passed 10/18/16
- @Test
public void testSanityJmx() throws Exception {
System.out.println("\nIntegrityMonitorTest: Entering testSanityJmx\n\n");
@@ -267,8 +285,6 @@ public class IntegrityMonitorTest {
}
- @Ignore // Test passed 10/18/16
- @Test
public void testIM() throws Exception {
System.out.println("\nIntegrityMonitorTest: Entering testIM\n\n");
@@ -554,8 +570,6 @@ public class IntegrityMonitorTest {
}
- @Ignore // Test passed 10/18/16
- @Test
public void testSanityState() throws Exception {
System.out.println("\nIntegrityMonitorTest: Entering testSanityState\n\n");
@@ -618,8 +632,6 @@ public class IntegrityMonitorTest {
System.out.println("\n\ntestSanityState: Exit\n\n");
}
- @Ignore // Test passed 10/18/16
- @Test
public void testRefreshStateAudit() throws Exception {
logger.debug("\nIntegrityMonitorTest: testRefreshStateAudit Enter\n\n");
@@ -731,4 +743,94 @@ public class IntegrityMonitorTest {
logger.debug("\nIntegrityMonitorTest: testRefreshStateAudit Exit\n\n");
}
+
+ public void testStateCheck() throws Exception {
+ System.out.println("\nIntegrityMonitorTest: Entering testStateCheck\n\n");
+
+ // parameters are passed via a properties file
+ myProp.put(IntegrityMonitorProperties.DEPENDENCY_GROUPS, "group1_dep1");
+ myProp.put(IntegrityMonitorProperties.TEST_VIA_JMX, "false");
+ myProp.put(IntegrityMonitorProperties.FAILED_COUNTER_THRESHOLD, "1");
+ myProp.put(IntegrityMonitorProperties.FP_MONITOR_INTERVAL, "10");
+ IntegrityMonitor.updateProperties(myProp);
+ /*
+ * The default monitorInterval is 30 and the default failedCounterThreshold is 3
+ * Since stateCheck() uses the faileCounterThreshold * monitorInterval to determine
+ * if an entry is stale, it will be stale after 30 seconds.
+ */
+
+ et = em.getTransaction();
+ et.begin();
+
+ // Make sure we start with the DB clean
+ em.createQuery("DELETE FROM StateManagementEntity").executeUpdate();
+ em.createQuery("DELETE FROM ResourceRegistrationEntity").executeUpdate();
+ em.createQuery("DELETE FROM ForwardProgressEntity").executeUpdate();
+
+ em.flush();
+ et.commit();
+
+ IntegrityMonitor.deleteInstance();
+
+ IntegrityMonitor im = IntegrityMonitor.getInstance(resourceName, myProp);
+
+ // Add a group1 dependent resources to put an entry in the forward progress table
+ // This sets lastUpdated to the current time
+ ForwardProgressEntity fpe = new ForwardProgressEntity();
+ fpe.setFpcCount(0);
+ fpe.setResourceName("group1_dep1");
+ et = em.getTransaction();
+ et.begin();
+ em.persist(fpe);
+ em.flush();
+ et.commit();
+
+ //Now add new group1 stateManager instances
+ StateManagement sm2 = new StateManagement(emf, "group1_dep1");
+
+ boolean sanityPass = true;
+ //Thread.sleep(15000);
+ Thread.sleep(5000);
+ try {
+ im.evaluateSanity();
+ } catch (Exception e) {
+ System.out.println("testStateCheck: After 15 sec sleep - evaluateSanity exception: " + e);
+ sanityPass = false;
+ }
+ assertTrue(sanityPass); // expect sanity test to pass
+
+ //now wait 30 seconds. The dependency entry should now be stale and the sanitry check should fail
+
+ sanityPass = true;
+ //Thread.sleep(30000);
+ Thread.sleep(10000);
+ try {
+ im.evaluateSanity();
+ } catch (Exception e) {
+ System.out.println("testStateCheck: After 10 sec sleep - evaluateSanity exception: " + e);
+ sanityPass = false;
+ }
+ assertFalse(sanityPass); // expect sanity test to fail
+
+ // undo dependency groups, jmx test properties settings and failed counter threshold
+ myProp.put(IntegrityMonitorProperties.DEPENDENCY_GROUPS, "");
+ myProp.put(IntegrityMonitorProperties.TEST_VIA_JMX, "false");
+ myProp.put(IntegrityMonitorProperties.FAILED_COUNTER_THRESHOLD, Integer.toString(IntegrityMonitorProperties.DEFAULT_FAILED_COUNTER_THRESHOLD));
+ myProp.put(IntegrityMonitorProperties.FP_MONITOR_INTERVAL, Integer.toString(IntegrityMonitorProperties.DEFAULT_MONITOR_INTERVAL));
+ IntegrityMonitor.updateProperties(myProp);
+
+ et = em.getTransaction();
+
+ et.begin();
+ // Make sure we leave the DB clean
+ em.createQuery("DELETE FROM StateManagementEntity").executeUpdate();
+ em.createQuery("DELETE FROM ResourceRegistrationEntity").executeUpdate();
+ em.createQuery("DELETE FROM ForwardProgressEntity").executeUpdate();
+
+ em.flush();
+ et.commit();
+
+ System.out.println("\n\ntestStateCheck: Exit\n\n");
+ }
+
}
diff --git a/integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/StateManagementTest.java b/integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/StateManagementTest.java
index 3247d781..f51f5ac7 100644
--- a/integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/StateManagementTest.java
+++ b/integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/StateManagementTest.java
@@ -41,6 +41,7 @@ import javax.persistence.Query;
+
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -49,7 +50,6 @@ import org.junit.Ignore;
import org.junit.Test;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.openecomp.policy.common.im.StateManagement;
import org.openecomp.policy.common.im.StateTransition;
import org.openecomp.policy.common.im.StandbyStatusException;
@@ -57,6 +57,11 @@ import org.openecomp.policy.common.im.StateChangeNotifier;
import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
import org.openecomp.policy.common.logging.flexlogger.Logger;
+/*
+ * All JUnits are designed to run in the local development environment
+ * where they have write privileges and can execute time-sensitive
+ * tasks.
+ */
public class StateManagementTest {
private static Logger logger = FlexLogger.getLogger(StateManagementTest.class);
diff --git a/integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/StateTransitionTest.java b/integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/StateTransitionTest.java
index b0e6e18e..d76cad0d 100644
--- a/integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/StateTransitionTest.java
+++ b/integrity-monitor/src/test/java/org/openecomp/policy/common/im/test/StateTransitionTest.java
@@ -50,7 +50,11 @@ import org.openecomp.policy.common.im.StandbyStatusException;
import org.openecomp.policy.common.im.StateChangeNotifier;
import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
import org.openecomp.policy.common.logging.flexlogger.Logger;
-
+/*
+ * All JUnits are designed to run in the local development environment
+ * where they have write privileges and can execute time-sensitive
+ * tasks.
+ */
public class StateTransitionTest {
private static Logger logger = FlexLogger.getLogger(StateTransitionTest.class);