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