use of com.emc.storageos.model.customservices.CustomServicesWorkflowList in project coprhd-controller by CoprHD.
the class WorkflowBuilder method updateWorkflowInventoryFiles.
private static boolean updateWorkflowInventoryFiles(final String localAnsiblePrimitiveId) {
boolean updatedWorkflows = false;
final CustomServicesWorkflowList customServicesWorkflowList = getCatalogClient().customServicesPrimitives().getWorkflows(localAnsiblePrimitiveId);
if (customServicesWorkflowList != null && CollectionUtils.isNotEmpty(customServicesWorkflowList.getWorkflows())) {
for (final NamedRelatedResourceRep resourceRep : customServicesWorkflowList.getWorkflows()) {
final URI workflowId = resourceRep.getId();
final CustomServicesWorkflowRestRep customServicesWorkflowRestRep = getCatalogClient().customServicesPrimitives().getWorkflow(workflowId);
if (null != customServicesWorkflowRestRep) {
Logger.info("Updating workflow {} with new host inventory files", workflowId);
final CustomServicesWorkflowUpdateParam param = new CustomServicesWorkflowUpdateParam();
for (final CustomServicesWorkflowDocument.Step step : customServicesWorkflowRestRep.getDocument().getSteps()) {
addInventoryFileInputs(step);
}
param.setDocument(customServicesWorkflowRestRep.getDocument());
getCatalogClient().customServicesPrimitives().editWorkflow(workflowId, param);
updatedWorkflows = true;
}
}
}
return updatedWorkflows;
}
use of com.emc.storageos.model.customservices.CustomServicesWorkflowList 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.CustomServicesWorkflowList in project coprhd-controller by CoprHD.
the class WorkflowBuilder method getWFDirectories.
public static void getWFDirectories() {
final List<Node> topLevelNodes = new ArrayList<Node>();
prepareRootNodes(topLevelNodes);
// get workflow directories and prepare nodes
final WFBulkRep wfBulkRep = getCatalogClient().wfDirectories().getAll();
String nodeParent;
final Map<URI, WFDirectoryRestRep> fileParents = new HashMap<URI, WFDirectoryRestRep>();
for (WFDirectoryRestRep wfDirectoryRestRep : wfBulkRep.getWfDirectories()) {
if (null == wfDirectoryRestRep.getParent()) {
nodeParent = MY_LIBRARY_ROOT;
} else {
nodeParent = wfDirectoryRestRep.getParent().getId().toString();
}
final Node node = new Node(wfDirectoryRestRep.getId().toString(), wfDirectoryRestRep.getName(), nodeParent, WFBuilderNodeTypes.FOLDER.toString());
// add workflows that are under this node
if (null != wfDirectoryRestRep.getWorkflows()) {
for (URI u : wfDirectoryRestRep.getWorkflows()) {
fileParents.put(u, wfDirectoryRestRep);
}
}
topLevelNodes.add(node);
}
// Add primitives
addPrimitivesByType(topLevelNodes, StepType.LOCAL_ANSIBLE.toString(), MY_LIBRARY_ROOT, fileParents);
addPrimitivesByType(topLevelNodes, StepType.REMOTE_ANSIBLE.toString(), MY_LIBRARY_ROOT, fileParents);
addPrimitivesByType(topLevelNodes, StepType.SHELL_SCRIPT.toString(), MY_LIBRARY_ROOT, fileParents);
addPrimitivesByType(topLevelNodes, StepType.REST.toString(), MY_LIBRARY_ROOT, fileParents);
addPrimitivesByType(topLevelNodes, StepType.VIPR_REST.toString(), VIPR_PRIMITIVE_ROOT, null);
// Add workflows
final CustomServicesWorkflowList customServicesWorkflowList = getCatalogClient().customServicesPrimitives().getWorkflows();
if (null != customServicesWorkflowList && null != customServicesWorkflowList.getWorkflows()) {
for (NamedRelatedResourceRep o : customServicesWorkflowList.getWorkflows()) {
final String parent = fileParents.containsKey(o.getId()) ? fileParents.get(o.getId()).getId().toString() : MY_LIBRARY_ROOT;
topLevelNodes.add(new Node(o.getId().toString(), o.getName(), parent, StepType.WORKFLOW.toString()));
}
}
renderJSON(topLevelNodes);
}
use of com.emc.storageos.model.customservices.CustomServicesWorkflowList 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());
}
}
Aggregations