use of com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage in project coprhd-controller by CoprHD.
the class WorkflowHelper method addResource.
private static void addResource(Builder builder, NamedURI id, CustomServicesResourceDAOs resourceDAOs) {
final CustomServicesResourceDAO<?> dao = resourceDAOs.getByModel(URIUtil.getTypeName(id.getURI()));
if (null == dao) {
throw new RuntimeException("Resource type for " + id + " not found");
}
final CustomServicesPrimitiveResourceType resource = dao.getResource(id.getURI());
if (null == resource) {
throw new RuntimeException("Resource " + id + " not found");
}
builder.addResource(new ResourcePackage(CustomServicesPrimitiveMapper.map(resource), resource.resource()));
for (final NamedElement related : dao.listRelatedResources(id.getURI())) {
addResource(builder, new NamedURI(related.getId(), related.getName()), resourceDAOs);
}
}
use of com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage 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.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage 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();
}
}
Aggregations