use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class DeleteInputProcessor method processInputOperation.
@Override
protected void processInputOperation(Csar csar, Topology topology, DeleteInputOperation operation, Map<String, PropertyDefinition> inputs) {
if (!inputs.containsKey(operation.getInputName())) {
throw new NotFoundException("Input " + operation.getInputName() + "not found in topology");
}
for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
NodeType nodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
removeInputIdInProperties(nodeTemplate.getProperties(), nodeType.getProperties(), operation.getInputName());
if (nodeTemplate.getRelationships() != null) {
for (RelationshipTemplate relationshipTemplate : nodeTemplate.getRelationships().values()) {
RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
removeInputIdInProperties(relationshipTemplate.getProperties(), relationshipType.getProperties(), operation.getInputName());
}
}
if (nodeTemplate.getCapabilities() != null) {
for (Capability capability : nodeTemplate.getCapabilities().values()) {
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
removeInputIdInProperties(capability.getProperties(), capabilityType.getProperties(), operation.getInputName());
}
}
}
deletePreConfiguredInput(csar, topology, operation);
inputs.remove(operation.getInputName());
log.debug("Remove the input " + operation.getInputName() + " from the topology " + topology.getId());
}
use of org.alien4cloud.tosca.model.types.NodeType 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.types.NodeType in project alien4cloud by alien4cloud.
the class AddNodeProcessor method process.
@Override
public void process(Csar csar, Topology topology, AddNodeOperation operation) {
NameValidationUtils.validateNodeName(operation.getNodeName());
AlienUtils.failIfExists(topology.getNodeTemplates(), operation.getNodeName(), "A node template with the given name {} already exists in the topology {}.", operation.getNodeName(), topology.getId());
NodeType nodeType = toscaTypeSearchService.findByIdOrFail(NodeType.class, operation.getIndexedNodeTypeId());
if (nodeType.getSubstitutionTopologyId() != null) {
// it's a try to add this topology's type
if (nodeType.getSubstitutionTopologyId().equals(topology.getId())) {
throw new CyclicReferenceException("Cyclic reference : a topology template can not reference itself");
}
// detect try to add a substitution topology that indirectly reference this one
topologyCompositionService.recursivelyDetectTopologyCompositionCyclicReference(topology.getId(), nodeType.getSubstitutionTopologyId());
}
if (topology.getNodeTemplates() == null) {
topology.setNodeTemplates(new LinkedHashMap<>());
}
log.debug("Create node template [ {} ]", operation.getNodeName());
NodeType loadedIndexedNodeType = topologyService.loadType(topology, nodeType);
NodeTemplate nodeTemplate = TemplateBuilder.buildNodeTemplate(loadedIndexedNodeType);
nodeTemplate.setName(operation.getNodeName());
if (operation.getCoords() != null) {
// Set the position information of the node as meta-data.
nodeTemplate.setTags(Lists.newArrayList(new Tag(Constants.X_META, String.valueOf(operation.getCoords().getX())), new Tag(Constants.Y_META, String.valueOf(operation.getCoords().getY()))));
}
topology.getNodeTemplates().put(operation.getNodeName(), nodeTemplate);
log.debug("Adding a new Node template <" + operation.getNodeName() + "> bound to the node type <" + operation.getIndexedNodeTypeId() + "> to the topology <" + topology.getId() + "> .");
TopologyContext topologyContext = workflowBuilderService.buildTopologyContext(topology, csar);
workflowBuilderService.addNode(topologyContext, operation.getNodeName());
if (!operation.isSkipAutoCompletion()) {
danglingRequirementService.addDanglingRequirements(topology, topologyContext, nodeTemplate, operation.getRequirementSkipAutoCompletion());
}
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class DuplicateNodeProcessor method duplicateNodeTemplate.
private void duplicateNodeTemplate(NodeTemplate nodeTemplateToDuplicate, Map<String, String> duplicatedNodesNameMappings, Map<String, NodeTemplate> nodeTemplates, Topology topology, Csar csar) {
// Build the new one
NodeTemplate newNodeTemplate = CloneUtil.clone(nodeTemplateToDuplicate);
newNodeTemplate.setName(copyName(nodeTemplateToDuplicate.getName(), nodeTemplates.keySet()));
// load type
NodeType type = ToscaContext.getOrFail(NodeType.class, nodeTemplateToDuplicate.getType());
topologyService.loadType(topology, type);
log.debug("Duplicating node template [ {} ] into [ {} ] on the topology [ {} ] .", nodeTemplateToDuplicate.getName(), newNodeTemplate.getName(), topology.getId());
// Put the new one in the topology
nodeTemplates.put(newNodeTemplate.getName(), newNodeTemplate);
// register the name mapping for further use
duplicatedNodesNameMappings.put(nodeTemplateToDuplicate.getName(), newNodeTemplate.getName());
// copy outputs
copyOutputs(topology, nodeTemplateToDuplicate.getName(), newNodeTemplate.getName());
TopologyContext topologyContext = workflowBuilderService.buildTopologyContext(topology, csar);
// add the new node to the workflow
workflowBuilderService.addNode(topologyContext, newNodeTemplate.getName());
// copy hosted nodes
safe(TopologyNavigationUtil.getHostedNodes(topology, nodeTemplateToDuplicate.getName())).forEach(nodeTemplate -> duplicateNodeTemplate(nodeTemplate, duplicatedNodesNameMappings, nodeTemplates, topology, csar));
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class ResetNodeDeploymentArtifactProcessor method process.
@Override
public void process(Csar csar, Topology topology, ResetNodeDeploymentArtifactOperation operation) {
// Get the node template's artifacts to reset
Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates);
DeploymentArtifact currentArtifact = nodeTemplate.getArtifacts() == null ? null : nodeTemplate.getArtifacts().get(operation.getArtifactName());
if (currentArtifact == null) {
throw new NotFoundException("Artifact with key [" + operation.getArtifactName() + "] do not exist in node template [" + nodeTemplate.getName() + "].");
}
// Get the node type's artifact
Map<String, NodeType> nodeTypes = topologyServiceCore.getIndexedNodeTypesFromTopology(topology, false, false, true);
NodeType nodeType = nodeTypes.get(nodeTemplate.getType());
DeploymentArtifact artifactFromNodeType = nodeType.getArtifacts() == null ? null : nodeType.getArtifacts().get(operation.getArtifactName());
if (artifactFromNodeType == null) {
throw new NotFoundException("Artifact with key [" + operation.getArtifactName() + "] do not exist in node type [" + nodeType.getId() + "].");
}
currentArtifact.setArtifactRef(artifactFromNodeType.getArtifactRef());
currentArtifact.setArtifactName(artifactFromNodeType.getArtifactName());
currentArtifact.setArtifactType(artifactFromNodeType.getArtifactType());
currentArtifact.setArtifactRepository(artifactFromNodeType.getArtifactRepository());
currentArtifact.setRepositoryName(artifactFromNodeType.getRepositoryName());
currentArtifact.setRepositoryURL(artifactFromNodeType.getRepositoryURL());
currentArtifact.setRepositoryCredential(artifactFromNodeType.getRepositoryCredential());
}
Aggregations