Search in sources :

Example 1 with ResourcePackage

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);
    }
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) ResourcePackage(com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage) CustomServicesPrimitiveResourceType(com.emc.storageos.primitives.CustomServicesPrimitiveResourceType) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)

Example 2 with ResourcePackage

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());
}
Also used : CustomServicesPrimitiveResourceRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceRestRep) CustomServicesPrimitiveRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep) ResourcePackage(com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage) CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow) CustomServicesWorkflowRestRep(com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 3 with ResourcePackage

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();
    }
}
Also used : CustomServicesPrimitiveRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep) ResourcePackage(com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Date(java.util.Date) GZIPOutputStream(java.util.zip.GZIPOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) CustomServicesWorkflowRestRep(com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

ResourcePackage (com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage)3 NamedURI (com.emc.storageos.db.client.model.NamedURI)3 CustomServicesPrimitiveRestRep (com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep)2 CustomServicesWorkflowRestRep (com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep)2 URI (java.net.URI)2 NamedElement (com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)1 CustomServicesWorkflow (com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow)1 CustomServicesPrimitiveResourceRestRep (com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceRestRep)1 CustomServicesPrimitiveResourceType (com.emc.storageos.primitives.CustomServicesPrimitiveResourceType)1 BufferedOutputStream (java.io.BufferedOutputStream)1 Date (java.util.Date)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 TarArchiveOutputStream (org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)1