use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class DeleteNodeProcessor method removeRelationShipReferences.
/**
* Removes all relationships connected to the removed node (either as source or target)
*
* @param removedNode The name of the removed node
* @param topology The topology in which to remove the references.
* @param typesTobeUnloaded List of types to remove from the topology (when relationships are removed)
*/
private void removeRelationShipReferences(String removedNode, Csar csar, Topology topology, List<String> typesTobeUnloaded) {
List<String> relationshipsToRemove = Lists.newArrayList();
for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
if (removedNode.equals(nodeTemplate.getName())) {
// remove all relationships
for (Entry<String, RelationshipTemplate> relationshipTemplateEntry : safe(nodeTemplate.getRelationships()).entrySet()) {
typesTobeUnloaded.add(relationshipTemplateEntry.getValue().getType());
workflowBuilderService.removeRelationship(topology, csar, nodeTemplate.getName(), relationshipTemplateEntry.getKey(), relationshipTemplateEntry.getValue());
}
} else {
// This is for later removal
relationshipsToRemove.clear();
for (RelationshipTemplate relationshipTemplate : safe(nodeTemplate.getRelationships()).values()) {
if (removedNode.equals(relationshipTemplate.getTarget())) {
relationshipsToRemove.add(relationshipTemplate.getName());
typesTobeUnloaded.add(relationshipTemplate.getType());
workflowBuilderService.removeRelationship(topology, csar, nodeTemplate.getName(), relationshipTemplate.getName(), relationshipTemplate);
}
}
// remove the relationship from the node's relationship map.
for (String relationshipToRemove : relationshipsToRemove) {
nodeTemplate.getRelationships().remove(relationshipToRemove);
}
}
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class ReplaceNodeProcessor method removeTheRelationshipsOnSource.
/**
* If the node to replace is an target of relationship, we should swapped the relationship on source and clean used workflow steps
*/
private Map<String, Map<String, RelationshipTemplate>> removeTheRelationshipsOnSource(Topology topology, Csar csar, String nodeToReplace) {
Map<String, Map<String, RelationshipTemplate>> relationshipDeleted = Maps.newLinkedHashMap();
for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
if (!nodeToReplace.equals(nodeTemplate.getName())) {
List<String> relationshipsToRemove = Lists.newArrayList();
for (RelationshipTemplate relationshipTemplate : safe(nodeTemplate.getRelationships()).values()) {
if (nodeToReplace.equals(relationshipTemplate.getTarget())) {
relationshipsToRemove.add(relationshipTemplate.getName());
if (!relationshipDeleted.containsKey(relationshipTemplate.getName())) {
Map<String, RelationshipTemplate> relationships = Maps.newHashMap();
// we save the RelationshipTemplate, so we will preserve the current properties of this relationship
relationshipDeleted.put(nodeTemplate.getName(), relationships);
}
relationshipDeleted.get(nodeTemplate.getName()).put(relationshipTemplate.getName(), relationshipTemplate);
// we should remove this relationship to maintain a great a workflow
workflowBuilderService.removeRelationship(topology, csar, nodeTemplate.getName(), relationshipTemplate.getName(), relationshipTemplate);
}
}
}
}
return relationshipDeleted;
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class UpdateCapabilityPropertyValueProcessor method process.
@Override
@SneakyThrows
public void process(Csar csar, Topology topology, UpdateCapabilityPropertyValueOperation operation) {
String propertyName = operation.getPropertyName();
Object propertyValue = operation.getPropertyValue();
Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates);
Capability capability = nodeTemplate.getCapabilities().get(operation.getCapabilityName());
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
if (!capabilityType.getProperties().containsKey(propertyName)) {
throw new NotFoundException("Property <" + propertyName + "> doesn't exists for node <" + operation.getNodeName() + "> of type <" + capabilityType + ">");
}
log.debug("Updating property [ {} ] of the capability [ {} ] for the Node template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", propertyName, capability.getType(), operation.getNodeName(), topology.getId(), capabilityType.getProperties().get(propertyName), propertyValue);
try {
propertyService.setCapabilityPropertyValue(capability, capabilityType.getProperties().get(propertyName), propertyName, propertyValue);
} catch (ConstraintFunctionalException e) {
throw new PropertyValueException("Error when setting node " + operation.getNodeName() + " property.", e, propertyName, propertyValue);
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class UpdateNodePropertyValueProcessor method process.
@Override
public void process(Csar csar, Topology topology, UpdateNodePropertyValueOperation operation) {
Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
NodeTemplate nodeTemp = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates);
String propertyName = operation.getPropertyName();
Object propertyValue = operation.getPropertyValue();
NodeType node = ToscaContext.getOrFail(NodeType.class, nodeTemp.getType());
PropertyDefinition propertyDefinition = node.getProperties().get(propertyName);
if (propertyDefinition == null) {
throw new NotFoundException("Property <" + propertyName + "> doesn't exists for node <" + operation.getNodeName() + "> of type <" + nodeTemp.getType() + ">");
}
log.debug("Updating property [ {} ] of the Node template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", propertyName, operation.getNodeName(), topology.getId(), nodeTemp.getProperties().get(propertyName), propertyValue);
try {
propertyService.setPropertyValue(nodeTemp, propertyDefinition, propertyName, propertyValue);
} catch (ConstraintFunctionalException e) {
throw new PropertyValueException("Error when setting node " + operation.getNodeName() + " property.", e, propertyName, propertyValue);
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class RenameInputArtifactProcessor method process.
@Override
public void process(Csar csar, Topology topology, RenameInputArtifactOperation operation) {
if (operation.getNewInputName() == null || operation.getNewInputName().isEmpty() || !operation.getNewInputName().matches("\\w+")) {
throw new InvalidNameException("newInputName", operation.getNewInputName(), "\\w+");
}
if (safe(topology.getInputArtifacts()).containsKey(operation.getNewInputName())) {
throw new AlreadyExistException("Input artifact with name <" + operation.getNewInputName() + "> already exists.");
}
if (!safe(topology.getInputArtifacts()).containsKey(operation.getInputName())) {
throw new NotFoundException("Input artifact with name <" + operation.getInputName() + "> does not exists.");
}
DeploymentArtifact inputArtifact = topology.getInputArtifacts().remove(operation.getInputName());
topology.getInputArtifacts().put(operation.getNewInputName(), inputArtifact);
// change the value of concerned node template artifacts
for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
for (DeploymentArtifact dArtifact : safe(nodeTemplate.getArtifacts()).values()) {
InputArtifactUtil.updateInputArtifactIdIfNeeded(dArtifact, operation.getInputName(), operation.getNewInputName());
}
}
}
Aggregations