Search in sources :

Example 6 with CustomServicesPrimitiveResourceRestRep

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

the class WorkflowBuilder method createLocalAnsiblePrimitive.

private static void createLocalAnsiblePrimitive(@Valid final LocalAnsiblePrimitiveForm localAnsible) {
    try {
        final CustomServicesPrimitiveResourceRestRep primitiveResourceRestRep;
        if (localAnsible.isExisting()) {
            primitiveResourceRestRep = getCatalogClient().customServicesPrimitives().getPrimitiveResource(new URI(localAnsible.getExistingResource()));
        } else if (null != localAnsible.getAnsiblePackage()) {
            // upload ansible package
            primitiveResourceRestRep = getCatalogClient().customServicesPrimitives().createPrimitiveResource("ANSIBLE", localAnsible.getAnsiblePackage(), localAnsible.getAnsiblePackageName());
        } else {
            throw new Exception("Error while uploading/retrieving primitive resource");
        }
        if (null != primitiveResourceRestRep) {
            try {
                // Upload ansible inventory files
                uploadInventoryFiles(primitiveResourceRestRep.getId(), localAnsible.getInventoryFiles());
            } catch (final Exception e1) {
                if (primitiveResourceRestRep != null) {
                    // Resource was created but primitive creation failed
                    // Resource was created but inventory creation failed. Remove inventory that was created (if any)
                    updateInventoryFiles(primitiveResourceRestRep.getId(), "");
                    getCatalogClient().customServicesPrimitives().deletePrimitiveResource(primitiveResourceRestRep.getId());
                }
                throw e1;
            }
            // Create Primitive
            final CustomServicesPrimitiveCreateParam primitiveCreateParam = new CustomServicesPrimitiveCreateParam();
            primitiveCreateParam.setType(StepType.LOCAL_ANSIBLE.toString());
            primitiveCreateParam.setName(localAnsible.getName());
            primitiveCreateParam.setDescription(localAnsible.getDescription());
            primitiveCreateParam.setFriendlyName(localAnsible.getName());
            primitiveCreateParam.setResource(primitiveResourceRestRep.getId());
            primitiveCreateParam.setAttributes(new HashMap<String, String>());
            primitiveCreateParam.getAttributes().put(CustomServicesConstants.ANSIBLE_PLAYBOOK, localAnsible.getAnsiblePlaybook());
            final ImmutableMap.Builder<String, InputCreateList> builder = ImmutableMap.<String, InputCreateList>builder();
            // Add Input Groups
            addInputs(localAnsible.getInputs(), builder, CustomServicesConstants.INPUT_PARAMS);
            primitiveCreateParam.setInput(builder.build());
            if (StringUtils.isNotEmpty(localAnsible.getOutputs())) {
                primitiveCreateParam.setOutput(getListFromInputOutputString(localAnsible.getOutputs()));
            }
            final CustomServicesPrimitiveRestRep primitiveRestRep;
            try {
                primitiveRestRep = getCatalogClient().customServicesPrimitives().createPrimitive(primitiveCreateParam);
            } catch (final Exception e1) {
                if (primitiveResourceRestRep != null) {
                    // Resource was created but primitive creation failed
                    // Resource was created but primitive creation failed. Remove inventory that was created (if any)
                    updateInventoryFiles(primitiveResourceRestRep.getId(), "");
                    getCatalogClient().customServicesPrimitives().deletePrimitiveResource(primitiveResourceRestRep.getId());
                }
                throw e1;
            }
            if (primitiveRestRep != null) {
                // add this to wf directory
                addResourceToWFDirectory(primitiveRestRep.getId(), localAnsible.getWfDirID());
            } else {
                flash.error("Error while creating primitive");
            }
            flash.success(MessagesUtils.get("wfBuilder.operation.save.success"));
        } else {
            flash.error("Error while uploading primitive resource");
        }
    } catch (final Exception e) {
        Logger.error(e.getMessage());
        flash.error(e.getMessage());
    }
}
Also used : CustomServicesPrimitiveResourceRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceRestRep) CustomServicesPrimitiveCreateParam(com.emc.storageos.model.customservices.CustomServicesPrimitiveCreateParam) CustomServicesPrimitiveRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep) InputCreateList(com.emc.storageos.model.customservices.CustomServicesPrimitiveCreateParam.InputCreateList) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with CustomServicesPrimitiveResourceRestRep

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

the class WorkflowBuilder method createShellScriptPrimitive.

private static void createShellScriptPrimitive(final ShellScriptPrimitiveForm shellPrimitive) {
    try {
        final String filename = FilenameUtils.getBaseName(shellPrimitive.getScript().getName());
        final CustomServicesPrimitiveResourceRestRep primitiveResourceRestRep = getCatalogClient().customServicesPrimitives().createPrimitiveResource("SCRIPT", shellPrimitive.getScript(), filename);
        if (null != primitiveResourceRestRep) {
            final CustomServicesPrimitiveCreateParam primitiveCreateParam = new CustomServicesPrimitiveCreateParam();
            primitiveCreateParam.setType(StepType.SHELL_SCRIPT.toString());
            primitiveCreateParam.setName(shellPrimitive.getName());
            primitiveCreateParam.setFriendlyName(shellPrimitive.getName());
            primitiveCreateParam.setDescription(shellPrimitive.getDescription());
            primitiveCreateParam.setResource(primitiveResourceRestRep.getId());
            if (StringUtils.isNotEmpty(shellPrimitive.getInputs())) {
                final List<String> list = getListFromInputOutputString(shellPrimitive.getInputs());
                final InputCreateList input = new InputCreateList();
                input.setInput(list);
                final ImmutableMap.Builder<String, InputCreateList> builder = ImmutableMap.<String, InputCreateList>builder().put(CustomServicesConstants.INPUT_PARAMS, input);
                primitiveCreateParam.setInput(builder.build());
            }
            if (StringUtils.isNotEmpty(shellPrimitive.getOutputs())) {
                primitiveCreateParam.setOutput(getListFromInputOutputString(shellPrimitive.getOutputs()));
            }
            final CustomServicesPrimitiveRestRep primitiveRestRep;
            try {
                primitiveRestRep = getCatalogClient().customServicesPrimitives().createPrimitive(primitiveCreateParam);
            } catch (final Exception e1) {
                if (primitiveResourceRestRep != null) {
                    // Resource was created but primitive creation failed
                    getCatalogClient().customServicesPrimitives().deletePrimitiveResource(primitiveResourceRestRep.getId());
                }
                throw e1;
            }
            if (primitiveRestRep != null) {
                // add this to wf directory
                addResourceToWFDirectory(primitiveRestRep.getId(), shellPrimitive.getWfDirID());
            } else {
                flash.error("Error while creating primitive");
            }
            flash.success(MessagesUtils.get("wfBuilder.operation.save.success"));
        } else {
            flash.error("Error while uploading primitive resource");
        }
    } catch (final Exception e) {
        Logger.error(e.getMessage());
        flash.error(e.getMessage());
    }
}
Also used : CustomServicesPrimitiveResourceRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceRestRep) CustomServicesPrimitiveCreateParam(com.emc.storageos.model.customservices.CustomServicesPrimitiveCreateParam) CustomServicesPrimitiveRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep) InputCreateList(com.emc.storageos.model.customservices.CustomServicesPrimitiveCreateParam.InputCreateList) ImmutableMap(com.google.common.collect.ImmutableMap) URISyntaxException(java.net.URISyntaxException)

Aggregations

CustomServicesPrimitiveResourceRestRep (com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceRestRep)7 CustomServicesPrimitiveRestRep (com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep)5 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 CustomServicesPrimitiveCreateParam (com.emc.storageos.model.customservices.CustomServicesPrimitiveCreateParam)2 InputCreateList (com.emc.storageos.model.customservices.CustomServicesPrimitiveCreateParam.InputCreateList)2 CustomServicesPrimitiveUpdateParam (com.emc.storageos.model.customservices.CustomServicesPrimitiveUpdateParam)2 CustomServicesWorkflowList (com.emc.storageos.model.customservices.CustomServicesWorkflowList)2 InputUpdateParam (com.emc.storageos.model.customservices.InputUpdateParam)2 OutputUpdateParam (com.emc.storageos.model.customservices.OutputUpdateParam)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ResourcePackage (com.emc.sa.workflow.CustomServicesWorkflowPackage.ResourcePackage)1 AbstractChangeTrackingSet (com.emc.storageos.db.client.model.AbstractChangeTrackingSet)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 CustomServicesWorkflow (com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow)1 CustomServicesWorkflowRestRep (com.emc.storageos.model.customservices.CustomServicesWorkflowRestRep)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1