import java.util.List;
import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.CompletableFuture;
-import org.apache.commons.lang3.StringUtils;
import org.onap.policy.appclcm.AppcLcmBody;
import org.onap.policy.appclcm.AppcLcmCommonHeader;
import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
import org.onap.policy.appclcm.AppcLcmResponseCode;
import org.onap.policy.appclcm.AppcLcmResponseStatus;
import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
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;
public class AppcLcmOperation extends BidirectionalTopicOperation<AppcLcmDmaapWrapper, AppcLcmDmaapWrapper> {
private static final String MISSING_STATUS = "APPC-LCM response is missing the response status";
public static final String VNF_ID_KEY = "vnf-id";
+ private static final List<String> PROPERTY_NAMES = List.of(OperationProperties.AAI_TARGET_ENTITY);
+
/**
* 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.
* @param config configuration for this operation
*/
public AppcLcmOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config) {
- super(params, config, AppcLcmDmaapWrapper.class);
-
- if (StringUtils.isBlank(params.getTargetEntity())) {
- throw new IllegalArgumentException("missing targetEntity");
- }
- }
-
- /**
- * Ensures that A&AI customer query has been performed, and then runs the guard query.
- * Starts the GUARD using startGuardAsync.
- */
- @Override
- protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
- return startGuardAsync();
+ super(params, config, AppcLcmDmaapWrapper.class, PROPERTY_NAMES);
}
@Override
protected AppcLcmDmaapWrapper makeRequest(int attempt) {
- VirtualControlLoopEvent onset = params.getContext().getEvent();
- String subRequestId = UUID.randomUUID().toString();
+ String subRequestId = getSubRequestId();
AppcLcmCommonHeader header = new AppcLcmCommonHeader();
- header.setOriginatorId(onset.getRequestId().toString());
- header.setRequestId(onset.getRequestId());
+ header.setOriginatorId(params.getRequestId().toString());
+ header.setRequestId(params.getRequestId());
header.setSubRequestId(subRequestId);
AppcLcmInput inputRequest = new AppcLcmInput();
* Action Identifiers are required for APPC LCM requests. For R1, the recipes
* supported by Policy only require a vnf-id.
*/
- inputRequest.setActionIdentifiers(Map.of(VNF_ID_KEY, params.getTargetEntity()));
+ String target = getProperty(OperationProperties.AAI_TARGET_ENTITY);
+ inputRequest.setActionIdentifiers(Map.of(VNF_ID_KEY, target));
/*
* For R1, the payloads will not be required for the Restart, Rebuild, or Migrate
AppcLcmDmaapWrapper dmaapRequest = new AppcLcmDmaapWrapper();
dmaapRequest.setBody(body);
dmaapRequest.setVersion("2.0");
- dmaapRequest.setCorrelationId(onset.getRequestId() + "-" + subRequestId);
+ dmaapRequest.setCorrelationId(params.getRequestId() + "-" + subRequestId);
dmaapRequest.setRpcName(recipeFormatter.getUrlRecipe());
dmaapRequest.setType("request");
*/
private void convertPayload(Map<String, Object> source, AppcLcmInput request) {
try {
- String encodedPayloadString = makeCoder().encode(source);
+ String encodedPayloadString = getCoder().encode(source);
request.setPayload(encodedPayloadString);
} catch (CoderException e) {
throw new IllegalArgumentException("Cannot convert payload", e);
*/
@Override
protected List<String> getExpectedKeyValues(int attempt, AppcLcmDmaapWrapper request) {
- return List.of(request.getBody().getInput().getCommonHeader().getSubRequestId());
+ return List.of(getSubRequestId());
}
@Override
* Sets the message to the status description, if available.
*/
@Override
- public OperationOutcome setOutcome(OperationOutcome outcome, PolicyResult result, AppcLcmDmaapWrapper response) {
+ public OperationOutcome setOutcome(OperationOutcome outcome, OperationResult result, AppcLcmDmaapWrapper response) {
+ outcome.setResponse(response);
+
AppcLcmResponseStatus status = getStatus(response);
if (status == null) {
return setOutcome(outcome, result);