* ============LICENSE_START=======================================================
* SdnrOperation
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.controlloop.actor.sdnr;
import java.util.List;
-import java.util.concurrent.CompletableFuture;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
return List.of(getSubRequestId());
}
- @Override
- protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
- 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
return Status.FAILURE;
}
- StatusCodeEnum code = StatusCodeEnum.fromStatusCode(response.getStatus().getCode());
+ var code = StatusCodeEnum.fromStatusCode(response.getStatus().getCode());
if (code == null) {
logger.warn("unknown SDNR response status code: {}", response.getStatus().getCode());
return Status.FAILURE;
}
- switch (code) {
- case SUCCESS:
- case PARTIAL_SUCCESS:
- return Status.SUCCESS;
- case FAILURE:
- case PARTIAL_FAILURE:
- return Status.FAILURE;
- case ERROR:
- case REJECT:
+ return switch (code) {
+ case SUCCESS, PARTIAL_SUCCESS -> Status.SUCCESS;
+ case FAILURE, PARTIAL_FAILURE -> Status.FAILURE;
+ case ERROR, REJECT -> {
logger.warn("SDNR request was not accepted, code={}", code);
- return Status.FAILURE;
- case ACCEPTED:
- default:
+ yield Status.FAILURE;
+ }
+ default ->
// awaiting a "final" response
- return Status.STILL_WAITING;
- }
+ Status.STILL_WAITING;
+ };
}
/**
return setOutcome(outcome, result);
}
- PciResponse pciResponse = responseWrapper.getBody().getOutput();
+ var pciResponse = responseWrapper.getBody().getOutput();
if (pciResponse.getStatus() == null || pciResponse.getStatus().getValue() == null) {
return setOutcome(outcome, result);
}
/* Construct an SDNR request using pci Model */
- PciMessage dmaapRequest = new PciMessage();
+ var dmaapRequest = new PciMessage();
dmaapRequest.setVersion("1.0");
dmaapRequest.setCorrelationId(params.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();
+ final var sdnrRequest = new PciRequest();
/* The common header is a required field for all SDNR requests. */
- PciCommonHeader requestCommonHeader = new PciCommonHeader();
+ var requestCommonHeader = new PciCommonHeader();
requestCommonHeader.setRequestId(params.getRequestId());
requestCommonHeader.setSubRequestId(subRequestId);
sdnrRequest.setCommonHeader(requestCommonHeader);
- sdnrRequest.setPayload(getEventPayload());
+ sdnrRequest.setPayload(getRequiredProperty(OperationProperties.EVENT_PAYLOAD, "event payload"));
sdnrRequest.setAction(params.getOperation());
/*
* Once the pci request is constructed, add it into the body of the dmaap wrapper.
*/
- PciBody body = new PciBody();
+ var body = new PciBody();
body.setInput(sdnrRequest);
dmaapRequest.setBody(body);
/* Return the request to be sent through dmaap. */
return dmaapRequest;
}
-
- /**
- * Gets the event payload, first checking for it in the properties and then in the
- * event.
- *
- * @return the event payload
- */
- protected String getEventPayload() {
- if (containsProperty(OperationProperties.EVENT_PAYLOAD)) {
- return getProperty(OperationProperties.EVENT_PAYLOAD);
- }
-
- return params.getContext().getEvent().getPayload();
- }
}