Search in sources :

Example 16 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class DefaultNodeMatcherTest method abstract_template_should_be_matched_if_service_is_available_2.

@Test
public void abstract_template_should_be_matched_if_service_is_available_2() throws Exception {
    // Given
    Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>();
    // When
    NodeTemplate wantedNodeTemplate = nodeTemplate("alien.service.MongoDB");
    NodeType wantedNodeType = new NodeType();
    wantedNodeType.setAbstract(true);
    List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, wantedNodeType, locationResources, emptyMatchingConfigurations);
    // Then
    assertThat(proposition).hasSize(1);
    assertThat(proposition.get(0).isService()).isTrue();
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) HashMap(java.util.HashMap) MatchingConfiguration(alien4cloud.model.deployment.matching.MatchingConfiguration) NodeType(org.alien4cloud.tosca.model.types.NodeType) Test(org.junit.Test)

Example 17 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class TopologySubstitutionService method fillRequirements.

private void fillRequirements(Topology topology, NodeType substituteNodeType) {
    if (topology.getSubstitutionMapping().getRequirements() != null) {
        for (Map.Entry<String, SubstitutionTarget> e : topology.getSubstitutionMapping().getRequirements().entrySet()) {
            String key = e.getKey();
            String nodeName = e.getValue().getNodeTemplateName();
            String requirementName = e.getValue().getTargetId();
            NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
            NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
            RequirementDefinition requirementDefinition = IndexedModelUtils.getRequirementDefinitionById(nodeTemplateType.getRequirements(), requirementName);
            // We cannot change the capability definition here or we will change the original one so we need a clone
            requirementDefinition = CloneUtil.clone(requirementDefinition);
            requirementDefinition.setId(key);
            substituteNodeType.getRequirements().add(requirementDefinition);
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) Map(java.util.Map)

Example 18 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class TopologySubstitutionService method fillCapabilities.

private void fillCapabilities(Topology topology, NodeType substituteNodeType) {
    if (topology.getSubstitutionMapping().getCapabilities() != null) {
        for (Map.Entry<String, SubstitutionTarget> e : topology.getSubstitutionMapping().getCapabilities().entrySet()) {
            String key = e.getKey();
            String nodeName = e.getValue().getNodeTemplateName();
            String capabilityName = e.getValue().getTargetId();
            NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
            NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
            CapabilityDefinition capabilityDefinition = IndexedModelUtils.getCapabilityDefinitionById(nodeTemplateType.getCapabilities(), capabilityName);
            // We cannot change the capability definition here or we will change the original one so we need a clone
            capabilityDefinition = CloneUtil.clone(capabilityDefinition);
            capabilityDefinition.setId(key);
            substituteNodeType.getCapabilities().add(capabilityDefinition);
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) Map(java.util.Map)

Example 19 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class TopologySubstitutionService method fillSubstituteAttributesFromOutputProperties.

private void fillSubstituteAttributesFromOutputProperties(Topology topology, NodeType substituteNodeType) {
    Map<String, Set<String>> outputProperties = topology.getOutputProperties();
    if (outputProperties != null) {
        for (Map.Entry<String, Set<String>> ope : outputProperties.entrySet()) {
            String nodeName = ope.getKey();
            NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
            NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
            for (String propertyName : ope.getValue()) {
                PropertyDefinition pd = nodeTemplateType.getProperties().get(propertyName);
                // is a conflict
                addAttributeFromPropertyDefinition(pd, propertyName, substituteNodeType);
            }
        }
    }
}
Also used : Set(java.util.Set) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Map(java.util.Map) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 20 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class TopologySubstitutionService method updateSubstitutionType.

@ToscaContextual
public void updateSubstitutionType(final Topology topology, Csar csar) {
    if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) {
        return;
    }
    // first we update the csar and the dependencies
    NodeType nodeType = ToscaContext.getOrFail(NodeType.class, topology.getSubstitutionMapping().getSubstitutionType());
    if (csar.getDependencies() == null) {
        csar.setDependencies(Sets.newHashSet());
    }
    boolean updateCsar = false;
    if (csar.getDependencies().add(csarDependencyLoader.buildDependencyBean(nodeType.getArchiveName(), nodeType.getArchiveVersion()))) {
        updateCsar = true;
    }
    Path archiveGitPath = csarRepositry.getExpandedCSAR(csar.getName(), csar.getVersion());
    String hash = FileUtil.deepSHA1(archiveGitPath);
    if (!hash.equals(csar.getHash())) {
        csar.setHash(hash);
        updateCsar = true;
    }
    if (updateCsar) {
        csarService.save(csar);
    }
    // We create the nodeType that will serve as substitute
    NodeType substituteNodeType = buildSubstituteNodeType(topology, csar, nodeType);
    // inputs from topology become properties of type
    substituteNodeType.setProperties(topology.getInputs());
    // output attributes become attributes for the type
    fillSubstituteAttributesFromTypeAtttributes(topology, substituteNodeType);
    // output properties become attributes for the type
    fillSubstituteAttributesFromOutputProperties(topology, substituteNodeType);
    // output capabilities properties also become attributes for the type
    fillAttributesFromOutputCapabilitiesProperties(topology, substituteNodeType);
    // capabilities substitution
    fillCapabilities(topology, substituteNodeType);
    // requirement substitution
    fillRequirements(topology, substituteNodeType);
    // finally we index the created type
    indexerService.indexInheritableElement(csar.getName(), csar.getVersion(), substituteNodeType, csar.getDependencies());
    // Dispatch event
    publisher.publishEvent(new SubstitutionTypeChangedEvent(this, topology, substituteNodeType));
}
Also used : Path(java.nio.file.Path) SubstitutionTypeChangedEvent(org.alien4cloud.tosca.editor.events.SubstitutionTypeChangedEvent) NodeType(org.alien4cloud.tosca.model.types.NodeType) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

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