class AppcRunTasks {

    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);
        }
    }

}