Search in sources :

Example 1 with Step

use of com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step in project coprhd-controller by CoprHD.

the class ValidationHelper method validateStepInputs.

private void validateStepInputs(Map<String, CustomServicesValidationResponse.ErrorStep> errorSteps, final boolean cycleExists) {
    for (final Step step : stepsHash.values()) {
        final CustomServicesValidationResponse.ErrorStep errorStep = new CustomServicesValidationResponse.ErrorStep();
        final Map<String, CustomServicesValidationResponse.ErrorInputGroup> errorInputGroup = validateStepInput(step, cycleExists);
        if (!errorInputGroup.isEmpty()) {
            if (errorSteps.containsKey(step.getId())) {
                errorSteps.get(step.getId()).setInputGroups(errorInputGroup);
            } else {
                errorStep.setInputGroups(errorInputGroup);
                errorSteps.put(step.getId(), errorStep);
            }
        }
    }
}
Also used : Step(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step) CustomServicesValidationResponse(com.emc.storageos.model.customservices.CustomServicesValidationResponse)

Example 2 with Step

use of com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step in project coprhd-controller by CoprHD.

the class ValidationHelper method checkOtherStepType.

private String checkOtherStepType(final String inputStepId, final Input input, final boolean cycleExists) {
    String errorMessage = EMPTY_STRING;
    if (StringUtils.isEmpty(input.getValue())) {
        return CustomServicesConstants.ERROR_MSG_INPUT_FROM_OTHER_STEP_NOT_DEFINED;
    }
    final String[] paramVal = input.getValue().split("\\.", 2);
    final String stepId = paramVal[CustomServicesConstants.STEP_ID];
    final String attribute = paramVal[CustomServicesConstants.INPUT_FIELD];
    final Step referredStep = stepsHash.get(stepId);
    if (referredStep == null) {
        return String.format("%s - %s", CustomServicesConstants.ERROR_MSG_STEP_NOT_DEFINED, stepId);
    } else {
        if (cycleExists) {
            // cycle is resolved
            return errorMessage;
        }
        if (!getKeysByValue(descendant, inputStepId).contains(stepId)) {
            return String.format("%s(%s) - %s", referredStep.getFriendlyName(), stepId, CustomServicesConstants.ERROR_MSG_STEP_IS_NOT_ANCESTER);
        }
    }
    if (input.getType().equals(CustomServicesConstants.InputType.FROM_STEP_INPUT.toString())) {
        errorMessage = validateOtherStepInput(referredStep, attribute);
    } else if (input.getType().equals(CustomServicesConstants.InputType.FROM_STEP_OUTPUT.toString())) {
        errorMessage = validateOtherStepOutput(referredStep, attribute);
    }
    return errorMessage;
}
Also used : Step(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step)

Example 3 with Step

use of com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step in project coprhd-controller by CoprHD.

the class WorkflowHelper method addWorkflow.

private static void addWorkflow(final Builder builder, final URI id, final ModelClient client, final CustomServicesPrimitiveDAOs daos, final CustomServicesResourceDAOs resourceDAOs) {
    final CustomServicesWorkflow dbWorkflow = client.customServicesWorkflows().findById(id);
    if (null == dbWorkflow) {
        throw APIException.notFound.unableToFindEntityInURL(id);
    }
    final CustomServicesWorkflowRestRep workflow = CustomServicesWorkflowMapper.map(dbWorkflow);
    builder.addWorkflow(workflow);
    for (final Step step : workflow.getDocument().getSteps()) {
        final String stepId = step.getId();
        if (!StepType.END.toString().equalsIgnoreCase(stepId) && !StepType.START.toString().equalsIgnoreCase(stepId)) {
            final URI operation = step.getOperation();
            final String type = URIUtil.getTypeName(operation);
            if (type.equals(CustomServicesWorkflow.class.getSimpleName())) {
                addWorkflow(builder, operation, client, daos, resourceDAOs);
            } else if (!type.equals(CustomServicesViPRPrimitive.class.getSimpleName())) {
                addOperation(builder, operation, daos, resourceDAOs);
            }
        }
    }
}
Also used : CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow) CustomServicesWorkflowRestRep(com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep) Step(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) CustomServicesViPRPrimitive(com.emc.storageos.primitives.java.vipr.CustomServicesViPRPrimitive)

Example 4 with Step

use of com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step in project coprhd-controller by CoprHD.

the class WorkflowServiceDescriptor method mapWorkflowToServiceDescriptor.

private ServiceDescriptor mapWorkflowToServiceDescriptor(final CustomServicesWorkflow from) {
    final ServiceDescriptor to = new ServiceDescriptor();
    try {
        final CustomServicesWorkflowDocument wfDocument = WorkflowHelper.toWorkflowDocument(from);
        if (StringUtils.isEmpty(from.getState()) || from.getState().equals(CustomServicesWorkflowStatus.NONE) || from.getState().equals(CustomServicesWorkflowStatus.INVALID)) {
            log.error("Workflow state is not valid. State:{} Workflow name:{}", from.getState(), from.getLabel());
            throw new IllegalStateException(String.format("Workflow state is not valid. State %s Workflow name: %s Workflow id: %s", from.getState(), from.getLabel(), from.getId()));
        }
        to.setCategory(CUSTOM_SERVICE_CATEGORY);
        to.setDescription(StringUtils.isNotBlank(wfDocument.getDescription()) ? wfDocument.getDescription() : wfDocument.getName());
        to.setDestructive(false);
        final String wfID = URIUtil.asString(from.getId());
        to.setServiceId(StringUtils.isNotBlank(wfID) ? wfID : wfDocument.getName());
        to.setTitle(wfDocument.getName());
        to.setWorkflowId(wfDocument.getName());
        to.setRoles(new ArrayList<String>(Arrays.asList(Role.SYSTEM_ADMIN.toString())));
        for (final Step step : wfDocument.getSteps()) {
            if (null != step.getInputGroups()) {
                // Looping through all input groups
                for (final InputGroup inputGroup : step.getInputGroups().values()) {
                    final MultiValueMap tableMap = new MultiValueMap();
                    for (final Input wfInput : inputGroup.getInputGroup()) {
                        final ServiceField serviceField = new ServiceField();
                        if (CustomServicesConstants.InputType.FROM_USER.toString().equals(wfInput.getType())) {
                            serviceField.setType(wfInput.getInputFieldType());
                        } else if (CustomServicesConstants.InputType.ASSET_OPTION_SINGLE.toString().equals(wfInput.getType())) {
                            serviceField.setType(wfInput.getValue());
                        } else if (CustomServicesConstants.InputType.ASSET_OPTION_MULTI.toString().equals(wfInput.getType())) {
                            serviceField.setType(wfInput.getValue());
                            serviceField.setSelect(ServiceField.SELECT_MANY);
                        } else if (CustomServicesConstants.InputType.FROM_USER_MULTI.toString().equals(wfInput.getType())) {
                            serviceField.setType(ServiceField.TYPE_CHOICE);
                            if (StringUtils.isNotBlank(wfInput.getDefaultValue())) {
                                // For list of options
                                final Map<String, String> options = new HashMap<>();
                                final List<String> defaultList = Arrays.asList(wfInput.getDefaultValue().split(","));
                                for (final String value : defaultList) {
                                    // making the key and value the same
                                    options.put(value, value);
                                }
                                serviceField.setOptions(options);
                                serviceField.setInitialValue(options.get(defaultList.get(0)));
                            } else if (MapUtils.isNotEmpty(wfInput.getOptions())) {
                                // For options Map
                                serviceField.setOptions(wfInput.getOptions());
                            }
                        } else {
                            continue;
                        }
                        final String inputName = wfInput.getName();
                        if (StringUtils.isNotBlank(wfInput.getDescription())) {
                            serviceField.setDescription(wfInput.getDescription());
                        }
                        final String friendlyName = StringUtils.isBlank(wfInput.getFriendlyName()) ? inputName : wfInput.getFriendlyName();
                        serviceField.setLabel(friendlyName);
                        serviceField.setName(friendlyName.replaceAll(CustomServicesConstants.SPACES_REGEX, StringUtils.EMPTY));
                        serviceField.setRequired(wfInput.getRequired());
                        if (!(CustomServicesConstants.InputType.FROM_USER_MULTI.toString().equals(wfInput.getType()))) {
                            // Initial value already set for FROM_USER_MULTI
                            serviceField.setInitialValue(wfInput.getDefaultValue());
                        }
                        // Setting all unlocked fields as lockable
                        if (!wfInput.getLocked()) {
                            serviceField.setLockable(true);
                        }
                        // if there is a table name we will build ServiceFieldTable later
                        if (null != wfInput.getTableName()) {
                            tableMap.put(wfInput.getTableName(), serviceField);
                        } else {
                            to.getItems().put(friendlyName, serviceField);
                        }
                    }
                    for (final String table : (Set<String>) tableMap.keySet()) {
                        final ServiceFieldTable serviceFieldTable = new ServiceFieldTable();
                        serviceFieldTable.setType(ServiceItem.TYPE_TABLE);
                        serviceFieldTable.setLabel(table);
                        serviceFieldTable.setName(table);
                        for (final ServiceField serviceField : (List<ServiceField>) tableMap.getCollection(table)) {
                            serviceFieldTable.addItem(serviceField);
                        }
                        to.getItems().put(table, serviceFieldTable);
                    }
                }
            }
        }
    } catch (final IOException io) {
        log.error("Error deserializing workflow", io);
        throw new IllegalStateException(String.format("Error deserializing workflow %s", from.getLabel()));
    }
    log.debug("Mapped workflow service descriptor for {}", from.getLabel());
    return to;
}
Also used : Set(java.util.Set) ServiceFieldTable(com.emc.sa.descriptor.ServiceFieldTable) CustomServicesWorkflowDocument(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument) Step(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step) IOException(java.io.IOException) InputGroup(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.InputGroup) Input(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Input) ServiceDescriptor(com.emc.sa.descriptor.ServiceDescriptor) ServiceField(com.emc.sa.descriptor.ServiceField) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) MultiValueMap(org.apache.commons.collections.map.MultiValueMap) Map(java.util.Map) MultiValueMap(org.apache.commons.collections.map.MultiValueMap)

Example 5 with Step

use of com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step in project coprhd-controller by CoprHD.

the class CustomServicesService method wfExecutor.

/**
 * Method to parse Workflow Definition JSON
 *
 * @throws Exception
 */
public void wfExecutor(final URI uri, final Map<String, CustomServicesWorkflowDocument.InputGroup> stepInput) throws Exception {
    logger.info("CS: Parsing Workflow Definition");
    final ImmutableMap<String, Step> stepsHash = getStepHash(uri);
    Step step = stepsHash.get(StepType.START.toString());
    String next = step.getNext().getDefaultStep();
    long timeout = System.currentTimeMillis();
    while (next != null && !next.equals(StepType.END.toString())) {
        step = stepsHash.get(next);
        ExecutionUtils.currentContext().logInfo("customServicesService.stepStatus", step.getId(), step.getFriendlyName(), step.getType());
        updateInputPerStep(step);
        final CustomServicesTaskResult res;
        try {
            final MakeCustomServicesExecutor task = executor.get(step.getType());
            task.setParam(getClient().getRestClient());
            res = ViPRExecutionUtils.execute(task.makeCustomServicesExecutor(inputPerStep.get(step.getId()), step));
            boolean isSuccess = isSuccess(step, res);
            if (isSuccess) {
                try {
                    updateOutputPerStep(step, res);
                } catch (final Exception e) {
                    logger.warn("Failed to parse output" + e + "step Id: {}", step.getId());
                }
            }
            next = getNext(isSuccess, res, step);
        } catch (final Exception e) {
            logger.warn("failed to execute step step Id:{}", step.getId() + "Try to get failure path. Exception Received:", e);
            next = getNext(false, null, step);
        }
        if (next == null) {
            ExecutionUtils.currentContext().logError("customServicesService.logStatus", "Step Id: " + step.getId() + "\t Step Name: " + step.getFriendlyName() + "Failed. Failing the Workflow");
            throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("Workflow Execution failed");
        }
        if ((System.currentTimeMillis() - timeout) > CustomServicesConstants.WORKFLOW_TIMEOUT) {
            throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("Operation Timed out");
        }
    }
}
Also used : MakeCustomServicesExecutor(com.emc.sa.service.vipr.customservices.tasks.MakeCustomServicesExecutor) CustomServicesTaskResult(com.emc.sa.service.vipr.customservices.tasks.CustomServicesTaskResult) Step(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step) IOException(java.io.IOException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)

Aggregations

Step (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step)7 CustomServicesWorkflow (com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow)2 CustomServicesValidationResponse (com.emc.storageos.model.customservices.CustomServicesValidationResponse)2 CustomServicesWorkflowDocument (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ServiceDescriptor (com.emc.sa.descriptor.ServiceDescriptor)1 ServiceField (com.emc.sa.descriptor.ServiceField)1 ServiceFieldTable (com.emc.sa.descriptor.ServiceFieldTable)1 CustomServicesTaskResult (com.emc.sa.service.vipr.customservices.tasks.CustomServicesTaskResult)1 MakeCustomServicesExecutor (com.emc.sa.service.vipr.customservices.tasks.MakeCustomServicesExecutor)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 Input (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Input)1 InputGroup (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.InputGroup)1 CustomServicesWorkflowRestRep (com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep)1 CustomServicesViPRPrimitive (com.emc.storageos.primitives.java.vipr.CustomServicesViPRPrimitive)1 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 URI (java.net.URI)1