X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-interactions%2Fmodel-actors%2Factor.so%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontrolloop%2Factor%2Fso%2FVfModuleCreate.java;h=b778c10d7f587985c139c9d7da6b6dadcf6fec54;hb=e7b9884cc75d9346dc56145725d2aa69a6cd4f43;hp=fb8fe607279728f5694f1e573d85e69e0d4f8f82;hpb=433f782f16f43a8431d8d91c2a055fd2a0603f42;p=policy%2Fmodels.git diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java index fb8fe6072..b778c10d7 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/VfModuleCreate.java @@ -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. @@ -20,23 +21,24 @@ 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.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; +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.so.SoCloudConfiguration; +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; @@ -44,19 +46,27 @@ import org.onap.policy.so.SoRelatedInstanceListElement; 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 - * 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. - *

- * Note: currently, this only supports storing the count for a single target VF. + * 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"; - public static final String PAYLOAD_KEY_VF_COUNT = "vfCount"; + private static final String PATH_PREFIX = "/"; + + // @formatter:off + private static final List PROPERTY_NAMES = List.of( + OperationProperties.AAI_SERVICE, + OperationProperties.AAI_SERVICE_MODEL, + OperationProperties.AAI_VNF, + OperationProperties.AAI_VNF_MODEL, + OperationProperties.AAI_DEFAULT_CLOUD_REGION, + OperationProperties.AAI_DEFAULT_TENANT, + OperationProperties.DATA_VF_COUNT); + // @formatter:off /** * Constructs the object. @@ -64,68 +74,49 @@ public class VfModuleCreate extends SoOperation { * @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, params.getTargetEntityIds()); + setUsePolling(); // ensure we have the necessary parameters validateTarget(); } - /** - * Ensures that A&AI customer query has been performed, and then runs the guard. - */ - @Override - @SuppressWarnings("unchecked") - protected CompletableFuture 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 makeGuardPayload() { - Map payload = super.makeGuardPayload(); - - // run guard with the proposed vf count - payload.put(PAYLOAD_KEY_VF_COUNT, getVfCount() + 1); - - return payload; - } - @Override protected CompletableFuture startOperationAsync(int attempt, OperationOutcome outcome) { // starting a whole new attempt - reset the count - resetGetCount(); + resetPollCount(); Pair pair = makeRequest(); - String path = pair.getLeft(); + String path = getPath() + pair.getLeft(); SoRequest request = pair.getRight(); - Entity 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); - // TODO should this use "path" or the full "url"? + Entity entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON); - return handleResponse(outcome, url, callback -> getClient().post(callback, path, entity, null)); + Map headers = createSimpleHeaders(); + + return handleResponse(outcome, url, callback -> getClient().post(callback, path, entity, headers)); } /** - * 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; } /** @@ -134,12 +125,13 @@ public class VfModuleCreate extends SoOperation { * @return a pair containing the request URL and the new request */ protected Pair 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(); + final ServiceInstance vnfServiceItem = getServiceInstance(); + final Tenant tenantItem = getDefaultTenant(); + final CloudRegion cloudRegionItem = getDefaultCloudRegion(); + final ModelVer vnfModel = getVnfModel(); + final ModelVer vnfServiceModel = getServiceModel(); SoRequest request = new SoRequest(); request.setOperationType(SoOperationType.SCALE_OUT); @@ -153,7 +145,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); @@ -176,10 +168,8 @@ public class VfModuleCreate extends SoOperation { .setModelInvariantId(vnfServiceItem.getModelInvariantId()); relatedInstanceListElement1.getRelatedInstance().getModelInfo() .setModelVersionId(vnfServiceItem.getModelVersionId()); - relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelName( - aaiCqResponse.getModelVerByVersionId(vnfServiceItem.getModelVersionId()).getModelName()); - relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelVersion( - aaiCqResponse.getModelVerByVersionId(vnfServiceItem.getModelVersionId()).getModelVersion()); + relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelName(vnfModel.getModelName()); + relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelVersion(vnfModel.getModelVersion()); // VNF Item relatedInstanceListElement2.getRelatedInstance().setInstanceId(vnfItem.getVnfId()); @@ -189,10 +179,9 @@ public class VfModuleCreate extends SoOperation { .setModelInvariantId(vnfItem.getModelInvariantId()); relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelVersionId(vnfItem.getModelVersionId()); + relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelName(vnfServiceModel.getModelName()); relatedInstanceListElement2.getRelatedInstance().getModelInfo() - .setModelName(aaiCqResponse.getModelVerByVersionId(vnfItem.getModelVersionId()).getModelName()); - relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelVersion( - aaiCqResponse.getModelVerByVersionId(vnfItem.getModelVersionId()).getModelVersion()); + .setModelVersion(vnfServiceModel.getModelVersion()); relatedInstanceListElement2.getRelatedInstance().getModelInfo() .setModelCustomizationId(vnfItem.getModelCustomizationId()); @@ -208,23 +197,9 @@ public class VfModuleCreate extends SoOperation { buildConfigurationParameters().ifPresent(request.getRequestDetails()::setConfigurationParameters); // compute the path - String path = "/serviceInstantiation/v7/serviceInstances/" + vnfServiceItem.getServiceInstanceId() + "/vnfs/" - + vnfItem.getVnfId() + "/vfModules/scaleOut"; + String path = PATH_PREFIX + vnfServiceItem.getServiceInstanceId() + "/vnfs/" + vnfItem.getVnfId() + + "/vfModules/scaleOut"; return Pair.of(path, request); } - - /** - * Construct cloudConfiguration for the SO requestDetails. Overridden for custom - * query. - * - * @param tenantItem tenant item from A&AI named-query response - * @return SO cloud configuration - */ - private SoCloudConfiguration constructCloudConfigurationCq(Tenant tenantItem, CloudRegion cloudRegionItem) { - SoCloudConfiguration cloudConfiguration = new SoCloudConfiguration(); - cloudConfiguration.setTenantId(tenantItem.getTenantId()); - cloudConfiguration.setLcpCloudRegionId(cloudRegionItem.getCloudRegionId()); - return cloudConfiguration; - } }