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();
}
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());
}
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();
}
}
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());
}
}
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());
}
}
Aggregations