aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-03-06 13:07:08 -0500
committerJim Hahn <jrh3@att.com>2020-03-09 17:48:38 -0400
commitf9e2f54dbb36f029a41e37f6eccc3426672cb9bb (patch)
treecc17a7aedb964a22453b847d5905ef21d52da30c /controlloop/common/eventmanager/src
parent58fd666f277fcee16966d5410e4fd737832a3443 (diff)
Bug fixes to new rules
Also added VdnsTest, VfwTest, and VcpeTest. Fixed a number of issues with notifications: - event data (e.g., AAI) was missing - notification was missing for the start of an operation - "message" and "history" fields should contain Target object, target entity - "message" field was missing various details (e.g., start time) Still missing subRequestId - that will require enhancements to the actors. Issue-ID: POLICY-2385 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I7fc33ebcd5939d2f33a9d209ac6119e390e0836d
Diffstat (limited to 'controlloop/common/eventmanager/src')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java14
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java21
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java16
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java36
4 files changed, 71 insertions, 16 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java
index dc2b513a6..f2e99a9ad 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java
@@ -25,6 +25,7 @@ import static org.onap.policy.controlloop.ControlLoopTargetType.VM;
import static org.onap.policy.controlloop.ControlLoopTargetType.VNF;
import java.io.Serializable;
+import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
@@ -268,11 +269,11 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
} catch (ControlLoopException | RuntimeException e) {
// processor problem - this is fatal
logger.warn("{}: cannot start next step for {}", closedLoopControlName, requestId, e);
+ finalResult = FinalResult.FINAL_FAILURE_EXCEPTION;
notification = makeNotification();
notification.setNotification(ControlLoopNotificationType.FINAL_FAILURE);
notification.setMessage("Policy processing aborted due to policy error");
notification.setHistory(controlLoopHistory);
- finalResult = FinalResult.FINAL_FAILURE_EXCEPTION;
}
}
@@ -301,8 +302,6 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
VirtualControlLoopEvent event = context.getEvent();
- notification.setHistory(operation.getHistory());
-
switch (operation.getState()) {
case LOCK_DENIED:
notification.setNotification(ControlLoopNotificationType.REJECTED);
@@ -327,6 +326,11 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
notification.setMessage("Guard result for " + operation.getActor() + " " + operation.getOperation()
+ " is Deny");
break;
+ case OPERATION_STARTED:
+ notification.setNotification(ControlLoopNotificationType.OPERATION);
+ notification.setMessage(operation.getOperationMessage());
+ notification.setHistory(Collections.emptyList());
+ break;
case OPERATION_SUCCESS:
notification.setNotification(ControlLoopNotificationType.OPERATION_SUCCESS);
break;
@@ -375,7 +379,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
* @return a new notification
*/
public VirtualControlLoopNotification makeNotification() {
- VirtualControlLoopNotification notif = new VirtualControlLoopNotification();
+ VirtualControlLoopNotification notif = new VirtualControlLoopNotification(context.getEvent());
notif.setNotification(ControlLoopNotificationType.OPERATION);
notif.setFrom("policy");
notif.setPolicyScope(policyScope);
@@ -384,7 +388,7 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable {
if (finalResult == null) {
ControlLoopOperationManager2 oper = currentOperation.get();
if (oper != null) {
- notif.setMessage(oper.getOperationMessage());
+ notif.setMessage(oper.getOperationHistory());
notif.setHistory(oper.getHistory());
}
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java
index 6bdaa1575..b880fd190 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java
@@ -76,6 +76,7 @@ public class ControlLoopOperationManager2 implements Serializable {
GUARD_STARTED,
GUARD_PERMITTED,
GUARD_DENIED,
+ OPERATION_STARTED,
OPERATION_SUCCESS,
OPERATION_FAILURE,
CONTROL_LOOP_TIMEOUT
@@ -197,6 +198,7 @@ public class ControlLoopOperationManager2 implements Serializable {
attempt = ControlLoopOperationManager2.this.attempts;
policyResult = outcome.getResult();
clOperation = outcome.toControlLoopOperation();
+ clOperation.setTarget(policy.getTarget().toString());
}
}
@@ -356,7 +358,7 @@ public class ControlLoopOperationManager2 implements Serializable {
* @param outcome outcome provided to the callback
*/
private void onStart(OperationOutcome outcome) {
- if (GUARD_ACTOR.equals(outcome.getActor())) {
+ if (outcome.isFor(actor, operation) || GUARD_ACTOR.equals(outcome.getActor())) {
addOutcome(outcome);
}
}
@@ -477,10 +479,23 @@ public class ControlLoopOperationManager2 implements Serializable {
break;
default:
- // operation completed
- ++attempts;
+ if (outcome.getEnd() == null) {
+ // operation started
+ ++attempts;
+ state = State.OPERATION_STARTED;
+ operationHistory.add(new Operation(outcome));
+ break;
+ }
+
+ /*
+ * Operation completed. If the last entry was a "start" (i.e., "end" field
+ * is null), then replace it. Otherwise, just add the completion.
+ */
state = (outcome.getResult() == PolicyResult.SUCCESS ? State.OPERATION_SUCCESS
: State.OPERATION_FAILURE);
+ if (!operationHistory.isEmpty() && operationHistory.peekLast().getClOperation().getEnd() == null) {
+ operationHistory.removeLast();
+ }
operationHistory.add(new Operation(outcome));
storeOperationInDataBase();
break;
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java
index 522d9f57b..d09c2c88b 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java
@@ -137,14 +137,17 @@ public class ControlLoopEventManager2Test {
when(oper1.getActor()).thenReturn("First");
when(oper1.getOperation()).thenReturn("OperationA");
when(oper1.getOperationMessage()).thenReturn("message-A");
+ when(oper1.getOperationHistory()).thenReturn("history-A");
when(oper2.getActor()).thenReturn("Second");
when(oper2.getOperation()).thenReturn("OperationB");
when(oper2.getOperationMessage()).thenReturn("message-B");
+ when(oper2.getOperationHistory()).thenReturn("history-B");
when(oper3.getActor()).thenReturn("Third");
when(oper3.getOperation()).thenReturn("OperationC");
when(oper3.getOperationMessage()).thenReturn("message-C");
+ when(oper3.getOperationHistory()).thenReturn("history-C");
when(workMem.getFactHandle(any())).thenReturn(factHandle);
@@ -365,13 +368,17 @@ public class ControlLoopEventManager2Test {
mgr.updated(oper1);
verifyNotification(ControlLoopNotificationType.OPERATION, "Guard result for First OperationA is Deny");
+ when(oper1.getState()).thenReturn(State.OPERATION_STARTED);
+ mgr.updated(oper1);
+ verifyNotification(ControlLoopNotificationType.OPERATION, "message-A");
+
when(oper1.getState()).thenReturn(State.OPERATION_SUCCESS);
mgr.updated(oper1);
- verifyNotification(ControlLoopNotificationType.OPERATION_SUCCESS, "message-A");
+ verifyNotification(ControlLoopNotificationType.OPERATION_SUCCESS, "history-A");
when(oper1.getState()).thenReturn(State.OPERATION_FAILURE);
mgr.updated(oper1);
- verifyNotification(ControlLoopNotificationType.OPERATION_FAILURE, "message-A");
+ verifyNotification(ControlLoopNotificationType.OPERATION_FAILURE, "history-A");
// should still be active
assertTrue(mgr.isActive());
@@ -427,6 +434,9 @@ public class ControlLoopEventManager2Test {
@Test
public void testMakeNotification() throws ControlLoopException {
+ // before started
+ assertNotNull(mgr.makeNotification());
+
mgr.start();
nextStep(oper1, true, PolicyResult.SUCCESS);
@@ -434,7 +444,7 @@ public class ControlLoopEventManager2Test {
// check notification while running
VirtualControlLoopNotification notif = mgr.getNotification();
- assertEquals("message-A", notif.getMessage());
+ assertEquals("history-A", notif.getMessage());
List<ControlLoopOperation> history = notif.getHistory();
assertNotNull(history);
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java
index a14cc1708..e946d2edc 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java
@@ -188,6 +188,9 @@ public class ControlLoopOperationManager2Test {
assertEquals(ControlLoopOperationManager2.State.GUARD_PERMITTED, mgr.getState());
assertTrue(mgr.nextStep());
+ assertEquals(ControlLoopOperationManager2.State.OPERATION_STARTED, mgr.getState());
+
+ assertTrue(mgr.nextStep());
assertEquals(ControlLoopOperationManager2.State.OPERATION_SUCCESS, mgr.getState());
assertFalse(mgr.nextStep());
@@ -196,7 +199,7 @@ public class ControlLoopOperationManager2Test {
assertEquals(PolicyResult.SUCCESS, outcome.getResult());
assertTrue(outcome.isFinalOutcome());
- verify(mgrctx, times(3)).updated(mgr);
+ verify(mgrctx, times(4)).updated(mgr);
}
/**
@@ -204,7 +207,7 @@ public class ControlLoopOperationManager2Test {
*/
@Test
public void testStartDetmTargetException() {
- policy.setTarget(null);
+ policy.setTarget(new Target());
mgr.start(REMAINING_MS);
runToCompletion();
@@ -454,13 +457,16 @@ public class ControlLoopOperationManager2Test {
assertEquals(ControlLoopOperationManager2.State.GUARD_PERMITTED, mgr.getState());
assertTrue(mgr.nextStep());
+ assertEquals(ControlLoopOperationManager2.State.OPERATION_STARTED, mgr.getState());
+
+ assertTrue(mgr.nextStep());
assertEquals(ControlLoopOperationManager2.State.OPERATION_SUCCESS, mgr.getState());
assertFalse(mgr.nextStep());
assertEquals(PolicyResult.SUCCESS, mgr.getOutcomes().peek().getResult());
- verify(mgrctx, times(3)).updated(mgr);
+ verify(mgrctx, times(4)).updated(mgr);
}
@Test
@@ -600,10 +606,13 @@ public class ControlLoopOperationManager2Test {
assertEquals(ControlLoopOperationManager2.State.GUARD_PERMITTED, mgr.getState());
assertTrue(mgr.nextStep());
+ assertEquals(ControlLoopOperationManager2.State.OPERATION_STARTED, mgr.getState());
+
+ assertTrue(mgr.nextStep());
assertEquals(ControlLoopOperationManager2.State.OPERATION_SUCCESS, mgr.getState());
assertFalse(mgr.nextStep());
- verify(mgrctx, times(3)).updated(mgr);
+ verify(mgrctx, times(4)).updated(mgr);
verifyDb(1, PolicyResult.SUCCESS, null);
}
@@ -627,6 +636,9 @@ public class ControlLoopOperationManager2Test {
assertEquals(ControlLoopOperationManager2.State.GUARD_PERMITTED, mgr.getState());
assertTrue(mgr.nextStep());
+ assertEquals(ControlLoopOperationManager2.State.OPERATION_STARTED, mgr.getState());
+
+ assertTrue(mgr.nextStep());
assertEquals(ControlLoopOperationManager2.State.OPERATION_FAILURE, mgr.getState());
verifyDb(1, PolicyResult.FAILURE, null);
@@ -637,6 +649,9 @@ public class ControlLoopOperationManager2Test {
runToCompletion();
assertTrue(mgr.nextStep());
+ assertEquals(ControlLoopOperationManager2.State.OPERATION_STARTED, mgr.getState());
+
+ assertTrue(mgr.nextStep());
assertEquals(ControlLoopOperationManager2.State.OPERATION_FAILURE, mgr.getState());
verifyDb(2, PolicyResult.FAILURE, null);
@@ -646,13 +661,16 @@ public class ControlLoopOperationManager2Test {
genOpOutcome();
assertTrue(mgr.nextStep());
+ assertEquals(ControlLoopOperationManager2.State.OPERATION_STARTED, mgr.getState());
+
+ assertTrue(mgr.nextStep());
assertEquals(ControlLoopOperationManager2.State.OPERATION_SUCCESS, mgr.getState());
verifyDb(3, PolicyResult.SUCCESS, null);
assertThat(mgr.toString()).contains("attempts=3");
assertFalse(mgr.nextStep());
- verify(mgrctx, times(5)).updated(mgr);
+ verify(mgrctx, times(8)).updated(mgr);
}
@Test
@@ -802,8 +820,16 @@ public class ControlLoopOperationManager2Test {
runToCompletion();
+ // guard start
assertTrue(mgr.nextStep());
+
+ // guard permit
assertTrue(mgr.nextStep());
+
+ // operation start
+ assertTrue(mgr.nextStep());
+
+ // operation success
assertFalse(mgr.nextStep());
}