aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-04-08 12:37:20 -0400
committerJim Hahn <jrh3@att.com>2020-04-08 14:36:45 -0400
commitdf6d6bb862fb0af49a8873479f9e3b609553deca (patch)
treebc5ef9a08ccb0c0a4a27951c56c5b42350d297ea /models-interactions
parent9b3ff5f270572a6760ff07dda9577cdadb53b088 (diff)
SDNR Actor enhancements
Made the following changes: - Enhanced SDNR Actor to support any operation name specified within the policy, constructing the same request, but passing a different "RPC name" and "Action" in the request. - Added ControlLoopResponse to OperationOutcome - Modified SDNR Actor to populate ControlLoopResponse Issue-ID: POLICY-2468 Change-Id: I50ee0674077d975f3cd211454656edc47d78520f Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions')
-rw-r--r--models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperation.java50
-rw-r--r--models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProvider.java17
-rw-r--r--models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java58
-rw-r--r--models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperationTest.java140
-rw-r--r--models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java13
-rw-r--r--models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java98
-rw-r--r--models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java12
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java3
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java10
9 files changed, 179 insertions, 222 deletions
diff --git a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperation.java b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperation.java
deleted file mode 100644
index 2b7f644b6..000000000
--- a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperation.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SdnrOperation
- * ================================================================================
- * Copyright (C) 2020 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.onap.policy.controlloop.actor.sdnr;
-
-import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
-import org.onap.policy.sdnr.PciMessage;
-
-public class ModifyConfigOperation extends SdnrOperation {
- public static final String NAME = "ModifyConfig";
-
- /**
- * Constructs the object.
- *
- * @param params operation parameters
- * @param config configuration for this operation
- */
- public ModifyConfigOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config) {
- super(params, config);
- }
-
- @Override
- protected PciMessage makeRequest(int attempt) {
- final PciMessage request = super.makeRequest(attempt);
- //
- // Set the recipe and action information
- //
- request.setRpcName(NAME.toLowerCase());
- request.getBody().getInput().setAction(NAME);
- return request;
- }
-}
diff --git a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProvider.java b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProvider.java
index 8c799e5cf..5cb7af6ee 100644
--- a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProvider.java
+++ b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProvider.java
@@ -29,6 +29,7 @@ import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.ControlLoopResponse;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.actorserviceprovider.Operator;
import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicActor;
import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperator;
import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicActorParams;
@@ -43,6 +44,10 @@ import org.onap.policy.sdnr.PciResponseWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * SDNR is an unusual actor in that it uses a single, generic operator to initiate all
+ * operation types. The action taken is always the same, only the operation name changes.
+ */
public class SdnrActorServiceProvider extends BidirectionalTopicActor<BidirectionalTopicActorParams> {
private static final String NAME = "SDNR";
@@ -75,8 +80,16 @@ public class SdnrActorServiceProvider extends BidirectionalTopicActor<Bidirectio
public SdnrActorServiceProvider() {
super(NAME, BidirectionalTopicActorParams.class);
- addOperator(new BidirectionalTopicOperator(NAME, ModifyConfigOperation.NAME, this, SdnrOperation.SELECTOR_KEYS,
- ModifyConfigOperation::new));
+ addOperator(new BidirectionalTopicOperator(NAME, SdnrOperation.NAME, this, SdnrOperation.SELECTOR_KEYS,
+ SdnrOperation::new));
+ }
+
+ @Override
+ public Operator getOperator(String name) {
+ /*
+ * All operations are managed by the same operator, regardless of the name.
+ */
+ return super.getOperator(SdnrOperation.NAME);
}
// TODO old code: remove lines down to **HERE**
diff --git a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java
index b5066c72a..40face7fa 100644
--- a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java
+++ b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java
@@ -22,6 +22,7 @@ package org.onap.policy.controlloop.actor.sdnr;
import java.util.List;
import java.util.concurrent.CompletableFuture;
+import org.onap.policy.controlloop.ControlLoopResponse;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation;
@@ -38,10 +39,15 @@ import org.onap.policy.sdnr.util.StatusCodeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMessage> {
+public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMessage> {
private static final Logger logger = LoggerFactory.getLogger(SdnrOperation.class);
/**
+ * Operation name as it should appear within config files.
+ */
+ public static final String NAME = "any";
+
+ /**
* Keys used to match the response with the request listener. The sub request ID is a
* UUID, so it can be used to uniquely identify the response.
* <p/>
@@ -68,27 +74,27 @@ public abstract class SdnrOperation extends BidirectionalTopicOperation<PciMessa
return startGuardAsync();
}
+ /*
+ * NOTE: This should avoid throwing exceptions, so that a ControlLoopResponse can be
+ * added to the outcome. Consequently, it returns FAILURE if a required field is
+ * missing from the response.
+ */
@Override
protected Status detmStatus(String rawResponse, PciMessage responseWrapper) {
PciResponse response = responseWrapper.getBody().getOutput();
if (response.getStatus() == null) {
- throw new IllegalArgumentException("SDNR response is missing the response status");
+ logger.warn("SDNR response is missing the response status");
+ return Status.FAILURE;
}
StatusCodeEnum code = StatusCodeEnum.fromStatusCode(response.getStatus().getCode());
if (code == null) {
- throw new IllegalArgumentException("unknown SDNR response status code: " + response.getStatus().getCode());
+ logger.warn("unknown SDNR response status code: {}", response.getStatus().getCode());
+ return Status.FAILURE;
}
- /*
- * Response and Payload are just printed and no further action needed since
- * casablanca release
- */
- logger.info("SDNR Response Code {} Message is {}", code, response.getStatus().getValue());
- logger.info("SDNR Response Payload is {}", response.getPayload());
-
switch (code) {
case SUCCESS:
case PARTIAL_SUCCESS:
@@ -98,7 +104,8 @@ public abstract class SdnrOperation extends BidirectionalTopicOperation<PciMessa
return Status.FAILURE;
case ERROR:
case REJECT:
- throw new IllegalArgumentException("SDNR request was not accepted, code=" + code);
+ logger.warn("SDNR request was not accepted, code={}", code);
+ return Status.FAILURE;
case ACCEPTED:
default:
// awaiting a "final" response
@@ -112,19 +119,45 @@ public abstract class SdnrOperation extends BidirectionalTopicOperation<PciMessa
@Override
public OperationOutcome setOutcome(OperationOutcome outcome, PolicyResult result, PciMessage responseWrapper) {
if (responseWrapper.getBody() == null || responseWrapper.getBody().getOutput() == null) {
+ outcome.setControlLoopResponse(makeControlLoopResponse(null));
return setOutcome(outcome, result);
}
PciResponse response = responseWrapper.getBody().getOutput();
if (response.getStatus() == null || response.getStatus().getValue() == null) {
+ outcome.setControlLoopResponse(makeControlLoopResponse(response.getPayload()));
return setOutcome(outcome, result);
}
outcome.setResult(result);
outcome.setMessage(response.getStatus().getValue());
+ outcome.setControlLoopResponse(makeControlLoopResponse(response.getPayload()));
return outcome;
}
+ /**
+ * Converts the SDNR response to a ControlLoopResponse.
+ *
+ * @param responsePayload payload from the response
+ *
+ * @return a new ControlLoopResponse
+ */
+ private ControlLoopResponse makeControlLoopResponse(String responsePayload) {
+ VirtualControlLoopEvent event = params.getContext().getEvent();
+
+ ControlLoopResponse clRsp = new ControlLoopResponse();
+ clRsp.setPayload(responsePayload);
+ clRsp.setFrom(params.getActor());
+ clRsp.setTarget("DCAE");
+ clRsp.setClosedLoopControlName(event.getClosedLoopControlName());
+ clRsp.setPolicyName(event.getPolicyName());
+ clRsp.setPolicyVersion(event.getPolicyVersion());
+ clRsp.setRequestId(event.getRequestId());
+ clRsp.setVersion(event.getVersion());
+
+ return clRsp;
+ }
+
@Override
protected PciMessage makeRequest(int attempt) {
VirtualControlLoopEvent onset = params.getContext().getEvent();
@@ -136,6 +169,7 @@ public abstract class SdnrOperation extends BidirectionalTopicOperation<PciMessa
dmaapRequest.setVersion("1.0");
dmaapRequest.setCorrelationId(onset.getRequestId() + "-" + subRequestId);
dmaapRequest.setType("request");
+ dmaapRequest.setRpcName(params.getOperation().toLowerCase());
/* This is the actual request that is placed in the dmaap wrapper. */
final PciRequest sdnrRequest = new PciRequest();
@@ -147,6 +181,7 @@ public abstract class SdnrOperation extends BidirectionalTopicOperation<PciMessa
sdnrRequest.setCommonHeader(requestCommonHeader);
sdnrRequest.setPayload(onset.getPayload());
+ sdnrRequest.setAction(params.getOperation());
/*
* Once the pci request is constructed, add it into the body of the dmaap wrapper.
@@ -154,7 +189,6 @@ public abstract class SdnrOperation extends BidirectionalTopicOperation<PciMessa
PciBody body = new PciBody();
body.setInput(sdnrRequest);
dmaapRequest.setBody(body);
- logger.info("SDNR Request to be sent is {}", dmaapRequest);
/* Return the request to be sent through dmaap. */
return dmaapRequest;
diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperationTest.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperationTest.java
deleted file mode 100644
index 27ffb5225..000000000
--- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperationTest.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*--
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2020 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.onap.policy.controlloop.actor.sdnr;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.atomic.AtomicBoolean;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
-import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
-import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.sdnr.PciMessage;
-
-public class ModifyConfigOperationTest extends BasicSdnrOperation {
-
- private ModifyConfigOperation oper;
-
- public ModifyConfigOperationTest() {
- super(DEFAULT_ACTOR, ModifyConfigOperation.NAME);
- }
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- BasicBidirectionalTopicOperation.initBeforeClass(MY_SINK, MY_SOURCE);
- }
-
- @AfterClass
- public static void tearDownAfterClass() {
- destroyAfterClass();
- }
-
- @Before
- public void setUp() throws Exception {
- super.setUp();
- oper = new ModifyConfigOperation(params, config);
- }
-
- @After
- @Override
- public void tearDown() {
- super.tearDown();
- }
-
-
- /**
- * Tests "success" case with simulator.
- */
- @Test
- public void testSuccess() throws Exception {
- BidirectionalTopicParams opParams =
- BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SOURCE).build();
- config = new BidirectionalTopicConfig(blockingExecutor, opParams, topicMgr, SdnrOperation.SELECTOR_KEYS);
-
- params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
-
- oper = new ModifyConfigOperation(params, config) {
- @Override
- protected CompletableFuture<OperationOutcome> startGuardAsync() {
- return null;
- }
- };
-
- outcome = oper.start().get();
- assertEquals(PolicyResult.SUCCESS, outcome.getResult());
- }
-
- @Test
- public void testConstructor() {
- assertEquals(DEFAULT_ACTOR, oper.getActorName());
- assertEquals(ModifyConfigOperation.NAME, oper.getName());
- }
-
- @Test
- public void testStartPreprocessorAsync() throws Exception {
- final CompletableFuture<OperationOutcome> future2 = new CompletableFuture<>();
- context = mock(ControlLoopEventContext.class);
- when(context.getEvent()).thenReturn(event);
- params = params.toBuilder().context(context).build();
-
- AtomicBoolean guardStarted = new AtomicBoolean();
-
- oper = new ModifyConfigOperation(params, config) {
- @Override
- protected CompletableFuture<OperationOutcome> startGuardAsync() {
- guardStarted.set(true);
- return super.startGuardAsync();
- }
- };
- CompletableFuture<OperationOutcome> future3 = oper.startPreprocessorAsync();
-
- assertNotNull(future3);
- assertFalse(future.isDone());
- assertTrue(guardStarted.get());
-
- future2.complete(params.makeOutcome());
- assertTrue(executor.runAll(100));
- assertTrue(future3.isDone());
- assertEquals(PolicyResult.SUCCESS, future3.get().getResult());
- }
-
- @Test
- public void testMakeRequest() throws CoderException {
- oper.generateSubRequestId(1);
-
- PciMessage request = oper.makeRequest(1);
- assertNotNull(request);
- }
-}
diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java
index 8101b12fd..12a1666a0 100644
--- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java
+++ b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProviderTest.java
@@ -22,18 +22,19 @@ package org.onap.policy.controlloop.actor.sdnr;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.time.Instant;
import java.util.HashMap;
import java.util.UUID;
-
import org.junit.Test;
import org.onap.policy.controlloop.ControlLoopEventStatus;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.ControlLoopResponse;
import org.onap.policy.controlloop.ControlLoopTargetType;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.actorserviceprovider.Operator;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.policy.Target;
import org.onap.policy.controlloop.policy.TargetType;
@@ -94,6 +95,16 @@ public class SdnrActorServiceProviderTest {
}
@Test
+ public void testGetOperator() {
+ SdnrActorServiceProvider sp = new SdnrActorServiceProvider();
+
+ // should always return the same operator regardless of the name
+ Operator oper = sp.getOperator("unknown");
+ assertNotNull(oper);
+ assertSame(oper, sp.getOperator("another"));
+ }
+
+ @Test
public void testGetControlLoopResponse() {
PciRequest sdnrRequest;
sdnrRequest = SdnrActorServiceProvider.constructRequest(onsetEvent, operation, policy).getBody();
diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java
index 836b1ae57..2bb0d9469 100644
--- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java
+++ b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java
@@ -20,22 +20,33 @@
package org.onap.policy.controlloop.actor.sdnr;
-import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.util.Arrays;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.controlloop.ControlLoopResponse;
import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
+import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation.Status;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.sdnr.PciCommonHeader;
import org.onap.policy.sdnr.PciMessage;
+import org.onap.policy.sdnr.PciRequest;
import org.onap.policy.sdnr.util.StatusCodeEnum;
public class SdnrOperationTest extends BasicSdnrOperation {
@@ -60,7 +71,7 @@ public class SdnrOperationTest extends BasicSdnrOperation {
public void setUp() throws Exception {
super.setUp();
- operation = new SdnrOperation(params, config) {};
+ operation = new SdnrOperation(params, config);
}
@After
@@ -84,8 +95,13 @@ public class SdnrOperationTest extends BasicSdnrOperation {
assertNotNull(request.getBody());
assertEquals("1.0", request.getVersion());
assertEquals("request", request.getType());
+ assertEquals(DEFAULT_OPERATION.toLowerCase(), request.getRpcName());
- PciCommonHeader header = request.getBody().getInput().getCommonHeader();
+ PciRequest input = request.getBody().getInput();
+ assertNotNull(input);
+ assertEquals(DEFAULT_OPERATION, input.getAction());
+
+ PciCommonHeader header = input.getCommonHeader();
assertNotNull(header);
assertEquals(params.getRequestId(), header.getRequestId());
}
@@ -99,9 +115,66 @@ public class SdnrOperationTest extends BasicSdnrOperation {
operation.getExpectedKeyValues(50, request));
}
+ /**
+ * Tests "success" case with simulator.
+ */
+ @Test
+ public void testSuccess() throws Exception {
+ BidirectionalTopicParams opParams =
+ BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SOURCE).build();
+ config = new BidirectionalTopicConfig(blockingExecutor, opParams, topicMgr, SdnrOperation.SELECTOR_KEYS);
+
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+
+ operation = new SdnrOperation(params, config) {
+ @Override
+ protected CompletableFuture<OperationOutcome> startGuardAsync() {
+ return null;
+ }
+ };
+
+ outcome = operation.start().get();
+ assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+
+ ControlLoopResponse clresp = outcome.getControlLoopResponse();
+ assertNotNull(clresp);
+
+ assertEquals(DEFAULT_ACTOR, clresp.getFrom());
+ assertEquals("DCAE", clresp.getTarget());
+ assertEquals(CL_NAME, clresp.getClosedLoopControlName());
+ assertEquals(EVENT_POLICY_NAME, clresp.getPolicyName());
+ assertEquals(EVENT_POLICY_VERSION, clresp.getPolicyVersion());
+ assertEquals(EVENT_VERSION, clresp.getVersion());
+ assertEquals(REQ_ID, clresp.getRequestId());
+ assertNotNull(clresp.getPayload());
+ }
+
@Test
- public void testStartPreprocessorAsync() {
- assertNotNull(operation.startPreprocessorAsync());
+ public void testStartPreprocessorAsync() throws Exception {
+ final CompletableFuture<OperationOutcome> future2 = new CompletableFuture<>();
+ context = mock(ControlLoopEventContext.class);
+ when(context.getEvent()).thenReturn(event);
+ params = params.toBuilder().context(context).build();
+
+ AtomicBoolean guardStarted = new AtomicBoolean();
+
+ operation = new SdnrOperation(params, config) {
+ @Override
+ protected CompletableFuture<OperationOutcome> startGuardAsync() {
+ guardStarted.set(true);
+ return super.startGuardAsync();
+ }
+ };
+ CompletableFuture<OperationOutcome> future3 = operation.startPreprocessorAsync();
+
+ assertNotNull(future3);
+ assertFalse(future.isDone());
+ assertTrue(guardStarted.get());
+
+ future2.complete(params.makeOutcome());
+ assertTrue(executor.runAll(100));
+ assertTrue(future3.isDone());
+ assertEquals(PolicyResult.SUCCESS, future3.get().getResult());
}
@Test
@@ -110,14 +183,12 @@ public class SdnrOperationTest extends BasicSdnrOperation {
// null status
response.getBody().getOutput().setStatus(null);
- assertThatIllegalArgumentException().isThrownBy(() -> operation.detmStatus("", response))
- .withMessage("SDNR response is missing the response status");
+ assertEquals(Status.FAILURE, operation.detmStatus("", response));
response.getBody().getOutput().setStatus(status);
// invalid code
status.setCode(-45);
- assertThatIllegalArgumentException().isThrownBy(() -> operation.detmStatus("", response))
- .withMessage("unknown SDNR response status code: -45");
+ assertEquals(Status.FAILURE, operation.detmStatus("", response));
status.setValue(StatusCodeEnum.ACCEPTED.toString());
@@ -130,18 +201,15 @@ public class SdnrOperationTest extends BasicSdnrOperation {
status.setValue(StatusCodeEnum.REJECT.toString());
status.setCode(StatusCodeEnum.toValue(StatusCodeEnum.REJECT));
- assertThatIllegalArgumentException().isThrownBy(() -> operation.detmStatus("", response))
- .withMessage("SDNR request was not accepted, code=" + StatusCodeEnum.REJECT.toString());
+ assertEquals(Status.FAILURE, operation.detmStatus("", response));
status.setValue(StatusCodeEnum.REJECT.toString());
status.setCode(313);
- assertThatIllegalArgumentException().isThrownBy(() -> operation.detmStatus("", response))
- .withMessage("SDNR request was not accepted, code=" + StatusCodeEnum.REJECT.toString());
+ assertEquals(Status.FAILURE, operation.detmStatus("", response));
status.setValue(StatusCodeEnum.ERROR.toString());
status.setCode(StatusCodeEnum.toValue(StatusCodeEnum.ERROR));
- assertThatIllegalArgumentException().isThrownBy(() -> operation.detmStatus("", response))
- .withMessage("SDNR request was not accepted, code=" + StatusCodeEnum.ERROR.toString());
+ assertEquals(Status.FAILURE, operation.detmStatus("", response));
status.setValue(StatusCodeEnum.FAILURE.toString());
status.setCode(450);
diff --git a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java
index 3b1871f20..c0ea44715 100644
--- a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java
+++ b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java
@@ -56,9 +56,13 @@ import org.onap.policy.controlloop.policy.PolicyResult;
public class BasicOperation {
protected static final UUID REQ_ID = UUID.randomUUID();
protected static final String SUB_REQ_ID = "my-sub-request-id";
- protected static final String DEFAULT_ACTOR = "default-actor";
- protected static final String DEFAULT_OPERATION = "default-operation";
+ protected static final String DEFAULT_ACTOR = "default-Actor";
+ protected static final String DEFAULT_OPERATION = "default-Operation";
protected static final String TARGET_ENTITY = "my-target";
+ protected static final String CL_NAME = "my-closed-loop";
+ protected static final String EVENT_POLICY_NAME = "my-event-policy-name";
+ protected static final String EVENT_POLICY_VERSION = "my-event-policy-version";
+ protected static final String EVENT_VERSION = "my-event-version";
protected static final Executor blockingExecutor = command -> {
Thread thread = new Thread(command);
@@ -158,6 +162,10 @@ public class BasicOperation {
event = new VirtualControlLoopEvent();
event.setRequestId(REQ_ID);
event.setAai(enrichment);
+ event.setClosedLoopControlName(CL_NAME);
+ event.setPolicyName(EVENT_POLICY_NAME);
+ event.setPolicyVersion(EVENT_POLICY_VERSION);
+ event.setVersion(EVENT_VERSION);
context = new ControlLoopEventContext(event);
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java
index d8db70619..e2d94b3b3 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcome.java
@@ -25,6 +25,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.onap.policy.controlloop.ControlLoopOperation;
+import org.onap.policy.controlloop.ControlLoopResponse;
import org.onap.policy.controlloop.policy.PolicyResult;
/**
@@ -42,6 +43,7 @@ public class OperationOutcome {
private PolicyResult result = PolicyResult.SUCCESS;
private String message;
private boolean finalOutcome;
+ private ControlLoopResponse controlLoopResponse;
/**
* Copy constructor.
@@ -58,6 +60,7 @@ public class OperationOutcome {
this.result = source.result;
this.message = source.message;
this.finalOutcome = source.finalOutcome;
+ this.controlLoopResponse = source.controlLoopResponse;
}
/**
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java
index 4e9728336..77d2253e1 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/OperationOutcomeTest.java
@@ -23,12 +23,14 @@ package org.onap.policy.controlloop.actorserviceprovider;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.time.Instant;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.controlloop.ControlLoopOperation;
+import org.onap.policy.controlloop.ControlLoopResponse;
import org.onap.policy.controlloop.policy.PolicyResult;
public class OperationOutcomeTest {
@@ -41,10 +43,16 @@ public class OperationOutcomeTest {
private static final PolicyResult RESULT = PolicyResult.FAILURE_GUARD;
private static final String MESSAGE = "my-message";
+ private ControlLoopResponse response;
private OperationOutcome outcome;
+ /**
+ * Sets up.
+ */
@Before
public void setUp() {
+ response = new ControlLoopResponse();
+
outcome = new OperationOutcome();
}
@@ -62,6 +70,7 @@ public class OperationOutcomeTest {
assertEquals(SUB_REQ_ID, outcome2.getSubRequestId());
assertEquals(RESULT, outcome2.getResult());
assertEquals(MESSAGE, outcome2.getMessage());
+ assertSame(response, outcome2.getControlLoopResponse());
}
@Test
@@ -133,5 +142,6 @@ public class OperationOutcomeTest {
outcome.setStart(START);
outcome.setSubRequestId(SUB_REQ_ID);
outcome.setTarget(TARGET);
+ outcome.setControlLoopResponse(response);
}
}