Search in sources :

Example 6 with CustomServicesWorkflow

use of com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow in project coprhd-controller by CoprHD.

the class WorkflowServiceDescriptor method getDescriptor.

public ServiceDescriptor getDescriptor(String serviceName) {
    log.debug("Getting workflow descriptor for {}", serviceName);
    List<CustomServicesWorkflow> results = customServicesWorkflowManager.getByNameOrId(serviceName);
    if (null == results || results.isEmpty()) {
        throw new IllegalStateException(String.format("No workflow with the name %s", serviceName));
    }
    if (results.size() > 1) {
        throw new IllegalStateException(String.format("Multiple workflows with the name %s", serviceName));
    }
    CustomServicesWorkflow customServicesWorkflow = results.get(0);
    return mapWorkflowToServiceDescriptor(customServicesWorkflow);
}
Also used : CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow)

Example 7 with CustomServicesWorkflow

use of com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow 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 8 with CustomServicesWorkflow

use of com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow in project coprhd-controller by CoprHD.

the class WorkflowHelper method importWorkflow.

private static CustomServicesWorkflow importWorkflow(final CustomServicesWorkflowPackage workflowPackage, final WFDirectory wfDirectory, final ModelClient client, final CustomServicesPrimitiveDAOs daos, final CustomServicesResourceDAOs resourceDAOs) throws JsonGenerationException, JsonMappingException, IOException {
    for (final Entry<URI, ResourcePackage> resource : workflowPackage.resources().entrySet()) {
        final CustomServicesResourceDAO<?> dao = resourceDAOs.getByModel(URIUtil.getTypeName(resource.getKey()));
        final CustomServicesPrimitiveResourceRestRep metadata = resource.getValue().metadata();
        if (null == dao) {
            throw new RuntimeException("Type not found for ID " + metadata.getId());
        }
        if (!dao.importResource(metadata, resource.getValue().bytes())) {
            log.info("Resource " + resource.getKey() + " previously imported");
        }
    }
    for (final Entry<URI, CustomServicesPrimitiveRestRep> operation : workflowPackage.operations().entrySet()) {
        final CustomServicesPrimitiveDAO<?> dao = daos.getByModel(URIUtil.getTypeName(operation.getKey()));
        if (null == dao) {
            throw new RuntimeException("Type not found for ID " + operation.getKey());
        }
        if (dao.importPrimitive(operation.getValue())) {
            wfDirectory.addWorkflows(Collections.singleton(operation.getKey()));
        } else {
            log.info("Primitive " + operation.getKey() + " previously imported");
        }
    }
    for (final Entry<URI, CustomServicesWorkflowRestRep> workflow : workflowPackage.workflows().entrySet()) {
        final CustomServicesWorkflow model = client.customServicesWorkflows().findById(workflow.getKey());
        if (null == model || model.getInactive()) {
            importWorkflow(workflow.getValue(), client, wfDirectory);
        } else {
            log.info("Workflow " + workflow.getKey() + " previously imported");
        }
    }
    return client.customServicesWorkflows().findById(workflowPackage.metadata().getId());
}
Also used : CustomServicesPrimitiveResourceRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceRestRep) CustomServicesPrimitiveRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep) ResourcePackage(com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage) CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow) CustomServicesWorkflowRestRep(com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 9 with CustomServicesWorkflow

use of com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow in project coprhd-controller by CoprHD.

the class CustomServicesWorkflowService method getCustomServicesWorkflow.

private CustomServicesWorkflow getCustomServicesWorkflow(final URI id) {
    CustomServicesWorkflow workflow = queryResource(id);
    ArgValidator.checkEntityNotNull(workflow, id, true);
    return workflow;
}
Also used : CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow)

Example 10 with CustomServicesWorkflow

use of com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow in project coprhd-controller by CoprHD.

the class CustomServicesWorkflowService method updateWorkflow.

@PUT
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public CustomServicesWorkflowRestRep updateWorkflow(@PathParam("id") final URI id, final CustomServicesWorkflowUpdateParam workflow) {
    final CustomServicesWorkflow customServicesWorkflow;
    try {
        customServicesWorkflow = getCustomServicesWorkflow(id);
        if (null == customServicesWorkflow) {
            throw APIException.notFound.unableToFindEntityInURL(id);
        } else if (customServicesWorkflow.getInactive()) {
            throw APIException.notFound.entityInURLIsInactive(id);
        }
        switch(CustomServicesWorkflowStatus.valueOf(customServicesWorkflow.getState())) {
            case PUBLISHED:
                throw APIException.methodNotAllowed.notSupportedWithReason("Published workflow cannot be edited.");
            default:
                if (StringUtils.isNotBlank(workflow.getDocument().getName())) {
                    final String label = workflow.getDocument().getName().trim();
                    if (!label.equalsIgnoreCase(customServicesWorkflow.getLabel())) {
                        checkForDuplicateName(label, CustomServicesWorkflow.class);
                        if (customServicesWorkflowManager.hasCatalogServices(label)) {
                            throw APIException.badRequests.duplicateLabel(label + " (Workflow name cannot be same as the existing Catalog Base Service)");
                        }
                    }
                }
                final String currentSteps = customServicesWorkflow.getSteps();
                WorkflowHelper.update(customServicesWorkflow, workflow.getDocument());
                // On update, if there is any change to steps, resetting workflow status to initial state -NONE
                if (StringUtils.isNotBlank(currentSteps) && StringUtils.isNotBlank(customServicesWorkflow.getSteps()) && !currentSteps.equals(customServicesWorkflow.getSteps())) {
                    customServicesWorkflow.setState(CustomServicesWorkflowStatus.NONE.toString());
                }
        }
    } catch (IOException e) {
        throw APIException.internalServerErrors.genericApisvcError("Error serializing workflow", e);
    }
    customServicesWorkflowManager.save(customServicesWorkflow);
    return map(customServicesWorkflow);
}
Also used : CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

CustomServicesWorkflow (com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow)18 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)6 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 IOException (java.io.IOException)4 POST (javax.ws.rs.POST)4 NamedElement (com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)3 URI (java.net.URI)3 NamedURI (com.emc.storageos.db.client.model.NamedURI)2 CustomServicesWorkflowDocument (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument)2 Step (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step)2 CustomServicesWorkflowRestRep (com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep)2 ArrayList (java.util.ArrayList)2 ServiceDescriptor (com.emc.sa.descriptor.ServiceDescriptor)1 ResourcePackage (com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage)1 ValidationHelper (com.emc.sa.workflow.ValidationHelper)1 CatalogService (com.emc.storageos.db.client.model.uimodels.CatalogService)1 CustomServicesPrimitiveResourceRestRep (com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceRestRep)1 CustomServicesPrimitiveRestRep (com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep)1 CustomServicesValidationResponse (com.emc.storageos.model.customservices.CustomServicesValidationResponse)1