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());
}
}
use of com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep in project coprhd-controller by CoprHD.
the class WorkflowBuilder method addPrimitivesByType.
private static void addPrimitivesByType(final List<Node> topLevelNodes, final String type, String parentDefault, final Map<URI, WFDirectoryRestRep> fileParents) {
final CustomServicesPrimitiveList primitiveList = getCatalogClient().customServicesPrimitives().getPrimitivesByType(type);
if (null == primitiveList || null == primitiveList.getPrimitives()) {
return;
}
final List<String> categories = new ArrayList<String>();
final List<String> services = new ArrayList<String>();
final List<CustomServicesPrimitiveRestRep> primitives = getCatalogClient().customServicesPrimitives().getByIds(primitiveList.getPrimitives());
for (final CustomServicesPrimitiveRestRep primitive : primitives) {
final String parent = (fileParents != null && fileParents.containsKey(primitive.getId())) ? fileParents.get(primitive.getId()).getId().toString() : parentDefault;
final Node node;
if (StepType.VIPR_REST.toString().equals(type)) {
final String[] folders = primitive.getName().split("/");
final String service;
if (folders.length == 3) {
if (!categories.contains(folders[0])) {
topLevelNodes.add(new Node(folders[0], folders[0], parent, WFBuilderNodeTypes.FOLDER.toString()));
categories.add(folders[0]);
}
if (!services.contains(folders[1])) {
topLevelNodes.add(new Node(folders[1], folders[1], folders[0], WFBuilderNodeTypes.FOLDER.toString()));
services.add(folders[1]);
}
service = folders[1];
} else {
service = parent;
}
node = new Node(primitive.getId().toString(), primitive.getFriendlyName(), service, type);
} else {
node = new Node(primitive.getId().toString(), primitive.getName(), parent, type);
}
node.data = primitive;
topLevelNodes.add(node);
}
}
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 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();
}
Aggregations