Search in sources :

Example 6 with Step

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

the class ValidationHelper method validateSteps.

private CustomServicesValidationResponse.Error validateSteps(final ModelClient client) {
    final CustomServicesValidationResponse.Error workflowError = new CustomServicesValidationResponse.Error();
    final Map<String, CustomServicesValidationResponse.ErrorStep> errorSteps = new HashMap<>();
    if (stepsHash.get(StepType.START.toString()) == null || stepsHash.get(StepType.END.toString()) == null) {
        workflowError.setErrorMessage(CustomServicesConstants.ERROR_MSG_START_END_NOT_DEFINED);
    }
    for (final Step step : stepsHash.values()) {
        final List<String> errorList = new ArrayList<>();
        String errorString = validateCurrentStep(step);
        boolean addErrorStep = false;
        final CustomServicesValidationResponse.ErrorStep errorStep = new CustomServicesValidationResponse.ErrorStep();
        if (StringUtils.isNotBlank(errorString)) {
            errorList.add(errorString);
            addErrorStep = true;
        }
        errorString = validateOperationAndType(step, client);
        if (StringUtils.isNotBlank(errorString)) {
            errorList.add(errorString);
            addErrorStep = true;
        }
        if (addErrorStep) {
            errorStep.setErrorMessages(errorList);
            errorSteps.put(step.getId(), errorStep);
        }
    }
    boolean cycleExists = addErrorStepsWithoutParent(errorSteps);
    validateStepInputs(errorSteps, cycleExists);
    if (MapUtils.isNotEmpty(errorSteps)) {
        workflowError.setErrorSteps(errorSteps);
    }
    return workflowError;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CustomServicesValidationResponse(com.emc.storageos.model.customservices.CustomServicesValidationResponse) Step(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step)

Example 7 with Step

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

the class CustomServicesService method getStepHash.

private ImmutableMap<String, Step> getStepHash(final URI uri) throws Exception {
    final String raw;
    raw = ExecutionUtils.currentContext().getOrder().getWorkflowDocument();
    if (null == raw) {
        throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("Invalid custom service.  Workflow document cannot be null");
    }
    final CustomServicesWorkflowDocument obj = WorkflowHelper.toWorkflowDocument(raw);
    final List<CustomServicesWorkflow> wfs = customServicesWorkflowManager.getByNameOrId(obj.getName());
    if (wfs == null || wfs.isEmpty() || wfs.size() > 1) {
        throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("Workflow list is null or empty or more than one workflow per Workflow name:" + obj.getName());
    }
    if (wfs.get(0) == null || StringUtils.isEmpty(wfs.get(0).getState())) {
        throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("Workflow state is null or empty for workflow:" + obj.getName());
    }
    if (wfs.get(0).getState().equals(CustomServicesWorkflow.CustomServicesWorkflowStatus.NONE.toString()) || wfs.get(0).getState().equals(CustomServicesWorkflow.CustomServicesWorkflowStatus.INVALID.toString())) {
        throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("Workflow state is not valid. Cannot run workflow" + obj.getName() + "State:" + wfs.get(0).getState());
    }
    final List<Step> steps = obj.getSteps();
    final ImmutableMap.Builder<String, Step> builder = ImmutableMap.builder();
    for (final Step step : steps) {
        builder.put(step.getId(), step);
    }
    final ImmutableMap<String, Step> stepsHash = builder.build();
    ExecutionUtils.currentContext().logInfo("customServicesService.status", obj.getName());
    return stepsHash;
}
Also used : CustomServicesWorkflowDocument(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument) CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow) Step(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step) ImmutableMap(com.google.common.collect.ImmutableMap)

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