Search in sources :

Example 1 with ControllerSelectionReference

use of org.onap.so.db.catalog.beans.ControllerSelectionReference in project so by onap.

the class AppcRunTasks method runAppcCommand.

public void runAppcCommand(BuildingBlockExecution execution, Action action) {
    logger.trace("Start runAppcCommand ");
    String appcCode = "1002";
    String appcMessage = "";
    try {
        GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
        GenericVnf vnf = null;
        try {
            vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
        } catch (BBObjectNotFoundException e) {
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "No valid VNF exists");
        }
        String vnfId = null;
        String vnfName = null;
        String vnfType = null;
        String vnfHostIpAddress = null;
        if (vnf != null) {
            vnfId = vnf.getVnfId();
            vnfName = vnf.getVnfName();
            vnfType = vnf.getVnfType();
            vnfHostIpAddress = vnf.getIpv4OamAddress();
        }
        String msoRequestId = gBBInput.getRequestContext().getMsoRequestId();
        String aicIdentity = execution.getVariable("aicIdentity");
        String vmIdList = execution.getVariable("vmIdList");
        String vserverIdList = execution.getVariable("vserverIdList");
        String identityUrl = execution.getVariable("identityUrl");
        ControllerSelectionReference controllerSelectionReference = catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(vnfType, action.toString());
        String controllerType;
        if (controllerSelectionReference != null) {
            controllerType = controllerSelectionReference.getControllerName();
        } else {
            controllerType = CONTROLLER_TYPE_DEFAULT;
        }
        String vfModuleId = null;
        VfModule vfModule = null;
        try {
            vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
        } catch (BBObjectNotFoundException e) {
        }
        if (vfModule != null) {
            vfModuleId = vfModule.getVfModuleId();
        }
        HashMap<String, String> payloadInfo = buildPayloadInfo(vnfName, aicIdentity, vnfHostIpAddress, vmIdList, vserverIdList, identityUrl, vfModuleId);
        Optional<String> payload = Optional.empty();
        RequestParameters requestParameters = gBBInput.getRequestContext().getRequestParameters();
        if (requestParameters != null) {
            String pay = requestParameters.getPayload();
            if (pay != null) {
                payload = Optional.of(pay);
            } else {
                String payloadFromUserParams = buildPayloadFromUserParams(gBBInput.getRequestContext().getUserParams());
                payload = Optional.of(payloadFromUserParams);
            }
        }
        logger.debug("Running APP-C action: {}", action.toString());
        logger.debug("VNFID: {}", vnfId);
        appCClient.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
        appcCode = appCClient.getErrorCode();
        appcMessage = appCClient.getErrorMessage();
        mapRollbackVariables(execution, action, appcCode);
    } catch (Exception e) {
        logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION.toString(), "Caught exception in runAppcCommand", "BPMN", ErrorCode.UnknownError.getValue(), "Error on request to APPC", e);
        appcCode = GENERIC_APPC_ERROR_CODE;
        appcMessage = e.getMessage();
    }
    logger.error("Error Message: {}", appcMessage);
    logger.error("ERROR CODE: {}", appcCode);
    logger.trace("End of runAppCommand ");
    if (appcCode != null && !"0".equals(appcCode)) {
        exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);
    }
}
Also used : BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) ControllerSelectionReference(org.onap.so.db.catalog.beans.ControllerSelectionReference) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException) RequestParameters(org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters)

Example 2 with ControllerSelectionReference

use of org.onap.so.db.catalog.beans.ControllerSelectionReference in project so by onap.

the class ControllerExecutionBB method getControllerActor.

/**
 * this method is used to get the controller actor, there could be few places to get the actor(ordered by priority),
 *
 * <ol>
 * <li>Execution Context, i.e, BuildingBlockExecution</li>
 * <li>Resource customization table, pnf_resource_customization for PNF or vnf_resource_customization for VNF</li>
 * <li>controller_selection_reference, resource_type and action will be used to fetch from this table</li>
 * </ol>
 *
 * @param execution BuildingBlockExecution instance
 * @param controllerScope controller scope, e.g, pnf, vnf, vfModule
 * @param resourceCustomizationUuid resource customization UUID, e.g, pnfCustomizationUuid, vnfCustomizationUuid
 * @param controllerAction controller action, e.g, configAssign, configDeploy
 * @return controller actor name
 */
@Override
protected String getControllerActor(BuildingBlockExecution execution, String controllerScope, String resourceCustomizationUuid, String controllerAction) {
    /**
     * Firstly, check the execution context for actor parameter.
     */
    String controllerActor = getParameterFromExecution(execution, CONTROLLER_ACTOR_PARAM);
    /**
     * If no meaningful controller actor value found in the execution context and the value is not SO-REF-DATA.
     */
    if (Strings.isNullOrEmpty(controllerActor) && !isSoRefControllerActor(controllerActor)) {
        /**
         * For BuildingBlockExecution, we should try to get the resource information from Cached metadata.
         *
         * As the current cached metadata doesn't support controller actor, we use the
         * {@link org.onap.so.db.catalog.client.CatalogDbClient} to fetch information. Once the change is done in
         * cached metadata, this part should be refactored as well.
         */
        if (isPnfResourceScope(controllerScope)) {
            PnfResourceCustomization pnfResourceCustomization = catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(resourceCustomizationUuid);
            controllerActor = pnfResourceCustomization.getControllerActor();
        } else if (isServiceResourceScope(controllerScope)) {
            return controllerActor;
        } else if (isVnfResourceScope(controllerScope)) {
            VnfResourceCustomization vnfResourceCustomization = catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(resourceCustomizationUuid);
            controllerActor = vnfResourceCustomization.getControllerActor();
        } else {
            logger.warn("Unrecognized scope: {}", controllerScope);
        }
    }
    /**
     * Lastly, can NOT find the controller actor information from resource customization table or the return value
     * is SO-REF-DATA.
     */
    if (Strings.isNullOrEmpty(controllerActor) || isSoRefControllerActor(controllerActor)) {
        String resourceType = getParameterFromExecution(execution, RESOURCE_TYPE_PARAM);
        ControllerSelectionReference reference = catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(resourceType, controllerAction);
        controllerActor = reference.getControllerName();
    }
    return controllerActor;
}
Also used : PnfResourceCustomization(org.onap.so.db.catalog.beans.PnfResourceCustomization) ControllerSelectionReference(org.onap.so.db.catalog.beans.ControllerSelectionReference) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization)

Example 3 with ControllerSelectionReference

use of org.onap.so.db.catalog.beans.ControllerSelectionReference in project so by onap.

the class AppcOrchestratorPreProcessor method buildAppcTaskRequest.

public void buildAppcTaskRequest(BuildingBlockExecution execution, String actionName) {
    try {
        Action action = Action.valueOf(actionName);
        ApplicationControllerTaskRequest appcTaskRequest = new ApplicationControllerTaskRequest();
        appcTaskRequest.setAction(action);
        GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
        GenericVnf vnf = null;
        try {
            vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
        } catch (BBObjectNotFoundException e) {
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "No valid VNF exists");
        }
        String vnfId = null;
        String vnfName = null;
        String vnfType = null;
        String vnfHostIpAddress = null;
        if (vnf != null) {
            vnfId = vnf.getVnfId();
            vnfName = vnf.getVnfName();
            vnfType = vnf.getVnfType();
            vnfHostIpAddress = vnf.getIpv4OamAddress();
        }
        String msoRequestId = gBBInput.getRequestContext().getMsoRequestId();
        String aicIdentity = execution.getVariable("aicIdentity");
        String identityUrl = execution.getVariable("identityUrl");
        appcTaskRequest.setIdentityUrl(identityUrl);
        String requestorId = gBBInput.getRequestContext().getRequestorId();
        appcTaskRequest.setRequestorId(requestorId);
        if (gBBInput.getRequestContext().getRequestParameters() != null) {
            String payload = gBBInput.getRequestContext().getRequestParameters().getPayload();
            if (payload == null) {
                payload = "";
            }
            String existingSoftwareVersion = JsonUtils.getJsonValue(payload, "existing_software_version");
            appcTaskRequest.setExistingSoftwareVersion(existingSoftwareVersion);
            String newSoftwareVersion = JsonUtils.getJsonValue(payload, "new_software_version");
            appcTaskRequest.setNewSoftwareVersion(newSoftwareVersion);
            String operationsTimeout = JsonUtils.getJsonValue(payload, "operations_timeout");
            appcTaskRequest.setOperationsTimeout(operationsTimeout);
            Map<String, String> configMap = new HashMap<>();
            ObjectMapper objectMapper = new ObjectMapper();
            String configParamsStr = JsonUtils.getJsonValue(payload, "configuration_parameters");
            if (configParamsStr != null) {
                configMap = objectMapper.readValue(configParamsStr, new TypeReference<HashMap<String, String>>() {
                });
            }
            appcTaskRequest.setConfigParams(configMap);
        }
        ControllerSelectionReference controllerSelectionReference = catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(vnfType, action.toString());
        String controllerType = null;
        if (controllerSelectionReference != null) {
            controllerType = controllerSelectionReference.getControllerName();
        } else {
            controllerType = CONTROLLER_TYPE_DEFAULT;
        }
        appcTaskRequest.setControllerType(controllerType);
        execution.setVariable("vmIdList", null);
        execution.setVariable("vserverIdList", null);
        execution.setVariable("vmIndex", 0);
        execution.setVariable("vmIdListSize", 0);
        String vfModuleId = null;
        VfModule vfModule = null;
        try {
            vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
        } catch (BBObjectNotFoundException e) {
        }
        if (vfModule != null) {
            vfModuleId = vfModule.getVfModuleId();
        }
        if (action.equals(Action.Snapshot)) {
            try {
                getVserversForAppc(execution, vnf);
            } catch (Exception e) {
                logger.warn("Unable to retrieve vservers for vnf: " + vnfId);
            }
        }
        ApplicationControllerVnf applicationControllerVnf = new ApplicationControllerVnf();
        applicationControllerVnf.setVnfHostIpAddress(vnfHostIpAddress);
        applicationControllerVnf.setVnfId(vnfId);
        applicationControllerVnf.setVnfName(vnfName);
        appcTaskRequest.setApplicationControllerVnf(applicationControllerVnf);
        verifyApplicationControllerTaskRequest(execution, appcTaskRequest);
        execution.setVariable("appcOrchestratorRequest", appcTaskRequest);
        logger.debug("SET APPC ORCHESTRATOR REQUEST");
    } catch (Exception e) {
        logger.error("Error building ApplicationControllerTaskRequest Object", e.getMessage());
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e);
    }
}
Also used : Action(org.onap.appc.client.lcm.model.Action) ApplicationControllerTaskRequest(org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) HashMap(java.util.HashMap) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException) ValidationException(org.onap.so.exceptions.ValidationException) BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException) ApplicationControllerVnf(org.onap.so.appc.orchestrator.service.beans.ApplicationControllerVnf) ControllerSelectionReference(org.onap.so.db.catalog.beans.ControllerSelectionReference) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with ControllerSelectionReference

use of org.onap.so.db.catalog.beans.ControllerSelectionReference in project so by onap.

the class ConfigurationScaleOutTest method setParamsForConfigurationScaleOutTest.

@Test
public void setParamsForConfigurationScaleOutTest() throws Exception {
    ControllerSelectionReference controllerSelectionReference = new ControllerSelectionReference();
    controllerSelectionReference.setControllerName("testName");
    controllerSelectionReference.setActionCategory("testAction");
    controllerSelectionReference.setVnfType("testVnfType");
    String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNCClientGetResponse.json")));
    String expectedPayload = "{\"request-parameters\":{\"vnf-host-ip-address\":\"10.222.22.2\"," + "\"vf-module-id\":\"testVfModuleId1\"},\"configuration-parameters\"" + ":{\"vnf-id\":\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\",\"availability-zone\":\"AZ-MN02\"}}";
    execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), sdncResponse);
    doReturn(controllerSelectionReference).when(catalogDbClient).getControllerSelectionReferenceByVnfTypeAndActionCategory(genericVnf.getVnfType(), Action.ConfigScaleOut.toString());
    configurationScaleOut.setParamsForConfigurationScaleOut(execution);
    assertEquals(genericVnf.getVnfId(), execution.getVariable("vnfId"));
    assertEquals(genericVnf.getVnfName(), execution.getVariable("vnfName"));
    assertEquals("ConfigScaleOut", execution.getVariable("action"));
    assertEquals(requestContext.getMsoRequestId(), execution.getVariable("msoRequestId"));
    assertEquals(controllerSelectionReference.getControllerName(), execution.getVariable("controllerType"));
    assertEquals(vfModule.getVfModuleId(), execution.getVariable("vfModuleId"));
    assertEquals(expectedPayload, execution.getVariable("payload"));
}
Also used : ControllerSelectionReference(org.onap.so.db.catalog.beans.ControllerSelectionReference) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) Test(org.junit.Test)

Example 5 with ControllerSelectionReference

use of org.onap.so.db.catalog.beans.ControllerSelectionReference in project so by onap.

the class AppcOrchestratorPreProcessorTest method mockReferenceResponseForConfigModify.

private void mockReferenceResponseForConfigModify() {
    ControllerSelectionReference reference = new ControllerSelectionReference();
    reference.setControllerName("APPC");
    when(catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(eq("TEST-VNF-TYPE"), eq(Action.ConfigModify.toString()))).thenReturn(reference);
}
Also used : ControllerSelectionReference(org.onap.so.db.catalog.beans.ControllerSelectionReference)

Aggregations

ControllerSelectionReference (org.onap.so.db.catalog.beans.ControllerSelectionReference)15 Test (org.junit.Test)6 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)4 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)4 HashMap (java.util.HashMap)3 VfModule (org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Action (org.onap.appc.client.lcm.model.Action)2 BaseTaskTest (org.onap.so.bpmn.BaseTaskTest)2 RequestParameters (org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters)2 BBObjectNotFoundException (org.onap.so.client.exception.BBObjectNotFoundException)2 PnfResourceCustomization (org.onap.so.db.catalog.beans.PnfResourceCustomization)2 VnfResourceCustomization (org.onap.so.db.catalog.beans.VnfResourceCustomization)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Map (java.util.Map)1 BaseIntegrationTest (org.onap.so.BaseIntegrationTest)1 ApplicationControllerTaskRequest (org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest)1 ApplicationControllerVnf (org.onap.so.appc.orchestrator.service.beans.ApplicationControllerVnf)1 ConfigScaleOutPayload (org.onap.so.bpmn.appc.payload.beans.ConfigScaleOutPayload)1