Search in sources :

Example 36 with NodeType

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

the class ToscaParserSimpleProfileAlien130Test method testParseTopologyReferenceToNormative.

@Test
public void testParseTopologyReferenceToNormative() throws FileNotFoundException, ParsingException {
    Csar csar = new Csar("tosca-normative-types", "1.0.0.wd03-SNAPSHOT");
    NodeType mockedCompute = getMockedCompute();
    NodeType mockedSoftware = getMockedSoftwareComponent();
    CapabilityType mockedContainer = Mockito.mock(CapabilityType.class);
    Mockito.when(mockedContainer.getElementId()).thenReturn("tosca.capabilities.Container");
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockedSoftware);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Container"), Mockito.any(Set.class))).thenReturn(mockedContainer);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedCompute);
    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-topology-template-node-from-derived-type-from-import.yml"));
    Mockito.verify(csarRepositorySearchService).getArchive(csar.getName(), csar.getVersion());
    assertNoBlocker(parsingResult);
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Test(org.junit.Test)

Example 37 with NodeType

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

the class ToscaParserSimpleProfileAlien130Test method testCapabilities.

@Test
public void testCapabilities() throws ParsingException {
    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("tosca.capabilities.Endpoint"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Container"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
    RelationshipType connectsTo = new RelationshipType();
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.ConnectsTo"), Mockito.any(Set.class))).thenReturn(connectsTo);
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "requirement_capabilities.yaml"));
    ParserTestUtil.displayErrors(parsingResult);
    parsingResult.getResult().getNodeTypes().values().forEach(nodeType -> {
        nodeType.getRequirements().forEach(requirementDefinition -> {
            switch(requirementDefinition.getId()) {
                case "host":
                    Assert.assertEquals("tosca.capabilities.Container", requirementDefinition.getType());
                    break;
                case "endpoint":
                case "another_endpoint":
                    Assert.assertEquals("tosca.capabilities.Endpoint", requirementDefinition.getType());
                    Assert.assertEquals(0, requirementDefinition.getLowerBound());
                    Assert.assertEquals(Integer.MAX_VALUE, requirementDefinition.getUpperBound());
                    Assert.assertEquals("tosca.relationships.ConnectsTo", requirementDefinition.getRelationshipType());
                    break;
            }
        });
        nodeType.getCapabilities().forEach(capabilityDefinition -> {
            switch(capabilityDefinition.getId()) {
                case "host":
                    Assert.assertEquals("tosca.capabilities.Container", capabilityDefinition.getType());
                    break;
                case "endpoint":
                case "another_endpoint":
                    Assert.assertEquals("tosca.capabilities.Endpoint", capabilityDefinition.getType());
                    assertNotNull(capabilityDefinition.getDescription());
            }
        });
    });
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Test(org.junit.Test)

Example 38 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType 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 39 with NodeType

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

the class ToscaParserSimpleProfileAlien130Test method testParseTopologyWithWorkflows.

@Test
public void testParseTopologyWithWorkflows() throws FileNotFoundException, ParsingException {
    Csar csar = new Csar("tosca-normative-types", "1.0.0.wd03-SNAPSHOT");
    NodeType mockedCompute = getMockedCompute();
    NodeType mockedSoftware = getMockedSoftwareComponent();
    CapabilityType mockedContainer = Mockito.mock(CapabilityType.class);
    Mockito.when(mockedContainer.getElementId()).thenReturn("tosca.capabilities.Container");
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockedSoftware);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Container"), Mockito.any(Set.class))).thenReturn(mockedContainer);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedCompute);
    RelationshipType hostedOn = Mockito.mock(RelationshipType.class);
    Mockito.when(hostedOn.getElementId()).thenReturn("tosca.relationships.HostedOn");
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(hostedOn);
    Mockito.when(csarRepositorySearchService.getArchive(csar.getName(), csar.getVersion())).thenReturn(csar);
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-workflows.yml"));
    Mockito.verify(csarRepositorySearchService).getArchive(csar.getName(), csar.getVersion());
    assertNoBlocker(parsingResult);
    Assert.assertEquals(3, parsingResult.getContext().getParsingErrors().size());
    assertNotNull(parsingResult.getResult().getTopology());
    Assert.assertEquals(5, parsingResult.getResult().getTopology().getWorkflows().size());
    // check invalid names were renamed
    assertTrue(parsingResult.getResult().getTopology().getWorkflows().containsKey("invalidName_"));
    assertTrue(parsingResult.getResult().getTopology().getWorkflows().containsKey("invalid_Name"));
    assertTrue(parsingResult.getResult().getTopology().getWorkflows().containsKey("invalid_Name_1"));
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Test(org.junit.Test)

Example 40 with NodeType

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

the class ToscaParserSimpleProfileAlien130Test method testAttributesConcatValid.

@SuppressWarnings("unchecked")
@Test
public void testAttributesConcatValid() throws Throwable {
    Csar csar = new Csar("tosca-normative-types", "1.0.0-SNAPSHOT-wd03");
    // Mockito.when(csarRepositorySearchService.getArchive(csar.getId())).thenReturn(csar);
    NodeType mockedResult = Mockito.mock(NodeType.class);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedResult);
    Mockito.when(mockedResult.getId()).thenReturn("tosca.nodes.Compute:1.0.0-SNAPSHOT-wd03");
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-node-type-inputs.yml"));
    Mockito.verify(csarRepositorySearchService).getArchive(csar.getName(), csar.getVersion());
    assertNoBlocker(parsingResult);
    ArchiveRoot archiveRoot = parsingResult.getResult();
    assertNotNull(archiveRoot.getArchive());
    Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
    // check nodetype elements
    Entry<String, NodeType> entry = archiveRoot.getNodeTypes().entrySet().iterator().next();
    Assert.assertEquals("alien.test.TestComputeConcat", entry.getKey());
    NodeType nodeType = entry.getValue();
    nodeType.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
    Map<String, IValue> attributes = nodeType.getAttributes();
    IValue simpleDefinition = attributes.get("simple_definition");
    IValue ipAddressDefinition = attributes.get("ip_address");
    IValue simpleConcat = attributes.get("simple_concat");
    IValue complexConcat = attributes.get("complex_concat");
    // check attributes types
    assertTrue(simpleDefinition.getClass().equals(AttributeDefinition.class));
    assertTrue(ipAddressDefinition.getClass().equals(AttributeDefinition.class));
    assertTrue(simpleConcat.getClass().equals(ConcatPropertyValue.class));
    assertTrue(complexConcat.getClass().equals(ConcatPropertyValue.class));
    // Test nodeType serialization
    String nodeTypeJson = JsonUtil.toString(nodeType);
    // recover node from serialized string
    NodeType nodeTypeDeserialized = JsonUtil.readObject(nodeTypeJson, NodeType.class);
    assertNotNull(nodeTypeDeserialized);
    attributes = nodeTypeDeserialized.getAttributes();
    simpleDefinition = attributes.get("simple_definition");
    ipAddressDefinition = attributes.get("ip_address");
    simpleConcat = attributes.get("simple_concat");
    complexConcat = attributes.get("complex_concat");
    // check attributes types after deserialization
    assertTrue(simpleDefinition.getClass().equals(AttributeDefinition.class));
    assertTrue(ipAddressDefinition.getClass().equals(AttributeDefinition.class));
    assertTrue(simpleConcat.getClass().equals(ConcatPropertyValue.class));
    assertTrue(complexConcat.getClass().equals(ConcatPropertyValue.class));
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) IValue(org.alien4cloud.tosca.model.definitions.IValue) NodeType(org.alien4cloud.tosca.model.types.NodeType) AttributeDefinition(org.alien4cloud.tosca.model.definitions.AttributeDefinition) ConcatPropertyValue(org.alien4cloud.tosca.model.definitions.ConcatPropertyValue) Test(org.junit.Test)

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