summaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/main
diff options
context:
space:
mode:
authorTemoc Rodriguez <cr056n@att.com>2017-09-01 08:52:02 -0700
committerTemoc Rodriguez <cr056n@att.com>2017-09-07 09:48:49 -0700
commita91cb6c62a217238bbfccf16fb1440e3fec174de (patch)
treee74ca6d86d5811da0be4ccaf75141e40042cf20a /controlloop/common/eventmanager/src/main
parent37b497d346a65ee9de077fdb24bee73cfe19b50e (diff)
Add in-mem db to ControlLoopXacmlGuardTest
Add in-mem specification in test/resources/META-INF/persistence.xml for junit. Use system properties to choose which db to use. Removed named parameters in PIPEngineHistory.java. Change 6.3.0 versions of drools-core to 6.5.0 in pom. Make PIPEngineGetHistory query more general. Increased sleep times in junit. Issue-ID: POLICY-55 Change-Id: I6bc65fd88c43c4e7143f27a7e6d8666c2c4df060 Signed-off-by: Temoc Rodriguez <cr056n@att.com>
Diffstat (limited to 'controlloop/common/eventmanager/src/main')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java106
-rw-r--r--controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml40
2 files changed, 75 insertions, 71 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
index 94b6e1618..3c264ab24 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
@@ -7,9 +7,9 @@
* 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.
@@ -33,30 +33,30 @@ import org.onap.policy.appc.Response;
import org.onap.policy.appc.ResponseCode;
import org.onap.policy.appclcm.LCMResponseWrapper;
import org.onap.policy.controlloop.ControlLoopEvent;
+import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.controlloop.actor.appc.APPCActorServiceProvider;
import org.onap.policy.controlloop.actor.vfc.VFCActorServiceProvider;
+import org.onap.policy.controlloop.policy.Policy;
+import org.onap.policy.controlloop.policy.PolicyResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.onap.policy.controlloop.actor.appclcm.AppcLcmActorServiceProvider;
public class ControlLoopOperationManager implements Serializable {
-
+
/**
- *
+ *
*/
private static final long serialVersionUID = -3773199283624595410L;
private static final Logger logger = LoggerFactory.getLogger(ControlLoopOperationManager.class);
@Override
public String toString() {
- return "ControlLoopOperationManager [onset=" + (onset != null ? onset.requestID : "null") + ", policy="
+ return "ControlLoopOperationManager [onset=" + (onset != null ? onset.requestID : "null") + ", policy="
+ (policy != null ? policy.getId() : "null") + ", attempts=" + attempts
- + ", policyResult=" + policyResult
+ + ", policyResult=" + policyResult
+ ", currentOperation=" + currentOperation + ", operationHistory=" + operationHistory
+ "]";
}
@@ -94,17 +94,17 @@ public class ControlLoopOperationManager implements Serializable {
public ControlLoopOperation operation = new ControlLoopOperation();
public PolicyResult policyResult = null;
public int attempt = 0;
-
+
@Override
public String toString() {
return "Operation [attempt=" + attempt + ", policyResult=" + policyResult + ", operation=" + operation
+ "]";
}
}
-
+
private String guardApprovalStatus = "NONE";//"NONE", "PERMIT", "DENY"
private Object operationRequest;
-
+
public Object getOperationRequest() {
return operationRequest;
}
@@ -115,14 +115,14 @@ public class ControlLoopOperationManager implements Serializable {
public void setGuardApprovalStatus(String guardApprovalStatus) {
this.guardApprovalStatus = guardApprovalStatus;
}
-
-
- public ControlLoopOperationManager(/*ATTControlLoopEvent*/ControlLoopEvent onset, Policy policy, ControlLoopEventManager em) throws ControlLoopException {
+
+
+ public ControlLoopOperationManager(ControlLoopEvent onset, Policy policy, ControlLoopEventManager em) throws ControlLoopException {
this.onset = onset;
this.policy = policy;
this.guardApprovalStatus = "NONE";
this.eventManager = em;
-
+
//
// Let's make a sanity check
//
@@ -141,7 +141,7 @@ public class ControlLoopOperationManager implements Serializable {
throw new ControlLoopException("ControlLoopEventManager: policy has an unknown actor.");
}
}
-
+
public Object startOperation(/*VirtualControlLoopEvent*/ControlLoopEvent onset) {
//
// They shouldn't call us if we currently running something
@@ -198,13 +198,13 @@ public class ControlLoopOperationManager implements Serializable {
//
switch (policy.getActor()) {
case "APPC":
- /*
- * If the recipe is ModifyConfig, a legacy APPC
+ /*
+ * If the recipe is ModifyConfig, a legacy APPC
* request is constructed. Otherwise an LCMRequest
* is constructed.
*/
if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) {
-
+
this.operationRequest = APPCActorServiceProvider.constructRequest((VirtualControlLoopEvent)onset, operation.operation, this.policy);
}
else {
@@ -229,7 +229,7 @@ public class ControlLoopOperationManager implements Serializable {
}
return null;
}
-
+
public PolicyResult onResponse(Object response) {
//
// Which response is it?
@@ -316,9 +316,9 @@ public class ControlLoopOperationManager implements Serializable {
}
}
else if (response instanceof LCMResponseWrapper) {
-
+
LCMResponseWrapper dmaapResponse = (LCMResponseWrapper) response;
-
+
/*
* Parse out the operation attempt using the subrequestid
*/
@@ -326,13 +326,13 @@ public class ControlLoopOperationManager implements Serializable {
if (operationAttempt == null) {
this.completeOperation(operationAttempt, "Policy was unable to parse APP-C SubRequestID (it was null).", PolicyResult.FAILURE_EXCEPTION);
}
-
+
/*
- * Process the APPCLCM response to see what PolicyResult
+ * Process the APPCLCM response to see what PolicyResult
* should be returned
*/
AbstractMap.SimpleEntry<PolicyResult, String> result = AppcLcmActorServiceProvider.processResponse(dmaapResponse);
-
+
if (result.getKey() != null) {
this.completeOperation(operationAttempt, result.getValue(), result.getKey());
if (PolicyResult.FAILURE_TIMEOUT.equals(this.policyResult)) {
@@ -344,7 +344,7 @@ public class ControlLoopOperationManager implements Serializable {
}
return null;
}
-
+
public Integer getOperationTimeout() {
//
// Sanity check
@@ -356,7 +356,7 @@ public class ControlLoopOperationManager implements Serializable {
logger.debug("getOperationTimeout returning {}", this.policy.getTimeout());
return this.policy.getTimeout();
}
-
+
public String getOperationTimeoutString(int defaultTimeout) {
Integer to = this.getOperationTimeout();
if (to == null || to == 0) {
@@ -364,11 +364,11 @@ public class ControlLoopOperationManager implements Serializable {
}
return to.toString() + "s";
}
-
+
public PolicyResult getOperationResult() {
return this.policyResult;
}
-
+
public String getOperationMessage() {
if (this.currentOperation != null && this.currentOperation.operation != null) {
return this.currentOperation.operation.toMessage();
@@ -378,7 +378,7 @@ public class ControlLoopOperationManager implements Serializable {
}
return null;
}
-
+
public String getOperationMessage(String guardResult) {
if (this.currentOperation != null && this.currentOperation.operation != null) {
return this.currentOperation.operation.toMessage()+ ", Guard result: " + guardResult;
@@ -388,7 +388,7 @@ public class ControlLoopOperationManager implements Serializable {
}
return null;
}
-
+
public String getOperationHistory() {
if (this.currentOperation != null && this.currentOperation.operation != null) {
return this.currentOperation.operation.toHistory();
@@ -398,23 +398,23 @@ public class ControlLoopOperationManager implements Serializable {
}
return null;
}
-
+
public LinkedList<ControlLoopOperation> getHistory() {
LinkedList<ControlLoopOperation> history = new LinkedList<ControlLoopOperation>();
for (Operation op : this.operationHistory) {
history.add(new ControlLoopOperation(op.operation));
-
+
}
return history;
}
-
+
public void setOperationHasTimedOut() {
//
//
//
this.completeOperation(this.attempts, "Operation timed out", PolicyResult.FAILURE_TIMEOUT);
}
-
+
public void setOperationHasGuardDeny() {
//
//
@@ -469,11 +469,11 @@ public class ControlLoopOperationManager implements Serializable {
//
return true;
}
-
+
public boolean isOperationRunning() {
return (this.currentOperation != null);
}
-
+
private boolean isRetriesMaxedOut() {
if (policy.getRetry() == null || policy.getRetry() == 0) {
//
@@ -484,19 +484,23 @@ public class ControlLoopOperationManager implements Serializable {
}
return (this.attempts > policy.getRetry());
}
-
+
private void storeOperationInDataBase(){
-
+
+ String OpsHistPU = System.getProperty("OperationsHistoryPU");
+ if(OpsHistPU == null || !OpsHistPU.equals("TestOperationsHistoryPU")){
+ OpsHistPU = "OperationsHistoryPU";
+ }
EntityManager em;
try{
- em = Persistence.createEntityManagerFactory("OperationsHistoryPU").createEntityManager();//emf.createEntityManager();
+ em = Persistence.createEntityManagerFactory(OpsHistPU).createEntityManager();
}catch(Exception e){
logger.error("storeOperationInDataBase threw: ", e);
- return;
+ return;
}
-
- OperationsHistoryDbEntry newEntry = new OperationsHistoryDbEntry();
-
+
+ OperationsHistoryDbEntry newEntry = new OperationsHistoryDbEntry();
+
newEntry.closedLoopName = this.onset.closedLoopControlName;
newEntry.requestId = this.onset.requestID.toString();
newEntry.actor = this.currentOperation.operation.actor;
@@ -507,17 +511,17 @@ public class ControlLoopOperationManager implements Serializable {
newEntry.endtime = new Timestamp(this.currentOperation.operation.end.toEpochMilli());
newEntry.message = this.currentOperation.operation.message;
newEntry.outcome = this.currentOperation.operation.outcome;
-
+
em.getTransaction().begin();
em.persist(newEntry);
em.getTransaction().commit();
-
+
em.close();
}
-
-
+
+
private void completeOperation(Integer attempt, String message, PolicyResult result) {
if (attempt == null) {
logger.debug("attempt cannot be null (i.e. subRequestID)");
@@ -556,7 +560,7 @@ public class ControlLoopOperationManager implements Serializable {
}
}
logger.debug("Could not find associated operation");
-
+
}
-
+
}
diff --git a/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml b/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
index f007c4951..27c64b60a 100644
--- a/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
+++ b/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
@@ -1,22 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<persistence xmlns="http://java.sun.com/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
- http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
-
- <persistence-unit name="OperationsHistoryPU" transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
- <!-- <jar-file>packedEntity.jar</jar-file>-->
- <class>org.onap.policy.controlloop.eventmanager.OperationsHistoryDbEntry</class>
- <properties>
- <property name="eclipselink.ddl-generation" value="create-tables"/>
- <property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" />
- <!-- <property name="javax.persistence.jdbc.url" value="jdbc:mariadb://localhost:7779/policy"/>-->
- <property name="javax.persistence.jdbc.url" value="jdbc:mariadb://localhost:3306/policy"/>
- <property name="javax.persistence.jdbc.user" value="root"/>
- <property name="javax.persistence.jdbc.password" value="aaaa"/>
- <property name="eclipselink.logging.level" value="INFO" />
- </properties>
- </persistence-unit>
-
+<persistence version="2.1"
+ xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
+
+ <persistence-unit name="OperationsHistoryPU"
+ transaction-type="RESOURCE_LOCAL">
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+ <!-- <jar-file>packedEntity.jar</jar-file> -->
+ <class>org.onap.policy.controlloop.eventmanager.OperationsHistoryDbEntry</class>
+ <properties>
+ <property name="eclipselink.ddl-generation" value="create-tables" />
+ <property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" />
+ <property name="javax.persistence.jdbc.url" value="jdbc:mariadb://localhost:3306/policy" />
+ <property name="javax.persistence.jdbc.user" value="root" />
+ <property name="javax.persistence.jdbc.password" value="aaaa" />
+ <property name="eclipselink.logging.level" value="WARNING" />
+ </properties>
+ </persistence-unit>
+
+
</persistence>