Search in sources :

Example 66 with ArchiveRoot

use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.

the class AbstractToscaParserSimpleProfileTest method testDefinitionVersionValid.

@Test
public void testDefinitionVersionValid() throws FileNotFoundException, ParsingException {
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-definition-version.yml"));
    Assert.assertEquals(0, parsingResult.getContext().getParsingErrors().size());
    ArchiveRoot archiveRoot = parsingResult.getResult();
    Assert.assertNotNull(archiveRoot.getArchive());
    Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) Test(org.junit.Test)

Example 67 with ArchiveRoot

use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.

the class ToscaParserAlien200Test method parseTopologyTemplateWithActivities.

@Test
public void parseTopologyTemplateWithActivities() throws ParsingException {
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-activities.yml"));
    assertFalse(parsingResult.getResult().getTopology().getWorkflows().isEmpty());
    assertNotNull(parsingResult.getResult().getTopology().getWorkflows().get("install"));
    Workflow wf = parsingResult.getResult().getTopology().getWorkflows().get("install");
    // check activities
    assertEquals(1, wf.getSteps().get("Compute_install").getActivities().size());
    assertEquals(1, wf.getSteps().get("Compute_install_0").getActivities().size());
    assertEquals(1, wf.getSteps().get("Compute_install_1").getActivities().size());
    // check activities of an other step
    assertTrue(wf.getSteps().get("Compute_uninstall").getActivities().size() == 1);
    assertTrue(wf.getSteps().get("Compute_uninstall_0").getActivities().size() == 1);
    assertEquals(1, wf.getSteps().get("Compute_install").getOnSuccess().size());
    assertEquals(1, wf.getSteps().get("Compute_install_0").getOnSuccess().size());
    assertEquals(1, wf.getSteps().get("Compute_install_1").getOnSuccess().size());
    assertEquals(1, wf.getSteps().get("Compute_uninstall").getOnSuccess().size());
    assertEquals(0, wf.getSteps().get("Compute_uninstall_0").getOnSuccess().size());
    // check onSuccess
    assertTrue(wf.getSteps().get("Compute_install").getOnSuccess().contains("Compute_install_0"));
    assertTrue(wf.getSteps().get("Compute_install_0").getOnSuccess().contains("Compute_install_1"));
    assertTrue(wf.getSteps().get("Compute_install_1").getOnSuccess().contains("Compute_uninstall"));
    assertTrue(wf.getSteps().get("Compute_uninstall").getOnSuccess().contains("Compute_uninstall_0"));
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Test(org.junit.Test)

Example 68 with ArchiveRoot

use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.

the class ToscaParserAlien200Test method parsingInvalidRelationshipTargetInWorkflowStepShouldFail.

@Test
public void parsingInvalidRelationshipTargetInWorkflowStepShouldFail() throws ParsingException {
    Mockito.reset(csarRepositorySearchService);
    Mockito.when(csarRepositorySearchService.getArchive("tosca-normative-types", "1.0.0-ALIEN14")).thenReturn(Mockito.mock(Csar.class));
    NodeType mockType = Mockito.mock(NodeType.class);
    Mockito.when(mockType.isAbstract()).thenReturn(true);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockType);
    Mockito.when(mockType.getCapabilities()).thenReturn(Lists.newArrayList(new CapabilityDefinition("host", "tosca.capabilities.Container", 1)));
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockType);
    mockType = Mockito.mock(NodeType.class);
    Mockito.when(mockType.getRequirements()).thenReturn(Lists.newArrayList(new RequirementDefinition("host", "tosca.capabilities.Container")));
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockType);
    CapabilityType mockCapaType = Mockito.mock(CapabilityType.class);
    Mockito.when(mockCapaType.getElementId()).thenReturn("tosca.capabilities.Container");
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Container"), Mockito.any(Set.class))).thenReturn(mockCapaType);
    RelationshipType mockRelType = Mockito.mock(RelationshipType.class);
    Mockito.when(mockRelType.getElementId()).thenReturn("tosca.relationships.HostedOn");
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(mockRelType);
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-workflow-relationship-operation-invalid-target.yml"));
    // Same error is duplicated but is it that bad ?
    assertEquals(2, parsingResult.getContext().getParsingErrors().size());
    assertEquals(ErrorCode.UNKNWON_WORKFLOW_STEP_RELATIONSHIP_TARGET, parsingResult.getContext().getParsingErrors().get(0).getErrorCode());
}
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) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) Test(org.junit.Test)

Example 69 with ArchiveRoot

use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.

the class ToscaParserAlien200Test method testPolicyTypeParsing.

@Test
public void testPolicyTypeParsing() throws ParsingException {
    Mockito.reset(csarRepositorySearchService);
    Mockito.when(csarRepositorySearchService.getArchive("tosca-normative-types", "1.0.0-ALIEN14")).thenReturn(Mockito.mock(Csar.class));
    PolicyType mockRoot = Mockito.mock(PolicyType.class);
    Mockito.when(mockRoot.isAbstract()).thenReturn(true);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(PolicyType.class), Mockito.eq("tosca.policies.Root"), Mockito.any(Set.class))).thenReturn(mockRoot);
    NodeType mockType = Mockito.mock(NodeType.class);
    Mockito.when(mockType.isAbstract()).thenReturn(true);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockType);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockType);
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-policy-type.yml"));
    assertEquals(0, parsingResult.getContext().getParsingErrors().size());
    ArchiveRoot archiveRoot = parsingResult.getResult();
    assertNotNull(archiveRoot.getArchive());
    assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
    assertEquals(3, archiveRoot.getPolicyTypes().size());
    PolicyType minPolicyType = archiveRoot.getPolicyTypes().get("org.alien4cloud.sample.MinimalPolicyType");
    assertNotNull(minPolicyType);
    assertEquals("org.alien4cloud.test.policies.PolicyTypes", minPolicyType.getArchiveName());
    assertEquals("2.0.0-SNAPSHOT", minPolicyType.getArchiveVersion());
    assertEquals("org.alien4cloud.sample.MinimalPolicyType", minPolicyType.getElementId());
    assertEquals("This is a sample policy type with minimal definition", minPolicyType.getDescription());
    assertEquals(1, minPolicyType.getDerivedFrom().size());
    assertEquals("tosca.policies.Root", minPolicyType.getDerivedFrom().get(0));
    PolicyType simplePolicyType = archiveRoot.getPolicyTypes().get("org.alien4cloud.sample.SimpleConditionPolicyType");
    assertNotNull(simplePolicyType);
    assertEquals("org.alien4cloud.test.policies.PolicyTypes", simplePolicyType.getArchiveName());
    assertEquals("2.0.0-SNAPSHOT", simplePolicyType.getArchiveVersion());
    assertEquals("org.alien4cloud.sample.SimpleConditionPolicyType", simplePolicyType.getElementId());
    assertEquals("This is a sample policy type with simple definition", simplePolicyType.getDescription());
    assertEquals(1, simplePolicyType.getDerivedFrom().size());
    assertEquals("tosca.policies.Root", simplePolicyType.getDerivedFrom().get(0));
    assertEquals(2, simplePolicyType.getTags().size());
    assertEquals("sample_meta", simplePolicyType.getTags().get(0).getName());
    assertEquals("a meta data", simplePolicyType.getTags().get(0).getValue());
    assertEquals("anoter_meta", simplePolicyType.getTags().get(1).getName());
    assertEquals("another meta data", simplePolicyType.getTags().get(1).getValue());
    assertEquals(1, simplePolicyType.getProperties().size());
    assertNotNull(simplePolicyType.getProperties().get("sample_property"));
    assertEquals("string", simplePolicyType.getProperties().get("sample_property").getType());
    assertEquals(2, simplePolicyType.getTargets().size());
    assertTrue(simplePolicyType.getTargets().contains("tosca.nodes.Compute"));
    assertTrue(simplePolicyType.getTargets().contains("tosca.nodes.Root"));
    PolicyType policyType = archiveRoot.getPolicyTypes().get("org.alien4cloud.sample.PolicyType");
    assertNotNull(policyType);
    assertEquals("org.alien4cloud.test.policies.PolicyTypes", policyType.getArchiveName());
    assertEquals("2.0.0-SNAPSHOT", policyType.getArchiveVersion());
    assertEquals("org.alien4cloud.sample.PolicyType", policyType.getElementId());
    assertEquals("This is a sample policy type", policyType.getDescription());
    assertEquals(1, policyType.getDerivedFrom().size());
    assertEquals("tosca.policies.Root", policyType.getDerivedFrom().get(0));
    assertEquals(2, policyType.getTags().size());
    assertEquals("sample_meta", policyType.getTags().get(0).getName());
    assertEquals("a meta data", policyType.getTags().get(0).getValue());
    assertEquals("anoter_meta", policyType.getTags().get(1).getName());
    assertEquals("another meta data", policyType.getTags().get(1).getValue());
    assertEquals(1, policyType.getProperties().size());
    assertNotNull(policyType.getProperties().get("sample_property"));
    assertEquals("string", policyType.getProperties().get("sample_property").getType());
    assertEquals(2, policyType.getTargets().size());
    assertTrue(simplePolicyType.getTargets().contains("tosca.nodes.Compute"));
    assertTrue(simplePolicyType.getTargets().contains("tosca.nodes.Root"));
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) PolicyType(org.alien4cloud.tosca.model.types.PolicyType) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) Test(org.junit.Test)

Example 70 with ArchiveRoot

use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.

the class ToscaParserAlien200Test method parseTopologyTemplateWithInlineWorkflow.

@Test
public void parseTopologyTemplateWithInlineWorkflow() throws ParsingException {
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-inline-workflow.yml"));
    assertFalse(parsingResult.getResult().getTopology().getWorkflows().isEmpty());
    assertNotNull(parsingResult.getResult().getTopology().getWorkflows().get("install"));
    Workflow wf = parsingResult.getResult().getTopology().getWorkflows().get("install");
    assertEquals(1, wf.getSteps().get("Compute_install_0").getActivities().size());
    assertTrue(wf.getSteps().get("Compute_install_0").getActivities().get(0) instanceof InlineWorkflowActivity);
    InlineWorkflowActivity activity = (InlineWorkflowActivity) wf.getSteps().get("Compute_install_0").getActivities().get(0);
    assertTrue(activity.getInline().equals("my_custom_wf"));
    WorkflowUtils.processInlineWorkflows(parsingResult.getResult().getTopology().getWorkflows());
    assertFalse(wf.getSteps().containsKey("Compute_install_0"));
    assertTrue(wf.getSteps().containsKey("Compute_install_0_Compute_stop"));
    assertTrue(wf.getSteps().containsKey("Compute_install_0_Compute_uninstall"));
    assertTrue(wf.getSteps().containsKey("Some_other_inline_Compute_stop"));
    assertTrue(wf.getSteps().containsKey("Some_other_inline_Compute_uninstall"));
    assertTrue(wf.getSteps().get("Compute_install").getOnSuccess().contains("Compute_install_0_Compute_stop"));
    assertTrue(wf.getSteps().get("Compute_install_0_Compute_stop").getPrecedingSteps().contains("Compute_install"));
    assertEquals(1, wf.getSteps().get("Compute_install").getOnSuccess().size());
    assertEquals(0, wf.getSteps().get("Compute_install").getPrecedingSteps().size());
    assertEquals(1, wf.getSteps().get("Compute_install_0_Compute_stop").getPrecedingSteps().size());
    assertFalse(wf.getSteps().get("Compute_install").getOnSuccess().contains("Compute_install_0_Compute_uninstall"));
    assertFalse(wf.getSteps().get("Compute_install_0_Compute_uninstall").getPrecedingSteps().contains("Compute_install"));
    assertTrue(wf.getSteps().get("Compute_install_0_Compute_stop").getOnSuccess().contains("Compute_install_0_Compute_uninstall"));
    assertTrue(wf.getSteps().get("Compute_install_0_Compute_uninstall").getPrecedingSteps().contains("Compute_install_0_Compute_stop"));
    assertEquals(1, wf.getSteps().get("Compute_install_0_Compute_stop").getOnSuccess().size());
    assertEquals(1, wf.getSteps().get("Compute_install_0_Compute_uninstall").getPrecedingSteps().size());
    assertEquals(1, wf.getSteps().get("Compute_install_0_Compute_uninstall").getOnSuccess().size());
    assertTrue(wf.getSteps().get("Compute_install_0_Compute_uninstall").getOnSuccess().contains("Compute_start"));
    assertTrue(wf.getSteps().get("Compute_start").getPrecedingSteps().contains("Compute_install_0_Compute_uninstall"));
    assertTrue(wf.getSteps().get("Some_other_inline_Compute_stop").getOnSuccess().contains("Some_other_inline_Compute_uninstall"));
    assertTrue(wf.getSteps().get("Some_other_inline_Compute_uninstall").getPrecedingSteps().contains("Some_other_inline_Compute_stop"));
    assertTrue(wf.getSteps().get("inception_inline_inception_inline_Compute_stop").getOnSuccess().contains("inception_inline_inception_inline_Compute_uninstall"));
    assertTrue(wf.getSteps().get("inception_inline_inception_inline_Compute_uninstall").getPrecedingSteps().contains("inception_inline_inception_inline_Compute_stop"));
}
Also used : InlineWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.InlineWorkflowActivity) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Test(org.junit.Test)

Aggregations

ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)76 Test (org.junit.Test)43 Set (java.util.Set)26 NodeType (org.alien4cloud.tosca.model.types.NodeType)26 Csar (org.alien4cloud.tosca.model.Csar)25 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)16 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)14 ParsingError (alien4cloud.tosca.parser.ParsingError)13 Path (java.nio.file.Path)11 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)9 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)8 Node (org.yaml.snakeyaml.nodes.Node)8 PluginArchive (alien4cloud.orchestrators.plugin.model.PluginArchive)6 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)6 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)6 ParsingException (alien4cloud.tosca.parser.ParsingException)5 Map (java.util.Map)5 Topology (org.alien4cloud.tosca.model.templates.Topology)5 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)4 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)4