Search in sources :

Example 1 with RequirementDefinition

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

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

the class TopologyDTOBuilder method getCapabilityTypes.

private <T extends Topology> Map<String, CapabilityType> getCapabilityTypes(AbstractTopologyDTO<T> topologyDTO) {
    Map<String, CapabilityType> types = Maps.newHashMap();
    Map<String, NodeType> delayedNodeTypeAddMap = Maps.newHashMap();
    for (NodeType nodeType : topologyDTO.getNodeTypes().values()) {
        if (nodeType != null) {
            for (CapabilityDefinition capabilityDefinition : safe(nodeType.getCapabilities())) {
                types.put(capabilityDefinition.getType(), ToscaContext.get(CapabilityType.class, capabilityDefinition.getType()));
            }
            for (RequirementDefinition requirementDefinition : safe(nodeType.getRequirements())) {
                CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, requirementDefinition.getType());
                if (capabilityType != null) {
                    types.put(requirementDefinition.getType(), capabilityType);
                } else {
                    // requirements are authorized to be a node type rather than a capability type TODO is it still possible in TOSCA ?
                    NodeType indexedNodeType = ToscaContext.get(NodeType.class, requirementDefinition.getType());
                    // add it to the actual node types map
                    delayedNodeTypeAddMap.put(requirementDefinition.getType(), indexedNodeType);
                }
            }
        }
    }
    for (Map.Entry<String, NodeType> delayedNodeType : delayedNodeTypeAddMap.entrySet()) {
        topologyDTO.getNodeTypes().put(delayedNodeType.getKey(), delayedNodeType.getValue());
    }
    return types;
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with RequirementDefinition

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

the class ToscaParserSimpleProfileAlien130Test method getMockedSoftwareComponent.

private NodeType getMockedSoftwareComponent() {
    NodeType mockedSoftware = new NodeType();
    mockedSoftware.setArchiveName("tosca-normative-types");
    mockedSoftware.setArchiveVersion("1.0.0.wd03-SNAPSHOT");
    RequirementDefinition hostRequirement = new RequirementDefinition("host", "tosca.capabilities.Container", null, "", "tosca.relationships.HostedOn", "host", 1, Integer.MAX_VALUE, null);
    mockedSoftware.setRequirements(Lists.<RequirementDefinition>newArrayList(hostRequirement));
    mockedSoftware.setElementId("tosca.nodes.SoftwareComponent");
    return mockedSoftware;
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition)

Example 4 with RequirementDefinition

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

the class AbstractToscaParserSimpleProfileTest method testNodeType.

@SuppressWarnings("unchecked")
@Test
public void testNodeType() throws FileNotFoundException, ParsingException {
    Mockito.reset(csarRepositorySearchService);
    NodeType mockedResult = Mockito.mock(NodeType.class);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockedResult);
    Mockito.when(mockedResult.getDerivedFrom()).thenReturn(Lists.newArrayList("tosca.nodes.Root"));
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockedResult);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedResult);
    CapabilityType mockedCapabilityResult = Mockito.mock(CapabilityType.class);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("mytypes.mycapabilities.MyCapabilityTypeName"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("mytypes.mycapabilities.MyCapabilityTypeName"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Endpoint"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
    RelationshipType hostedOn = new RelationshipType();
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(hostedOn);
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-node-type.yml"));
    ParserTestUtil.displayErrors(parsingResult);
    assertNoBlocker(parsingResult);
    ArchiveRoot archiveRoot = parsingResult.getResult();
    Assert.assertNotNull(archiveRoot.getArchive());
    Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
    Assert.assertEquals(1, archiveRoot.getNodeTypes().size());
    // check node type.
    NodeType nodeType = archiveRoot.getNodeTypes().get("my_company.my_types.MyAppNodeType");
    Assert.assertNotNull(nodeType);
    Assert.assertEquals(Lists.newArrayList("tosca.nodes.SoftwareComponent", "tosca.nodes.Root"), nodeType.getDerivedFrom());
    Assert.assertEquals("My company’s custom applicaton", nodeType.getDescription());
    // validate properties parsing
    Assert.assertEquals(4, nodeType.getProperties().size());
    PropertyDefinition def1 = new PropertyDefinition();
    def1.setType("string");
    def1.setDefault(new ScalarPropertyValue("default"));
    def1.setDescription("application password");
    List<PropertyConstraint> constraints = Lists.newArrayList();
    constraints.add(new MinLengthConstraint(6));
    constraints.add(new MaxLengthConstraint(10));
    def1.setConstraints(constraints);
    PropertyDefinition def2 = new PropertyDefinition();
    def2.setType("integer");
    def2.setDescription("application port number");
    PropertyDefinition def3 = new PropertyDefinition();
    def3.setType("scalar-unit.size");
    def3.setDefault(new ScalarPropertyValue("1 GB"));
    LessThanConstraint ltConstraint = new LessThanConstraint();
    ltConstraint.setLessThan("1 TB");
    constraints = Lists.<PropertyConstraint>newArrayList(ltConstraint);
    def3.setConstraints(constraints);
    PropertyDefinition def4 = new PropertyDefinition();
    def4.setType("scalar-unit.time");
    def4.setDefault(new ScalarPropertyValue("1 d"));
    GreaterThanConstraint gtConstraint = new GreaterThanConstraint();
    gtConstraint.setGreaterThan("1 h");
    constraints = Lists.<PropertyConstraint>newArrayList(gtConstraint);
    def4.setConstraints(constraints);
    Assert.assertEquals(MapUtil.newHashMap(new String[] { "my_app_password", "my_app_duration", "my_app_size", "my_app_port" }, new PropertyDefinition[] { def1, def4, def3, def2 }), nodeType.getProperties());
    // check requirements
    Assert.assertEquals(2, nodeType.getRequirements().size());
    RequirementDefinition rd0 = nodeType.getRequirements().get(0);
    Assert.assertEquals("host", rd0.getId());
    Assert.assertEquals(1, rd0.getLowerBound());
    Assert.assertEquals(1, rd0.getUpperBound());
    RequirementDefinition rd1 = nodeType.getRequirements().get(1);
    Assert.assertEquals("other", rd1.getId());
    Assert.assertEquals(0, rd1.getLowerBound());
    Assert.assertEquals(Integer.MAX_VALUE, rd1.getUpperBound());
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Set(java.util.Set) MinLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) MaxLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint) LessThanConstraint(org.alien4cloud.tosca.model.definitions.constraints.LessThanConstraint) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) GreaterThanConstraint(org.alien4cloud.tosca.model.definitions.constraints.GreaterThanConstraint) Test(org.junit.Test)

Example 5 with RequirementDefinition

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

the class SearchTest method prepareToscaElement.

private void prepareToscaElement() {
    List<CapabilityDefinition> capa = Lists.newArrayList(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 = Lists.newArrayList(new RequirementDefinition("Runtime", "Runtime"), new RequirementDefinition("server", "server"), new RequirementDefinition("blob", "blob"));
    List<String> der = Lists.newArrayList("Parent1", "Parent2");
    indexedNodeTypeTest = createIndexedNodeType("1", "positive", "1.0", "", capa, req, der, new ArrayList<String>());
    indexedNodeTypeTest.setId("1");
    dataTest.add(indexedNodeTypeTest);
    capa = Lists.newArrayList(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 = Lists.newArrayList(new RequirementDefinition("Pant", "Pant"), new RequirementDefinition("DBZ", "DBZ"), new RequirementDefinition("Animes", "Animes"));
    der = Lists.newArrayList("Songoku", "Kami");
    indexedNodeTypeTest2 = createIndexedNodeType("2", "pokerFace", "1.0", "", capa, req, der, new ArrayList<String>());
    dataTest.add(indexedNodeTypeTest2);
    capa = Lists.newArrayList(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 = Lists.newArrayList(new RequirementDefinition("OnePiece", "OnePiece"), new RequirementDefinition("beelzebub", "beelzebub"), new RequirementDefinition("DBGT", "DBGT"));
    der = Lists.newArrayList("Jerome", "Sandrini");
    indexedNodeTypeTest3 = createIndexedNodeType("3", "nagative", "1.5", "", capa, req, der, new ArrayList<String>());
    dataTest.add(indexedNodeTypeTest3);
    capa = Lists.newArrayList(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 = Lists.newArrayList(new RequirementDefinition("Naruto", "Naruto"), new RequirementDefinition("FT", "FT"), new RequirementDefinition("Bleach", "Bleach"));
    der = Lists.newArrayList("Luc", "Boutier");
    indexedNodeTypeTest4 = createIndexedNodeType("4", "pokerFace", "2.0", "", capa, req, der, new ArrayList<String>());
    dataTest.add(indexedNodeTypeTest4);
}
Also used : ArrayList(java.util.ArrayList) 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