Java 17 Upgrade
[policy/models.git] / models-interactions / model-actors / actor.so / src / main / java / org / onap / policy / controlloop / actor / so / VfModuleCreate.java
index 7e95bda..a51be00 100644 (file)
@@ -2,7 +2,9 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Wipro Limited.
+ * 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.so;
 
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
 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.aai.domain.yang.ModelVer;
-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.utils.NetLoggerUtil.EventType;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
@@ -50,10 +46,8 @@ 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
- * response and stores it in the context. It also passes the count+1 to the guard. Once
- * the "create" completes successfully, it bumps the VF count that's stored in the
- * context.
+ * Operation to create a VF Module. When this completes successfully, it increments its VF
+ * Count property.
  */
 public class VfModuleCreate extends SoOperation {
     public static final String NAME = "VF Module Create";
@@ -78,44 +72,13 @@ public class VfModuleCreate extends SoOperation {
      * @param config configuration for this operation
      */
     public VfModuleCreate(ControlLoopOperationParams params, HttpPollingConfig config) {
-        super(params, config, PROPERTY_NAMES);
+        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() {
-        if (params.isPreprocessed()) {
-            return null;
-        }
-
-        // 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) {
 
@@ -144,7 +107,7 @@ public class VfModuleCreate extends SoOperation {
      */
     @Override
     protected Status detmStatus(Response rawResponse, SoResponse response) {
-        Status status = super.detmStatus(rawResponse, response);
+        var status = super.detmStatus(rawResponse, response);
 
         if (status == Status.SUCCESS) {
             setVfCount(getVfCount() + 1);
@@ -159,15 +122,15 @@ public class VfModuleCreate extends SoOperation {
      * @return a pair containing the request URL and the new request
      */
     protected Pair<String, SoRequest> makeRequest() {
-        final SoModelInfo soModelInfo = prepareSoModelInfo();
-        final GenericVnf vnfItem = getVnfItem(soModelInfo);
-        final ServiceInstance vnfServiceItem = getServiceInstance();
-        final Tenant tenantItem = getDefaultTenant();
-        final CloudRegion cloudRegionItem = getDefaultCloudRegion();
-        final ModelVer vnfModel = getVnfModel(vnfItem);
-        final ModelVer vnfServiceModel = getServiceModel(vnfServiceItem);
-
-        SoRequest request = new SoRequest();
+        final var soModelInfo = prepareSoModelInfo();
+        final var vnfItem = getVnfItem();
+        final var vnfServiceItem = getServiceInstance();
+        final var tenantItem = getDefaultTenant();
+        final var cloudRegionItem = getDefaultCloudRegion();
+        final ModelVer vnfModel = getVnfModel();
+        final ModelVer vnfServiceModel = getServiceModel();
+
+        var request = new SoRequest();
         request.setOperationType(SoOperationType.SCALE_OUT);
 
         //
@@ -179,7 +142,7 @@ public class VfModuleCreate extends SoOperation {
         request.getRequestDetails().getRequestParameters().setUserParams(null);
 
         // cloudConfiguration
-        request.getRequestDetails().setCloudConfiguration(constructCloudConfigurationCq(tenantItem, cloudRegionItem));
+        request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem, cloudRegionItem));
 
         // modelInfo
         request.getRequestDetails().setModelInfo(soModelInfo);
@@ -189,8 +152,8 @@ public class VfModuleCreate extends SoOperation {
         request.getRequestDetails().getRequestInfo().setInstanceName("vfModuleName");
 
         // relatedInstanceList
-        SoRelatedInstanceListElement relatedInstanceListElement1 = new SoRelatedInstanceListElement();
-        SoRelatedInstanceListElement relatedInstanceListElement2 = new SoRelatedInstanceListElement();
+        var relatedInstanceListElement1 = new SoRelatedInstanceListElement();
+        var relatedInstanceListElement2 = new SoRelatedInstanceListElement();
         relatedInstanceListElement1.setRelatedInstance(new SoRelatedInstance());
         relatedInstanceListElement2.setRelatedInstance(new SoRelatedInstance());
 
@@ -231,8 +194,8 @@ public class VfModuleCreate extends SoOperation {
         buildConfigurationParameters().ifPresent(request.getRequestDetails()::setConfigurationParameters);
 
         // compute the path
-        String path = PATH_PREFIX + vnfServiceItem.getServiceInstanceId() + "/vnfs/" + vnfItem.getVnfId()
-                        + "/vfModules/scaleOut";
+        String svcId = getRequiredText("service instance ID", vnfServiceItem.getServiceInstanceId());
+        String path = PATH_PREFIX + svcId + "/vnfs/" + vnfItem.getVnfId() + "/vfModules/scaleOut";
 
         return Pair.of(path, request);
     }