summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.sdnr/src/main
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/model-actors/actor.sdnr/src/main
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/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.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
3 files changed, 61 insertions, 64 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;