Search in sources :

Example 1 with CustomServicesWorkflow

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

the class CustomServicesWorkflowService method download.

/**
 * Download the resource and set it in the response header
 *
 * @param id The ID of the resource to download
 * @param response HttpServletResponse the servlet response to update with the file octet stream
 * @return Response containing the octet stream of the primitive resource
 */
@GET
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Path("{id}/export")
public Response download(@PathParam("id") final URI id, @Context final HttpServletResponse response) {
    final CustomServicesWorkflow customServicesWorkflow = getCustomServicesWorkflow(id);
    switch(CustomServicesWorkflowStatus.valueOf(customServicesWorkflow.getState())) {
        case PUBLISHED:
            final byte[] bytes;
            try {
                bytes = WorkflowHelper.exportWorkflow(id, client, daos, resourceDAOs, KeyStoreUtil.getViPRKeystore(coordinator));
            } catch (final GeneralSecurityException | IOException | InterruptedException e) {
                throw APIException.internalServerErrors.genericApisvcError("Failed to open keystore ", e);
            }
            response.setContentLength(bytes.length);
            response.setHeader("Content-Disposition", "attachment; filename=" + customServicesWorkflow.getLabel().toString() + EXPORT_EXTENSION);
            return Response.ok(bytes).build();
        default:
            throw APIException.methodNotAllowed.notSupportedForUnpublishedWorkflow(customServicesWorkflow.getState());
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow) IOException(java.io.IOException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with CustomServicesWorkflow

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

the class CustomServicesWorkflowService method publishWorkflow.

@POST
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Path("/{id}/publish")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public CustomServicesWorkflowRestRep publishWorkflow(@PathParam("id") final URI id) {
    CustomServicesWorkflow customServicesWorkflow = getCustomServicesWorkflow(id);
    switch(CustomServicesWorkflowStatus.valueOf(customServicesWorkflow.getState())) {
        case PUBLISHED:
            // If worklow is already in published state, ignoring
            return map(customServicesWorkflow);
        case VALID:
            // Workflow can only be published when it is in VALID state
            CustomServicesWorkflow updated = WorkflowHelper.updateState(customServicesWorkflow, CustomServicesWorkflowStatus.PUBLISHED.toString());
            customServicesWorkflowManager.save(updated);
            return map(updated);
        default:
            throw APIException.methodNotAllowed.notSupportedWithReason(String.format("Worklow cannot be published with its current state: %s", customServicesWorkflow.getState()));
    }
}
Also used : CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 3 with CustomServicesWorkflow

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

the class CustomServicesWorkflowService method addWorkflow.

@POST
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public CustomServicesWorkflowRestRep addWorkflow(final CustomServicesWorkflowCreateParam workflow) {
    if (StringUtils.isNotBlank(workflow.getDocument().getName())) {
        final String label = workflow.getDocument().getName().trim();
        checkForDuplicateName(label, CustomServicesWorkflow.class);
        if (customServicesWorkflowManager.hasCatalogServices(label)) {
            throw APIException.badRequests.duplicateLabel(label + " (Workflow name cannot be same as the existing Catalog Base Service)");
        }
    } else {
        throw APIException.badRequests.requiredParameterMissingOrEmpty("name");
    }
    final CustomServicesWorkflow newWorkflow;
    try {
        newWorkflow = WorkflowHelper.create(workflow.getDocument());
    } catch (IOException e) {
        throw APIException.internalServerErrors.genericApisvcError("Error serializing workflow", e);
    }
    customServicesWorkflowManager.save(newWorkflow);
    return map(newWorkflow);
}
Also used : CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow) IOException(java.io.IOException) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 4 with CustomServicesWorkflow

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

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

the class CustomServicesWorkflowService method unpublishWorkflow.

@POST
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Path("/{id}/unpublish")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public CustomServicesWorkflowRestRep unpublishWorkflow(@PathParam("id") final URI id) {
    CustomServicesWorkflow customServicesWorkflow = getCustomServicesWorkflow(id);
    // Workflow can only be unpublished when it is in PUBLISHED state
    switch(CustomServicesWorkflowStatus.valueOf(customServicesWorkflow.getState())) {
        case VALID:
            // workflow is not published, ignoring
            return map(customServicesWorkflow);
        case PUBLISHED:
            // Check if there are any existing services created from this WF
            if (customServicesWorkflowManager.hasCatalogServices(URIUtil.asString(customServicesWorkflow.getId()))) {
                throw APIException.methodNotAllowed.notSupportedWithReason("Cannot unpublish workflow. It has associated catalog services");
            }
            CustomServicesWorkflow updated = WorkflowHelper.updateState(customServicesWorkflow, CustomServicesWorkflowStatus.VALID.toString());
            customServicesWorkflowManager.save(updated);
            return map(updated);
        default:
            throw APIException.methodNotAllowed.notSupportedWithReason(String.format("Worklow cannot be unpublished with its current state: %s", customServicesWorkflow.getState()));
    }
}
Also used : CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) 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