Search in sources :

Example 6 with CustomServicesWorkflowRestRep

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);
            }
        }
    }
}
Also used : CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow) CustomServicesWorkflowRestRep(com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep) Step(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) CustomServicesViPRPrimitive(com.emc.storageos.primitives.java.vipr.CustomServicesViPRPrimitive)

Example 7 with CustomServicesWorkflowRestRep

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());
}
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 8 with CustomServicesWorkflowRestRep

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

Example 9 with CustomServicesWorkflowRestRep

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;
}
Also used : CustomServicesWorkflowRestRep(com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep) IOException(java.io.IOException)

Example 10 with CustomServicesWorkflowRestRep

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);
}
Also used : CustomServicesWorkflowRestRep(com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep)

Aggregations

CustomServicesWorkflowRestRep (com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep)11 URI (java.net.URI)5 NamedURI (com.emc.storageos.db.client.model.NamedURI)3 CustomServicesWorkflowDocument (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument)3 CustomServicesWorkflowUpdateParam (com.emc.storageos.model.customservices.CustomServicesWorkflowUpdateParam)3 ResourcePackage (com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage)2 CustomServicesWorkflow (com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow)2 CustomServicesPrimitiveRestRep (com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep)2 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)1 CustomServicesPrimitiveResourceRestRep (com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceRestRep)1 CustomServicesWorkflowCreateParam (com.emc.storageos.model.customservices.CustomServicesWorkflowCreateParam)1 Step (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step)1 CustomServicesWorkflowList (com.emc.storageos.model.customservices.CustomServicesWorkflowList)1 CustomServicesViPRPrimitive (com.emc.storageos.primitives.java.vipr.CustomServicesViPRPrimitive)1 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 Date (java.util.Date)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 TarArchiveOutputStream (org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)1