Search in sources :

Example 1 with CustomServicesPrimitiveRestRep

use of com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep in project coprhd-controller by CoprHD.

the class CustomServicesViprPrimitiveDAO method bulk.

@Override
public Iterator<CustomServicesPrimitiveRestRep> bulk(final Collection<URI> ids) {
    ImmutableList.Builder<CustomServicesPrimitiveRestRep> primitives = ImmutableList.<CustomServicesPrimitiveRestRep>builder();
    for (final URI id : ids) {
        final CustomServicesViPRPrimitive primitive = PRIMITIVES_MAP.get(id);
        final ModelObject model = primitive == null ? null : primitive.asModelObject();
        ArgValidator.checkEntityNotNull(model, id, false);
        primitives.add(CustomServicesPrimitiveMapper.map(primitive));
    }
    return primitives.build().iterator();
}
Also used : ModelObject(com.emc.storageos.db.client.model.ModelObject) CustomServicesPrimitiveRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep) ImmutableList(com.google.common.collect.ImmutableList) URI(java.net.URI) CustomServicesViPRPrimitive(com.emc.storageos.primitives.java.vipr.CustomServicesViPRPrimitive)

Example 2 with CustomServicesPrimitiveRestRep

use of com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep 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 CustomServicesPrimitiveRestRep

use of com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep 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 4 with CustomServicesPrimitiveRestRep

use of com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep in project coprhd-controller by CoprHD.

the class WorkflowBuilder method editShellScriptPrimitive.

private static void editShellScriptPrimitive(final ShellScriptPrimitiveForm shellPrimitive) {
    try {
        final URI shellPrimitiveID = new URI(shellPrimitive.getId());
        // Check primitive is already used in workflow/s
        final CustomServicesPrimitiveRestRep primitiveRestRep = getCatalogClient().customServicesPrimitives().getPrimitive(shellPrimitiveID);
        if (null != primitiveRestRep) {
            final CustomServicesWorkflowList customServicesWorkflowList = getCatalogClient().customServicesPrimitives().getWorkflows(shellPrimitive.getId());
            if (customServicesWorkflowList != null && customServicesWorkflowList.getWorkflows() != null) {
                if (!customServicesWorkflowList.getWorkflows().isEmpty()) {
                    flash.error("Operation %s is being used in Workflow", primitiveRestRep.getName());
                    return;
                }
            }
            // Update name, description
            final CustomServicesPrimitiveUpdateParam primitiveUpdateParam = new CustomServicesPrimitiveUpdateParam();
            primitiveUpdateParam.setName(shellPrimitive.getName());
            primitiveUpdateParam.setFriendlyName(shellPrimitive.getName());
            primitiveUpdateParam.setDescription(shellPrimitive.getDescription());
            // Get and update differences between existing and new inputs
            final List<String> newInputs = getListFromInputOutputString(shellPrimitive.getInputs());
            final List<String> existingInputs = convertInputParamsGroupsToList(primitiveRestRep.getInputGroups());
            final InputUpdateParam inputUpdateParam = new InputUpdateParam();
            inputUpdateParam.setRemove(getInputParamsDiff(existingInputs, newInputs));
            inputUpdateParam.setAdd(getInputParamsDiff(newInputs, existingInputs));
            primitiveUpdateParam.setInput(inputUpdateParam);
            // Get and update differences between existing and new outputs
            final List<String> newOutputs = getListFromInputOutputString(shellPrimitive.getOutputs());
            final List<String> existingOutputs = convertOutputGroupsToList(primitiveRestRep.getOutput());
            OutputUpdateParam outputUpdateParam = new OutputUpdateParam();
            outputUpdateParam.setRemove((List<String>) CollectionUtils.subtract(existingOutputs, newOutputs));
            outputUpdateParam.setAdd((List<String>) CollectionUtils.subtract(newOutputs, existingOutputs));
            primitiveUpdateParam.setOutput(outputUpdateParam);
            final CustomServicesPrimitiveResourceRestRep primitiveResourceRestRep;
            if (shellPrimitive.isNewScript()) {
                // create new resource
                String filename = FilenameUtils.getBaseName(shellPrimitive.getScript().getName());
                primitiveResourceRestRep = getCatalogClient().customServicesPrimitives().createPrimitiveResource("SCRIPT", shellPrimitive.getScript(), filename);
                if (null != primitiveResourceRestRep) {
                    // Update resource link
                    primitiveUpdateParam.setResource(primitiveResourceRestRep.getId());
                    try {
                        getCatalogClient().customServicesPrimitives().updatePrimitive(shellPrimitiveID, primitiveUpdateParam);
                    } catch (final Exception e1) {
                        if (primitiveResourceRestRep != null) {
                            // Resource was created but primitive creation failed
                            getCatalogClient().customServicesPrimitives().deletePrimitiveResource(primitiveResourceRestRep.getId());
                        }
                        throw e1;
                    }
                }
            } else {
                getCatalogClient().customServicesPrimitives().updatePrimitive(shellPrimitiveID, primitiveUpdateParam);
            }
            flash.success(MessagesUtils.get("wfBuilder.operation.edit.success"));
        }
    } catch (final Exception e) {
        Logger.error(e.getMessage());
        flash.error(e.getMessage());
    }
}
Also used : InputUpdateParam(com.emc.storageos.model.customservices.InputUpdateParam) CustomServicesPrimitiveRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep) CustomServicesPrimitiveResourceRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceRestRep) CustomServicesPrimitiveUpdateParam(com.emc.storageos.model.customservices.CustomServicesPrimitiveUpdateParam) OutputUpdateParam(com.emc.storageos.model.customservices.OutputUpdateParam) CustomServicesWorkflowList(com.emc.storageos.model.customservices.CustomServicesWorkflowList) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException)

Example 5 with CustomServicesPrimitiveRestRep

use of com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep in project coprhd-controller by CoprHD.

the class WorkflowBuilder method editLocalAnsiblePrimitive.

private static void editLocalAnsiblePrimitive(final LocalAnsiblePrimitiveForm localAnsible) {
    try {
        final URI localAnsiblePrimitiveID = new URI(localAnsible.getId());
        final CustomServicesPrimitiveRestRep primitiveRestRep = getCatalogClient().customServicesPrimitives().getPrimitive(localAnsiblePrimitiveID);
        if (null != primitiveRestRep) {
            // Update name, description
            final CustomServicesPrimitiveUpdateParam primitiveUpdateParam = new CustomServicesPrimitiveUpdateParam();
            primitiveUpdateParam.setName(localAnsible.getName());
            primitiveUpdateParam.setFriendlyName(localAnsible.getName());
            primitiveUpdateParam.setDescription(localAnsible.getDescription());
            // Get and update differences between existing and new inputs
            final List<String> newInputs = getListFromInputOutputString(localAnsible.getInputs());
            final List<String> existingInputs = convertInputParamsGroupsToList(primitiveRestRep.getInputGroups());
            final InputUpdateParam inputUpdateParam = new InputUpdateParam();
            inputUpdateParam.setRemove(getInputParamsDiff(existingInputs, newInputs));
            inputUpdateParam.setAdd(getInputParamsDiff(newInputs, existingInputs));
            primitiveUpdateParam.setInput(inputUpdateParam);
            // Get and update differences between existing and new outputs
            final List<String> newOutputs = getListFromInputOutputString(localAnsible.getOutputs());
            final List<String> existingOutputs = convertOutputGroupsToList(primitiveRestRep.getOutput());
            final OutputUpdateParam outputUpdateParam = new OutputUpdateParam();
            outputUpdateParam.setRemove((List<String>) CollectionUtils.subtract(existingOutputs, newOutputs));
            outputUpdateParam.setAdd((List<String>) CollectionUtils.subtract(newOutputs, existingOutputs));
            primitiveUpdateParam.setOutput(outputUpdateParam);
            // Set playbook
            primitiveUpdateParam.setAttributes(new HashMap<String, String>());
            primitiveUpdateParam.getAttributes().put(CustomServicesConstants.ANSIBLE_PLAYBOOK, localAnsible.getAnsiblePlaybook());
            URI packageId = null;
            boolean updateDone = false;
            if (!localAnsible.isExisting()) {
                // NEW RESOURCE
                // Before creating resource check if this primitive is not used
                final CustomServicesWorkflowList customServicesWorkflowList = getCatalogClient().customServicesPrimitives().getWorkflows(localAnsible.getId());
                if (customServicesWorkflowList != null && customServicesWorkflowList.getWorkflows() != null) {
                    if (!customServicesWorkflowList.getWorkflows().isEmpty()) {
                        flash.error("Primitive %s is being used in Workflow", primitiveRestRep.getName());
                        return;
                    }
                }
                // create new resource
                final CustomServicesPrimitiveResourceRestRep primitiveResourceRestRep = getCatalogClient().customServicesPrimitives().createPrimitiveResource("ANSIBLE", localAnsible.getAnsiblePackage(), localAnsible.getAnsiblePackageName());
                if (null != primitiveResourceRestRep) {
                    // Update resource link
                    packageId = primitiveResourceRestRep.getId();
                    primitiveUpdateParam.setResource(packageId);
                }
            } else {
                // EXISTING RESOURCE
                packageId = new URI(localAnsible.getExistingResource());
                primitiveUpdateParam.setResource(packageId);
                // Changes to existing inventory files
                updateDone = updateInventoryFiles(packageId, localAnsible.getUpdatedInventoryFiles());
            }
            // Upload new inventory files
            final boolean uploadDone = uploadInventoryFiles(packageId, localAnsible.getInventoryFiles());
            // Update workflows with new inventory files
            boolean updatedWorkflows = false;
            if (uploadDone || updateDone) {
                updatedWorkflows = updateWorkflowInventoryFiles(localAnsible.getId());
            }
            // If this primitive is part of any workflow, ignore update
            if (!updatedWorkflows) {
                getCatalogClient().customServicesPrimitives().updatePrimitive(localAnsiblePrimitiveID, primitiveUpdateParam);
            } else {
                Logger.info("Ignoring local ansible primitive {} update as it is part of workflow", localAnsible.getName());
            }
            flash.success(MessagesUtils.get("wfBuilder.operation.edit.success"));
        }
    } catch (final Exception e) {
        Logger.error(e.getMessage());
        flash.error(e.getMessage());
    }
}
Also used : InputUpdateParam(com.emc.storageos.model.customservices.InputUpdateParam) CustomServicesPrimitiveRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep) CustomServicesPrimitiveResourceRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceRestRep) CustomServicesPrimitiveUpdateParam(com.emc.storageos.model.customservices.CustomServicesPrimitiveUpdateParam) OutputUpdateParam(com.emc.storageos.model.customservices.OutputUpdateParam) CustomServicesWorkflowList(com.emc.storageos.model.customservices.CustomServicesWorkflowList) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException)

Aggregations

CustomServicesPrimitiveRestRep (com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep)15 URISyntaxException (java.net.URISyntaxException)9 URI (java.net.URI)8 CustomServicesPrimitiveResourceRestRep (com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceRestRep)5 CustomServicesPrimitiveUpdateParam (com.emc.storageos.model.customservices.CustomServicesPrimitiveUpdateParam)5 CustomServicesPrimitiveCreateParam (com.emc.storageos.model.customservices.CustomServicesPrimitiveCreateParam)4 InputCreateList (com.emc.storageos.model.customservices.CustomServicesPrimitiveCreateParam.InputCreateList)4 InputUpdateParam (com.emc.storageos.model.customservices.InputUpdateParam)4 OutputUpdateParam (com.emc.storageos.model.customservices.OutputUpdateParam)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 ResourcePackage (com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage)2 NamedURI (com.emc.storageos.db.client.model.NamedURI)2 CustomServicesWorkflowList (com.emc.storageos.model.customservices.CustomServicesWorkflowList)2 CustomServicesWorkflowRestRep (com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep)2 ModelObject (com.emc.storageos.db.client.model.ModelObject)1 CustomServicesWorkflow (com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow)1 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)1 CustomServicesPrimitiveList (com.emc.storageos.model.customservices.CustomServicesPrimitiveList)1 CustomServicesPrimitiveResourceList (com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceList)1 CustomServicesWorkflowDocument (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument)1