Search in sources :

Example 1 with CustomServicesWorkflowDocument

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

the class CustomServicesWorkflowService method validateWorkflow.

@POST
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Path("/{id}/validate")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public CustomServicesValidationResponse validateWorkflow(@PathParam("id") final URI id) {
    try {
        final CustomServicesWorkflowDocument wfDocument = WorkflowHelper.toWorkflowDocument(getCustomServicesWorkflow(id));
        final ValidationHelper customServicesValidationHelper = new ValidationHelper(wfDocument);
        final CustomServicesValidationResponse validationResponse = customServicesValidationHelper.validate(id, client);
        // update the status of workflow VALID / INVALID in the DB
        final CustomServicesWorkflow wfstatusUpdated = WorkflowHelper.updateState(getCustomServicesWorkflow(id), validationResponse.getStatus());
        customServicesWorkflowManager.save(wfstatusUpdated);
        return validationResponse;
    } catch (final IOException e) {
        throw APIException.internalServerErrors.genericApisvcError("Failed to deserialize workflow document", e);
    }
}
Also used : ValidationHelper(com.emc.sa.workflow.ValidationHelper) CustomServicesWorkflowDocument(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument) CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow) CustomServicesValidationResponse(com.emc.storageos.model.customservices.CustomServicesValidationResponse) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with CustomServicesWorkflowDocument

use of com.emc.storageos.model.customservices.CustomServicesWorkflowDocument 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 3 with CustomServicesWorkflowDocument

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

the class WorkflowHelper method toWorkflowDocument.

public static CustomServicesWorkflowDocument toWorkflowDocument(final CustomServicesWorkflow workflow) throws JsonParseException, JsonMappingException, IOException {
    final CustomServicesWorkflowDocument document = new CustomServicesWorkflowDocument();
    document.setName(workflow.getLabel());
    document.setDescription(workflow.getDescription());
    document.setSteps(toDocumentSteps(workflow.getSteps()));
    return document;
}
Also used : CustomServicesWorkflowDocument(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument)

Example 4 with CustomServicesWorkflowDocument

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

the class WorkflowBuilder method saveWorkflow.

public static void saveWorkflow(final URI workflowId, final CustomServicesWorkflowDocument workflowDoc) {
    final CustomServicesWorkflowUpdateParam param = new CustomServicesWorkflowUpdateParam();
    for (final CustomServicesWorkflowDocument.Step step : workflowDoc.getSteps()) {
        final String success_criteria = ESAPI.encoder().decodeForHTML(step.getSuccessCriteria());
        step.setSuccessCriteria(success_criteria);
        // If this workflow has any ansible steps add host_file input
        addInventoryFileInputs(step);
    }
    param.setDocument(workflowDoc);
    final CustomServicesWorkflowRestRep customServicesWorkflowRestRep = getCatalogClient().customServicesPrimitives().editWorkflow(workflowId, param);
}
Also used : CustomServicesWorkflowDocument(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument) CustomServicesWorkflowRestRep(com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep) CustomServicesWorkflowUpdateParam(com.emc.storageos.model.customservices.CustomServicesWorkflowUpdateParam)

Example 5 with CustomServicesWorkflowDocument

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

the class WorkflowBuilder method createWorkflow.

public static void createWorkflow(final String workflowName, final String dirID) throws URISyntaxException {
    // Create workflow with just name
    final CustomServicesWorkflowCreateParam param = new CustomServicesWorkflowCreateParam();
    final CustomServicesWorkflowDocument document = new CustomServicesWorkflowDocument();
    document.setName(workflowName);
    List<CustomServicesWorkflowDocument.Step> steps = getStartEndSteps();
    document.setSteps(steps);
    param.setDocument(document);
    final CustomServicesWorkflowRestRep customServicesWorkflowRestRep = getCatalogClient().customServicesPrimitives().createWorkflow(param);
    // Add this workflowid to directory
    if (null != customServicesWorkflowRestRep) {
        addResourceToWFDirectory(customServicesWorkflowRestRep.getId(), dirID);
    } else {
        flash.error("Error creating workflow");
    }
    renderJSON(customServicesWorkflowRestRep);
}
Also used : CustomServicesWorkflowCreateParam(com.emc.storageos.model.customservices.CustomServicesWorkflowCreateParam) CustomServicesWorkflowDocument(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument) CustomServicesWorkflowRestRep(com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep)

Aggregations

CustomServicesWorkflowDocument (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument)6 CustomServicesWorkflow (com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow)2 Step (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step)2 CustomServicesWorkflowRestRep (com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep)2 IOException (java.io.IOException)2 ServiceDescriptor (com.emc.sa.descriptor.ServiceDescriptor)1 ServiceField (com.emc.sa.descriptor.ServiceField)1 ServiceFieldTable (com.emc.sa.descriptor.ServiceFieldTable)1 ValidationHelper (com.emc.sa.workflow.ValidationHelper)1 CustomServicesValidationResponse (com.emc.storageos.model.customservices.CustomServicesValidationResponse)1 CustomServicesWorkflowCreateParam (com.emc.storageos.model.customservices.CustomServicesWorkflowCreateParam)1 Input (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Input)1 InputGroup (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.InputGroup)1 CustomServicesWorkflowUpdateParam (com.emc.storageos.model.customservices.CustomServicesWorkflowUpdateParam)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1