Search in sources :

Example 1 with InputUpdateParam

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

the class WorkflowBuilder method editRestAPIPrimitive.

private static void editRestAPIPrimitive(final RestAPIPrimitiveForm restAPIPrimitive) {
    try {
        final URI restPrimitiveID = new URI(restAPIPrimitive.getId());
        final CustomServicesPrimitiveRestRep primitiveRestRep = getCatalogClient().customServicesPrimitives().getPrimitive(restPrimitiveID);
        if (null != primitiveRestRep) {
            // Update name, description
            final CustomServicesPrimitiveUpdateParam primitiveUpdateParam = new CustomServicesPrimitiveUpdateParam();
            primitiveUpdateParam.setName(restAPIPrimitive.getName());
            primitiveUpdateParam.setFriendlyName(restAPIPrimitive.getName());
            primitiveUpdateParam.setDescription(restAPIPrimitive.getDescription());
            // Get and update differences between existing and new inputs
            final InputUpdateParam inputUpdateParam = new InputUpdateParam();
            inputUpdateParam.setRemove(new HashMap<String, InputUpdateList>());
            inputUpdateParam.setAdd(new HashMap<String, InputUpdateList>());
            prepareInputUpdates(CustomServicesConstants.INPUT_PARAMS, restAPIPrimitive.getInputs(), primitiveRestRep, inputUpdateParam);
            prepareInputUpdates(CustomServicesConstants.HEADERS, restAPIPrimitive.getHeaders(), primitiveRestRep, inputUpdateParam);
            prepareInputUpdates(CustomServicesConstants.QUERY_PARAMS, restAPIPrimitive.getQueryParams(), primitiveRestRep, inputUpdateParam);
            primitiveUpdateParam.setInput(inputUpdateParam);
            // Get and update differences between existing and new outputs
            final List<String> newOutputs = getListFromInputOutputString(restAPIPrimitive.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 attributes
            primitiveUpdateParam.setAttributes(new HashMap<String, String>());
            primitiveUpdateParam.getAttributes().put(CustomServicesConstants.PATH.toString(), restAPIPrimitive.getRequestURL());
            if (restAPIPrimitive.getRawBody() == null) {
                primitiveUpdateParam.getAttributes().put(CustomServicesConstants.BODY.toString(), "");
            } else {
                primitiveUpdateParam.getAttributes().put(CustomServicesConstants.BODY.toString(), restAPIPrimitive.getRawBody());
            }
            // Only supported protocol is "https". Once other protocols are supported this value should come from UI form
            primitiveUpdateParam.getAttributes().put(CustomServicesConstants.METHOD.toString(), restAPIPrimitive.getMethod());
            primitiveUpdateParam.getAttributes().put(CustomServicesConstants.AUTH_TYPE.toString(), restAPIPrimitive.getAuthType());
            getCatalogClient().customServicesPrimitives().updatePrimitive(restPrimitiveID, 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) CustomServicesPrimitiveUpdateParam(com.emc.storageos.model.customservices.CustomServicesPrimitiveUpdateParam) OutputUpdateParam(com.emc.storageos.model.customservices.OutputUpdateParam) InputUpdateList(com.emc.storageos.model.customservices.InputUpdateParam.InputUpdateList) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException)

Example 2 with InputUpdateParam

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

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

the class WorkflowBuilder method editRemoteAnsiblePrimitive.

private static void editRemoteAnsiblePrimitive(final RemoteAnsiblePrimitiveForm remoteAnsible) {
    try {
        final URI shellPrimitiveID = new URI(remoteAnsible.getId());
        final CustomServicesPrimitiveRestRep primitiveRestRep = getCatalogClient().customServicesPrimitives().getPrimitive(shellPrimitiveID);
        if (null != primitiveRestRep) {
            // Update name, description
            final CustomServicesPrimitiveUpdateParam primitiveUpdateParam = new CustomServicesPrimitiveUpdateParam();
            primitiveUpdateParam.setName(remoteAnsible.getName());
            primitiveUpdateParam.setFriendlyName(remoteAnsible.getName());
            primitiveUpdateParam.setDescription(remoteAnsible.getDescription());
            // Get and update differences between existing and new inputs
            final List<String> newInputs = getListFromInputOutputString(remoteAnsible.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(remoteAnsible.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);
            // Attributes
            primitiveUpdateParam.setAttributes(new HashMap<String, String>());
            primitiveUpdateParam.getAttributes().put(CustomServicesConstants.ANSIBLE_PLAYBOOK, remoteAnsible.getPlaybookPath());
            primitiveUpdateParam.getAttributes().put(CustomServicesConstants.ANSIBLE_BIN, remoteAnsible.getAnsibleBinPath());
            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) CustomServicesPrimitiveUpdateParam(com.emc.storageos.model.customservices.CustomServicesPrimitiveUpdateParam) OutputUpdateParam(com.emc.storageos.model.customservices.OutputUpdateParam) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException)

Example 4 with InputUpdateParam

use of com.emc.storageos.model.customservices.InputUpdateParam 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)4 CustomServicesPrimitiveUpdateParam (com.emc.storageos.model.customservices.CustomServicesPrimitiveUpdateParam)4 InputUpdateParam (com.emc.storageos.model.customservices.InputUpdateParam)4 OutputUpdateParam (com.emc.storageos.model.customservices.OutputUpdateParam)4 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 CustomServicesPrimitiveResourceRestRep (com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceRestRep)2 CustomServicesWorkflowList (com.emc.storageos.model.customservices.CustomServicesWorkflowList)2 InputUpdateList (com.emc.storageos.model.customservices.InputUpdateParam.InputUpdateList)1