package org.onap.policy.controlloop.actor.so;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.aai.domain.yang.CloudRegion;
import org.onap.aai.domain.yang.GenericVnf;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig;
import org.onap.policy.so.SoModelInfo;
import org.onap.policy.so.SoOperationType;
import org.onap.policy.so.SoRelatedInstance;
import org.onap.policy.so.SoRequest;
import org.onap.policy.so.SoRequestDetails;
import org.onap.policy.so.SoRequestParameters;
+import org.onap.policy.so.SoResponse;
/**
* Operation to create a VF Module. This gets the VF count from the A&AI Custom Query
private static final String PATH_PREFIX = "/";
+ // @formatter:off
+ private static final List<String> PROPERTY_NAMES = List.of(
+ OperationProperties.AAI_MODEL_SERVICE,
+ OperationProperties.AAI_MODEL_VNF,
+ OperationProperties.AAI_MODEL_CLOUD_REGION,
+ OperationProperties.AAI_MODEL_TENANT,
+ OperationProperties.DATA_VF_COUNT);
+ // @formatter:off
+
/**
* Constructs the object.
*
* @param params operation parameters
* @param config configuration for this operation
*/
- public VfModuleCreate(ControlLoopOperationParams params, HttpConfig config) {
- super(params, config);
+ public VfModuleCreate(ControlLoopOperationParams params, HttpPollingConfig config) {
+ super(params, config, PROPERTY_NAMES);
// ensure we have the necessary parameters
validateTarget();
@Override
@SuppressWarnings("unchecked")
protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
+ if (params.isPreprocessed()) {
+ return null;
+ }
// need the VF count
ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
// starting a whole new attempt - reset the count
- resetGetCount();
+ resetPollCount();
Pair<String, SoRequest> pair = makeRequest();
String path = getPath() + pair.getLeft();
SoRequest request = pair.getRight();
- Entity<SoRequest> entity = Entity.entity(request, MediaType.APPLICATION_JSON);
String url = getClient().getBaseUrl() + path;
- logMessage(EventType.OUT, CommInfrastructure.REST, url, request);
+ String strRequest = prettyPrint(request);
+ logMessage(EventType.OUT, CommInfrastructure.REST, url, strRequest);
+
+ Entity<String> entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON);
Map<String, Object> headers = createSimpleHeaders();
}
/**
- * Increments the VF count that's stored in the context.
+ * Increments the VF count that's stored in the context, if the request was
+ * successful.
*/
@Override
- protected void successfulCompletion() {
- setVfCount(getVfCount() + 1);
+ protected Status detmStatus(Response rawResponse, SoResponse response) {
+ Status status = super.detmStatus(rawResponse, response);
+
+ if (status == Status.SUCCESS) {
+ setVfCount(getVfCount() + 1);
+ }
+
+ return status;
}
/**