aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions
diff options
context:
space:
mode:
authorBruno Sakoto <bruno.sakoto@bell.ca>2019-09-27 15:51:11 -0400
committerBruno Sakoto <bruno.sakoto@bell.ca>2019-10-07 08:23:13 -0400
commit1d0d9ebabda67d6c770b4854a8154763aa6e75d6 (patch)
tree787dcdccda0080da650aeaecf99ed5ea3f170d41 /models-interactions
parent5af913104ec412086deab4d599359751246e4ba3 (diff)
Changes in model to integrate cds actor
* Create class for CDS response Issue-ID: POLICY-2088 Change-Id: I813a310f7d5123fac4bb1c3880d108391096250f Signed-off-by: Bruno Sakoto <bruno.sakoto@bell.ca>
Diffstat (limited to 'models-interactions')
-rw-r--r--models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProvider.java41
-rw-r--r--models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java18
-rw-r--r--models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/CdsResponse.java45
-rw-r--r--models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/properties/CdsServerProperties.java2
4 files changed, 82 insertions, 24 deletions
diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProvider.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProvider.java
index 1ad184e49..272b4e1c3 100644
--- a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProvider.java
+++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProvider.java
@@ -38,6 +38,7 @@ import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
+import org.onap.policy.cds.CdsResponse;
import org.onap.policy.cds.api.CdsProcessorListener;
import org.onap.policy.cds.client.CdsProcessorGrpcClient;
import org.onap.policy.cds.properties.CdsServerProperties;
@@ -171,9 +172,9 @@ public class CdsActorServiceProvider implements Actor {
.isNullOrEmpty(cbaActionName);
}
- class CdsActorServiceManager implements CdsProcessorListener {
+ public class CdsActorServiceManager implements CdsProcessorListener {
- private final AtomicReference<String> cdsResponse = new AtomicReference<>();
+ private final AtomicReference<String> cdsStatus = new AtomicReference<>();
/**
* {@inheritDoc}.
@@ -184,16 +185,16 @@ public class CdsActorServiceProvider implements Actor {
EventType eventType = message.getStatus().getEventType();
switch (eventType) {
case EVENT_COMPONENT_FAILURE:
- cdsResponse.compareAndSet(null, CdsActorConstants.FAILED);
+ cdsStatus.compareAndSet(null, CdsActorConstants.FAILED);
break;
case EVENT_COMPONENT_PROCESSING:
- cdsResponse.compareAndSet(null, CdsActorConstants.PROCESSING);
+ cdsStatus.compareAndSet(null, CdsActorConstants.PROCESSING);
break;
case EVENT_COMPONENT_EXECUTED:
- cdsResponse.compareAndSet(null, CdsActorConstants.SUCCESS);
+ cdsStatus.compareAndSet(null, CdsActorConstants.SUCCESS);
break;
default:
- cdsResponse.compareAndSet(null, CdsActorConstants.FAILED);
+ cdsStatus.compareAndSet(null, CdsActorConstants.FAILED);
break;
}
}
@@ -204,7 +205,7 @@ public class CdsActorServiceProvider implements Actor {
@Override
public void onError(final Throwable throwable) {
Status status = Status.fromThrowable(throwable);
- cdsResponse.compareAndSet(null, CdsActorConstants.ERROR);
+ cdsStatus.compareAndSet(null, CdsActorConstants.ERROR);
LOGGER.error("Failed processing blueprint {} {}", status, throwable);
}
@@ -214,30 +215,36 @@ public class CdsActorServiceProvider implements Actor {
* @param cdsClient CDS grpc client object.
* @param cdsProps CDS properties.
* @param executionServiceInput a valid CDS grpc request object.
- * @return Status of the CDS request, null if timeout happens or onError is invoked for any reason.
+ * @return the cds response.
*/
- public String sendRequestToCds(CdsProcessorGrpcClient cdsClient, CdsServerProperties cdsProps,
- ExecutionServiceInput executionServiceInput) {
+ public CdsResponse sendRequestToCds(CdsProcessorGrpcClient cdsClient, CdsServerProperties cdsProps,
+ ExecutionServiceInput executionServiceInput) {
try {
LOGGER.trace("Start CdsActorServiceProvider.executeCdsBlueprintProcessor {}.", executionServiceInput);
// TO-DO: Handle requests asynchronously once the callback support is added to actors.
CountDownLatch countDownLatch = cdsClient.sendRequest(executionServiceInput);
boolean status = countDownLatch.await(cdsProps.getTimeout(), TimeUnit.SECONDS);
if (!status) {
- cdsResponse.compareAndSet(null, CdsActorConstants.TIMED_OUT);
+ cdsStatus.compareAndSet(null, CdsActorConstants.TIMED_OUT);
}
- LOGGER.info("CDS response {}", getCdsResponse());
+ LOGGER.info("CDS status response {}", getCdsStatus());
} catch (InterruptedException ex) {
LOGGER.error("Caught exception in executeCdsBlueprintProcessor in CdsActorServiceProvider: ", ex);
- cdsResponse.compareAndSet(null, CdsActorConstants.INTERRUPTED);
+ cdsStatus.compareAndSet(null, CdsActorConstants.INTERRUPTED);
Thread.currentThread().interrupt();
}
- LOGGER.info("Status of the CDS gRPC request is: {}", getCdsResponse());
- return getCdsResponse();
+ LOGGER.info("Status of the CDS gRPC request is: {}", getCdsStatus());
+
+ CdsResponse response = new CdsResponse();
+ response.setRequestId(
+ executionServiceInput != null && executionServiceInput.getCommonHeader() != null
+ ? executionServiceInput.getCommonHeader().getRequestId() : null);
+ response.setStatus(this.getCdsStatus());
+ return response;
}
- String getCdsResponse() {
- return cdsResponse.get();
+ String getCdsStatus() {
+ return cdsStatus.get();
}
}
}
diff --git a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java
index 0152521af..28a1676ed 100644
--- a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java
+++ b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/CdsActorServiceProviderTest.java
@@ -20,6 +20,7 @@ package org.onap.policy.controlloop.actor.cds;
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.Matchers.any;
import static org.mockito.Matchers.anyLong;
@@ -49,6 +50,7 @@ import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType;
import org.onap.ccsdk.cds.controllerblueprints.common.api.Status;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
+import org.onap.policy.cds.CdsResponse;
import org.onap.policy.cds.client.CdsProcessorGrpcClient;
import org.onap.policy.cds.properties.CdsServerProperties;
import org.onap.policy.controlloop.ControlLoopOperation;
@@ -188,18 +190,20 @@ public class CdsActorServiceProviderTest {
when(cdsClient.sendRequest(any(ExecutionServiceInput.class))).thenReturn(countDownLatch);
CdsActorServiceProvider.CdsActorServiceManager cdsActorSvcMgr = cdsActor.new CdsActorServiceManager();
- String response = cdsActorSvcMgr
+ CdsResponse response = cdsActorSvcMgr
.sendRequestToCds(cdsClient, cdsProps, ExecutionServiceInput.newBuilder().build());
assertTrue(Thread.interrupted());
- assertEquals(response, CdsActorConstants.INTERRUPTED);
+ assertNotNull(response);
+ assertEquals(CdsActorConstants.INTERRUPTED, response.getStatus());
}
@Test
public void testSendRequestToCdsLatchTimedOut() {
CdsActorServiceProvider.CdsActorServiceManager cdsActorSvcMgr = cdsActor.new CdsActorServiceManager();
- String response = cdsActorSvcMgr
+ CdsResponse response = cdsActorSvcMgr
.sendRequestToCds(cdsClient, cdsProps, ExecutionServiceInput.newBuilder().build());
- assertEquals(response, CdsActorConstants.TIMED_OUT);
+ assertNotNull(response);
+ assertEquals(CdsActorConstants.TIMED_OUT, response.getStatus());
}
@Test
@@ -216,21 +220,21 @@ public class CdsActorServiceProviderTest {
// #1: Failure test
cdsActorSvcMgr.onMessage(message);
- assertEquals(cdsActorSvcMgr.getCdsResponse(), CdsActorConstants.FAILED);
+ assertEquals(CdsActorConstants.FAILED, cdsActorSvcMgr.getCdsStatus());
// #2: Success test
cdsActorSvcMgr = sendRequestToCds();
message = ExecutionServiceOutput.newBuilder()
.setStatus(Status.newBuilder().setEventType(EventType.EVENT_COMPONENT_EXECUTED).build()).build();
cdsActorSvcMgr.onMessage(message);
- assertEquals(cdsActorSvcMgr.getCdsResponse(), CdsActorConstants.SUCCESS);
+ assertEquals(CdsActorConstants.SUCCESS, cdsActorSvcMgr.getCdsStatus());
// #3: Processing test
cdsActorSvcMgr = sendRequestToCds();
message = ExecutionServiceOutput.newBuilder()
.setStatus(Status.newBuilder().setEventType(EventType.EVENT_COMPONENT_PROCESSING).build()).build();
cdsActorSvcMgr.onMessage(message);
- assertEquals(cdsActorSvcMgr.getCdsResponse(), CdsActorConstants.PROCESSING);
+ assertEquals(CdsActorConstants.PROCESSING, cdsActorSvcMgr.getCdsStatus());
}
private CdsActorServiceManager sendRequestToCds() {
diff --git a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/CdsResponse.java b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/CdsResponse.java
new file mode 100644
index 000000000..fca1aa2e9
--- /dev/null
+++ b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/CdsResponse.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Bell Canada.
+ * ================================================================================
+ * 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.cds;
+
+import java.io.Serializable;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+/**
+ * Class representing a CDS response.
+ */
+@Getter
+@Setter
+@ToString
+public class CdsResponse implements Serializable {
+
+ private String requestId;
+ private String status;
+
+ /**
+ * Default empty constructor.
+ */
+ public CdsResponse() {
+ super();
+ }
+
+}
diff --git a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/properties/CdsServerProperties.java b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/properties/CdsServerProperties.java
index 2e919814b..850531848 100644
--- a/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/properties/CdsServerProperties.java
+++ b/models-interactions/model-impl/cds/src/main/java/org/onap/policy/cds/properties/CdsServerProperties.java
@@ -42,6 +42,8 @@ public class CdsServerProperties implements ParameterGroup {
private static final String SERVER_PROPERTIES_TYPE = "CDS gRPC Server Properties";
// CDS carrier properties
+
+ // Request timeout in seconds
@Min(value = 1)
private int timeout;