Search in sources :

Example 16 with CapabilityDefinition

use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition 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 17 with CapabilityDefinition

use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition 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 18 with CapabilityDefinition

use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition 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 19 with CapabilityDefinition

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

Example 20 with CapabilityDefinition

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

the class EsQuickSearchTest 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("app", "Parent2");
    indexedNodeTypeTest = TestModelUtil.createIndexedNodeType("1", "app-1", "1.0", "", capa, req, der, new ArrayList<String>(), null, new Date(), new Date());
    componentDataTest.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>(), null, new Date(), new Date());
    componentDataTest.add(indexedNodeTypeTest2);
}
Also used : ArrayList(java.util.ArrayList) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) Date(java.util.Date)

Aggregations

CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)24 NodeType (org.alien4cloud.tosca.model.types.NodeType)16 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)11 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)9 Capability (org.alien4cloud.tosca.model.templates.Capability)5 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)5 ArrayList (java.util.ArrayList)4 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)4 Date (java.util.Date)3 Map (java.util.Map)3 Csar (org.alien4cloud.tosca.model.Csar)3 FacetedSearchResult (alien4cloud.dao.model.FacetedSearchResult)2 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)2 HashMap (java.util.HashMap)2 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)2 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)2 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)2 EqualConstraint (org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)2 RelationshipEntry (org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry)2 Test (org.junit.Test)2