Search in sources :

Example 11 with RequirementDefinition

use of org.alien4cloud.tosca.model.definitions.RequirementDefinition in project alien4cloud by alien4cloud.

the class EsDaoCrudTest method prepareToscaElement.

private void prepareToscaElement() {
    List<CapabilityDefinition> capa = Arrays.asList(new CapabilityDefinition("container", "container", 1), new CapabilityDefinition("container1", "container1", 1), new CapabilityDefinition("container2", "container2", 1), new CapabilityDefinition("container3", "container3", 1));
    List<RequirementDefinition> req = Arrays.asList(new RequirementDefinition("Runtime", "Runtime"), new RequirementDefinition("server", "server"), new RequirementDefinition("blob", "blob"));
    List<String> der = Arrays.asList("Parent1", "Parent2");
    indexedNodeTypeTest = TestModelUtil.createIndexedNodeType("1", "positive", "1.0", "", capa, req, der, new ArrayList<String>(0), threeTags, new Date(), new Date());
}
Also used : ArrayList(java.util.ArrayList) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) Date(java.util.Date)

Example 12 with RequirementDefinition

use of org.alien4cloud.tosca.model.definitions.RequirementDefinition in project alien4cloud by alien4cloud.

the class EsDaoSearchTest method prepareToscaElement.

private void prepareToscaElement() {
    List<CapabilityDefinition> capa = Arrays.asList(new CapabilityDefinition("container", "container", 1), new CapabilityDefinition("container1", "container1", 1), new CapabilityDefinition("container2", "container2", 1), new CapabilityDefinition("container3", "container3", 1), new CapabilityDefinition("war", "war", 1));
    List<RequirementDefinition> req = Arrays.asList(new RequirementDefinition("Runtime", "Runtime"), new RequirementDefinition("server", "server"), new RequirementDefinition("blob", "blob"));
    List<String> der = Arrays.asList("Parent1", "Parent2");
    indexedNodeTypeTest = TestModelUtil.createIndexedNodeType("1", "positive", "1.0", "", capa, req, der, new ArrayList<String>(), threeTags, new Date(), new Date());
    dataTest.add(indexedNodeTypeTest);
    capa = Arrays.asList(new CapabilityDefinition("banana", "banana", 1), new CapabilityDefinition("banana1", "banana1", 1), new CapabilityDefinition("container", "container", 1), new CapabilityDefinition("banana3", "banana3", 1), new CapabilityDefinition("zar", "zar", 1));
    req = Arrays.asList(new RequirementDefinition("Pant", "Pant"), new RequirementDefinition("DBZ", "DBZ"), new RequirementDefinition("Animes", "Animes"));
    der = Arrays.asList("Songoku", "Kami");
    indexedNodeTypeTest2 = TestModelUtil.createIndexedNodeType("2", "pokerFace", "1.0", "", capa, req, der, new ArrayList<String>(), threeTags, new Date(), new Date());
    dataTest.add(indexedNodeTypeTest2);
    capa = Arrays.asList(new CapabilityDefinition("potatoe", "potatoe", 1), new CapabilityDefinition("potatoe2", "potatoe2", 1), new CapabilityDefinition("potatoe3", "potatoe3", 1), new CapabilityDefinition("potatoe4", "potatoe4", 1), new CapabilityDefinition("zor", "zor", 1));
    req = Arrays.asList(new RequirementDefinition("OnePiece", "OnePiece"), new RequirementDefinition("beelzebub", "beelzebub"), new RequirementDefinition("DBGT", "DBGT"));
    der = Arrays.asList("Jerome", "Sandrini");
    indexedNodeTypeTest3 = TestModelUtil.createIndexedNodeType("3", "nagative", "1.5", "", capa, req, der, new ArrayList<String>(), threeTags, new Date(), new Date());
    dataTest.add(indexedNodeTypeTest3);
    capa = Arrays.asList(new CapabilityDefinition("yams", "yams", 1), new CapabilityDefinition("yams1", "yams1", 1), new CapabilityDefinition("positiveYes", "positiveYes", 1), new CapabilityDefinition("yams3", "yams3", 1), new CapabilityDefinition("war world", "war world", 1));
    req = Arrays.asList(new RequirementDefinition("Naruto", "Naruto"), new RequirementDefinition("FT", "FT"), new RequirementDefinition("Bleach", "Bleach"));
    der = Arrays.asList("Luc", "Boutier");
    indexedNodeTypeTest4 = TestModelUtil.createIndexedNodeType("4", "pokerFace", "2.0", "", capa, req, der, new ArrayList<String>(), threeTags, new Date(), new Date());
    dataTest.add(indexedNodeTypeTest4);
}
Also used : ArrayList(java.util.ArrayList) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) Date(java.util.Date)

Example 13 with RequirementDefinition

use of org.alien4cloud.tosca.model.definitions.RequirementDefinition in project alien4cloud by alien4cloud.

the class ReplaceNodeProcessor method updateRelationshipsCapabilitiesRelationships.

private void updateRelationshipsCapabilitiesRelationships(Topology topology, NodeTemplate nodeTemplate) {
    List<RelationshipEntry> targetRelationships = TopologyUtils.getTargetRelationships(nodeTemplate.getName(), topology.getNodeTemplates());
    for (RelationshipEntry targetRelationshipEntry : targetRelationships) {
        RelationshipTemplate targetRelationship = targetRelationshipEntry.getRelationship();
        Capability capability = safe(nodeTemplate.getCapabilities()).get(targetRelationship.getTargetedCapabilityName());
        if (capability == null || isCapabilityNotOfType(capability, targetRelationship.getRequirementType())) {
            Entry<String, Capability> capabilityEntry = NodeTemplateUtils.getCapabilitEntryyByType(nodeTemplate, targetRelationship.getRequirementType());
            targetRelationship.setTargetedCapabilityName(capabilityEntry.getKey());
            // check that the relationship type is still valid with the new capability
            RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, targetRelationship.getType());
            if (!isValidRelationship(relationshipType, capabilityEntry.getValue())) {
                NodeType sourceNodeType = ToscaContext.get(NodeType.class, targetRelationshipEntry.getSource().getType());
                RequirementDefinition requirementDefinition = NodeTypeUtils.getRequirementById(sourceNodeType, targetRelationshipEntry.getRelationship().getRequirementName());
                NodeType targetNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
                CapabilityDefinition capabilityDefinition = NodeTypeUtils.getCapabilityById(targetNodeType, capabilityEntry.getKey());
                RelationshipType validRelationshipType = danglingRequirementService.fetchValidRelationshipType(requirementDefinition, capabilityDefinition);
                targetRelationship.setType(validRelationshipType.getElementId());
                targetRelationship.setType(validRelationshipType.getElementId());
                targetRelationship.setArtifacts(newLinkedHashMap(safe(validRelationshipType.getArtifacts())));
                targetRelationship.setAttributes(newLinkedHashMap(safe(validRelationshipType.getAttributes())));
                Map<String, AbstractPropertyValue> properties = new LinkedHashMap();
                TemplateBuilder.fillProperties(properties, validRelationshipType.getProperties(), null);
                targetRelationship.setProperties(properties);
            }
        }
    }
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) LinkedHashMap(java.util.LinkedHashMap) Maps.newLinkedHashMap(com.google.common.collect.Maps.newLinkedHashMap) RelationshipEntry(org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 14 with RequirementDefinition

use of org.alien4cloud.tosca.model.definitions.RequirementDefinition in project alien4cloud by alien4cloud.

the class TopologySubstitutionService method buildSubstituteNodeType.

private NodeType buildSubstituteNodeType(Topology topology, Csar csar, NodeType nodeType) {
    NodeType substituteNodeType = new NodeType();
    substituteNodeType.setArchiveName(csar.getName());
    substituteNodeType.setArchiveVersion(csar.getVersion());
    substituteNodeType.setElementId(csar.getName());
    substituteNodeType.setDerivedFrom(Lists.newArrayList(nodeType.getElementId()));
    substituteNodeType.setSubstitutionTopologyId(topology.getId());
    substituteNodeType.setWorkspace(topology.getWorkspace());
    List<CapabilityDefinition> capabilities = Lists.newArrayList();
    substituteNodeType.setCapabilities(capabilities);
    List<RequirementDefinition> requirements = Lists.newArrayList();
    substituteNodeType.setRequirements(requirements);
    substituteNodeType.setAttributes(Maps.newHashMap());
    return substituteNodeType;
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition)

Example 15 with RequirementDefinition

use of org.alien4cloud.tosca.model.definitions.RequirementDefinition in project alien4cloud by alien4cloud.

the class ToscaWithDependenciesBuilder method buildNodeTypeWithDependencies.

private TypeWithDependenciesResult buildNodeTypeWithDependencies(NodeType nodeType) {
    TypeWithDependenciesResult result = new TypeWithDependenciesResult();
    result.setToscaType(nodeType);
    for (CapabilityDefinition capabilityDefinition : nodeType.getCapabilities()) {
        result.add(ToscaContext.getOrFail(CapabilityType.class, capabilityDefinition.getType()));
    }
    for (RequirementDefinition requirementDefinition : nodeType.getRequirements()) {
        CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, requirementDefinition.getType());
        if (capabilityType != null) {
            result.add(capabilityType);
        } else {
            // requirements are authorized to be a node type rather than a capability type TODO is it still possible in TOSCA ?
            result.add(ToscaContext.get(NodeType.class, requirementDefinition.getType()));
        }
    }
    result.setDependencies(ToscaContext.get().getDependencies());
    // Fetch data types for the given type
    DataTypesFetcher.getDataTypesDependencies(Collections.singleton(nodeType), ToscaContext::get).values().forEach(result::add);
    return result;
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) ToscaContext(alien4cloud.tosca.context.ToscaContext) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition)

Aggregations

RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)20 NodeType (org.alien4cloud.tosca.model.types.NodeType)14 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)11 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)5 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)4 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)4 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)3 Date (java.util.Date)3 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)3 Set (java.util.Set)2 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)2 NodeFilter (org.alien4cloud.tosca.model.definitions.NodeFilter)2 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)2 Capability (org.alien4cloud.tosca.model.templates.Capability)2 Requirement (org.alien4cloud.tosca.model.templates.Requirement)2 Test (org.junit.Test)2 FacetedSearchResult (alien4cloud.dao.model.FacetedSearchResult)1 NodeFilterToSatisfy (alien4cloud.topology.task.NodeFilterToSatisfy)1