summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.sdnr/src/main
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2020-02-21 14:57:50 -0500
committerPamela Dragosh <pdragosh@research.att.com>2020-03-01 17:56:45 -0500
commitd0ba41b23a788bc557f451a0c66f0095c10dd390 (patch)
tree518c77533c5f852345e12bb661697e064a9dbe35 /models-interactions/model-actors/actor.sdnr/src/main
parent76a2d0ed90c281768793a279debbd6ee6e445fce (diff)
Add SDNR Actor
Actor for SDNR and necessary JUnit tests. Removed the Pair code. Issue-ID: POLICY-2382 Change-Id: I3da1d95f431cc076f12e9ad26280b92058fe51cc Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.sdnr/src/main')
-rw-r--r--models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperation.java57
-rw-r--r--models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrActorServiceProvider.java46
-rw-r--r--models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java163
3 files changed, 242 insertions, 24 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
new file mode 100644
index 000000000..67c3d4521
--- /dev/null
+++ b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperation.java
@@ -0,0 +1,57 @@
+/*-
+ * ============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 java.util.concurrent.CompletableFuture;
+import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.onap.policy.sdnr.PciRequestWrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ModifyConfigOperation extends SdnrOperation {
+ private static final Logger logger = LoggerFactory.getLogger(ModifyConfigOperation.class);
+
+ 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 PciRequestWrapper makeRequest(int attempt) {
+ PciRequestWrapper request = super.makeRequest(attempt);
+ //
+ // Set the recipe and action information
+ //
+ request.setRpcName(NAME.toLowerCase());
+ request.getBody().setAction(NAME);
+ logger.info("SDNR ModifyConfig Request to be sent is {}", request);
+ 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 0919779a5..8c799e5cf 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
@@ -25,10 +25,13 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.Collections;
import java.util.List;
+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.impl.ActorImpl;
+import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicActor;
+import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperator;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicActorParams;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.sdnr.PciCommonHeader;
@@ -40,27 +43,11 @@ import org.onap.policy.sdnr.PciResponseWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class SdnrActorServiceProvider extends ActorImpl {
+public class SdnrActorServiceProvider extends BidirectionalTopicActor<BidirectionalTopicActorParams> {
private static final String NAME = "SDNR";
- public static class Pair<A, B> {
- public final A result;
- public final B message;
-
- public Pair(A result, B message) {
- this.result = result;
- this.message = message;
- }
-
- public A getResult() {
- return this.result;
- }
-
- public B getMessage() {
- return this.message;
- }
- }
+ // TODO old code: remove lines down to **HERE**
private static final Logger logger = LoggerFactory.getLogger(SdnrActorServiceProvider.class);
@@ -80,10 +67,20 @@ public class SdnrActorServiceProvider extends ActorImpl {
private static final ImmutableMap<String, List<String>> payloads = new ImmutableMap.Builder<String, List<String>>()
.put(RECIPE_MODIFY, ImmutableList.of(SDNR_REQUEST_PARAMS, SDNR_CONFIG_PARAMS)).build();
+ // **HERE**
+
+ /**
+ * Constructor.
+ */
public SdnrActorServiceProvider() {
- super(NAME);
+ super(NAME, BidirectionalTopicActorParams.class);
+
+ addOperator(new BidirectionalTopicOperator(NAME, ModifyConfigOperation.NAME, this, SdnrOperation.SELECTOR_KEYS,
+ ModifyConfigOperation::new));
}
+ // TODO old code: remove lines down to **HERE**
+
@Override
public String actor() {
return NAME;
@@ -195,7 +192,7 @@ public class SdnrActorServiceProvider extends ActorImpl {
* @return an key-value pair that contains the Policy result and SDNR response
* message
*/
- public static SdnrActorServiceProvider.Pair<PolicyResult, String> processResponse(
+ public static Pair<PolicyResult, String> processResponse(
PciResponseWrapper dmaapResponse) {
logger.info("SDNR processResponse called : {}", dmaapResponse);
@@ -214,7 +211,7 @@ public class SdnrActorServiceProvider extends ActorImpl {
*/
if (sdnrResponse.getStatus() == null) {
message = "Policy was unable to parse SDN-R response status field (it was null).";
- return new SdnrActorServiceProvider.Pair<>(PolicyResult.FAILURE_EXCEPTION, message);
+ return Pair.of(PolicyResult.FAILURE_EXCEPTION, message);
}
/*
@@ -223,7 +220,7 @@ public class SdnrActorServiceProvider extends ActorImpl {
String responseValue = PciResponseCode.toResponseValue(sdnrResponse.getStatus().getCode());
if (responseValue == null) {
message = "Policy was unable to parse SDN-R response status code field.";
- return new SdnrActorServiceProvider.Pair<>(PolicyResult.FAILURE_EXCEPTION, message);
+ return Pair.of(PolicyResult.FAILURE_EXCEPTION, message);
}
logger.info("SDNR Response Code is {}", responseValue);
@@ -255,7 +252,7 @@ public class SdnrActorServiceProvider extends ActorImpl {
default:
result = PolicyResult.FAILURE_EXCEPTION;
}
- return new SdnrActorServiceProvider.Pair<>(result, message);
+ return Pair.of(result, message);
}
/**
@@ -290,4 +287,5 @@ public class SdnrActorServiceProvider extends ActorImpl {
return clRsp;
}
+ // **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
new file mode 100644
index 000000000..5faa31d7c
--- /dev/null
+++ b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java
@@ -0,0 +1,163 @@
+/*-
+ * ============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 java.util.List;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.actorserviceprovider.topic.SelectorKey;
+import org.onap.policy.controlloop.policy.PolicyResult;
+import org.onap.policy.sdnr.PciCommonHeader;
+import org.onap.policy.sdnr.PciRequest;
+import org.onap.policy.sdnr.PciRequestWrapper;
+import org.onap.policy.sdnr.PciResponse;
+import org.onap.policy.sdnr.PciResponseWrapper;
+import org.onap.policy.sdnr.util.StatusCodeEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class SdnrOperation extends BidirectionalTopicOperation<PciRequestWrapper, PciResponseWrapper> {
+ private static final Logger logger = LoggerFactory.getLogger(SdnrOperation.class);
+
+ /**
+ * 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/>
+ * Note: if these change, then {@link #getExpectedKeyValues(int, Request)} must be
+ * updated accordingly.
+ */
+ public static final List<SelectorKey> SELECTOR_KEYS = List.of(new SelectorKey("CommonHeader", "SubRequestID"));
+
+ public SdnrOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config) {
+ super(params, config, PciResponseWrapper.class);
+ }
+
+ /**
+ * Note: these values must match {@link #SELECTOR_KEYS}.
+ */
+ @Override
+ protected List<String> getExpectedKeyValues(int attempt, PciRequestWrapper request) {
+ return List.of(request.getBody().getCommonHeader().getSubRequestId());
+ }
+
+ @Override
+ protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
+ return startGuardAsync();
+ }
+
+ @Override
+ protected Status detmStatus(String rawResponse, PciResponseWrapper responseWrapper) {
+ PciResponse response = responseWrapper.getBody();
+
+ if (response == null || response.getStatus() == null) {
+ throw new IllegalArgumentException("SDNR response is missing the response status");
+ }
+
+ StatusCodeEnum code = StatusCodeEnum.fromStatusCode(response.getStatus().getCode());
+
+ if (code == null) {
+ throw new IllegalArgumentException(
+ "unknown SDNR response status code: " + response.getStatus().getCode());
+ }
+
+ /*
+ * 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:
+ return Status.SUCCESS;
+ case FAILURE:
+ case PARTIAL_FAILURE:
+ return Status.FAILURE;
+ case ERROR:
+ case REJECT:
+ throw new IllegalArgumentException("SDNR request was not accepted, code=" + code);
+ case ACCEPTED:
+ default:
+ // awaiting a "final" response
+ return Status.STILL_WAITING;
+ }
+ }
+
+ /**
+ * Sets the message to the status description, if available.
+ */
+ @Override
+ public OperationOutcome setOutcome(OperationOutcome outcome, PolicyResult result,
+ PciResponseWrapper responseWrapper) {
+ PciResponse response = responseWrapper.getBody();
+ if (response.getStatus() == null || response.getStatus().getValue() == null) {
+ return setOutcome(outcome, result);
+ }
+
+ outcome.setResult(result);
+ outcome.setMessage(response.getStatus().getValue());
+ return outcome;
+ }
+
+ @Override
+ protected PciRequestWrapper makeRequest(int attempt) {
+ VirtualControlLoopEvent onset = params.getContext().getEvent();
+ String subRequestId = UUID.randomUUID().toString();
+
+ /* Construct an SDNR request using pci Model */
+
+ /*
+ * The actual pci request is placed in a wrapper used to send through dmaap. The
+ * current version is 2.0 as of R1.
+ */
+ PciRequestWrapper dmaapRequest = new PciRequestWrapper();
+ dmaapRequest.setVersion("1.0");
+ dmaapRequest.setCorrelationId(onset.getRequestId() + "-" + subRequestId);
+ dmaapRequest.setType("request");
+
+ /* This is the actual request that is placed in the dmaap wrapper. */
+ final PciRequest sdnrRequest = new PciRequest();
+
+ /* The common header is a required field for all SDNR requests. */
+ PciCommonHeader requestCommonHeader = new PciCommonHeader();
+ requestCommonHeader.setRequestId(onset.getRequestId());
+ requestCommonHeader.setSubRequestId(subRequestId);
+
+ sdnrRequest.setCommonHeader(requestCommonHeader);
+ sdnrRequest.setPayload(onset.getPayload());
+
+ /*
+ * Once the pci request is constructed, add it into the body of the dmaap
+ * wrapper.
+ */
+ dmaapRequest.setBody(sdnrRequest);
+ logger.info("SDNR Request to be sent is {}", dmaapRequest);
+
+ /* Return the request to be sent through dmaap. */
+ return dmaapRequest;
+ }
+}