summaryrefslogtreecommitdiffstats
path: root/policy-persistence/src
diff options
context:
space:
mode:
authorRalph Straubs <rs8887@att.com>2017-04-21 04:23:55 -0500
committerRalph Straubs <rs8887@att.com>2017-04-21 05:55:16 -0500
commit5bd9ff4130799247be3be88fc02f3ce0efd014c0 (patch)
tree327ed17fae044265b08c419913290e2f9bcddcec /policy-persistence/src
parent8f7e5de17521836a96fa1c771a1651f63216675c (diff)
Batch submit -- force rebuild
[ECOMPD2TD-1126 1707] Delay the start of the election handler by one more update interval to allow updatedDate to be set and recoginized by other nodes. [ECOMPD2TD-1073 1707] Remove pessimistic locks from DB access to prevent DB deadlock [US867397-policy-management-feature-api] Split original FeatureAPI into three service interfaces. These are: - the original FeatureAPI for core - PolicyControllerFeatureAPI (additional interface methods yet to come ..) - PolicyEngineFeatureAPI (additional interface methods yet to come ..) Additional extensions will be done in the future. This is to have equivalent functionality with what it is already there. [US867397-policy-management-feature-api] Split original FeatureAPI into three service interfaces. These are: - the original FeatureAPI for core - PolicyControllerFeatureAPI (additional interface methods yet to come ..) - PolicyEngineFeatureAPI (additional interface methods yet to come ..) Additional extensions will be done in the future. This is to have equivalent functionality with what it is already there. [ECOMPD2TD-1167] Avoid redundant dependencies and remove obsolete sql scripts [ECOMPD2TD-848] Fix copied from ATT droolspdp repo -- add timestamp to metric and audit logs [ECOMPD2TD-1167] update jetty version to 9.3.14 [ECOMPD2TD-1167] pull in policy-core jar as a dependency of policy-management, instead of zip file [ECOMPD2TD-1159] Add property to ignore repository audit errors The property is called 'repository.audit.ignore.errors' -- it resides in 'IntegrityMonitor.properties', and it defaults to 'true'. When true, any errors that occur in the repository audit are logged, but not reported to integrity monitor. [US867397] additional hooks for policy engine, and support operation take over by feature bypassing further feature processing [US867397] additional hooks for policy engine, and support operation take over by feature bypassing further feature processing [US867397] fix reverse return javadoc comment [ECOMPD2TD-1192] Select correct persistent session information This is a modification to 'DroolsPdpsElectionHandler.DesignatedWaiter'. When going active, the list of persistent sessions needs to come from the most recent active DroolsPDP. The most recent active DroolsPDP is tracked in a local variable 'mostRecentPrimary', and the associated list of sessions needs to be extracted just prior to going active. The problem was that the list of sessions was extracted after the current DroolsPDP was set to 'mostRecentPrimary'. [ECOMPD2TD-1073 1707] Remove pessimistic locks from DB access to prevent DB deadlock [US860546] Add workaround for missing logger in message router [US860546] add DME2 properties to PolicyProperties [US860546] add DME2 support, pending unit testing [US860546] updated unit tests for dmaap/DME2 [US860546] removed System.out.println lines from BusConsumer and BusPublisher [US860546] modifications and additions to TopicEndpoint tests [US860546] remove block to append /events to serviceName in BusConsumer, BusPublisher [US860546] removing dmaap unit tests with ATT references [ECOMPD2TD-1167] Audit release repository by default [ECOMPD2TD-000] Cherry-pick versioning fixes from 1707.39.1 release branch [ECOMPD2TD-000] Fix policy-endpoints cambriaClient version [US865296] ECOMP Policy Logging Compliance, remove redundant timestamp from metric and audit log for logging compliance [US865296] ECOMP Policy Logging Compliance, remove TargetVirtualEntity from audit log, provide name to un-used column [US865296] ECOMP Policy Logging Compliance, remove Unused from AuditLogPattern, leave the column blank means un-used. [US000000] Cleanup and performance improvements 1) Changed 'OrderedServiceImpl' to ensure that the same service instance is used in every queue. This gets around the 'ServiceLoader' behavior that generates a new instance for each interface the service implements. 2) In 'PolicySession': add adaptive poll times within Drools sessions. Instead of always polling every 5 seconds, poll frequency increases when rules fire, and decreases when they don't. At present, the poll delay ranges from 100 milliseconds to 5 seconds, but at some point, it would be nice to make this configurable. 3) In 'PolicySession': add tests for 'logger.isDebugEnabled()' in session listener methods -- this results in a significant amount of real-time savings under load. [ECOMPD2TD-1126 1707] Changes to the election handler to deal with situations (race conditions) which can affect the site choice [ECOMPD2TD-1126 1707] Clean up of site afinity logic. Minor changes and a fix of the case where all pdpd are designated or all are hot standby. [ECOMPD2TD-1126 1707] Fixed issue with election handler and got all StandbyStateManagmentTest JUnits working. [ECOMPD2TD-1126 1707] Hopefully final changes to DroolsPdpsElectionHandler and StateManagementTest. Also removed the ResiliencyTestCases since they were redundant. [ECOMPD2TD-1126 1707] Found a minor bug in the computeMostRecentPrimary algorithm which I corrected and added a JUnit to confirm. [ECOMPD2TD-1126 1707] Removed code that was commented out of election handler to improve reability. Added an explanatory note to StandbyStateManagementTest. [US869183] Convert integrity monitor test endpoint to use HttpServletServer [US869183] add swagger-maven-plugin, update swagger annotation for IM test interface [US860371] Modified existing Dmaap and Ueb code to allow for https connectivity. HTTP/HTTPS is configurable via controller.properties file [US860520] Removed extra useHttps() method call from BusConsumer class where the consumer should be using http. Also, restored pom.xml to version at time feature branch was created. [US860520] Removed TopicEndpointTest.java. Added the ability to configure use of self-signed certificates for consumer topics. Functionality cannot be added for publisher at this time. Removed useHttps parameter field from multiple .builder methods to allow for greater ability to build source/sink objects without specifying http vs https connectivity. Other code cleanup and comments [US860520] -Deleted sys.out statements used in testing from BusConsumer/BusPublisher -Moved setProps method outside of if/else stub in BusConsumer -Could not add useHttps or selfSignedCerts to toString methods in BusConsumer -Move setProperty(contenttype, app/json) call outside of if/else branch in BusPublisher -Renamed doesAllowSelfSignedCerts method to is isAllowSelfSignedCerts and moved to BusTopicBase -Moved allowSelfSignedCerts member variable to BusTopicBase class. BusTopicBase is ancestor of SingleThreadedDmapp*/SingleThreadedUeb*/SingleThreadedBus* classes therefore, it will be inherited. -This changed resulted in cascading changes to the subclasses of BusTopicbase -Default is now set to disallow self-signed certs -Added several javadoc param annotations [US869183 1707] Changes to satisfy dependencies and correct pom syntax [ECOMPD2TD-1280] move DroolsPDPIntegrityMonitor.RestManager to its own class [ECOMPD2TD-1278] Resolve duplicate dependency issues (cherry-pick from 1707.40.1) [ECOMPD2TD-1278] revert cambriaClient back to 0.0.1 [ECOMPD2TD-1278] put dmaap version back to 0.2.12 [ECOMPD2TD-1280 1707] Fix Commons-lang3 version and common-modules version Conflicts: policy-endpoints/pom.xml policy-healthcheck/pom.xml policy-persistence/pom.xml pom.xml Change-Id: I803554bc64c55d2e82a3d6ad9120757f287144fb Signed-off-by: Ralph Straubs <rs8887@att.com>
Diffstat (limited to 'policy-persistence/src')
-rw-r--r--policy-persistence/src/main/java/org/openecomp/policy/drools/core/DroolsPDPIntegrityMonitor.java160
-rw-r--r--policy-persistence/src/main/java/org/openecomp/policy/drools/core/IntegrityMonitorRestManager.java91
-rw-r--r--policy-persistence/src/main/java/org/openecomp/policy/drools/core/RepositoryAudit.java57
-rw-r--r--policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/DroolsPdpsElectionHandler.java442
-rw-r--r--policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/JpaDroolsPdpsConnector.java17
-rw-r--r--policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/PersistenceFeature.java171
-rw-r--r--policy-persistence/src/main/resources/META-INF/services/org.openecomp.policy.drools.core.PolicySessionFeatureAPI (renamed from policy-persistence/src/main/resources/META-INF/services/org.openecomp.policy.drools.core.FeatureAPI)0
-rw-r--r--policy-persistence/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI1
-rw-r--r--policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/ResiliencyTestCases.java1267
-rw-r--r--policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/StandbyStateManagementTest.java497
-rw-r--r--policy-persistence/src/test/resources/IntegrityMonitor.properties6
-rw-r--r--policy-persistence/src/test/resources/META-INF/persistence.xml2
-rw-r--r--policy-persistence/src/test/server/config/IntegrityMonitor.properties7
13 files changed, 1070 insertions, 1648 deletions
diff --git a/policy-persistence/src/main/java/org/openecomp/policy/drools/core/DroolsPDPIntegrityMonitor.java b/policy-persistence/src/main/java/org/openecomp/policy/drools/core/DroolsPDPIntegrityMonitor.java
index 2b6058fd..dc63d719 100644
--- a/policy-persistence/src/main/java/org/openecomp/policy/drools/core/DroolsPDPIntegrityMonitor.java
+++ b/policy-persistence/src/main/java/org/openecomp/policy/drools/core/DroolsPDPIntegrityMonitor.java
@@ -22,23 +22,18 @@ package org.openecomp.policy.drools.core;
import java.io.File;
import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.OutputStream;
import java.net.InetSocketAddress;
-import java.util.LinkedList;
+import java.util.ArrayList;
import java.util.Properties;
-import java.util.concurrent.Callable;
import org.openecomp.policy.common.im.IntegrityMonitor;
-import org.openecomp.policy.common.logging.flexlogger.PropertyUtil;
+import org.openecomp.policy.common.logging.eelf.MessageCodes;
import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
import org.openecomp.policy.common.logging.flexlogger.Logger;
-import org.openecomp.policy.common.logging.eelf.MessageCodes;
-import org.openecomp.policy.drools.persistence.DroolsPdpsElectionHandler;
+import org.openecomp.policy.common.logging.flexlogger.PropertyUtil;
+import org.openecomp.policy.drools.http.server.HttpServletServer;
import org.openecomp.policy.drools.persistence.XacmlPersistenceProperties;
-import com.sun.net.httpserver.HttpExchange;
-import com.sun.net.httpserver.HttpHandler;
-import com.sun.net.httpserver.HttpServer;
+import org.openecomp.policy.drools.properties.Startable;
/**
* This class extends 'IntegrityMonitor' for use in the 'Drools PDP'
@@ -233,11 +228,11 @@ public class DroolsPDPIntegrityMonitor extends IntegrityMonitor
// create http server
try {
logger.info("init: Starting HTTP server, addr=" + addr);
- HttpServer server = HttpServer.create(addr, 0);
- server.createContext("/test", new TestHandler());
- server.setExecutor(null);
- server.start();
- System.out.println("init: Started server on hostPort=" + hostPort);
+ IntegrityMonitorRestServer server = new IntegrityMonitorRestServer();
+
+ server.init(integrityMonitorProperties);
+
+ System.out.println("init: Started server on hostPort=" + hostPort);
} catch (Exception e) {
if (PolicyContainer.isUnitTesting) {
System.out
@@ -378,100 +373,59 @@ public class DroolsPDPIntegrityMonitor extends IntegrityMonitor
*/
abstract void invoke(Properties droolsPersistenceProperties) throws Exception;
}
-
- /* ============================================================ */
-
- /**
- * This class is the HTTP handler for the REST 'test' invocation
- */
- static class TestHandler implements HttpHandler
- {
- /**
- * Handle an incoming REST 'test' invocation
- * @param ex used to pass incoming and outgoing HTTP information
- */
- @Override
- public void handle(HttpExchange ex) throws IOException
- {
-
- System.out.println("TestHandler.handle: Entering");
-
- // The responses are stored within the audit objects, so we need to
- // invoke the audits and get responses before we handle another
- // request.
- synchronized(TestHandler.class)
- {
- // will include messages associated with subsystem failures
- StringBuilder body = new StringBuilder();
-
- // 200=SUCCESS, 500=failure
- int responseValue = 200;
-
- if (im != null)
- {
- try
- {
- // call 'IntegrityMonitor.evaluateSanity()'
- im.evaluateSanity();
- }
- catch (Exception e)
- {
- // this exception isn't coming from one of the audits,
- // because those are caught in 'subsystemTest()'
- logger.error
- (MessageCodes.EXCEPTION_ERROR, e,
- "DroolsPDPIntegrityMonitor.evaluateSanity()");
-
- // include exception in HTTP response
- body.append("\nException: " + e + "\n");
- responseValue = 500;
+
+ 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() throws IllegalStateException {
+ try {
+ ArrayList<HttpServletServer> servers = HttpServletServer.factory.build(integrityMonitorRestServerProperties);
+
+ if (!servers.isEmpty()) {
+ server = servers.get(0);
+
+ try {
+ server.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
+ } catch (Exception e) {
+ return false;
}
-/*
- * Audit failures are being logged. A string will be generated which captures the
- * the audit failures. This string will be included in an exception coming from im.evaluateSanity().
- *
- // will contain list of subsystems where the audit failed
- LinkedList<String> subsystems = new LinkedList<String>();
+
+ return true;
+ }
- // 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 -- update 'subsystems', 'body',
- // and 'responseValue' with the new information
- subsystems.add(audit.getName());
- body
- .append('\n')
- .append(audit.getName())
- .append(":\n")
- .append(response)
- .append('\n');
- responseValue = 500;
- }
+ @Override
+ public boolean stop() throws IllegalStateException {
+ try {
+ server.stop();
+ } catch (Exception e) {
+ e.printStackTrace();
}
+
+ return true;
+ }
- if (subsystems.size() != 0)
- {
- // there is at least one failure -- add HTTP headers
- ex.getResponseHeaders().put("X-ECOMP-SubsystemFailure",
- subsystems);
- }
-*/
- // send response, including the contents of 'body'
- // (which is empty if everything is successful)
- ex.sendResponseHeaders(responseValue, body.length());
- OutputStream os = ex.getResponseBody();
- os.write(body.toString().getBytes());
- os.close();
- System.out.println("TestHandler.handle: Exiting");
+ @Override
+ public void shutdown() throws IllegalStateException {
+ this.stop();
}
- }
- }
+
+ @Override
+ public synchronized boolean isAlive() {
+ return this.integrityMonitorRestServerProperties != null;
+ }
+ }
+
public static DroolsPDPIntegrityMonitor getInstance() throws Exception{
logger.info("getInstance() called");
if (im == null) {
diff --git a/policy-persistence/src/main/java/org/openecomp/policy/drools/core/IntegrityMonitorRestManager.java b/policy-persistence/src/main/java/org/openecomp/policy/drools/core/IntegrityMonitorRestManager.java
new file mode 100644
index 00000000..e0cb0638
--- /dev/null
+++ b/policy-persistence/src/main/java/org/openecomp/policy/drools/core/IntegrityMonitorRestManager.java
@@ -0,0 +1,91 @@
+package org.openecomp.policy.drools.core;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.policy.common.logging.eelf.MessageCodes;
+import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
+import org.openecomp.policy.common.logging.flexlogger.Logger;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+@Api(value = "test")
+ @Path("/")
+public class IntegrityMonitorRestManager {
+ private static Logger logger = FlexLogger.getLogger(IntegrityMonitorRestManager.class);
+ private DroolsPDPIntegrityMonitor im;
+
+ /**
+ * Test interface for Integrity Monitor
+ *
+ * @return Exception message if exception, otherwise empty
+ */
+ @ApiOperation(
+ value = "Test endpoint for integrity monitor",
+ notes = "The TEST command is used to request data from a subcomponent "
+ + "instance that can be used to determine its operational state. "
+ + "A 200/success response status code should be returned if the "
+ + "subcomponent instance is functioning properly and able to respond to requests.",
+ response = String.class)
+ @ApiResponses(value = {
+ @ApiResponse(
+ code = 200,
+ message = "Integrity monitor sanity check passed"),
+ @ApiResponse(
+ code = 500,
+ message = "Integrity monitor sanity check encountered an exception. This can indicate operational state disabled or administrative state locked")
+ })
+ @GET
+ @Path("test")
+ public Response test() {
+ logger.error("integrity monitor /test accessed");
+ // The responses are stored within the audit objects, so we need to
+ // invoke the audits and get responses before we handle another
+ // request.
+ synchronized (IntegrityMonitorRestManager.class) {
+ // will include messages associated with subsystem failures
+ StringBuilder body = new StringBuilder();
+
+ // 200=SUCCESS, 500=failure
+ int responseValue = 200;
+
+ if (im == null) {
+ try {
+ im = DroolsPDPIntegrityMonitor.getInstance();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+
+ body.append("\nException: " + e + "\n");
+ responseValue = 500;
+ }
+ }
+
+ if (im != null) {
+ try {
+ // call 'IntegrityMonitor.evaluateSanity()'
+ im.evaluateSanity();
+ } catch (Exception e) {
+ // this exception isn't coming from one of the audits,
+ // because those are caught in 'subsystemTest()'
+ logger.error(MessageCodes.EXCEPTION_ERROR, e, "DroolsPDPIntegrityMonitor.evaluateSanity()");
+
+ // include exception in HTTP response
+ body.append("\nException: " + e + "\n");
+ responseValue = 500;
+ }
+ }
+
+ // send response, including the contents of 'body'
+ // (which is empty if everything is successful)
+ if (responseValue == 200)
+ return Response.status(Response.Status.OK).build();
+ else
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(body.toString()).build();
+ }
+ }
+} \ No newline at end of file
diff --git a/policy-persistence/src/main/java/org/openecomp/policy/drools/core/RepositoryAudit.java b/policy-persistence/src/main/java/org/openecomp/policy/drools/core/RepositoryAudit.java
index 86c672e2..c4301364 100644
--- a/policy-persistence/src/main/java/org/openecomp/policy/drools/core/RepositoryAudit.java
+++ b/policy-persistence/src/main/java/org/openecomp/policy/drools/core/RepositoryAudit.java
@@ -79,8 +79,12 @@ public class RepositoryAudit extends DroolsPDPIntegrityMonitor.AuditBase
logger.info("Running 'RepositoryAudit.invoke'");
boolean isActive = true;
+ boolean ignoreErrors = true; // ignore errors by default
String repoAuditIsActive = IntegrityMonitorProperties.getProperty("repository.audit.is.active");
- logger.debug("RepositoryAudit.invoke: repoAuditIsActive = " + repoAuditIsActive);
+ String repoAuditIgnoreErrors =
+ IntegrityMonitorProperties.getProperty("repository.audit.ignore.errors");
+ logger.debug("RepositoryAudit.invoke: repoAuditIsActive = " + repoAuditIsActive
+ + ", repoAuditIgnoreErrors = " + repoAuditIgnoreErrors);
if (repoAuditIsActive != null) {
try {
@@ -95,6 +99,18 @@ public class RepositoryAudit extends DroolsPDPIntegrityMonitor.AuditBase
return;
}
+ if (repoAuditIgnoreErrors != null)
+ {
+ try
+ {
+ ignoreErrors = Boolean.parseBoolean(repoAuditIgnoreErrors.trim());
+ }
+ catch (NumberFormatException e)
+ {
+ logger.warn("RepositoryAudit.invoke: Ignoring invalid property: repository.audit.ignore.errors = " + repoAuditIgnoreErrors);
+ }
+ }
+
// Fetch repository information from 'IntegrityMonitorProperties'
String repositoryId =
IntegrityMonitorProperties.getProperty("repository.audit.id");
@@ -126,9 +142,12 @@ public class RepositoryAudit extends DroolsPDPIntegrityMonitor.AuditBase
logger.error
("RepositoryAudit: Invalid 'repository.audit.timeout' value: '"
+ timeoutString + "'");
- response.append("Invalid 'repository.audit.timeout' value: '")
- .append(timeoutString).append("'\n");
- setResponse(response.toString());
+ if (!ignoreErrors)
+ {
+ response.append("Invalid 'repository.audit.timeout' value: '")
+ .append(timeoutString).append("'\n");
+ setResponse(response.toString());
+ }
}
}
@@ -191,8 +210,11 @@ public class RepositoryAudit extends DroolsPDPIntegrityMonitor.AuditBase
{
logger.error
("RepositoryAudit: 'mvn deploy:deploy-file' failed");
- response.append("'mvn deploy:deploy-file' failed\n");
- setResponse(response.toString());
+ if (!ignoreErrors)
+ {
+ response.append("'mvn deploy:deploy-file' failed\n");
+ setResponse(response.toString());
+ }
}
else
{
@@ -295,8 +317,11 @@ public class RepositoryAudit extends DroolsPDPIntegrityMonitor.AuditBase
{
logger.error
("RepositoryAudit: 'mvn compile' invocation failed");
- response.append("'mvn compile' invocation failed\n");
- setResponse(response.toString());
+ if (!ignoreErrors)
+ {
+ response.append("'mvn compile' invocation failed\n");
+ setResponse(response.toString());
+ }
}
/*
@@ -362,9 +387,12 @@ public class RepositoryAudit extends DroolsPDPIntegrityMonitor.AuditBase
// Audit ERROR: artifact download failed for some reason
logger.error("RepositoryAudit: "
+ artifact.toString() + ": does not exist");
- response.append("Failed to download artifact: ")
- .append(artifact).append('\n');
- setResponse(response.toString());
+ if (!ignoreErrors)
+ {
+ response.append("Failed to download artifact: ")
+ .append(artifact).append('\n');
+ setResponse(response.toString());
+ }
}
}
@@ -385,8 +413,11 @@ public class RepositoryAudit extends DroolsPDPIntegrityMonitor.AuditBase
{
logger.error
("RepositoryAudit: delete of uploaded artifact failed");
- response.append("delete of uploaded artifact failed\n");
- setResponse(response.toString());
+ if (!ignoreErrors)
+ {
+ response.append("delete of uploaded artifact failed\n");
+ setResponse(response.toString());
+ }
}
else
{
diff --git a/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/DroolsPdpsElectionHandler.java b/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/DroolsPdpsElectionHandler.java
index 82ee5d1d..40a8a56b 100644
--- a/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/DroolsPdpsElectionHandler.java
+++ b/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/DroolsPdpsElectionHandler.java
@@ -499,159 +499,38 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
/*
* We have checked the four combinations of isDesignated and isCurrent. Where appropriate,
* we added the PDPs to the potential list of designated pdps
- * Check if listOfDesignated is empty, has one entry or has multiple entries
- * If it has multiple designated PDPs, then we must determine if myPdp is on the list and if
- * it is the lowest priority. If it is on the list and it is not the lowest
- * priority, it must be demoted. Then, we must find the lowest priority
- * PDP so we can get the right list of sessions
+ *
+ * We need to give priority to pdps on the same site that is currently being used
+ * First, however, we must sanitize the list of designated to make sure their are
+ * only designated members or non-designated members. There should not be both in
+ * the list. Because there are real time delays, it is possible that both types could
+ * be on the list.
*/
- //we need to give priority to pdps on the same site that is currently being used
-
-
- //we need to figure out the last pdp that was the primary so we can get the last site name and the last session numbers
- DroolsPdp mostRecentPrimary = new DroolsPdpImpl(null, true, 1, new Date(0));
- mostRecentPrimary.setSiteName(null);
- for(DroolsPdp pdp : pdps){
- if(pdp.getDesignatedDate().compareTo(mostRecentPrimary.getDesignatedDate()) > 0){
- mostRecentPrimary = pdp;
- }
- }
-
- if(listOfDesignated.size() > 1){
- logger.debug
- //System.out.println
- ("DesignatedWaiter.run: myPdp: " + myPdp.getPdpId() + " listOfDesignated.size(): " + listOfDesignated.size());
- DroolsPdp rejectedPdp = null;
- DroolsPdp lowestPrioritySameSite = null;
- DroolsPdp lowestPriorityDifferentSite = null;
- for(DroolsPdp pdp : listOfDesignated){
- // We need to determine if another PDP is the lowest priority
- if(nullSafeEquals(pdp.getSiteName(),mostRecentPrimary.getSiteName())){
- if(lowestPrioritySameSite == null){
- if(lowestPriorityDifferentSite != null){
- rejectedPdp = lowestPriorityDifferentSite;
- }
- lowestPrioritySameSite = pdp;
- }else{
- if(pdp.getPdpId().equals((lowestPrioritySameSite.getPdpId()))){
- continue;//nothing to compare
- }
- if(pdp.comparePriority(lowestPrioritySameSite) <0){
- logger.debug
- //System.out.println
- ("\nDesignatedWaiter.run: myPdp" + myPdp.getPdpId() + " listOfDesignated pdp ID: " + pdp.getPdpId()
- + " has lower priority than pdp ID: " + lowestPrioritySameSite.getPdpId());
-
- //we need to reject lowestPrioritySameSite
- rejectedPdp = lowestPrioritySameSite;
- lowestPrioritySameSite = pdp;
- } else{
- //we need to reject pdp and keep lowestPrioritySameSite
- logger.debug
- //System.out.println
- ("\nDesignatedWaiter.run: myPdp" + myPdp.getPdpId() + " listOfDesignated pdp ID: " + pdp.getPdpId()
- + " has higher priority than pdp ID: " + lowestPrioritySameSite.getPdpId());
- rejectedPdp = pdp;
- }
- }
- } else{
- if(lowestPrioritySameSite != null){
- //if we already have a candidate for same site, we don't want to bother with different sites
- rejectedPdp = pdp;
- } else{
- if(lowestPriorityDifferentSite == null){
- lowestPriorityDifferentSite = pdp;
- continue;
- }
- if(pdp.getPdpId().equals((lowestPriorityDifferentSite.getPdpId()))){
- continue;//nothing to compare
- }
- if(pdp.comparePriority(lowestPriorityDifferentSite) <0){
- logger.debug
- //System.out.println
- ("\nDesignatedWaiter.run: myPdp" + myPdp.getPdpId() + " listOfDesignated pdp ID: " + pdp.getPdpId()
- + " has lower priority than pdp ID: " + lowestPriorityDifferentSite.getPdpId());
-
- //we need to reject lowestPriorityDifferentSite
- rejectedPdp = lowestPriorityDifferentSite;
- lowestPriorityDifferentSite = pdp;
- } else{
- //we need to reject pdp and keep lowestPriorityDifferentSite
- logger.debug
- //System.out.println
- ("\nDesignatedWaiter.run: myPdp" + myPdp.getPdpId() + " listOfDesignated pdp ID: " + pdp.getPdpId()
- + " has higher priority than pdp ID: " + lowestPriorityDifferentSite.getPdpId());
- rejectedPdp = pdp;
- }
- }
- }
- // If the rejectedPdp is myPdp, we need to stand it down and demote it. Each pdp is responsible
- // for demoting itself
- if(rejectedPdp != null && nullSafeEquals(rejectedPdp.getPdpId(),myPdp.getPdpId())){
- logger.debug
- //System.out.println
- ("\n\nDesignatedWaiter.run: myPdp: " + myPdp.getPdpId() + " listOfDesignated myPdp ID: " + myPdp.getPdpId()
- + " is NOT the lowest priority. Executing stateManagement.demote()" + "\n\n");
- // We found that myPdp is on the listOfDesignated and it is not the lowest priority
- // So, we must demote it
- try {
- //Keep the order like this. StateManagement is last since it triggers controller shutdown
- myPdp.setDesignated(false);
- pdpsConnector.setDesignated(myPdp, false);
- isDesignated = false;
- String standbyStatus = stateManagement.getStandbyStatus();
- if(!(standbyStatus.equals(StateManagement.HOT_STANDBY) ||
- standbyStatus.equals(StateManagement.COLD_STANDBY))){
- /*
- * Only call demote 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.
- */
- stateManagement.demote();
- }
- } catch (Exception e) {
- myPdp.setDesignated(false);
- pdpsConnector.setDesignated(myPdp, false);
- isDesignated = false;
- logger.error
- //System.out.println
- ("DesignatedWaiter.run: myPdp: " + myPdp.getPdpId() + " Caught Exception attempting to demote myPdp'"
- + myPdp.getPdpId()
- + "', message="
- + e.getMessage());
- System.out.println(new Date() + " DesignatedWaiter.run: caught unexpected exception "
- + "from stateManagement.demote()");
- e.printStackTrace();
- }
- }
- } //end: for(DroolsPdp pdp : listOfDesignated)
- if(lowestPrioritySameSite != null){
- lowestPriorityPdp = lowestPrioritySameSite;
- } else {
- lowestPriorityPdp = lowestPriorityDifferentSite;
- }
- //now we have a valid value for lowestPriorityPdp
- logger.debug
- //System.out.println
- ("\n\nDesignatedWaiter.run: myPdp: " + myPdp.getPdpId() + " listOfDesignated found the LOWEST priority pdp ID: "
- + lowestPriorityPdp.getPdpId()
- + " It is now the designatedPpd from the perspective of myPdp ID: " + myPdp + "\n\n");
- designatedPdp = lowestPriorityPdp;
- this.sessions = mostRecentPrimary.getSessions();
+
+ listOfDesignated = santizeDesignatedList(listOfDesignated);
- } else if(listOfDesignated.isEmpty()){
- logger.debug
- //System.out.println
- ("\nDesignatedWaiter.run: myPdp: " + myPdp.getPdpId() + " listOfDesignated is: EMPTY.");
- designatedPdp = null;
- } else{ //only one in listOfDesignated
- logger.debug
- //System.out.println
- ("\nDesignatedWaiter.run: myPdp: " + myPdp.getPdpId() + " listOfDesignated has ONE entry. PDP ID: "
- + listOfDesignated.get(0).getPdpId());
- designatedPdp = listOfDesignated.get(0);
- this.sessions = mostRecentPrimary.getSessions();
- }
+ /*
+ * We need to figure out the last pdp that was the primary so we can get the last site
+ * name and the last session numbers. We need to create a "dummy" droolspdp since
+ * it will be used in later comparrisons and cannot be null.
+ */
+
+ DroolsPdp mostRecentPrimary = computeMostRecentPrimary(pdps, listOfDesignated);
+
+
+ /*
+ * It is possible to get here with more than one pdp designated and providingservice. This normally
+ * occurs when there is a race condition with multiple nodes coming up at the same time. If that is
+ * the case we must determine which one is the one that should be designated and which one should
+ * be demoted.
+ *
+ * It is possible to have 0, 1, 2 or more but not all, or all designated.
+ * If we have one designated and current, we chose it and are done
+ * If we have 2 or more, but not all, we must determine which one is in the same site as
+ * the previously designated pdp.
+ */
+
+ designatedPdp = computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
if (designatedPdp == null) {
@@ -686,7 +565,10 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
* 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();
stateManagement.promote();
}
} catch (StandbyStatusException e) {
@@ -784,6 +666,262 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
} // end run
}
+ public ArrayList<DroolsPdp> santizeDesignatedList(ArrayList<DroolsPdp> listOfDesignated){
+
+ boolean containsDesignated = false;
+ boolean containsHotStandby = false;
+ ArrayList<DroolsPdp> listForRemoval = new ArrayList<DroolsPdp>();
+ for(DroolsPdp pdp : listOfDesignated){
+ logger.debug
+ //System.out.println
+ ("DesignatedWaiter.run sanitizing: pdp = " + pdp.getPdpId()
+ + " isDesignated = " + pdp.isDesignated());
+ if(pdp.isDesignated()){
+ containsDesignated = true;
+ }else {
+ containsHotStandby = true;
+ listForRemoval.add(pdp);
+ }
+ }
+ if(containsDesignated && containsHotStandby){
+ //remove the hot standby from the list
+ listOfDesignated.removeAll(listForRemoval);
+ containsHotStandby = false;
+ }
+ return listOfDesignated;
+ }
+
+ public DroolsPdp computeMostRecentPrimary(Collection<DroolsPdp> pdps, ArrayList<DroolsPdp> listOfDesignated){
+ boolean containsDesignated = false;
+ for(DroolsPdp pdp : listOfDesignated){
+ if(pdp.isDesignated()){
+ containsDesignated = true;
+ }
+ }
+ DroolsPdp mostRecentPrimary = new DroolsPdpImpl(null, true, 1, new Date(0));
+ mostRecentPrimary.setSiteName(null);
+ logger.debug
+ //System.out.println
+ ("DesignatedWaiter.run listOfDesignated.size() = " + listOfDesignated.size());
+ if(listOfDesignated.size() <=1){
+ logger.debug("DesignatedWainter.run: listOfDesignated.size <=1");
+ //Only one or none is designated or hot standby. Choose the latest designated date
+ for(DroolsPdp pdp : pdps){
+ logger.debug
+ //System.out.println
+ ("DesignatedWaiter.run pdp = " + pdp.getPdpId()
+ + " pdp.getDesignatedDate() = " + pdp.getDesignatedDate());
+ if(pdp.getDesignatedDate().compareTo(mostRecentPrimary.getDesignatedDate()) > 0){
+ mostRecentPrimary = pdp;
+ logger.debug
+ //System.out.println
+ ("DesignatedWaiter.run mostRecentPrimary = " + mostRecentPrimary.getPdpId());
+ }
+ }
+ }else if(listOfDesignated.size() == pdps.size()){
+ logger.debug("DesignatedWainter.run: listOfDesignated.size = pdps.size() which is " + pdps.size());
+ //They are all designated or all hot standby.
+ mostRecentPrimary = null;
+ for(DroolsPdp pdp : pdps){
+ if(mostRecentPrimary == null){
+ mostRecentPrimary = pdp;
+ continue;
+ }
+ if(containsDesignated){ //Choose the site of the first designated date
+ if(pdp.getDesignatedDate().compareTo(mostRecentPrimary.getDesignatedDate()) < 0){
+ mostRecentPrimary = pdp;
+ logger.debug
+ //System.out.println
+ ("DesignatedWaiter.run mostRecentPrimary = " + mostRecentPrimary.getPdpId());
+ }
+ }else{ //Choose the site with the latest designated date
+ if(pdp.getDesignatedDate().compareTo(mostRecentPrimary.getDesignatedDate()) > 0){
+ mostRecentPrimary = pdp;
+ logger.debug
+ //System.out.println
+ ("DesignatedWaiter.run mostRecentPrimary = " + mostRecentPrimary.getPdpId());
+ }
+ }
+ }
+ }else{
+ logger.debug("DesignatedWainter.run: Some but not all are designated or hot standby. ");
+ //Some but not all are designated or hot standby.
+ if(containsDesignated){
+ logger.debug("DesignatedWainter.run: containsDesignated = " + containsDesignated);
+ /*
+ * The list only contains designated. This is a problem. It is most likely a race
+ * condition that resulted in two thinking they should be designated. Choose the
+ * site with the latest designated date for the pdp not included on the designated list.
+ * This should be the site that had the last designation before this race condition
+ * occurred.
+ */
+ for(DroolsPdp pdp : pdps){
+ if(listOfDesignated.contains(pdp)){
+ continue; //Don't consider this entry
+ }
+ if(pdp.getDesignatedDate().compareTo(mostRecentPrimary.getDesignatedDate()) > 0){
+ mostRecentPrimary = pdp;
+ logger.debug
+ //System.out.println
+ ("DesignatedWaiter.run mostRecentPrimary = " + mostRecentPrimary.getPdpId());
+ }
+ }
+ }else{
+ logger.debug("DesignatedWainter.run: containsDesignated = " + containsDesignated);
+ //The list only contains hot standby. Choose the site of the latest designated date
+ for(DroolsPdp pdp : pdps){
+ if(pdp.getDesignatedDate().compareTo(mostRecentPrimary.getDesignatedDate()) > 0){
+ mostRecentPrimary = pdp;
+ logger.debug
+ //System.out.println
+ ("DesignatedWaiter.run mostRecentPrimary = " + mostRecentPrimary.getPdpId());
+ }
+ }
+ }
+ }
+ return mostRecentPrimary;
+ }
+
+ public DroolsPdp computeDesignatedPdp(ArrayList<DroolsPdp> listOfDesignated, DroolsPdp mostRecentPrimary){
+ DroolsPdp designatedPdp = null;
+ DroolsPdp lowestPriorityPdp = null;
+ if(listOfDesignated.size() > 1){
+ logger.debug
+ //System.out.println
+ ("DesignatedWaiter.run: myPdp: " + myPdp.getPdpId() + " listOfDesignated.size(): " + listOfDesignated.size());
+ DroolsPdp rejectedPdp = null;
+ DroolsPdp lowestPrioritySameSite = null;
+ DroolsPdp lowestPriorityDifferentSite = null;
+ for(DroolsPdp pdp : listOfDesignated){
+ // We need to determine if another PDP is the lowest priority
+ if(nullSafeEquals(pdp.getSiteName(),mostRecentPrimary.getSiteName())){
+ if(lowestPrioritySameSite == null){
+ if(lowestPriorityDifferentSite != null){
+ rejectedPdp = lowestPriorityDifferentSite;
+ }
+ lowestPrioritySameSite = pdp;
+ }else{
+ if(pdp.getPdpId().equals((lowestPrioritySameSite.getPdpId()))){
+ continue;//nothing to compare
+ }
+ if(pdp.comparePriority(lowestPrioritySameSite) <0){
+ logger.debug
+ //System.out.println
+ ("\nDesignatedWaiter.run: myPdp" + myPdp.getPdpId() + " listOfDesignated pdp ID: " + pdp.getPdpId()
+ + " has lower priority than pdp ID: " + lowestPrioritySameSite.getPdpId());
+
+ //we need to reject lowestPrioritySameSite
+ rejectedPdp = lowestPrioritySameSite;
+ lowestPrioritySameSite = pdp;
+ } else{
+ //we need to reject pdp and keep lowestPrioritySameSite
+ logger.debug
+ //System.out.println
+ ("\nDesignatedWaiter.run: myPdp" + myPdp.getPdpId() + " listOfDesignated pdp ID: " + pdp.getPdpId()
+ + " has higher priority than pdp ID: " + lowestPrioritySameSite.getPdpId());
+ rejectedPdp = pdp;
+ }
+ }
+ } else{
+ if(lowestPrioritySameSite != null){
+ //if we already have a candidate for same site, we don't want to bother with different sites
+ rejectedPdp = pdp;
+ } else{
+ if(lowestPriorityDifferentSite == null){
+ lowestPriorityDifferentSite = pdp;
+ continue;
+ }
+ if(pdp.getPdpId().equals((lowestPriorityDifferentSite.getPdpId()))){
+ continue;//nothing to compare
+ }
+ if(pdp.comparePriority(lowestPriorityDifferentSite) <0){
+ logger.debug
+ //System.out.println
+ ("\nDesignatedWaiter.run: myPdp" + myPdp.getPdpId() + " listOfDesignated pdp ID: " + pdp.getPdpId()
+ + " has lower priority than pdp ID: " + lowestPriorityDifferentSite.getPdpId());
+
+ //we need to reject lowestPriorityDifferentSite
+ rejectedPdp = lowestPriorityDifferentSite;
+ lowestPriorityDifferentSite = pdp;
+ } else{
+ //we need to reject pdp and keep lowestPriorityDifferentSite
+ logger.debug
+ //System.out.println
+ ("\nDesignatedWaiter.run: myPdp" + myPdp.getPdpId() + " listOfDesignated pdp ID: " + pdp.getPdpId()
+ + " has higher priority than pdp ID: " + lowestPriorityDifferentSite.getPdpId());
+ rejectedPdp = pdp;
+ }
+ }
+ }
+ // If the rejectedPdp is myPdp, we need to stand it down and demote it. Each pdp is responsible
+ // for demoting itself
+ if(rejectedPdp != null && nullSafeEquals(rejectedPdp.getPdpId(),myPdp.getPdpId())){
+ logger.debug
+ //System.out.println
+ ("\n\nDesignatedWaiter.run: myPdp: " + myPdp.getPdpId() + " listOfDesignated myPdp ID: " + myPdp.getPdpId()
+ + " is NOT the lowest priority. Executing stateManagement.demote()" + "\n\n");
+ // We found that myPdp is on the listOfDesignated and it is not the lowest priority
+ // So, we must demote it
+ try {
+ //Keep the order like this. StateManagement is last since it triggers controller shutdown
+ myPdp.setDesignated(false);
+ pdpsConnector.setDesignated(myPdp, false);
+ isDesignated = false;
+ String standbyStatus = stateManagement.getStandbyStatus();
+ if(!(standbyStatus.equals(StateManagement.HOT_STANDBY) ||
+ standbyStatus.equals(StateManagement.COLD_STANDBY))){
+ /*
+ * Only call demote 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.
+ */
+ stateManagement.demote();
+ }
+ } catch (Exception e) {
+ myPdp.setDesignated(false);
+ pdpsConnector.setDesignated(myPdp, false);
+ isDesignated = false;
+ logger.error
+ //System.out.println
+ ("DesignatedWaiter.run: myPdp: " + myPdp.getPdpId() + " Caught Exception attempting to demote myPdp'"
+ + myPdp.getPdpId()
+ + "', message="
+ + e.getMessage());
+ System.out.println(new Date() + " DesignatedWaiter.run: caught unexpected exception "
+ + "from stateManagement.demote()");
+ e.printStackTrace();
+ }
+ }
+ } //end: for(DroolsPdp pdp : listOfDesignated)
+ if(lowestPrioritySameSite != null){
+ lowestPriorityPdp = lowestPrioritySameSite;
+ } else {
+ lowestPriorityPdp = lowestPriorityDifferentSite;
+ }
+ //now we have a valid value for lowestPriorityPdp
+ logger.debug
+ //System.out.println
+ ("\n\nDesignatedWaiter.run: myPdp: " + myPdp.getPdpId() + " listOfDesignated found the LOWEST priority pdp ID: "
+ + lowestPriorityPdp.getPdpId()
+ + " It is now the designatedPpd from the perspective of myPdp ID: " + myPdp + "\n\n");
+ designatedPdp = lowestPriorityPdp;
+
+ } else if(listOfDesignated.isEmpty()){
+ logger.debug
+ //System.out.println
+ ("\nDesignatedWaiter.run: myPdp: " + myPdp.getPdpId() + " listOfDesignated is: EMPTY.");
+ designatedPdp = null;
+ } else{ //only one in listOfDesignated
+ logger.debug
+ //System.out.println
+ ("\nDesignatedWaiter.run: myPdp: " + myPdp.getPdpId() + " listOfDesignated has ONE entry. PDP ID: "
+ + listOfDesignated.get(0).getPdpId());
+ designatedPdp = listOfDesignated.get(0);
+ }
+ return designatedPdp;
+
+ }
+
private class TimerUpdateClass extends TimerTask{
@Override
@@ -926,7 +1064,7 @@ public class DroolsPdpsElectionHandler implements ThreadRunningChecker {
long nowModMs = nowMs % pdpUpdateInterval;
// Time to the start of the next pdpUpdateInterval multiple
- long startMs = pdpUpdateInterval - nowModMs;
+ long startMs = 2*pdpUpdateInterval - nowModMs;
// Give the start time a minimum of a 5 second cushion
if(startMs < 5000){
diff --git a/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/JpaDroolsPdpsConnector.java b/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/JpaDroolsPdpsConnector.java
index ac9255a2..d2032895 100644
--- a/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/JpaDroolsPdpsConnector.java
+++ b/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/JpaDroolsPdpsConnector.java
@@ -27,6 +27,7 @@ import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
+import javax.persistence.FlushModeType;
import javax.persistence.LockModeType;
import javax.persistence.Query;
@@ -54,7 +55,7 @@ public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
try {
em.getTransaction().begin();
Query droolsPdpsListQuery = em.createQuery("SELECT p FROM DroolsPdpEntity p");
- List<?> droolsPdpsList = droolsPdpsListQuery.setLockMode(LockModeType.PESSIMISTIC_READ).getResultList();
+ List<?> droolsPdpsList = droolsPdpsListQuery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
LinkedList<DroolsPdp> droolsPdpsReturnList = new LinkedList<DroolsPdp>();
for(Object o : droolsPdpsList){
if(o instanceof DroolsPdp){
@@ -105,7 +106,7 @@ public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
em.getTransaction().begin();
Query droolsPdpsListQuery = em.createQuery("SELECT p FROM DroolsPdpEntity p WHERE p.pdpId=:pdpId");
droolsPdpsListQuery.setParameter("pdpId", pdp.getPdpId());
- List<?> droolsPdpsList = droolsPdpsListQuery.setLockMode(LockModeType.PESSIMISTIC_WRITE).getResultList();
+ List<?> droolsPdpsList = droolsPdpsListQuery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
//em.getTransaction().begin();
DroolsPdpEntity droolsPdpEntity;
if(droolsPdpsList.size() == 1 && (droolsPdpsList.get(0) instanceof DroolsPdpEntity)){
@@ -210,7 +211,7 @@ public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
em.getTransaction().begin();
Query droolsPdpsListQuery = em.createQuery("SELECT p FROM DroolsPdpEntity p WHERE p.pdpId=:pdpId");
droolsPdpsListQuery.setParameter("pdpId", pdp.getPdpId());
- List<?> droolsPdpsList = droolsPdpsListQuery.setLockMode(LockModeType.PESSIMISTIC_WRITE).getResultList();
+ List<?> droolsPdpsList = droolsPdpsListQuery.setLockMode(LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
if(droolsPdpsList.size() == 1 && droolsPdpsList.get(0) instanceof DroolsPdpEntity){
if (logger.isDebugEnabled()) {
logger.debug("isPdpCurrent: PDP=" + pdp.getPdpId() + " designated but not current; setting designated to false");
@@ -254,7 +255,7 @@ public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
.createQuery("SELECT p FROM DroolsPdpEntity p WHERE p.pdpId=:pdpId");
droolsPdpsListQuery.setParameter("pdpId", pdp.getPdpId());
List<?> droolsPdpsList = droolsPdpsListQuery.setLockMode(
- LockModeType.PESSIMISTIC_WRITE).getResultList();
+ LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
if (droolsPdpsList.size() == 1
&& droolsPdpsList.get(0) instanceof DroolsPdpEntity) {
DroolsPdpEntity droolsPdpEntity = (DroolsPdpEntity) droolsPdpsList
@@ -306,7 +307,7 @@ public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
.createQuery("SELECT p FROM DroolsPdpEntity p WHERE p.pdpId=:pdpId");
droolsPdpsListQuery.setParameter("pdpId", pdpId);
List<?> droolsPdpsList = droolsPdpsListQuery.setLockMode(
- LockModeType.PESSIMISTIC_WRITE).getResultList();
+ LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
DroolsPdpEntity droolsPdpEntity;
if (droolsPdpsList.size() == 1
&& (droolsPdpsList.get(0) instanceof DroolsPdpEntity)) {
@@ -460,7 +461,7 @@ public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
.createQuery("SELECT p FROM DroolsPdpEntity p WHERE p.pdpId=:pdpId");
droolsPdpsListQuery.setParameter("pdpId", pdpId);
List<?> droolsPdpsList = droolsPdpsListQuery.setLockMode(
- LockModeType.PESSIMISTIC_WRITE).getResultList();
+ LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
if (droolsPdpsList.size() == 1
&& droolsPdpsList.get(0) instanceof DroolsPdpEntity) {
droolsPdpEntity = (DroolsPdpEntity) droolsPdpsList.get(0);
@@ -553,7 +554,7 @@ public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
.createQuery("SELECT p FROM DroolsPdpEntity p");
@SuppressWarnings("unchecked")
List<DroolsPdp> droolsPdpsList = droolsPdpsListQuery.setLockMode(
- LockModeType.NONE).getResultList();
+ LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
logger.info("deleteAllPdps: Deleting " + droolsPdpsList.size() + " PDPs");
for (DroolsPdp droolsPdp : droolsPdpsList) {
String pdpId = droolsPdp.getPdpId();
@@ -634,7 +635,7 @@ public class JpaDroolsPdpsConnector implements DroolsPdpsConnector {
.createQuery("SELECT p FROM DroolsSessionEntity p");
@SuppressWarnings("unchecked")
List<DroolsSession> droolsSessionsList = droolsSessionListQuery.setLockMode(
- LockModeType.NONE).getResultList();
+ LockModeType.NONE).setFlushMode(FlushModeType.COMMIT).getResultList();
logger.info("deleteAllSessions: Deleting " + droolsSessionsList.size() + " Sessions");
for (DroolsSession droolsSession : droolsSessionsList) {
logger.info("deleteAllSessions: Deleting droolsSession with pdpId="
diff --git a/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/PersistenceFeature.java b/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/PersistenceFeature.java
index e2c7f402..e592220e 100644
--- a/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/PersistenceFeature.java
+++ b/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/PersistenceFeature.java
@@ -43,10 +43,11 @@ import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
import org.openecomp.policy.common.logging.flexlogger.Logger;
import org.openecomp.policy.common.logging.flexlogger.PropertyUtil;
import org.openecomp.policy.drools.core.DroolsPDPIntegrityMonitor;
-import org.openecomp.policy.drools.core.FeatureAPI;
+import org.openecomp.policy.drools.core.PolicySessionFeatureAPI;
import org.openecomp.policy.drools.core.IntegrityMonitorProperties;
import org.openecomp.policy.drools.core.PolicyContainer;
import org.openecomp.policy.drools.core.PolicySession;
+import org.openecomp.policy.drools.features.PolicyEngineFeatureAPI;
import org.openecomp.policy.drools.im.PMStandbyStateChangeNotifier;
import org.openecomp.policy.drools.system.PolicyEngine;
@@ -64,7 +65,7 @@ import bitronix.tm.resource.jdbc.PoolingDataSource;
* 'PolicyContainer' and 'Main'. It was moved here as part of making this
* a separate optional feature.
*/
-public class PersistenceFeature implements FeatureAPI
+public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngineFeatureAPI
{
// get an instance of logger
private static Logger logger =
@@ -199,88 +200,116 @@ public class PersistenceFeature implements FeatureAPI
getContainerAdjunct(policySession.getPolicyContainer())
.destroyKieSession();
}
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void beforeStartEngine()
- {
- return;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void afterStartEngine()
- {
- PolicyEngine.manager.lock();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void beforeShutdownEngine()
- {
- return;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void beforeCreateController(String name, Properties properties)
- {
- return;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void afterCreateController(String name)
- {
- return;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void afterShutdownEngine()
- {
- return;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void beforeStartController(String name)
- {
- return;
- }
/**
* {@inheritDoc}
*/
@Override
- public void afterStartController(String name)
+ public boolean isPersistenceEnabled()
{
- return;
+ return(!persistenceDisabled);
}
-
+
/**
* {@inheritDoc}
*/
@Override
- public boolean isPersistenceEnabled()
+ public boolean afterStart(PolicyEngine engine)
{
- return(!persistenceDisabled);
+ // ASSERTION: engine == PolicyEngine.manager
+ PolicyEngine.manager.lock();
+ return false;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean beforeStart(PolicyEngine engine) {return false;}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean beforeShutdown(PolicyEngine engine) {return false;}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean afterShutdown(PolicyEngine engine) {return false;}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean beforeConfigure(PolicyEngine engine, Properties properties) {return false;}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean afterConfigure(PolicyEngine engine) {return false;}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean beforeActivate(PolicyEngine engine) {return false;}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean afterActivate(PolicyEngine engine) {return false;}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean beforeDeactivate(PolicyEngine engine) {return false;}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean afterDeactivate(PolicyEngine engine) {return false;}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean beforeStop(PolicyEngine engine) {return false;}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean afterStop(PolicyEngine engine) {return false;}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean beforeLock(PolicyEngine engine) {return false;}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean afterLock(PolicyEngine engine) {return false;}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean beforeUnlock(PolicyEngine engine) {return false;}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean afterUnlock(PolicyEngine engine) {return false;}
/**************************/
diff --git a/policy-persistence/src/main/resources/META-INF/services/org.openecomp.policy.drools.core.FeatureAPI b/policy-persistence/src/main/resources/META-INF/services/org.openecomp.policy.drools.core.PolicySessionFeatureAPI
index 540a4bd4..540a4bd4 100644
--- a/policy-persistence/src/main/resources/META-INF/services/org.openecomp.policy.drools.core.FeatureAPI
+++ b/policy-persistence/src/main/resources/META-INF/services/org.openecomp.policy.drools.core.PolicySessionFeatureAPI
diff --git a/policy-persistence/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI b/policy-persistence/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI
new file mode 100644
index 00000000..540a4bd4
--- /dev/null
+++ b/policy-persistence/src/main/resources/META-INF/services/org.openecomp.policy.drools.features.PolicyEngineFeatureAPI
@@ -0,0 +1 @@
+org.openecomp.policy.drools.persistence.PersistenceFeature
diff --git a/policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/ResiliencyTestCases.java b/policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/ResiliencyTestCases.java
deleted file mode 100644
index f58d304e..00000000
--- a/policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/ResiliencyTestCases.java
+++ /dev/null
@@ -1,1267 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * policy-persistence
- * ================================================================================
- * 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=========================================================
- */
-
-package org.openecomp.policy.drools.controller.test;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.Date;
-import java.util.Properties;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityTransaction;
-import javax.persistence.Persistence;
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import org.openecomp.policy.common.logging.eelf.PolicyLogger;
-import org.openecomp.policy.common.im.AdministrativeStateException;
-import org.openecomp.policy.common.im.IntegrityMonitor;
-import org.openecomp.policy.common.im.StandbyStatusException;
-import org.openecomp.policy.common.im.StateManagement;
-import org.openecomp.policy.drools.core.DroolsPDPIntegrityMonitor;
-import org.openecomp.policy.drools.core.IntegrityMonitorProperties;
-import org.openecomp.policy.drools.core.PolicyContainer;
-import org.openecomp.policy.drools.im.PMStandbyStateChangeNotifier;
-import org.openecomp.policy.drools.persistence.DroolsPdp;
-import org.openecomp.policy.drools.persistence.DroolsPdpEntity;
-import org.openecomp.policy.drools.persistence.DroolsPdpImpl;
-import org.openecomp.policy.drools.persistence.DroolsPdpsConnector;
-import org.openecomp.policy.drools.persistence.JpaDroolsPdpsConnector;
-import org.openecomp.policy.drools.persistence.DroolsPersistenceProperties;
-import org.openecomp.policy.drools.persistence.XacmlPersistenceProperties;
-import org.openecomp.policy.drools.system.Main;
-import org.openecomp.policy.drools.system.PolicyEngine;
-
-import org.apache.commons.lang3.time.DateUtils;
-
-/*
- * Cloned from StandbyStateManagement.java in support of US673632.
- * See MultiSite_v1-10.ppt, slide 38
- */
-public class ResiliencyTestCases {
-
- /*
- * Currently, the DroolsPdpsElectionHandler.DesignationWaiter is invoked every ten seconds, starting
- * at ten seconds after the minute boundary (e.g. 13:05:10). So, an 80 second sleep should be
- * sufficient to ensure that we wait for the DesignationWaiter to do its job, before
- * checking the results.
- */
- long sleepTime = 80000;
-
- /*
- * DroolsPdpsElectionHandler runs every ten seconds, so a 15 second sleep should be
- * plenty to ensure it has time to re-promote this PDP.
- */
- long electionWaitSleepTime = 15000;
-
- /*
- * Sleep 5 seconds after each test to allow interrupt (shutdown) recovery.
- */
- long interruptRecoveryTime = 5000;
-
- /*
- * See the IntegrityMonitor.getJmxUrl() method for the rationale behind this jmx related processing.
- */
- @BeforeClass
- public static void setUpClass() throws Exception {
-
- String userDir = System.getProperty("user.dir");
- PolicyLogger.debug("setUpClass: userDir=" + userDir);
- System.setProperty("com.sun.management.jmxremote.port", "9980");
- System.setProperty("com.sun.management.jmxremote.authenticate","false");
-
- // Make sure path to config directory is set correctly in PolicyContainer.main
- // Also make sure we ignore HTTP server failures resulting from port conflicts.
- PolicyContainer.isUnitTesting = true;
-
- }
-
- @AfterClass
- public static void tearDownClass() throws Exception {
- }
-
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
-
- }
-
- public void cleanDroolsDB() throws Exception{
- PolicyLogger.debug("\n\ncleanDroolsDB: Entering\n\n");
-
- PolicyLogger.debug("cleanDroolsDB: Reading droolsPersistenceProperties");
- Properties droolsPersistenceProperties = new Properties();
- droolsPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/droolsPersistence.properties")));
-
- PolicyLogger.debug("cleanDroolsDB: Creating emfDrools");
- EntityManagerFactory emf = Persistence.createEntityManagerFactory(
- "junitDroolsPU", droolsPersistenceProperties);
-
- PolicyLogger.debug("cleanDroolsDB: Cleaning up tables");
-
- EntityManager em = emf.createEntityManager();
- EntityTransaction et = em.getTransaction();
- et.begin();
-
- // Make sure the DB is clean
- PolicyLogger.debug("cleanDroolsDB: clean DroolsPdpEntity");
- em.createQuery("DELETE FROM DroolsPdpEntity").executeUpdate();
- PolicyLogger.debug("cleanDroolsDB: clean DroolsSessionEntity");
- em.createQuery("DELETE FROM DroolsSessionEntity").executeUpdate();
-
- em.flush();
- PolicyLogger.debug("cleanDroolsDB: after flush");
-
- et.commit();
-
- PolicyLogger.debug("\n\ncleanDroolsDB: Exiting\n\n");
- }
-
- public void cleanXacmlDB() throws Exception {
- PolicyLogger.debug("\n\ncleanXacmlDB: Entering\n\n");
-
- PolicyLogger.debug("cleanXacmlDB: Reading IntegrityMonitorProperties");
-
- PolicyLogger.debug("cleanXacmlDB: Reading xacmlPersistenceProperties");
- Properties xacmlPersistenceProperties = new Properties();
- xacmlPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/xacmlPersistence.properties")));
-
- PolicyLogger.debug("cleanXacmlDB: Creating emf");
- EntityManagerFactory emf = Persistence.createEntityManagerFactory(
- "junitXacmlPU", xacmlPersistenceProperties);
-
- EntityManager em = emf.createEntityManager();
- EntityTransaction et = em.getTransaction();
- et.begin();
-
- // Make sure the DB is clean
- PolicyLogger.debug("cleanXacmlDB: clean StateManagementEntity");
- em.createQuery("DELETE FROM StateManagementEntity").executeUpdate();
- PolicyLogger.debug("cleanXacmlDB: clean ResourceRegistrationEntity");
- em.createQuery("DELETE FROM ResourceRegistrationEntity").executeUpdate();
- PolicyLogger.debug("cleanXacmlDB: clean ForwardProgressEntity");
- em.createQuery("DELETE FROM ForwardProgressEntity").executeUpdate();
-
- em.flush();
- PolicyLogger.debug("cleandXacmlDB: after flush");
-
- et.commit();
-
- PolicyLogger.debug("\n\ncleanXacmlDB: Exiting\n\n");
-
- }
-
- @Ignore
- @Test
- public void singleNodeTests() throws Exception{
- //snNewInstall();
- snNewInstallBadDepData();
- /*snRecoveryFromBadDepData();
- snLock();
- snLockRestart();
- snUnlock();
- snUnlockRestart();*/
- }
-
- @Ignore
- @Test
- public void twoNodeTests() throws Exception{
- tnNewInstall();
- tnLockActive();
- tnUnlockColdStandby();
- tnFailActive();
- tnRecoverFailed();
- }
-
- @Ignore
- @Test
- public void twoSitesTwoNodesPerSiteTests() throws Exception{
- tstnNewInstall();
- tstnLock1Site1();
- tstnLock2Site1();
- tstnFailActiveSite2();
- tstnRecoverFailedSite2();
- tstnUnlockSite1();
- tstnFailSite2();
- }
-
-
- /*
- * Single Node Tests
- */
- public void snNewInstall() throws Exception{
- PolicyLogger.debug("\n\nsnNewInstall: Entry\n\n");
- cleanDroolsDB();
- cleanXacmlDB();
-
- //*******************************************
-
- PolicyLogger.debug("snNewInstall: Reading IntegrityMonitorProperties");
- Properties integrityMonitorProperties = new Properties();
- integrityMonitorProperties.load(new FileInputStream(new File(
- "src/test/server/config/IntegrityMonitor.properties")));
- IntegrityMonitorProperties.initProperties(integrityMonitorProperties);
- String thisPdpId = IntegrityMonitorProperties
- .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID);
-
- PolicyLogger.debug("snNewInstall: Reading xacmlPersistenceProperties");
- Properties xacmlPersistenceProperties = new Properties();
- xacmlPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/xacmlPersistence.properties")));
- XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties);
-
- PolicyLogger.debug("snNewInstall: Creating emfXacml");
- EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
- "junitXacmlPU", xacmlPersistenceProperties);
-
- PolicyLogger.debug("snNewInstall: Reading droolsPersistenceProperties");
- Properties droolsPersistenceProperties = new Properties();
- droolsPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/droolsPersistence.properties")));
- DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
-
- PolicyLogger.debug("snNewInstall: Creating emfDrools");
- EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
- "junitDroolsPU", droolsPersistenceProperties);
-
- DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
-
- PolicyLogger.debug("snNewInstall: Inserting PDP=" + thisPdpId + " as designated");
- DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date());
- conn.insertPdp(pdp);
- DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
- PolicyLogger.debug("snNewInstall: After insertion, DESIGNATED="
- + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated() == true);
-
- /*
- * When the Standby Status changes (from providingservice) to hotstandby
- * or coldstandby,the Active/Standby selection algorithm must stand down
- * if thePDP-D is currently the lead/active node and allow another PDP-D
- * to take over.
- *
- * It must also call lock on all engines in the engine management.
- *
- */
- PolicyLogger.debug("snNewInstall: Instantiating stateManagement object");
- StateManagement sm = new StateManagement(emfXacml, thisPdpId);
- PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier();
- sm.addObserver(pmStandbyStateChangeNotifier);
-
- // Artificially putting a PDP into service is really a two step process, 1)
- // inserting it as designated and 2) promoting it so that its standbyStatus
- // is providing service.
-
- PolicyLogger.debug("snNewInstall: Running policy-management.Main class");
- PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner();
- policyManagementRunner.start();
-
- PolicyLogger.debug("snNewInstall: Runner started; Sleeping "
- + interruptRecoveryTime + "ms before promoting PDP="
- + thisPdpId);
- Thread.sleep(interruptRecoveryTime);
-
- PolicyLogger.debug("snNewInstall: Promoting PDP=" + thisPdpId);
- sm.promote();
-
- String standbyStatus = sm.getStandbyStatus(thisPdpId);
- PolicyLogger.debug("snNewInstall: Before locking, PDP=" + thisPdpId + " has standbyStatus="
- + standbyStatus);
-
- PolicyLogger.debug("snNewInstall: Locking sm");
- sm.lock();
-
- Thread.sleep(interruptRecoveryTime);
- /*
- * Verify that the PDP is no longer designated.
- */
- droolsPdpEntity = conn.getPdp(thisPdpId);
- PolicyLogger.debug("snNewInstall: After lock sm.lock() invoked, DESIGNATED="
- + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated() == false);
-
- PolicyLogger.debug("snNewInstall: Stopping policyManagementRunner");
- policyManagementRunner.stopRunner();
-
- PolicyLogger.debug("\n\nsnNewInstall: Exiting\n\n");
- Thread.sleep(interruptRecoveryTime);
-
- //********************************************
-
- PolicyLogger.debug("\n\nsnNewInstall: Exit\n\n");
- }
-
- public void snNewInstallBadDepData() throws Exception{
- PolicyLogger.debug("\n\nsnNewInstallBadDepData: Entry\n\n");
- cleanDroolsDB();
- cleanXacmlDB();
-
- //*******************************************
-
- PolicyLogger.debug("snNewInstallBadDepData: Reading IntegrityMonitor_BadDependencyData.properties");
- Properties integrityMonitorProperties = new Properties();
- integrityMonitorProperties.load(new FileInputStream(new File(
- "src/test/server/config/IntegrityMonitor_BadDependencyData.properties")));
- IntegrityMonitorProperties.initProperties(integrityMonitorProperties);
- String thisPdpId = IntegrityMonitorProperties
- .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID);
-
- PolicyLogger.debug("snNewInstallBadDepData: Reading xacmlPersistenceProperties");
- Properties xacmlPersistenceProperties = new Properties();
- xacmlPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/xacmlPersistence.properties")));
- XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties);
-
- PolicyLogger.debug("snNewInstallBadDepData: Creating emfXacml");
- EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
- "junitXacmlPU", xacmlPersistenceProperties);
-
- PolicyLogger.debug("snNewInstallBadDepData: Reading droolsPersistenceProperties");
- Properties droolsPersistenceProperties = new Properties();
- droolsPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/droolsPersistence.properties")));
- DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
-
- PolicyLogger.debug("snNewInstallBadDepData: Creating emfDrools");
- EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
- "junitDroolsPU", droolsPersistenceProperties);
-
- DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
-
- PolicyLogger.debug("snNewInstallBadDepData: Inserting PDP=" + thisPdpId + " as designated");
- DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date());
- conn.insertPdp(pdp);
- DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
- //PolicyLogger.debug
- System.out.println
- ("\n\nsnNewInstallBadDepData: After insertion, DESIGNATED="
- + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId + "\n\n********************");
- assertTrue(droolsPdpEntity.isDesignated() == true);
-
- /*
- * When the Standby Status changes (from providingservice) to hotstandby
- * or coldstandby,the Active/Standby selection algorithm must stand down
- * if thePDP-D is currently the lead/active node and allow another PDP-D
- * to take over.
- */
- PolicyLogger.debug("snNewInstall: Instantiating stateManagement object");
- StateManagement sm = new StateManagement(emfXacml, thisPdpId);
- PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier();
- sm.addObserver(pmStandbyStateChangeNotifier);
-
- // Artificially putting a PDP into service is really a two step process, 1)
- // inserting it as designated and 2) promoting it so that its standbyStatus
- // is providing service.
-
- PolicyLogger.debug("snNewInstall: Running policy-management.Main class");
- PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner();
- policyManagementRunner.start();
-
- PolicyLogger.debug("snNewInstall: Runner started; Sleeping "
- + interruptRecoveryTime + "ms before promoting PDP="
- + thisPdpId);
- Thread.sleep(interruptRecoveryTime);
-
- PolicyLogger.debug("snNewInstall: Promoting PDP=" + thisPdpId);
- sm.promote();
-
- String standbyStatus = sm.getStandbyStatus(thisPdpId);
- PolicyLogger.debug("snNewInstall: Before locking, PDP=" + thisPdpId + " has standbyStatus="
- + standbyStatus);
-
- /*
- * Verify that the PDP is no longer designated.
- */
- droolsPdpEntity = conn.getPdp(thisPdpId);
- PolicyLogger.debug("snNewInstall: After lock sm.lock() invoked, DESIGNATED="
- + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated() == false);
-
- PolicyLogger.debug("snNewInstall: Stopping policyManagementRunner");
- policyManagementRunner.stopRunner();
-
- PolicyLogger.debug("\n\nsnNewInstall: Exiting\n\n");
- Thread.sleep(interruptRecoveryTime);
-
- //********************************************
-
- PolicyLogger.debug("\n\nsnNewInstallBadDepData: Exit\n\n");
- }
-
- public void snRecoveryFromBadDepData() throws Exception{
-
- }
-
- public void snLock() throws Exception {
-
- }
-
- public void snLockRestart() throws Exception {
-
- }
-
- public void snUnlock() throws Exception {
-
- }
-
- public void snUnlockRestart() throws Exception {
-
- }
-
- /*
- * Two Nodes tests
- */
- public void tnNewInstall() throws Exception {
-
- }
-
- public void tnLockActive() throws Exception {
-
- }
-
- public void tnUnlockColdStandby() throws Exception {
-
- }
-
- public void tnFailActive() throws Exception {
-
- }
-
- public void tnRecoverFailed() throws Exception {
-
- }
-
- /*
- * Two Sites, Two Nodes Each Site tests
- */
-
- public void tstnNewInstall() throws Exception {
-
- }
-
- public void tstnLock1Site1() throws Exception {
-
- }
-
- public void tstnLock2Site1() throws Exception {
-
- }
-
- public void tstnFailActiveSite2() throws Exception {
-
- }
-
- public void tstnRecoverFailedSite2() throws Exception {
-
- }
-
- public void tstnUnlockSite1() throws Exception {
-
- }
-
- public void tstnFailSite2() throws Exception {
-
- }
-
-
- @Ignore
- @Test
- public void testColdStandby() throws Exception {
-
- PolicyLogger.debug("\n\ntestColdStandby: Entering\n\n");
-
- PolicyLogger.debug("testColdStandby: Reading IntegrityMonitorProperties");
- Properties integrityMonitorProperties = new Properties();
- integrityMonitorProperties.load(new FileInputStream(new File(
- "src/test/server/config/IntegrityMonitor.properties")));
- IntegrityMonitorProperties.initProperties(integrityMonitorProperties);
- String thisPdpId = IntegrityMonitorProperties
- .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID);
-
- PolicyLogger.debug("testColdStandby: Reading xacmlPersistenceProperties");
- Properties xacmlPersistenceProperties = new Properties();
- xacmlPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/xacmlPersistence.properties")));
- XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties);
-
- PolicyLogger.debug("testColdStandby: Creating emfXacml");
- EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
- "junitXacmlPU", xacmlPersistenceProperties);
-
- PolicyLogger.debug("testColdStandby: Reading droolsPersistenceProperties");
- Properties droolsPersistenceProperties = new Properties();
- droolsPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/droolsPersistence.properties")));
- DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
-
- PolicyLogger.debug("testColdStandby: Creating emfDrools");
- EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
- "junitDroolsPU", droolsPersistenceProperties);
-
- DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
-
- PolicyLogger.debug("testColdStandby: Cleaning up tables");
- conn.deleteAllSessions();
- conn.deleteAllPdps();
-
- PolicyLogger.debug("testColdStandby: Inserting PDP=" + thisPdpId + " as designated");
- DroolsPdp pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date());
- conn.insertPdp(pdp);
- DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
- PolicyLogger.debug("testColdStandby: After insertion, DESIGNATED="
- + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated() == true);
-
- /*
- * When the Standby Status changes (from providingservice) to hotstandby
- * or coldstandby,the Active/Standby selection algorithm must stand down
- * if thePDP-D is currently the lead/active node and allow another PDP-D
- * to take over.
- *
- * It must also call lock on all engines in the engine management.
- *
- * Yes, this is kludgy, but we have a chicken and egg problem here: we
- * need a StateManagement object to invoke the
- * deleteAllStateManagementEntities method.
- */
- PolicyLogger.debug("testColdStandby: Instantiating stateManagement object");
- StateManagement sm = new StateManagement(emfXacml, "dummy");
- sm.deleteAllStateManagementEntities();
- sm = new StateManagement(emfXacml, thisPdpId);
- PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier();
- sm.addObserver(pmStandbyStateChangeNotifier);
-
- // Artificially putting a PDP into service is really a two step process, 1)
- // inserting it as designated and 2) promoting it so that its standbyStatus
- // is providing service.
-
- PolicyLogger.debug("testColdStandby: Running policy-management.Main class");
- PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner();
- policyManagementRunner.start();
-
- PolicyLogger.debug("testColdStandby: Runner started; Sleeping "
- + interruptRecoveryTime + "ms before promoting PDP="
- + thisPdpId);
- Thread.sleep(interruptRecoveryTime);
-
- PolicyLogger.debug("testColdStandby: Promoting PDP=" + thisPdpId);
- sm.promote();
-
- String standbyStatus = sm.getStandbyStatus(thisPdpId);
- PolicyLogger.debug("testColdStandby: Before locking, PDP=" + thisPdpId + " has standbyStatus="
- + standbyStatus);
-
- PolicyLogger.debug("testColdStandby: Locking sm");
- sm.lock();
-
- Thread.sleep(interruptRecoveryTime);
- /*
- * Verify that the PDP is no longer designated.
- */
- droolsPdpEntity = conn.getPdp(thisPdpId);
- PolicyLogger.debug("testColdStandby: After lock sm.lock() invoked, DESIGNATED="
- + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated() == false);
-
- PolicyLogger.debug("testColdStandby: Stopping policyManagementRunner");
- policyManagementRunner.stopRunner();
-
- PolicyLogger.debug("\n\ntestColdStandby: Exiting\n\n");
- Thread.sleep(interruptRecoveryTime);
-
- }
-
- /*
- * Tests hot standby when there is only one PDP.
- */
- @Ignore
- @Test
- public void testHotStandby1() throws Exception {
-
- PolicyLogger.debug("\n\ntestHotStandby1: Entering\n\n");
-
- PolicyLogger.debug("testHotStandby1: Reading IntegrityMonitorProperties");
- Properties integrityMonitorProperties = new Properties();
- integrityMonitorProperties.load(new FileInputStream(new File(
- "src/test/server/config/IntegrityMonitor.properties")));
- IntegrityMonitorProperties.initProperties(integrityMonitorProperties);
- String thisPdpId = IntegrityMonitorProperties
- .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID);
-
- PolicyLogger.debug("testHotStandby1: Reading xacmlPersistenceProperties");
- Properties xacmlPersistenceProperties = new Properties();
- xacmlPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/xacmlPersistence.properties")));
- XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties);
-
- PolicyLogger.debug("testHotStandby1: Creating emfXacml");
- EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
- "junitXacmlPU", xacmlPersistenceProperties);
-
- PolicyLogger.debug("testHotStandby1: Reading droolsPersistenceProperties");
- Properties droolsPersistenceProperties = new Properties();
- droolsPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/droolsPersistence.properties")));
- DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
-
- PolicyLogger.debug("testHotStandby1: Creating emfDrools");
- EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
- "junitDroolsPU", droolsPersistenceProperties);
-
- DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
-
- PolicyLogger.debug("testHotStandby1: Cleaning up tables");
- conn.deleteAllSessions();
- conn.deleteAllPdps();
-
- /*
- * Insert this PDP as not designated. Initial standby state will be
- * either null or cold standby. Demoting should transit state to
- * hot standby.
- */
- PolicyLogger.debug("testHotStandby1: Inserting PDP=" + thisPdpId + " as not designated");
- Date yesterday = DateUtils.addDays(new Date(), -1);
- DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
- conn.insertPdp(pdp);
- DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
- PolicyLogger.debug("testHotStandby1: After insertion, PDP=" + thisPdpId + " has DESIGNATED="
- + droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated() == false);
-
- PolicyLogger.debug("testHotStandby1: Instantiating stateManagement object");
- StateManagement sm = new StateManagement(emfXacml, "dummy");
- sm.deleteAllStateManagementEntities();
- sm = new StateManagement(emfXacml, thisPdpId);
- PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier();
- sm.addObserver(pmStandbyStateChangeNotifier);
-
- PolicyLogger.debug("testHotStandby1: Demoting PDP=" + thisPdpId);
- // demoting should cause state to transit to hotstandby
- sm.demote();
-
- PolicyLogger.debug("testHotStandby1: Running policy-management.Main class");
- PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner();
- policyManagementRunner.start();
-
- PolicyLogger.debug("testHotStandby1: Sleeping "
- + sleepTime
- + "ms, to allow JpaDroolsPdpsConnector time to check droolspdpentity table");
- Thread.sleep(sleepTime);
-
- /*
- * Verify that this formerly un-designated PDP in HOT_STANDBY is now designated and providing service.
- */
- droolsPdpEntity = conn.getPdp(thisPdpId);
- PolicyLogger.debug("testHotStandby1: After sm.demote() invoked, DESIGNATED="
- + droolsPdpEntity.isDesignated() + " for PDP=" + thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated() == true);
- String standbyStatus = sm.getStandbyStatus(thisPdpId);
- PolicyLogger.debug("testHotStandby1: After demotion, PDP=" + thisPdpId + " has standbyStatus="
- + standbyStatus);
- assertTrue(standbyStatus != null && standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
-
- PolicyLogger.debug("testHotStandby1: Stopping policyManagementRunner");
- policyManagementRunner.stopRunner();
-
- PolicyLogger.debug("\n\ntestHotStandby1: Exiting\n\n");
- Thread.sleep(interruptRecoveryTime);
-
- }
-
- /*
- * Tests hot standby when two PDPs are involved.
- */
- @Ignore
- @Test
- public void testHotStandby2() throws Exception {
-
- PolicyLogger.debug("\n\ntestHotStandby2: Entering\n\n");
-
- PolicyLogger.debug("testHotStandby2: Reading IntegrityMonitorProperties");
- Properties integrityMonitorProperties = new Properties();
- integrityMonitorProperties.load(new FileInputStream(new File(
- "src/test/server/config/IntegrityMonitor.properties")));
- IntegrityMonitorProperties.initProperties(integrityMonitorProperties);
- String thisPdpId = IntegrityMonitorProperties
- .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID);
-
- PolicyLogger.debug("testHotStandby2: Reading xacmlPersistenceProperties");
- Properties xacmlPersistenceProperties = new Properties();
- xacmlPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/xacmlPersistence.properties")));
- XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties);
-
- PolicyLogger.debug("testHotStandby2: Creating emfXacml");
- EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
- "junitXacmlPU", xacmlPersistenceProperties);
-
- PolicyLogger.debug("testHotStandby2: Reading droolsPersistenceProperties");
- Properties droolsPersistenceProperties = new Properties();
- droolsPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/droolsPersistence.properties")));
- DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
-
- PolicyLogger.debug("testHotStandby2: Creating emfDrools");
- EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
- "junitDroolsPU", droolsPersistenceProperties);
-
- DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
-
- PolicyLogger.debug("testHotStandby2: Cleaning up tables");
- conn.deleteAllSessions();
- conn.deleteAllPdps();
-
- /*
- * Insert a PDP that's designated but not current.
- */
- String activePdpId = "pdp2";
- PolicyLogger.debug("testHotStandby2: Inserting PDP=" + activePdpId + " as stale, designated PDP");
- Date yesterday = DateUtils.addDays(new Date(), -1);
- DroolsPdp pdp = new DroolsPdpImpl(activePdpId, true, 4, yesterday);
- conn.insertPdp(pdp);
- DroolsPdpEntity droolsPdpEntity = conn.getPdp(activePdpId);
- PolicyLogger.debug("testHotStandby2: After insertion, PDP=" + activePdpId + ", which is not current, has DESIGNATED="
- + droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated() == true);
-
- /*
- * Promote the designated PDP.
- *
- * We have a chicken and egg problem here: we need a StateManagement
- * object to invoke the deleteAllStateManagementEntities method.
- */
- PolicyLogger.debug("testHotStandy2: Promoting PDP=" + activePdpId);
- StateManagement sm = new StateManagement(emfXacml, "dummy");
- sm.deleteAllStateManagementEntities();
- sm = new StateManagement(emfXacml, activePdpId);
- PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier();
- sm.addObserver(pmStandbyStateChangeNotifier);
-
- // Artificially putting a PDP into service is really a two step process, 1)
- // inserting it as designated and 2) promoting it so that its standbyStatus
- // is providing service.
-
- /*
- * Insert this PDP as not designated. Initial standby state will be
- * either null or cold standby. Demoting should transit state to
- * hot standby.
- */
- PolicyLogger.debug("testHotStandby2: Inserting PDP=" + thisPdpId + " as not designated");
- pdp = new DroolsPdpImpl(thisPdpId, false, 4, yesterday);
- conn.insertPdp(pdp);
- droolsPdpEntity = conn.getPdp(thisPdpId);
- PolicyLogger.debug("testHotStandby2: After insertion, PDP=" + thisPdpId + " has DESIGNATED="
- + droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated() == false);
-
- PolicyLogger.debug("testHotStandby2: Demoting PDP=" + thisPdpId);
- StateManagement sm2 = new StateManagement(emfXacml, thisPdpId);
- sm2.addObserver(pmStandbyStateChangeNotifier);
-
- PolicyLogger.debug("testHotStandby2: Running policy-management.Main class");
- PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner();
- policyManagementRunner.start();
-
- PolicyLogger.debug("testHotStandby2: Runner started; Sleeping "
- + interruptRecoveryTime + "ms before promoting/demoting");
- Thread.sleep(interruptRecoveryTime);
-
- PolicyLogger.debug("testHotStandby2: Runner started; promoting PDP=" + activePdpId);
- sm.promote();
- String standbyStatus = sm.getStandbyStatus(activePdpId);
- PolicyLogger.debug("testHotStandby2: After promoting, PDP=" + activePdpId + " has standbyStatus="
- + standbyStatus);
-
- // demoting PDP should ensure that state transits to hotstandby
- PolicyLogger.debug("testHotStandby2: Runner started; demoting PDP=" + thisPdpId);
- sm2.demote();
- standbyStatus = sm.getStandbyStatus(thisPdpId);
- PolicyLogger.debug("testHotStandby2: After demoting, PDP=" + thisPdpId + " has standbyStatus="
- + standbyStatus);
-
- PolicyLogger.debug("testHotStandby2: Sleeping "
- + sleepTime
- + "ms, to allow JpaDroolsPdpsConnector time to check droolspdpentity table");
- Thread.sleep(sleepTime);
-
- /*
- * Verify that this PDP, demoted to HOT_STANDBY, is now
- * re-designated and providing service.
- */
- droolsPdpEntity = conn.getPdp(thisPdpId);
- PolicyLogger.debug("testHotStandby2: After demoting PDP=" + activePdpId
- + ", DESIGNATED=" + droolsPdpEntity.isDesignated()
- + " for PDP=" + thisPdpId);
- assertTrue(droolsPdpEntity.isDesignated() == true);
- standbyStatus = sm2.getStandbyStatus(thisPdpId);
- PolicyLogger.debug("testHotStandby2: After demoting PDP=" + activePdpId
- + ", PDP=" + thisPdpId + " has standbyStatus=" + standbyStatus);
- assertTrue(standbyStatus != null
- && standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
-
- PolicyLogger.debug("testHotStandby2: Stopping policyManagementRunner");
- policyManagementRunner.stopRunner();
-
- PolicyLogger.debug("\n\ntestHotStandby2: Exiting\n\n");
- Thread.sleep(interruptRecoveryTime);
-
- }
-
- /*
- * 1) Inserts and designates this PDP, then verifies that startTransaction
- * is successful.
- *
- * 2) Demotes PDP, and verifies that because there is only one PDP, it will
- * be immediately re-promoted, thus allowing startTransaction to be
- * successful.
- *
- * 3) Locks PDP and verifies that startTransaction results in
- * AdministrativeStateException.
- *
- * 4) Unlocks PDP and verifies that startTransaction results in
- * StandbyStatusException.
- *
- * 5) Promotes PDP and verifies that startTransaction is once again
- * successful.
- */
- @Ignore
- @Test
- public void testLocking1() throws Exception {
-
- PolicyLogger.debug("testLocking1: Reading IntegrityMonitorProperties");
- Properties integrityMonitorProperties = new Properties();
- integrityMonitorProperties.load(new FileInputStream(new File(
- "src/test/server/config/IntegrityMonitor.properties")));
- IntegrityMonitorProperties.initProperties(integrityMonitorProperties);
- String thisPdpId = IntegrityMonitorProperties
- .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID);
-
- PolicyLogger.debug("testLocking1: Reading xacmlPersistenceProperties");
- Properties xacmlPersistenceProperties = new Properties();
- xacmlPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/xacmlPersistence.properties")));
- XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties);
-
- PolicyLogger.debug("testLocking1: Creating emfXacml");
- EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
- "junitXacmlPU", xacmlPersistenceProperties);
-
- PolicyLogger.debug("testLocking1: Reading droolsPersistenceProperties");
- Properties droolsPersistenceProperties = new Properties();
- droolsPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/droolsPersistence.properties")));
- DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
-
- PolicyLogger.debug("testLocking1: Creating emfDrools");
- EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
- "junitDroolsPU", droolsPersistenceProperties);
-
- DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
-
- PolicyLogger.debug("testLocking1: Cleaning up tables");
- conn.deleteAllSessions();
- conn.deleteAllPdps();
-
- /*
- * Insert this PDP as designated. Initial standby state will be
- * either null or cold standby.
- */
- PolicyLogger.debug("testLocking1: Inserting PDP=" + thisPdpId + " as designated");
- DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 4, new Date());
- conn.insertPdp(pdp);
- DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
- PolicyLogger.debug("testLocking1: After insertion, PDP=" + thisPdpId + " has DESIGNATED="
- + droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated() == true);
-
- PolicyLogger.debug("testLocking1: Instantiating stateManagement object");
- StateManagement sm = new StateManagement(emfXacml, "dummy");
- sm.deleteAllStateManagementEntities();
- sm = new StateManagement(emfXacml, thisPdpId);
- PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier();
- sm.addObserver(pmStandbyStateChangeNotifier);
-
- PolicyLogger.debug("testLocking1: Running policy-management.Main class, designated="
- + conn.getPdp(thisPdpId).isDesignated());
- PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner();
- policyManagementRunner.start();
-
- PolicyLogger.debug("testLocking1: Runner started; Sleeping "
- + interruptRecoveryTime + "ms before promoting PDP="
- + thisPdpId);
- Thread.sleep(interruptRecoveryTime);
-
- PolicyLogger.debug("testLocking1: Promoting PDP=" + thisPdpId);
- sm.promote();
-
- PolicyLogger.debug("testLocking1: Sleeping "
- + sleepTime
- + "ms, to allow time for policy-management.Main class to come up, designated="
- + conn.getPdp(thisPdpId).isDesignated());
- Thread.sleep(sleepTime);
-
- PolicyLogger.debug("testLocking1: Waking up and invoking startTransaction on active PDP="
- + thisPdpId
- + ", designated="
- + conn.getPdp(thisPdpId).isDesignated());
- DroolsPDPIntegrityMonitor droolsPdpIntegrityMonitor = (DroolsPDPIntegrityMonitor) IntegrityMonitor
- .getInstance();
- try {
- droolsPdpIntegrityMonitor.startTransaction();
- droolsPdpIntegrityMonitor.endTransaction();
- PolicyLogger.debug("testLocking1: As expected, transaction successful");
- } catch (AdministrativeStateException e) {
- PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage());
- assertTrue(false);
- } catch (StandbyStatusException e) {
- PolicyLogger.error("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage());
- assertTrue(false);
- } catch (Exception e) {
- PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage());
- assertTrue(false);
- }
-
- // demoting should cause state to transit to hotstandby, followed by re-promotion,
- // since there is only one PDP.
- PolicyLogger.debug("testLocking1: demoting PDP=" + thisPdpId);
- sm = droolsPdpIntegrityMonitor.getStateManager();
- sm.demote();
-
- PolicyLogger.debug("testLocking1: sleeping" + electionWaitSleepTime
- + " to allow election handler to re-promote PDP=" + thisPdpId);
- Thread.sleep(electionWaitSleepTime);
-
- PolicyLogger.debug("testLocking1: Invoking startTransaction on re-promoted PDP="
- + thisPdpId
- + ", designated="
- + conn.getPdp(thisPdpId).isDesignated());
- try {
- droolsPdpIntegrityMonitor.startTransaction();
- droolsPdpIntegrityMonitor.endTransaction();
- PolicyLogger.debug("testLocking1: As expected, transaction successful");
- } catch (AdministrativeStateException e) {
- PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage());
- assertTrue(false);
- } catch (StandbyStatusException e) {
- PolicyLogger.error("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage());
- assertTrue(false);
- } catch (Exception e) {
- PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage());
- assertTrue(false);
- }
-
- // locking should cause state to transit to cold standby
- PolicyLogger.debug("testLocking1: locking PDP=" + thisPdpId);
- sm.lock();
-
- // Just to avoid any race conditions, sleep a little after locking
- PolicyLogger.debug("testLocking1: Sleeping a few millis after locking, to avoid race condition");
- Thread.sleep(100);
-
- PolicyLogger.debug("testLocking1: Invoking startTransaction on locked PDP="
- + thisPdpId
- + ", designated="
- + conn.getPdp(thisPdpId).isDesignated());
- try {
- droolsPdpIntegrityMonitor.startTransaction();
- PolicyLogger.error("testLocking1: startTransaction unexpectedly successful");
- assertTrue(false);
- } catch (AdministrativeStateException e) {
- PolicyLogger.debug("testLocking1: As expected, caught AdministrativeStateException, message=" + e.getMessage());
- } catch (StandbyStatusException e) {
- PolicyLogger.error("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage());
- assertTrue(false);
- } catch (Exception e) {
- PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage());
- assertTrue(false);
- } finally {
- droolsPdpIntegrityMonitor.endTransaction();
- }
-
- // unlocking should cause state to transit to hot standby
- PolicyLogger.debug("testLocking1: unlocking PDP=" + thisPdpId);
- sm.unlock();
-
- // Just to avoid any race conditions, sleep a little after locking
- PolicyLogger.debug("testLocking1: Sleeping a few millis after unlocking, to avoid race condition");
- Thread.sleep(100);
-
- PolicyLogger.debug("testLocking1: Invoking startTransaction on unlocked PDP="
- + thisPdpId
- + ", designated="
- + conn.getPdp(thisPdpId).isDesignated());
- try {
- droolsPdpIntegrityMonitor.startTransaction();
- PolicyLogger.error("testLocking1: startTransaction unexpectedly successful");
- assertTrue(false);
- } catch (AdministrativeStateException e) {
- PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage());
- assertTrue(false);
- } catch (StandbyStatusException e) {
- PolicyLogger.debug("testLocking1: As expected, caught StandbyStatusException, message=" + e.getMessage());
- } catch (Exception e) {
- PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage());
- assertTrue(false);
- } finally {
- droolsPdpIntegrityMonitor.endTransaction();
- }
-
- // promoting should cause state to transit to providing service
- PolicyLogger.debug("testLocking1: promoting PDP=" + thisPdpId);
- sm.promote();
-
- // Just to avoid any race conditions, sleep a little after promoting
- PolicyLogger.debug("testLocking1: Sleeping a few millis after promoting, to avoid race condition");
- Thread.sleep(100);
-
- PolicyLogger.debug("testLocking1: Invoking startTransaction on promoted PDP="
- + thisPdpId
- + ", designated="
- + conn.getPdp(thisPdpId).isDesignated());
- try {
- droolsPdpIntegrityMonitor.startTransaction();
- droolsPdpIntegrityMonitor.endTransaction();
- PolicyLogger.debug("testLocking1: As expected, transaction successful");
- } catch (AdministrativeStateException e) {
- PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage());
- assertTrue(false);
- } catch (StandbyStatusException e) {
- PolicyLogger.error("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage());
- assertTrue(false);
- } catch (Exception e) {
- PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage());
- assertTrue(false);
- }
-
- PolicyLogger.debug("testLocking1: Stopping policyManagementRunner");
- policyManagementRunner.stopRunner();
-
- PolicyLogger.debug("\n\ntestLocking1: Exiting\n\n");
- Thread.sleep(interruptRecoveryTime);
-
- }
-
- /*
- * 1) Inserts and designates this PDP, then verifies that startTransaction
- * is successful.
- *
- * 2) Inserts another PDP in hotstandby.
- *
- * 3) Demotes this PDP, and verifies 1) that other PDP is not promoted (because one
- * PDP cannot promote another PDP) and 2) that this PDP is re-promoted.
- */
- @Ignore
- @Test
- public void testLocking2() throws Exception {
-
- PolicyLogger.debug("\n\ntestLocking2: Entering\n\n");
-
- PolicyLogger.debug("testLocking2: Reading IntegrityMonitorProperties");
- Properties integrityMonitorProperties = new Properties();
- integrityMonitorProperties.load(new FileInputStream(new File(
- "src/test/server/config/IntegrityMonitor.properties")));
- IntegrityMonitorProperties.initProperties(integrityMonitorProperties);
- String thisPdpId = IntegrityMonitorProperties
- .getProperty(IntegrityMonitorProperties.PDP_INSTANCE_ID);
-
- PolicyLogger.debug("testLocking2: Reading xacmlPersistenceProperties");
- Properties xacmlPersistenceProperties = new Properties();
- xacmlPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/xacmlPersistence.properties")));
- XacmlPersistenceProperties.initProperties(xacmlPersistenceProperties);
-
- PolicyLogger.debug("testLocking2: Creating emfXacml");
- EntityManagerFactory emfXacml = Persistence.createEntityManagerFactory(
- "junitXacmlPU", xacmlPersistenceProperties);
-
- PolicyLogger.debug("testLocking2: Reading droolsPersistenceProperties");
- Properties droolsPersistenceProperties = new Properties();
- droolsPersistenceProperties.load(new FileInputStream(new File(
- "src/test/server/config/droolsPersistence.properties")));
- DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
-
- PolicyLogger.debug("testLocking2: Creating emfDrools");
- EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
- "junitDroolsPU", droolsPersistenceProperties);
-
- DroolsPdpsConnector conn = new JpaDroolsPdpsConnector(emfDrools);
-
- PolicyLogger.debug("testLocking2: Cleaning up tables");
- conn.deleteAllSessions();
- conn.deleteAllPdps();
-
- /*
- * Insert this PDP as designated. Initial standby state will be
- * either null or cold standby. Demoting should transit state to
- * hot standby.
- */
- PolicyLogger.debug("testLocking2: Inserting PDP=" + thisPdpId + " as designated");
- DroolsPdpImpl pdp = new DroolsPdpImpl(thisPdpId, true, 3, new Date());
- conn.insertPdp(pdp);
- DroolsPdpEntity droolsPdpEntity = conn.getPdp(thisPdpId);
- PolicyLogger.debug("testLocking2: After insertion, PDP=" + thisPdpId + " has DESIGNATED="
- + droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated() == true);
-
- PolicyLogger.debug("testLocking2: Instantiating stateManagement object and promoting PDP=" + thisPdpId);
- StateManagement sm = new StateManagement(emfXacml, "dummy");
- sm.deleteAllStateManagementEntities();
- sm = new StateManagement(emfXacml, thisPdpId);
- PMStandbyStateChangeNotifier pmStandbyStateChangeNotifier = new PMStandbyStateChangeNotifier();
- sm.addObserver(pmStandbyStateChangeNotifier);
-
- /*
- * Insert another PDP as not designated. Initial standby state will be
- * either null or cold standby. Demoting should transit state to
- * hot standby.
- */
- String standbyPdpId = "pdp2";
- PolicyLogger.debug("testLocking2: Inserting PDP=" + standbyPdpId + " as not designated");
- Date yesterday = DateUtils.addDays(new Date(), -1);
- pdp = new DroolsPdpImpl(standbyPdpId, false, 4, yesterday);
- conn.insertPdp(pdp);
- droolsPdpEntity = conn.getPdp(standbyPdpId);
- PolicyLogger.debug("testLocking2: After insertion, PDP=" + standbyPdpId + " has DESIGNATED="
- + droolsPdpEntity.isDesignated());
- assertTrue(droolsPdpEntity.isDesignated() == false);
-
- PolicyLogger.debug("testLocking2: Demoting PDP=" + standbyPdpId);
- StateManagement sm2 = new StateManagement(emfXacml, standbyPdpId);
- sm2.addObserver(pmStandbyStateChangeNotifier);
-
- PolicyLogger.debug("testLocking2: Running policy-management.Main class");
- PolicyManagementRunner policyManagementRunner = new PolicyManagementRunner();
- policyManagementRunner.start();
-
- PolicyLogger.debug("testLocking2: Runner started; Sleeping "
- + interruptRecoveryTime + "ms before promoting/demoting");
- Thread.sleep(interruptRecoveryTime);
-
- PolicyLogger.debug("testLocking2: Promoting PDP=" + thisPdpId);
- sm.promote();
-
- // demoting PDP should ensure that state transits to hotstandby
- PolicyLogger.debug("testLocking2: Demoting PDP=" + standbyPdpId);
- sm2.demote();
-
- PolicyLogger.debug("testLocking2: Sleeping "
- + sleepTime
- + "ms, to allow time for policy-management.Main class to come up");
- Thread.sleep(sleepTime);
-
- PolicyLogger.debug("testLocking2: Waking up and invoking startTransaction on active PDP="
- + thisPdpId
- + ", designated="
- + conn.getPdp(thisPdpId).isDesignated());
- DroolsPDPIntegrityMonitor droolsPdpIntegrityMonitor = (DroolsPDPIntegrityMonitor) IntegrityMonitor
- .getInstance();
- try {
- droolsPdpIntegrityMonitor.startTransaction();
- droolsPdpIntegrityMonitor.endTransaction();
- PolicyLogger.debug("testLocking2: As expected, transaction successful");
- } catch (AdministrativeStateException e) {
- PolicyLogger.error("testLocking2: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage());
- assertTrue(false);
- } catch (StandbyStatusException e) {
- PolicyLogger.error("testLocking2: Unexpectedly caught StandbyStatusException, message=" + e.getMessage());
- assertTrue(false);
- } catch (Exception e) {
- PolicyLogger.error("testLocking2: Unexpectedly caught Exception, message=" + e.getMessage());
- assertTrue(false);
- }
-
- // demoting should cause state to transit to hotstandby followed by re-promotion.
- PolicyLogger.debug("testLocking2: demoting PDP=" + thisPdpId);
- sm = droolsPdpIntegrityMonitor.getStateManager();
- sm.demote();
-
- PolicyLogger.debug("testLocking2: sleeping" + electionWaitSleepTime
- + " to allow election handler to re-promote PDP=" + thisPdpId);
- Thread.sleep(electionWaitSleepTime);
-
- PolicyLogger.debug("testLocking2: Waking up and invoking startTransaction on re-promoted PDP="
- + thisPdpId + ", designated="
- + conn.getPdp(thisPdpId).isDesignated());
- try {
- droolsPdpIntegrityMonitor.startTransaction();
- droolsPdpIntegrityMonitor.endTransaction();
- PolicyLogger.debug("testLocking2: As expected, transaction successful");
- } catch (AdministrativeStateException e) {
- PolicyLogger.error("testLocking2: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage());
- assertTrue(false);
- } catch (StandbyStatusException e) {
- PolicyLogger.error("testLocking2: Unexpectedly caught StandbyStatusException, message=" + e.getMessage());
- assertTrue(false);
- } catch (Exception e) {
- PolicyLogger.error("testLocking2: Unexpectedly caught Exception, message=" + e.getMessage());
- assertTrue(false);
- }
-
- PolicyLogger.debug("testLocking2: Verifying designated status for PDP="
- + standbyPdpId);
- boolean standbyPdpDesignated = conn.getPdp(standbyPdpId).isDesignated();
- assertTrue(standbyPdpDesignated == false);
-
- PolicyLogger.debug("testLocking2: Stopping policyManagementRunner");
- policyManagementRunner.stopRunner();
-
- PolicyLogger.debug("\n\ntestLocking2: Exiting\n\n");
- Thread.sleep(interruptRecoveryTime);
-
- }
-
- private class PolicyManagementRunner extends Thread {
-
- public void run() {
- PolicyLogger.debug("PolicyManagementRunner.run: Entering");
- String args[] = { "src/main/server/config" };
- try {
- Main.main(args);
- } catch (Exception e) {
- PolicyLogger
- .debug("PolicyManagementRunner.run: Exception thrown from Main.main(), message="
- + e.getMessage());
- }
- PolicyLogger.debug("PolicyManagementRunner.run: Exiting");
- }
-
- public void stopRunner() {
- PolicyEngine.manager.shutdown();
- }
-
- }
-
-}
diff --git a/policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/StandbyStateManagementTest.java b/policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/StandbyStateManagementTest.java
index af649866..7e1d396f 100644
--- a/policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/StandbyStateManagementTest.java
+++ b/policy-persistence/src/test/java/org/openecomp/policy/drools/controller/test/StandbyStateManagementTest.java
@@ -24,10 +24,16 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Date;
import java.util.Properties;
+import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.junit.After;
@@ -36,7 +42,6 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
-
import org.openecomp.policy.common.logging.eelf.PolicyLogger;
import org.openecomp.policy.common.im.AdministrativeStateException;
import org.openecomp.policy.common.im.IntegrityMonitor;
@@ -50,17 +55,24 @@ import org.openecomp.policy.drools.persistence.DroolsPdp;
import org.openecomp.policy.drools.persistence.DroolsPdpEntity;
import org.openecomp.policy.drools.persistence.DroolsPdpImpl;
import org.openecomp.policy.drools.persistence.DroolsPdpsConnector;
+import org.openecomp.policy.drools.persistence.DroolsPdpsElectionHandler;
import org.openecomp.policy.drools.persistence.JpaDroolsPdpsConnector;
import org.openecomp.policy.drools.persistence.DroolsPersistenceProperties;
import org.openecomp.policy.drools.persistence.XacmlPersistenceProperties;
import org.openecomp.policy.drools.system.Main;
import org.openecomp.policy.drools.system.PolicyEngine;
-
import org.apache.commons.lang3.time.DateUtils;
/*
- * Cloned from StandbyStateManagement.java in support of US673632.
- * See MultiSite_v1-10.ppt, slide 38
+ * All JUnits are designed to run in the local development environment
+ * where they have write privileges and can execute time-sensitive
+ * tasks.
+ *
+ * These tests can be run as JUnits, but there is some issue with running them
+ * as part of a "mvn install" build. Also, they take a very long time to run
+ * due to many real time breaks. Consequently, they are marked as @Ignore and
+ * only run from the desktop.
+ *
*/
public class StandbyStateManagementTest {
@@ -82,6 +94,12 @@ public class StandbyStateManagementTest {
* Sleep 5 seconds after each test to allow interrupt (shutdown) recovery.
*/
long interruptRecoveryTime = 5000;
+
+ private static EntityManagerFactory emfx;
+ private static EntityManagerFactory emfd;
+ private static EntityManager emx;
+ private static EntityManager emd;
+ private static EntityTransaction et;
/*
* See the IntegrityMonitor.getJmxUrl() method for the rationale behind this jmx related processing.
@@ -106,18 +124,423 @@ public class StandbyStateManagementTest {
@Before
public void setUp() throws Exception {
+ //Create teh data access for xaml db
+ Properties xacmlPersistenceProperties = new Properties();
+ xacmlPersistenceProperties.load(new FileInputStream(new File(
+ "src/test/server/config/xacmlPersistence.properties")));
+
+ emfx = Persistence.createEntityManagerFactory("junitXacmlPU", xacmlPersistenceProperties);
+
+ // Create an entity manager to use the DB
+ emx = emfx.createEntityManager();
+
+ //Create the data access for drools db
+ Properties droolsPersistenceProperties = new Properties();
+ droolsPersistenceProperties.load(new FileInputStream(new File(
+ "src/test/server/config/droolsPersistence.properties")));
+
+ emfd = Persistence.createEntityManagerFactory("junitDroolsPU", droolsPersistenceProperties);
+
+ // Create an entity manager to use the DB
+ emd = emfd.createEntityManager();
}
@After
public void tearDown() throws Exception {
}
-
+
+ public void cleanXacmlDb(){
+ et = emx.getTransaction();
+
+ et.begin();
+ // Make sure we leave the DB clean
+ emx.createQuery("DELETE FROM StateManagementEntity").executeUpdate();
+ emx.createQuery("DELETE FROM ResourceRegistrationEntity").executeUpdate();
+ emx.createQuery("DELETE FROM ForwardProgressEntity").executeUpdate();
+ emx.createQuery("DELETE FROM IntegrityAuditEntity").executeUpdate();
+ emx.flush();
+ et.commit();
+ }
+
+ public void cleanDroolsDb(){
+ et = emd.getTransaction();
+
+ et.begin();
+ // Make sure we leave the DB clean
+ emd.createQuery("DELETE FROM DroolsPdpEntity").executeUpdate();
+ emd.createQuery("DELETE FROM DroolsSessionEntity").executeUpdate();
+ emd.createQuery("DELETE FROM SessionInfo").executeUpdate();
+ emd.createQuery("DELETE FROM WorkItemInfo").executeUpdate();
+ emd.createQuery("DELETE FROM IntegrityAuditEntity").executeUpdate();
+ emd.flush();
+ et.commit();
+ }
+
@Ignore
@Test
+ public void runAllTests() throws Exception {
+ //testColdStandby();
+ //testHotStandby1();
+ //testHotStandby2();
+ //testLocking1();
+ //testLocking2();
+ testSanitizeDesignatedList();
+ testComputeMostRecentPrimary();
+ testComputeDesignatedPdp();
+ }
+
+ //@Ignore
+ //@Test
+ public void testSanitizeDesignatedList() throws Exception {
+
+ PolicyLogger.debug("\n\ntestSanitizeDesignatedList: Entering\n\n");
+
+ /*
+ * Get a DroolsPdpsConnector
+ */
+ PolicyLogger.debug("testSanitizeDesignatedList: Reading droolsPersistenceProperties");
+ Properties droolsPersistenceProperties = new Properties();
+ droolsPersistenceProperties.load(new FileInputStream(new File(
+ "src/test/server/config/droolsPersistence.properties")));
+ DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
+
+ PolicyLogger.debug("testSanitizeDesignatedList: Creating emfDrools");
+ EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
+ "junitDroolsPU", droolsPersistenceProperties);
+
+ DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfDrools);
+
+ /*
+ * Create 4 pdpd all not designated
+ */
+ DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, new Date());
+ DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, new Date());
+ DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, new Date());
+ DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, new Date());
+
+ ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
+ listOfDesignated.add(pdp1);
+ listOfDesignated.add(pdp2);
+ listOfDesignated.add(pdp3);
+ listOfDesignated.add(pdp4);
+
+ DroolsPDPIntegrityMonitor droolsPDPIntegrityMonitor;
+ try{
+ droolsPDPIntegrityMonitor = DroolsPDPIntegrityMonitor.init("src/test/server/config");
+ }catch(Exception e){
+ //If it already exists, just get it
+ droolsPDPIntegrityMonitor = DroolsPDPIntegrityMonitor.getInstance();
+ }
+ DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1, droolsPDPIntegrityMonitor);
+
+ listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
+
+ PolicyLogger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size = " + listOfDesignated.size() + "\n\n");
+
+ assertTrue(listOfDesignated.size()==4);
+
+ /*
+ * Now make 2 designated
+ */
+ pdp1.setDesignated(true);
+ pdp2.setDesignated(true);
+
+ listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
+
+ PolicyLogger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size after 2 designated = " + listOfDesignated.size() + "\n\n");
+
+ assertTrue(listOfDesignated.size()==2);
+ assertTrue(listOfDesignated.contains(pdp1));
+ assertTrue(listOfDesignated.contains(pdp2));
+
+ /*
+ * Now all are designated. But, we have to add back the previously non-designated nodes
+ */
+ pdp3.setDesignated(true);
+ pdp4.setDesignated(true);
+ listOfDesignated.add(pdp3);
+ listOfDesignated.add(pdp4);
+
+ listOfDesignated = droolsPdpsElectionHandler.santizeDesignatedList(listOfDesignated);
+
+ PolicyLogger.debug("\n\ntestSanitizeDesignatedList: listOfDesignated.size after all designated = " + listOfDesignated.size() + "\n\n");
+
+ assertTrue(listOfDesignated.size()==4);
+
+ }
+
+ //@Ignore
+ //@Test
+ public void testComputeMostRecentPrimary() throws Exception {
+
+ PolicyLogger.debug("\n\ntestComputeMostRecentPrimary: Entering\n\n");
+
+ /*
+ * Get a DroolsPdpsConnector
+ */
+ PolicyLogger.debug("testComputeMostRecentPrimary: Reading droolsPersistenceProperties");
+ Properties droolsPersistenceProperties = new Properties();
+ droolsPersistenceProperties.load(new FileInputStream(new File(
+ "src/test/server/config/droolsPersistence.properties")));
+ DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
+
+ PolicyLogger.debug("testComputeMostRecentPrimary: Creating emfDrools");
+ EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
+ "junitDroolsPU", droolsPersistenceProperties);
+
+ DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfDrools);
+
+ /*
+ * Create 4 pdpd all not designated
+ */
+ long designatedDateMS = new Date().getTime();
+ DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, new Date());
+ pdp1.setDesignatedDate(new Date(designatedDateMS - 2));
+
+ DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, new Date());
+ //oldest
+ pdp2.setDesignatedDate(new Date(designatedDateMS - 3));
+
+ DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, new Date());
+ pdp3.setDesignatedDate(new Date(designatedDateMS - 1));
+
+ DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, new Date());
+ //most recent
+ pdp4.setDesignatedDate(new Date(designatedDateMS));
+
+ ArrayList<DroolsPdp> listOfAllPdps = new ArrayList<DroolsPdp>();
+ listOfAllPdps.add(pdp1);
+ listOfAllPdps.add(pdp2);
+ listOfAllPdps.add(pdp3);
+ listOfAllPdps.add(pdp4);
+
+
+ ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
+ listOfDesignated.add(pdp1);
+ listOfDesignated.add(pdp2);
+ listOfDesignated.add(pdp3);
+ listOfDesignated.add(pdp4);
+
+
+ /*
+ * Because the way we sanitize the listOfDesignated, it will always contain all hot standby
+ * or all designated members.
+ */
+ DroolsPDPIntegrityMonitor droolsPDPIntegrityMonitor;
+ try{
+ droolsPDPIntegrityMonitor = DroolsPDPIntegrityMonitor.init("src/test/server/config");
+ }catch(Exception e){
+ //If it already exists, just get it
+ droolsPDPIntegrityMonitor = DroolsPDPIntegrityMonitor.getInstance();
+ }
+ DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1, droolsPDPIntegrityMonitor);
+
+ DroolsPdp mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
+
+ PolicyLogger.debug("\n\ntestComputeMostRecentPrimary: mostRecentPrimary.getPdpId() = " + mostRecentPrimary.getPdpId() + "\n\n");
+
+ /*
+ * If all of the pdps are included in the listOfDesignated and none are designated, it will choose
+ * the one which has the most recent designated date.
+ */
+ assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
+
+ /*
+ * Now let's designate all of those on the listOfDesignated. It will choose the first one designated
+ */
+ pdp1.setDesignated(true);
+ pdp2.setDesignated(true);
+ pdp3.setDesignated(true);
+ pdp4.setDesignated(true);
+
+ mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
+
+ PolicyLogger.debug("\n\ntestComputeMostRecentPrimary: All designated all on list, mostRecentPrimary.getPdpId() = " + mostRecentPrimary.getPdpId() + "\n\n");
+
+ /*
+ * If all of the pdps are included in the listOfDesignated and all are designated, it will choose
+ * the one which was designated first
+ */
+ assertTrue(mostRecentPrimary.getPdpId().equals("pdp2"));
+
+ /*
+ * Now we will designate only 2 and put just them in the listOfDesignated. The algorithm will now
+ * look for the most recently designated pdp which is not currently designated.
+ */
+ pdp3.setDesignated(false);
+ pdp4.setDesignated(false);
+
+ listOfDesignated.remove(pdp3);
+ listOfDesignated.remove(pdp4);
+
+ mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
+
+ PolicyLogger.debug("\n\ntestComputeMostRecentPrimary: mostRecentPrimary.getPdpId() = " + mostRecentPrimary.getPdpId() + "\n\n");
+
+ assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
+
+
+ /*
+ * Now we will have none designated and put two of them in the listOfDesignated. The algorithm will now
+ * look for the most recently designated pdp regardless of whether it is currently marked as designated.
+ */
+ pdp1.setDesignated(false);
+ pdp2.setDesignated(false);
+
+ mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
+
+ PolicyLogger.debug("\n\ntestComputeMostRecentPrimary: 2 on list mostRecentPrimary.getPdpId() = " + mostRecentPrimary.getPdpId() + "\n\n");
+
+ assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
+
+ /*
+ * If we have only one pdp on in the listOfDesignated, the most recently designated pdp will be chosen, regardless
+ * of its designation status
+ */
+ listOfDesignated.remove(pdp1);
+
+ mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
+
+ PolicyLogger.debug("\n\ntestComputeMostRecentPrimary: 1 on list mostRecentPrimary.getPdpId() = " + mostRecentPrimary.getPdpId() + "\n\n");
+
+ assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
+
+ /*
+ * Finally, if none are on the listOfDesignated, it will again choose the most recently designated pdp.
+ */
+ listOfDesignated.remove(pdp2);
+
+ mostRecentPrimary = droolsPdpsElectionHandler.computeMostRecentPrimary(listOfAllPdps, listOfDesignated);
+
+ PolicyLogger.debug("\n\ntestComputeMostRecentPrimary: 0 on list mostRecentPrimary.getPdpId() = " + mostRecentPrimary.getPdpId() + "\n\n");
+
+ assertTrue(mostRecentPrimary.getPdpId().equals("pdp4"));
+
+ }
+
+ //@Ignore
+ //@Test
+ public void testComputeDesignatedPdp() throws Exception{
+
+ PolicyLogger.debug("\n\ntestComputeDesignatedPdp: Entering\n\n");
+
+ /*
+ * Get a DroolsPdpsConnector
+ */
+ PolicyLogger.debug("testComputeDesignatedPdp: Reading droolsPersistenceProperties");
+ Properties droolsPersistenceProperties = new Properties();
+ droolsPersistenceProperties.load(new FileInputStream(new File(
+ "src/test/server/config/droolsPersistence.properties")));
+ DroolsPersistenceProperties.initProperties(droolsPersistenceProperties);
+
+ PolicyLogger.debug("testComputeDesignatedPdp: Creating emfDrools");
+ EntityManagerFactory emfDrools = Persistence.createEntityManagerFactory(
+ "junitDroolsPU", droolsPersistenceProperties);
+
+ DroolsPdpsConnector droolsPdpsConnector = new JpaDroolsPdpsConnector(emfDrools);
+
+ /*
+ * Create 4 pdpd all not designated. Two on site1. Two on site2
+ */
+ long designatedDateMS = new Date().getTime();
+ DroolsPdp pdp1 = new DroolsPdpImpl("pdp1", false, 4, new Date());
+ pdp1.setDesignatedDate(new Date(designatedDateMS - 2));
+ pdp1.setSiteName("site1");
+
+ DroolsPdp pdp2 = new DroolsPdpImpl("pdp2", false, 4, new Date());
+ pdp2.setDesignatedDate(new Date(designatedDateMS - 3));
+ pdp2.setSiteName("site1");
+
+ //oldest
+ DroolsPdp pdp3 = new DroolsPdpImpl("pdp3", false, 4, new Date());
+ pdp3.setDesignatedDate(new Date(designatedDateMS - 4));
+ pdp3.setSiteName("site2");
+
+ DroolsPdp pdp4 = new DroolsPdpImpl("pdp4", false, 4, new Date());
+ //most recent
+ pdp4.setDesignatedDate(new Date(designatedDateMS));
+ pdp4.setSiteName("site2");
+
+ ArrayList<DroolsPdp> listOfAllPdps = new ArrayList<DroolsPdp>();
+ listOfAllPdps.add(pdp1);
+ listOfAllPdps.add(pdp2);
+ listOfAllPdps.add(pdp3);
+ listOfAllPdps.add(pdp4);
+
+
+ ArrayList<DroolsPdp> listOfDesignated = new ArrayList<DroolsPdp>();
+
+ /*
+ * We will first test an empty listOfDesignated. As we know from the previous JUnit,
+ * the pdp with the most designated date will be chosen for mostRecentPrimary
+ */
+
+ DroolsPDPIntegrityMonitor droolsPDPIntegrityMonitor;
+ try{
+ droolsPDPIntegrityMonitor = DroolsPDPIntegrityMonitor.init("src/test/server/config");
+ }catch(Exception e){
+ //If it already exists, just get it
+ droolsPDPIntegrityMonitor = DroolsPDPIntegrityMonitor.getInstance();
+ }
+ DroolsPdpsElectionHandler droolsPdpsElectionHandler = new DroolsPdpsElectionHandler(droolsPdpsConnector, pdp1, droolsPDPIntegrityMonitor);
+
+ DroolsPdp mostRecentPrimary = pdp4;
+
+ DroolsPdp designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
+
+ /*
+ * The designatedPdp should be null
+ */
+ assertTrue(designatedPdp==null);
+
+ /*
+ * Now let's try having only one pdp in listOfDesignated, but not in the same site as the most recent primary
+ */
+
+ listOfDesignated.add(pdp2);
+
+ designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
+
+ /*
+ * Now the designatedPdp should be the one and only selection in the listOfDesignated
+ */
+ assertTrue(designatedPdp.getPdpId().equals(pdp2.getPdpId()));
+
+ /*
+ * Now let's put 2 pdps in the listOfDesignated, neither in the same site as the mostRecentPrimary
+ */
+ listOfDesignated.add(pdp1);
+
+ designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
+
+ /*
+ * The designatedPdp should now be the one with the lowest lexiographic score - pdp1
+ */
+ assertTrue(designatedPdp.getPdpId().equals(pdp1.getPdpId()));
+
+ /*
+ * Finally, we will have 2 pdps in the listOfDesignated, one in the same site with the mostRecentPrimary
+ */
+ listOfDesignated.remove(pdp1);
+ listOfDesignated.add(pdp3);
+
+ designatedPdp = droolsPdpsElectionHandler.computeDesignatedPdp(listOfDesignated, mostRecentPrimary);
+
+ /*
+ * The designatedPdp should now be the one on the same site as the mostRecentPrimary
+ */
+ assertTrue(designatedPdp.getPdpId().equals(pdp3.getPdpId()));
+ }
+
+
+ //@Ignore
+ //@Test
public void testColdStandby() throws Exception {
PolicyLogger.debug("\n\ntestColdStandby: Entering\n\n");
+ cleanXacmlDb();
+ cleanDroolsDb();
PolicyLogger.debug("testColdStandby: Reading IntegrityMonitorProperties");
Properties integrityMonitorProperties = new Properties();
@@ -213,7 +636,7 @@ public class StandbyStateManagementTest {
assertTrue(droolsPdpEntity.isDesignated() == false);
PolicyLogger.debug("testColdStandby: Stopping policyManagementRunner");
- policyManagementRunner.stopRunner();
+ //policyManagementRunner.stopRunner();
PolicyLogger.debug("\n\ntestColdStandby: Exiting\n\n");
Thread.sleep(interruptRecoveryTime);
@@ -223,11 +646,13 @@ public class StandbyStateManagementTest {
/*
* Tests hot standby when there is only one PDP.
*/
- @Ignore
- @Test
+ //@Ignore
+ //@Test
public void testHotStandby1() throws Exception {
PolicyLogger.debug("\n\ntestHotStandby1: Entering\n\n");
+ cleanXacmlDb();
+ cleanDroolsDb();
PolicyLogger.debug("testHotStandby1: Reading IntegrityMonitorProperties");
Properties integrityMonitorProperties = new Properties();
@@ -310,7 +735,7 @@ public class StandbyStateManagementTest {
assertTrue(standbyStatus != null && standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
PolicyLogger.debug("testHotStandby1: Stopping policyManagementRunner");
- policyManagementRunner.stopRunner();
+ //policyManagementRunner.stopRunner();
PolicyLogger.debug("\n\ntestHotStandby1: Exiting\n\n");
Thread.sleep(interruptRecoveryTime);
@@ -320,11 +745,13 @@ public class StandbyStateManagementTest {
/*
* Tests hot standby when two PDPs are involved.
*/
- @Ignore
- @Test
+ //@Ignore
+ //@Test
public void testHotStandby2() throws Exception {
PolicyLogger.info("\n\ntestHotStandby2: Entering\n\n");
+ cleanXacmlDb();
+ cleanDroolsDb();
PolicyLogger.info("testHotStandby2: Reading IntegrityMonitorProperties");
Properties integrityMonitorProperties = new Properties();
@@ -453,7 +880,7 @@ public class StandbyStateManagementTest {
&& standbyStatus.equals(StateManagement.PROVIDING_SERVICE));
PolicyLogger.info("testHotStandby2: Stopping policyManagementRunner");
- policyManagementRunner.stopRunner();
+ //policyManagementRunner.stopRunner();
PolicyLogger.info("\n\ntestHotStandby2: Exiting\n\n");
Thread.sleep(interruptRecoveryTime);
@@ -477,10 +904,13 @@ public class StandbyStateManagementTest {
* 5) Promotes PDP and verifies that startTransaction is once again
* successful.
*/
- @Ignore
- @Test
+ //@Ignore
+ //@Test
public void testLocking1() throws Exception {
-
+ PolicyLogger.debug("testLocking1: Entry");
+ cleanXacmlDb();
+ cleanDroolsDb();
+
PolicyLogger.debug("testLocking1: Reading IntegrityMonitorProperties");
Properties integrityMonitorProperties = new Properties();
integrityMonitorProperties.load(new FileInputStream(new File(
@@ -631,13 +1061,13 @@ public class StandbyStateManagementTest {
droolsPdpIntegrityMonitor.endTransaction();
}
- // unlocking should cause state to transit to hot standby
+ // unlocking should cause state to transit to hot standby and then providing service
PolicyLogger.debug("testLocking1: unlocking PDP=" + thisPdpId);
sm.unlock();
// Just to avoid any race conditions, sleep a little after locking
PolicyLogger.debug("testLocking1: Sleeping a few millis after unlocking, to avoid race condition");
- Thread.sleep(100);
+ Thread.sleep(electionWaitSleepTime);
PolicyLogger.debug("testLocking1: Invoking startTransaction on unlocked PDP="
+ thisPdpId
@@ -645,13 +1075,13 @@ public class StandbyStateManagementTest {
+ conn.getPdp(thisPdpId).isDesignated());
try {
droolsPdpIntegrityMonitor.startTransaction();
- PolicyLogger.error("testLocking1: startTransaction unexpectedly successful");
- assertTrue(false);
+ PolicyLogger.error("testLocking1: startTransaction successful as expected");
} catch (AdministrativeStateException e) {
PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage());
assertTrue(false);
} catch (StandbyStatusException e) {
- PolicyLogger.debug("testLocking1: As expected, caught StandbyStatusException, message=" + e.getMessage());
+ PolicyLogger.debug("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage());
+ assertTrue(false);
} catch (Exception e) {
PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage());
assertTrue(false);
@@ -659,35 +1089,35 @@ public class StandbyStateManagementTest {
droolsPdpIntegrityMonitor.endTransaction();
}
- // promoting should cause state to transit to providing service
- PolicyLogger.debug("testLocking1: promoting PDP=" + thisPdpId);
- sm.promote();
+ // demoting should cause state to transit to providing service
+ PolicyLogger.debug("testLocking1: demoting PDP=" + thisPdpId);
+ sm.demote();
// Just to avoid any race conditions, sleep a little after promoting
- PolicyLogger.debug("testLocking1: Sleeping a few millis after promoting, to avoid race condition");
+ PolicyLogger.debug("testLocking1: Sleeping a few millis after demoting, to avoid race condition");
Thread.sleep(100);
- PolicyLogger.debug("testLocking1: Invoking startTransaction on promoted PDP="
+ PolicyLogger.debug("testLocking1: Invoking startTransaction on demoted PDP="
+ thisPdpId
+ ", designated="
+ conn.getPdp(thisPdpId).isDesignated());
try {
droolsPdpIntegrityMonitor.startTransaction();
droolsPdpIntegrityMonitor.endTransaction();
- PolicyLogger.debug("testLocking1: As expected, transaction successful");
+ PolicyLogger.debug("testLocking1: Unexpectedly, transaction successful");
+ assertTrue(false);
} catch (AdministrativeStateException e) {
PolicyLogger.error("testLocking1: Unexpectedly caught AdministrativeStateException, message=" + e.getMessage());
assertTrue(false);
} catch (StandbyStatusException e) {
- PolicyLogger.error("testLocking1: Unexpectedly caught StandbyStatusException, message=" + e.getMessage());
- assertTrue(false);
+ PolicyLogger.error("testLocking1: As expected caught StandbyStatusException, message=" + e.getMessage());
} catch (Exception e) {
PolicyLogger.error("testLocking1: Unexpectedly caught Exception, message=" + e.getMessage());
assertTrue(false);
}
PolicyLogger.debug("testLocking1: Stopping policyManagementRunner");
- policyManagementRunner.stopRunner();
+ //policyManagementRunner.stopRunner();
PolicyLogger.debug("\n\ntestLocking1: Exiting\n\n");
Thread.sleep(interruptRecoveryTime);
@@ -703,11 +1133,13 @@ public class StandbyStateManagementTest {
* 3) Demotes this PDP, and verifies 1) that other PDP is not promoted (because one
* PDP cannot promote another PDP) and 2) that this PDP is re-promoted.
*/
- @Ignore
- @Test
+ //@Ignore
+ //@Test
public void testLocking2() throws Exception {
PolicyLogger.debug("\n\ntestLocking2: Entering\n\n");
+ cleanXacmlDb();
+ cleanDroolsDb();
PolicyLogger.debug("testLocking2: Reading IntegrityMonitorProperties");
Properties integrityMonitorProperties = new Properties();
@@ -856,7 +1288,7 @@ public class StandbyStateManagementTest {
assertTrue(standbyPdpDesignated == false);
PolicyLogger.debug("testLocking2: Stopping policyManagementRunner");
- policyManagementRunner.stopRunner();
+ //policyManagementRunner.stopRunner();
PolicyLogger.debug("\n\ntestLocking2: Exiting\n\n");
Thread.sleep(interruptRecoveryTime);
@@ -874,6 +1306,7 @@ public class StandbyStateManagementTest {
PolicyLogger
.info("PolicyManagementRunner.run: Exception thrown from Main.main(), message="
+ e.getMessage());
+ return;
}
PolicyLogger.info("PolicyManagementRunner.run: Exiting");
}
diff --git a/policy-persistence/src/test/resources/IntegrityMonitor.properties b/policy-persistence/src/test/resources/IntegrityMonitor.properties
index 0ab36286..4e182e02 100644
--- a/policy-persistence/src/test/resources/IntegrityMonitor.properties
+++ b/policy-persistence/src/test/resources/IntegrityMonitor.properties
@@ -60,8 +60,12 @@ pdp.initialWait=20000
resource.name=pdp1
#resource.name=${{resource_name}}
+# Flag to control the execution of the subsystemTest for the Database
+db.audit.is.active=false
-
+# Flag to control the execution of the subsystemTest for the Nexus Maven repository
+repository.audit.is.active=false
+repository.audit.ignore.errors=true
diff --git a/policy-persistence/src/test/resources/META-INF/persistence.xml b/policy-persistence/src/test/resources/META-INF/persistence.xml
index 51ec1613..ed8a8cd7 100644
--- a/policy-persistence/src/test/resources/META-INF/persistence.xml
+++ b/policy-persistence/src/test/resources/META-INF/persistence.xml
@@ -27,7 +27,7 @@
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>org.openecomp.policy.drools.persistence.DroolsPdpEntity</class>
<class>org.openecomp.policy.drools.persistence.DroolsSessionEntity</class>
- <class>org.openecomp.policy.drools.persistence.LastSiteEntity</class>
+ <!-- <class>org.openecomp.policy.drools.persistence.LastSiteEntity</class> -->
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
<class>org.openecomp.policy.common.ia.jpa.IntegrityAuditEntity</class>
diff --git a/policy-persistence/src/test/server/config/IntegrityMonitor.properties b/policy-persistence/src/test/server/config/IntegrityMonitor.properties
index b16beda9..5e7085ca 100644
--- a/policy-persistence/src/test/server/config/IntegrityMonitor.properties
+++ b/policy-persistence/src/test/server/config/IntegrityMonitor.properties
@@ -60,3 +60,10 @@ resource.name=pdp1
# -1 turns off audit
# zero forces audit to run continuously
integrity_audit_period_seconds=60
+
+# Flag to control the execution of the subsystemTest for the Database
+db.audit.is.active=false
+
+# Flag to control the execution of the subsystemTest for the Nexus Maven repository
+repository.audit.is.active=false
+repository.audit.ignore.errors=true \ No newline at end of file