use of com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep 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.model.customservices.CustomServicesWorkflowRestRep 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.model.customservices.CustomServicesWorkflowRestRep in project coprhd-controller by CoprHD.
the class WorkflowHelper method makeArchive.
/**
* @param out
* @param workflowPackage
* @throws IOException
* @throws JsonMappingException
* @throws JsonGenerationException
*/
private static void makeArchive(final ByteArrayOutputStream out, final CustomServicesWorkflowPackage workflowPackage) throws IOException {
try (final TarArchiveOutputStream tarOut = new TarArchiveOutputStream(new GZIPOutputStream(new BufferedOutputStream(out)))) {
tarOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
for (final Entry<URI, CustomServicesWorkflowRestRep> workflow : workflowPackage.workflows().entrySet()) {
final String name = WORKFLOWS_FOLDER + "/" + workflow.getKey().toString();
final byte[] content = MAPPER.writeValueAsBytes(workflow.getValue());
final Date modTime = workflow.getValue().getCreationTime().getTime();
addArchiveEntry(tarOut, name, modTime, content);
}
for (final Entry<URI, CustomServicesPrimitiveRestRep> operation : workflowPackage.operations().entrySet()) {
final String name = OPERATIONS_FOLDER + "/" + operation.getKey().toString();
final byte[] content = MAPPER.writeValueAsBytes(operation.getValue());
final Date modTime = operation.getValue().getCreationTime().getTime();
addArchiveEntry(tarOut, name, modTime, content);
}
for (final Entry<URI, ResourcePackage> resource : workflowPackage.resources().entrySet()) {
final String name = RESOURCES_FOLDER + "/" + resource.getKey().toString() + ".md";
final String resourceFile = RESOURCES_FOLDER + "/" + resource.getKey().toString();
final byte[] metadata = MAPPER.writeValueAsBytes(resource.getValue().metadata());
final Date modTime = resource.getValue().metadata().getCreationTime().getTime();
addArchiveEntry(tarOut, name, modTime, metadata);
addArchiveEntry(tarOut, resourceFile, modTime, resource.getValue().bytes());
}
tarOut.finish();
}
}
use of com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep in project coprhd-controller by CoprHD.
the class CustomServicesWorkflowMapper method map.
public static CustomServicesWorkflowRestRep map(CustomServicesWorkflow from) {
CustomServicesWorkflowRestRep to = new CustomServicesWorkflowRestRep();
mapDataObjectFields(from, to);
try {
to.setDocument(WorkflowHelper.toWorkflowDocument(from));
to.setState(from.getState());
} catch (IOException e) {
throw APIException.internalServerErrors.genericApisvcError("Error deserializing workflow", e);
}
return to;
}
use of com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep in project coprhd-controller by CoprHD.
the class WorkflowBuilder method unpublishWorkflow.
public static void unpublishWorkflow(final URI workflowId) {
CustomServicesWorkflowRestRep customServicesWorkflowRestRep = getCatalogClient().customServicesPrimitives().unpublishWorkflow(workflowId);
renderJSON(customServicesWorkflowRestRep);
}
Aggregations