Make Actors event-agnostic
[policy/models.git] / models-interactions / model-actors / actor.so / src / main / java / org / onap / policy / controlloop / actor / so / VfModuleDelete.java
index dc8b0d6..9adb62c 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP
  * ================================================================================
  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Wipro Limited.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -28,6 +29,7 @@ import java.net.http.HttpResponse;
 import java.net.http.HttpResponse.BodyHandlers;
 import java.nio.charset.StandardCharsets;
 import java.util.Base64;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.CompletableFuture;
@@ -40,12 +42,11 @@ import org.onap.aai.domain.yang.CloudRegion;
 import org.onap.aai.domain.yang.GenericVnf;
 import org.onap.aai.domain.yang.ServiceInstance;
 import org.onap.aai.domain.yang.Tenant;
-import org.onap.policy.aai.AaiConstants;
-import org.onap.policy.aai.AaiCqResponse;
 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
 import org.onap.policy.common.endpoints.http.client.HttpClient;
 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.HttpPollingConfig;
 import org.onap.policy.controlloop.actorserviceprovider.pipeline.PipelineControllerFuture;
@@ -56,16 +57,23 @@ import org.onap.policy.so.SoRequestDetails;
 import org.onap.policy.so.SoResponse;
 
 /**
- * Operation to delete a VF Module. This gets the VF count from the A&AI Custom Query
- * response and stores it in the context. It also passes the count-1 to the guard. Once
- * the "delete" completes successfully, it decrements the VF count that's stored in the
- * context.
+ * Operation to delete a VF Module. When this completes successfully, it decrements its VF
+ * Count property.
  */
 public class VfModuleDelete extends SoOperation {
     public static final String NAME = "VF Module Delete";
 
     private static final String PATH_PREFIX = "/";
 
+    // @formatter:off
+    private static final List<String> PROPERTY_NAMES = List.of(
+                            OperationProperties.AAI_SERVICE,
+                            OperationProperties.AAI_VNF,
+                            OperationProperties.AAI_DEFAULT_CLOUD_REGION,
+                            OperationProperties.AAI_DEFAULT_TENANT,
+                            OperationProperties.DATA_VF_COUNT);
+    // @formatter:on
+
     /**
      * Constructs the object.
      *
@@ -73,41 +81,14 @@ public class VfModuleDelete extends SoOperation {
      * @param config configuration for this operation
      */
     public VfModuleDelete(ControlLoopOperationParams params, HttpPollingConfig config) {
-        super(params, config);
+        super(params, config, PROPERTY_NAMES, params.getTargetEntityIds());
+
+        setUsePolling();
 
         // ensure we have the necessary parameters
         validateTarget();
     }
 
-    /**
-     * Ensures that A&AI custom query has been performed, and then runs the guard.
-     */
-    @Override
-    @SuppressWarnings("unchecked")
-    protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
-
-        // need the VF count
-        ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
-                        .operation(AaiCqResponse.OPERATION).payload(null).retry(null).timeoutSec(null).build();
-
-        // run Custom Query, extract the VF count, and then run the Guard
-
-        // @formatter:off
-        return sequence(() -> params.getContext().obtain(AaiCqResponse.CONTEXT_KEY, cqParams),
-                        this::obtainVfCount, this::startGuardAsync);
-        // @formatter:on
-    }
-
-    @Override
-    protected Map<String, Object> makeGuardPayload() {
-        Map<String, Object> payload = super.makeGuardPayload();
-
-        // run guard with the proposed vf count
-        payload.put(PAYLOAD_KEY_VF_COUNT, getVfCount() - 1);
-
-        return payload;
-    }
-
     @Override
     protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
 
@@ -225,12 +206,11 @@ public class VfModuleDelete extends SoOperation {
      * @return a pair containing the request URL and the new request
      */
     protected Pair<String, SoRequest> makeRequest() {
-        final AaiCqResponse aaiCqResponse = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY);
         final SoModelInfo soModelInfo = prepareSoModelInfo();
-        final GenericVnf vnfItem = getVnfItem(aaiCqResponse, soModelInfo);
-        final ServiceInstance vnfServiceItem = getServiceInstance(aaiCqResponse);
-        final Tenant tenantItem = getDefaultTenant(aaiCqResponse);
-        final CloudRegion cloudRegionItem = getDefaultCloudRegion(aaiCqResponse);
+        final GenericVnf vnfItem = getVnfItem(soModelInfo);
+        final ServiceInstance vnfServiceItem = getServiceInstance();
+        final Tenant tenantItem = getDefaultTenant();
+        final CloudRegion cloudRegionItem = getDefaultCloudRegion();
 
         SoRequest request = new SoRequest();
         request.setOperationType(SoOperationType.DELETE_VF_MODULE);
@@ -245,7 +225,7 @@ public class VfModuleDelete extends SoOperation {
         details.setConfigurationParameters(null);
 
         // cloudConfiguration
-        details.setCloudConfiguration(constructCloudConfigurationCq(tenantItem, cloudRegionItem));
+        details.setCloudConfiguration(constructCloudConfiguration(tenantItem, cloudRegionItem));
 
         // modelInfo
         details.setModelInfo(soModelInfo);