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());
}
}
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()));
}
}
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);
}
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);
}
}
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()));
}
}
Aggregations