use of com.emc.storageos.model.customservices.CustomServicesPrimitiveUpdateParam 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());
}
}
use of com.emc.storageos.model.customservices.CustomServicesPrimitiveUpdateParam 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());
}
}
use of com.emc.storageos.model.customservices.CustomServicesPrimitiveUpdateParam 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());
}
}
use of com.emc.storageos.model.customservices.CustomServicesPrimitiveUpdateParam in project coprhd-controller by CoprHD.
the class WorkflowBuilder method editPrimitiveName.
public static void editPrimitiveName(final URI primitiveID, final String newName) {
final CustomServicesPrimitiveRestRep primitiveRestRep = getCatalogClient().customServicesPrimitives().getPrimitive(primitiveID);
if (null != primitiveRestRep) {
// Update name
if (StringUtils.isBlank(newName) || newName.equals(primitiveRestRep.getName())) {
// empty or no change ignore.
return;
}
final CustomServicesPrimitiveUpdateParam primitiveUpdateParam = new CustomServicesPrimitiveUpdateParam();
primitiveUpdateParam.setName(newName);
primitiveUpdateParam.setFriendlyName(newName);
getCatalogClient().customServicesPrimitives().updatePrimitive(primitiveID, primitiveUpdateParam);
}
}
use of com.emc.storageos.model.customservices.CustomServicesPrimitiveUpdateParam 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());
}
}
Aggregations