summaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/eventmanager')
-rw-r--r--controlloop/common/eventmanager/pom.xml18
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java51
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/drools/impl/PolicyEngineJUnitImpl.java9
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java87
4 files changed, 117 insertions, 48 deletions
diff --git a/controlloop/common/eventmanager/pom.xml b/controlloop/common/eventmanager/pom.xml
index 8447ff74d..318d39fbc 100644
--- a/controlloop/common/eventmanager/pom.xml
+++ b/controlloop/common/eventmanager/pom.xml
@@ -60,6 +60,12 @@
</dependency>
<dependency>
<groupId>org.onap.policy.drools-applications</groupId>
+ <artifactId>actor.appclcm</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.drools-applications</groupId>
<artifactId>guard</artifactId>
<version>1.1.0-SNAPSHOT</version>
<scope>provided</scope>
@@ -83,6 +89,18 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.onap.policy.drools-applications</groupId>
+ <artifactId>appclcm</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.drools-applications</groupId>
+ <artifactId>trafficgenerator</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
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 09f69fb0b..94b6e1618 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
@@ -23,6 +23,7 @@ package org.onap.policy.controlloop.eventmanager;
import java.io.Serializable;
import java.sql.Timestamp;
import java.time.Instant;
+import java.util.AbstractMap;
import java.util.LinkedList;
import javax.persistence.EntityManager;
@@ -30,6 +31,7 @@ import javax.persistence.Persistence;
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.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
@@ -40,7 +42,7 @@ import org.onap.policy.controlloop.actor.appc.APPCActorServiceProvider;
import org.onap.policy.controlloop.actor.vfc.VFCActorServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
+import org.onap.policy.controlloop.actor.appclcm.AppcLcmActorServiceProvider;
public class ControlLoopOperationManager implements Serializable {
@@ -196,16 +198,22 @@ public class ControlLoopOperationManager implements Serializable {
//
switch (policy.getActor()) {
case "APPC":
- //Request request = APPCActorServiceProvider.constructRequest(onset, operation.operation, this.policy);
- this.operationRequest = APPCActorServiceProvider.constructRequest((VirtualControlLoopEvent)onset, operation.operation, this.policy);
+ /*
+ * 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 {
+ this.operationRequest = AppcLcmActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, operation.operation, this.policy);
+ }
//
// Save the operation
//
this.currentOperation = operation;
- //System.out.print("************* BEFORE STORING.....");
- //this.storeOperationInDataBase("startOperation");
- //System.out.print("************* AFTER STORING.....");
- //
return operationRequest;
case "MSO":
//
@@ -306,7 +314,34 @@ public class ControlLoopOperationManager implements Serializable {
}
return PolicyResult.FAILURE;
}
- }
+ }
+ else if (response instanceof LCMResponseWrapper) {
+
+ LCMResponseWrapper dmaapResponse = (LCMResponseWrapper) response;
+
+ /*
+ * Parse out the operation attempt using the subrequestid
+ */
+ Integer operationAttempt = AppcLcmActorServiceProvider.parseOperationAttempt(dmaapResponse.getBody().getCommonHeader().getSubRequestId());
+ 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
+ * 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)) {
+ return null;
+ }
+ return result.getKey();
+ }
+ return null;
+ }
return null;
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/drools/impl/PolicyEngineJUnitImpl.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/drools/impl/PolicyEngineJUnitImpl.java
index bb5cec8da..aed72815c 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/drools/impl/PolicyEngineJUnitImpl.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/drools/impl/PolicyEngineJUnitImpl.java
@@ -26,6 +26,7 @@ import java.util.Map;
import java.util.Queue;
import org.onap.policy.appc.Request;
+import org.onap.policy.appclcm.LCMRequestWrapper;
import org.onap.policy.controlloop.ControlLoopNotification;
import org.onap.policy.controlloop.util.Serialization;
import org.slf4j.Logger;
@@ -49,6 +50,10 @@ public class PolicyEngineJUnitImpl implements PolicyEngine {
Request request = (Request) obj;
logger.debug("Request: {} subrequst {}", request.Action, request.CommonHeader.SubRequestID);
}
+ else if (obj instanceof LCMRequestWrapper) {
+ LCMRequestWrapper dmaapRequest = (LCMRequestWrapper) obj;
+ logger.debug("Request: {} subrequest {}", dmaapRequest.getBody().getAction(), dmaapRequest.getBody().getCommonHeader().getSubRequestId());
+ }
//
// Does the bus exist?
//
@@ -57,7 +62,7 @@ public class PolicyEngineJUnitImpl implements PolicyEngine {
//
// Create the bus
//
- busMap.put(busType, new HashMap<String, Queue<Object>>());
+ busMap.put(busType, new HashMap<>());
}
//
// Get the bus
@@ -71,7 +76,7 @@ public class PolicyEngineJUnitImpl implements PolicyEngine {
//
// Create the topic
//
- topicMap.put(topic, new LinkedList<Object>());
+ topicMap.put(topic, new LinkedList<>());
}
//
// Get the topic queue
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java
index 6116d987e..90f61e0c9 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java
@@ -30,10 +30,10 @@ import java.util.HashMap;
import java.util.UUID;
import org.junit.Test;
-import org.onap.policy.appc.Request;
-import org.onap.policy.appc.Response;
-import org.onap.policy.appc.ResponseCode;
-import org.onap.policy.appc.ResponseValue;
+import org.onap.policy.appclcm.LCMRequest;
+import org.onap.policy.appclcm.LCMRequestWrapper;
+import org.onap.policy.appclcm.LCMResponse;
+import org.onap.policy.appclcm.LCMResponseWrapper;
import org.onap.policy.controlloop.ControlLoopEventStatus;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
@@ -53,7 +53,7 @@ public class ControlLoopOperationManagerTest {
onset.requestID = UUID.randomUUID();
onset.target = "vserver.selflink";
onset.closedLoopAlarmStart = Instant.now();
- onset.AAI = new HashMap<String, String>();
+ onset.AAI = new HashMap<>();
onset.AAI.put("cloud-region.identity-url", "foo");
onset.AAI.put("vserver.selflink", "bar");
onset.AAI.put("vserver.is-closed-loop-disabled", "false");
@@ -91,20 +91,24 @@ public class ControlLoopOperationManagerTest {
Object request = manager.startOperation(onset);
logger.debug("{}",manager);
assertNotNull(request);
- assertTrue(request instanceof Request);
- assertTrue(((Request)request).CommonHeader.SubRequestID.contentEquals("1"));
+ assertTrue(request instanceof LCMRequestWrapper);
+ LCMRequestWrapper dmaapRequest = (LCMRequestWrapper) request;
+ LCMRequest appcRequest = dmaapRequest.getBody();
+ assertTrue(appcRequest.getCommonHeader().getSubRequestId().contentEquals("1"));
assertFalse(manager.isOperationComplete());
assertTrue(manager.isOperationRunning());
//
// Accept
//
- Response response = new Response((Request) request);
- response.Status.Code = ResponseCode.ACCEPT.getValue();
- response.Status.Value = ResponseValue.ACCEPT.toString();
+ LCMResponseWrapper dmaapResponse = new LCMResponseWrapper();
+ LCMResponse appcResponse = new LCMResponse((LCMRequest) appcRequest);
+ appcResponse.getStatus().setCode(100);
+ appcResponse.getStatus().setMessage("ACCEPT");
+ dmaapResponse.setBody(appcResponse);
//
//
//
- PolicyResult result = manager.onResponse(response);
+ PolicyResult result = manager.onResponse(dmaapResponse);
logger.debug("{}",manager);
assertTrue(result == null);
assertFalse(manager.isOperationComplete());
@@ -112,11 +116,11 @@ public class ControlLoopOperationManagerTest {
//
// Now we are going to Fail it
//
- response = new Response((Request) request);
- response.Status.Code = ResponseCode.FAILURE.getValue();
- response.Status.Value = ResponseValue.FAILURE.toString();
- response.Status.Description = "AppC failed for some reason";
- result = manager.onResponse(response);
+ appcResponse = new LCMResponse(appcRequest);
+ appcResponse.getStatus().setCode(401);
+ appcResponse.getStatus().setMessage("AppC failed for some reason");
+ dmaapResponse.setBody(appcResponse);
+ result = manager.onResponse(dmaapResponse);
logger.debug("{}",manager);
assertTrue(result.equals(PolicyResult.FAILURE));
assertFalse(manager.isOperationComplete());
@@ -127,21 +131,24 @@ public class ControlLoopOperationManagerTest {
request = manager.startOperation(onset);
logger.debug("{}",manager);
assertNotNull(request);
- assertTrue(request instanceof Request);
- assertTrue(((Request)request).CommonHeader.SubRequestID.contentEquals("2"));
+ assertTrue(request instanceof LCMRequestWrapper);
+ dmaapRequest = (LCMRequestWrapper) request;
+ appcRequest = dmaapRequest.getBody();
+ assertTrue(appcRequest.getCommonHeader().getSubRequestId().contentEquals("2"));
assertFalse(manager.isOperationComplete());
assertTrue(manager.isOperationRunning());
//
//
//
- response = new Response((Request) request);
+ appcResponse = new LCMResponse((LCMRequest) appcRequest);
logger.debug("{}",manager);
- response.Status.Code = ResponseCode.ACCEPT.getValue();
- response.Status.Value = ResponseValue.ACCEPT.toString();
+ appcResponse.getStatus().setCode(100);
+ appcResponse.getStatus().setMessage("ACCEPT");
+ dmaapResponse.setBody(appcResponse);
//
//
//
- result = manager.onResponse(response);
+ result = manager.onResponse(dmaapResponse);
logger.debug("{}",manager);
assertTrue(result == null);
assertFalse(manager.isOperationComplete());
@@ -149,11 +156,11 @@ public class ControlLoopOperationManagerTest {
//
// Now we are going to Fail it
//
- response = new Response((Request) request);
- response.Status.Code = ResponseCode.FAILURE.getValue();
- response.Status.Value = ResponseValue.FAILURE.toString();
- response.Status.Description = "AppC failed for some reason";
- result = manager.onResponse(response);
+ appcResponse = new LCMResponse((LCMRequest) appcRequest);
+ appcResponse.getStatus().setCode(401);
+ appcResponse.getStatus().setMessage("AppC failed for some reason");
+ dmaapResponse.setBody(appcResponse);
+ result = manager.onResponse(dmaapResponse);
logger.debug("{}",manager);
assertTrue(result.equals(PolicyResult.FAILURE));
//
@@ -199,20 +206,24 @@ public class ControlLoopOperationManagerTest {
Object request = manager.startOperation(onset);
logger.debug("{}",manager);
assertNotNull(request);
- assertTrue(request instanceof Request);
- assertTrue(((Request)request).CommonHeader.SubRequestID.contentEquals("1"));
+ assertTrue((request) instanceof LCMRequestWrapper);
+ LCMRequestWrapper dmaapRequest = (LCMRequestWrapper) request;
+ LCMRequest appcRequest = dmaapRequest.getBody();
+ assertTrue((appcRequest).getCommonHeader().getSubRequestId().contentEquals("1"));
assertFalse(manager.isOperationComplete());
assertTrue(manager.isOperationRunning());
//
// Accept
//
- Response response = new Response((Request) request);
- response.Status.Code = ResponseCode.ACCEPT.getValue();
- response.Status.Value = ResponseValue.ACCEPT.toString();
+ LCMResponseWrapper dmaapResponse = new LCMResponseWrapper();
+ LCMResponse appcResponse = new LCMResponse(appcRequest);
+ dmaapResponse.setBody(appcResponse);
+ appcResponse.getStatus().setCode(100);
+ appcResponse.getStatus().setMessage("ACCEPT");
//
//
//
- PolicyResult result = manager.onResponse(response);
+ PolicyResult result = manager.onResponse(dmaapResponse);
logger.debug("{}",manager);
assertTrue(result == null);
assertFalse(manager.isOperationComplete());
@@ -229,11 +240,11 @@ public class ControlLoopOperationManagerTest {
//
// Now we are going to Fail the previous request
//
- response = new Response((Request) request);
- response.Status.Code = ResponseCode.FAILURE.getValue();
- response.Status.Value = ResponseValue.FAILURE.toString();
- response.Status.Description = "AppC failed for some reason";
- result = manager.onResponse(response);
+ appcResponse = new LCMResponse(appcRequest);
+ appcResponse.getStatus().setCode(401);
+ appcResponse.getStatus().setMessage("AppC failed for some reason");
+ dmaapResponse.setBody(appcResponse);
+ result = manager.onResponse(dmaapResponse);
logger.debug("{}",manager);
//
//