Search in sources :

Example 41 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class TemplateBuilder method buildNodeTemplate.

/**
 * Build a node template. Note that a Tosca Context is required.
 *
 * @param nodeType the type of the node
 * @param templateToMerge the template that can be used to merge into the new node template
 * @param adaptToType This flag allow to know if we should adapt the templateToMerge node to the type.
 * @return new constructed node template.
 */
public static NodeTemplate buildNodeTemplate(NodeType nodeType, NodeTemplate templateToMerge, boolean adaptToType) {
    // clone the type of the node to avoid impacts, this should be improved in the future
    nodeType = CloneUtil.clone(nodeType);
    NodeTemplate nodeTemplate = new NodeTemplate();
    fillAbstractInstantiableTemplate(nodeTemplate, nodeType, templateToMerge, !adaptToType);
    nodeTemplate.setCapabilities(Maps.newLinkedHashMap());
    nodeTemplate.setRequirements(Maps.newLinkedHashMap());
    fillCapabilitiesMap(nodeTemplate.getCapabilities(), nodeType.getCapabilities(), templateToMerge != null ? templateToMerge.getCapabilities() : null, adaptToType);
    fillRequirementsMap(nodeTemplate.getRequirements(), nodeType.getRequirements(), templateToMerge != null ? templateToMerge.getRequirements() : null, adaptToType);
    if (templateToMerge != null && templateToMerge.getRelationships() != null) {
        nodeTemplate.setRelationships(templateToMerge.getRelationships());
    }
    return nodeTemplate;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate)

Example 42 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class TopologyUtils method renameNodeTemplate.

/**
 * Rename formattedOldNodeName node template of a topology.
 *
 * @param topology
 * @param nodeTemplateName
 * @param newNodeTemplateName
 */
public static void renameNodeTemplate(Topology topology, String nodeTemplateName, String newNodeTemplateName) {
    Map<String, NodeTemplate> nodeTemplates = getNodeTemplates(topology);
    NodeTemplate nodeTemplate = getNodeTemplate(topology.getId(), nodeTemplateName, nodeTemplates);
    nodeTemplate.setName(newNodeTemplateName);
    nodeTemplates.put(newNodeTemplateName, nodeTemplate);
    nodeTemplates.remove(nodeTemplateName);
    refreshNodeTempNameInRelationships(nodeTemplateName, newNodeTemplateName, nodeTemplates);
    updateOnNodeTemplateNameChange(nodeTemplateName, newNodeTemplateName, topology);
    updateGroupMembers(topology, nodeTemplate, nodeTemplateName, newNodeTemplateName);
    updatePolicyMembers(topology, nodeTemplateName, newNodeTemplateName);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate)

Example 43 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class TopologyNavigationUtil method getHostOfTypeInHostingHierarchy.

/**
 * Deeply explore the hosted_on hierarchy of the given node to find a node of the given type.
 */
public static NodeTemplate getHostOfTypeInHostingHierarchy(Topology topology, NodeTemplate nodeTemplate, String hostType) {
    if (nodeTemplate.getRelationships() != null) {
        for (RelationshipTemplate relationshipTemplate : nodeTemplate.getRelationships().values()) {
            RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
            if (isOfType(relationshipType, NormativeRelationshipConstants.HOSTED_ON)) {
                NodeTemplate hostNode = topology.getNodeTemplates().get(relationshipTemplate.getTarget());
                NodeType hostNodeType = ToscaContext.get(NodeType.class, hostNode.getType());
                if (isOfType(hostNodeType, hostType)) {
                    return hostNode;
                } else {
                    return getHostOfTypeInHostingHierarchy(topology, hostNode, hostType);
                }
            }
        }
    }
    return null;
}
Also used : RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType)

Example 44 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class DanglingRequirementService method addDanglingNodes.

private void addDanglingNodes(Topology topology, TopologyContext topologyContext, NodeTemplate nodeTemplate, RequirementDefinition requirementDefinition, int count) {
    // TODO If the TOSCA context does not has the TOSCA normative types then add it automatically
    String danglingTemplateType = requirementDefinition.getNodeType() == null ? NormativeTypesConstant.ROOT_NODE_TYPE : requirementDefinition.getNodeType();
    NodeType danglingNodeType = ToscaContext.get(NodeType.class, danglingTemplateType);
    List<CapabilityDefinition> compatibleCapabilityByType = capabilityMatcherService.getCompatibleCapabilityByType(danglingNodeType, requirementDefinition.getType());
    CapabilityDefinition targetCapabilityDefinition = compatibleCapabilityByType.size() == 0 ? null : compatibleCapabilityByType.get(0);
    RelationshipType danglingRelationshipType = fetchValidRelationshipType(requirementDefinition, targetCapabilityDefinition);
    // check if the type is scalable (then count is used as a scalability parameter) or if we should add multiple instances
    CapabilityDefinition scalable = NodeTypeUtils.getCapabilityByType(danglingNodeType, NormativeCapabilityTypes.SCALABLE);
    if (scalable == null) {
        scalable = NodeTypeUtils.getCapabilityByType(danglingNodeType, AlienCapabilityTypes.CLUSTER_CONTROLLER);
    }
    List<NodeTemplate> addedNodes = Lists.newArrayList();
    if (scalable == null) {
        for (int i = 0; i < count; i++) {
            NodeTemplate addedNode = addDanglingNode(topology, topologyContext, nodeTemplate, requirementDefinition, danglingNodeType, danglingRelationshipType, targetCapabilityDefinition);
            addedNodes.add(addedNode);
        }
    } else {
        NodeTemplate danglingTemplate = addDanglingNode(topology, topologyContext, nodeTemplate, requirementDefinition, danglingNodeType, danglingRelationshipType, targetCapabilityDefinition);
        Capability scalableCapability = danglingTemplate.getCapabilities().get(scalable.getId());
        TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, count, scalableCapability);
        TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_MAX_INSTANCES, requirementDefinition.getUpperBound(), scalableCapability);
        addedNodes.add(danglingTemplate);
    }
    // Recursively add dangling nodes.
    for (NodeTemplate addedNode : addedNodes) {
        addDanglingRequirements(topology, topologyContext, addedNode, null);
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) EqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)

Example 45 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate 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)

Aggregations

NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)162 NodeType (org.alien4cloud.tosca.model.types.NodeType)52 Map (java.util.Map)40 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)37 Test (org.junit.Test)32 Capability (org.alien4cloud.tosca.model.templates.Capability)27 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)25 Topology (org.alien4cloud.tosca.model.templates.Topology)22 NotFoundException (alien4cloud.exception.NotFoundException)17 Then (cucumber.api.java.en.Then)15 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)15 HashMap (java.util.HashMap)14 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)13 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)13 TopologyDTO (alien4cloud.topology.TopologyDTO)12 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)12 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)11 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)11 DeploymentArtifact (org.alien4cloud.tosca.model.definitions.DeploymentArtifact)10 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)10