Search in sources :

Example 51 with NodeType

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());
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) NotFoundException(alien4cloud.exception.NotFoundException)

Example 52 with NodeType

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);
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException) PropertyValueException(org.alien4cloud.tosca.editor.exception.PropertyValueException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 53 with NodeType

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());
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Tag(alien4cloud.model.common.Tag) TopologyContext(alien4cloud.paas.wf.TopologyContext) CyclicReferenceException(alien4cloud.exception.CyclicReferenceException)

Example 54 with NodeType

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));
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) TopologyContext(alien4cloud.paas.wf.TopologyContext)

Example 55 with NodeType

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());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

Aggregations

NodeType (org.alien4cloud.tosca.model.types.NodeType)156 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)50 Test (org.junit.Test)44 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)26 Set (java.util.Set)26 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)23 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)22 Map (java.util.Map)19 Csar (org.alien4cloud.tosca.model.Csar)19 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)16 HashMap (java.util.HashMap)15 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)15 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)14 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)14 Topology (org.alien4cloud.tosca.model.templates.Topology)9 NotFoundException (alien4cloud.exception.NotFoundException)8 Capability (org.alien4cloud.tosca.model.templates.Capability)8 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)8 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)7 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7