private void buildApplicationAgnosticMetadata() { if (toscaParser.getServiceTemplateOfTopology() != null) { this.setApplicationAgnosticMetadata( new ApplicationAgnosticMetadata(toscaParser.getServiceTemplateOfTopology())); } else { this.setApplicationAgnosticMetadata(new ApplicationAgnosticMetadata()); } }
private List<AgnosticDeploymentArtifact> getAgnosticDeploymentArtifacts( TNodeTemplate nodeTemplate) throws TopologyTemplateFormatException { List<AgnosticDeploymentArtifact> result; List<TDeploymentArtifact> deploymentArtifacts = toscaParser.getDeploymentArtifact(nodeTemplate); result = getAgnosticDeploymentArtifacts(deploymentArtifacts); return result; }
private void buildAgnosticComponentList() throws NodeTemplateTypeNotSupportedException, AgnosticPropertyException, TopologyTemplateFormatException { generatedAgnosticComponents = new LinkedList<>(); for (TNodeTemplate nodeTemplate : toscaParser.getNodeTemplatesOfTopology()) { generatedAgnosticComponents.add(buildAgnosticComponent(nodeTemplate)); } }
@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()); }
private AgnosticDeploymentArtifact getAgnosticDeploymentArtifact( TDeploymentArtifact deploymentArtifact) throws TopologyTemplateFormatException { TArtifactTemplate artifactTemplate = toscaParser.getArtifactTemplate(deploymentArtifact); if (artifactTemplate == null) { throwExceptionForNotFoundArtifactTemplate(deploymentArtifact); } return new AgnosticDeploymentArtifact(artifactTemplate); }
private void buildAgnosticComponentRelations() throws TopologyTemplateFormatException { MatchingDictionary capabilityIdsNodeTemplateIsDictionary = createCapabilityIdsNodeTemplateIdsDictionary(generatedAgnosticComponents); MatchingDictionary requirementIdsNodeTemplateIsDictionary = createRequirementIdsNodeTemplateIdsDictionary(generatedAgnosticComponents); agnosticRelations = new HashMap<>(); for (TRelationshipTemplate relationshipTemplate : toscaParser.getRelationshipTemplatesOfTopology()) { addRelationTemplateToAgnosticRelation( relationshipTemplate, capabilityIdsNodeTemplateIsDictionary, requirementIdsNodeTemplateIsDictionary); } }
@SuppressWarnings("unchecked") @Test public void testNodeType() throws FileNotFoundException, ParsingException { Mockito.reset(repositorySearchService); IndexedNodeType mockedResult = Mockito.mock(IndexedNodeType.class); Mockito.when( repositorySearchService.getElementInDependencies( Mockito.eq(IndexedNodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(List.class))) .thenReturn(mockedResult); Mockito.when(mockedResult.getDerivedFrom()).thenReturn(Lists.newArrayList("tosca.nodes.Root")); Mockito.when( repositorySearchService.getElementInDependencies( Mockito.eq(IndexedNodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(List.class))) .thenReturn(mockedResult); Mockito.when( repositorySearchService.getElementInDependencies( Mockito.eq(IndexedNodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(List.class))) .thenReturn(mockedResult); IndexedCapabilityType mockedCapabilityResult = Mockito.mock(IndexedCapabilityType.class); Mockito.when( repositorySearchService.getElementInDependencies( Mockito.eq(IndexedCapabilityType.class), Mockito.eq("mytypes.mycapabilities.MyCapabilityTypeName"), Mockito.any(List.class))) .thenReturn(mockedCapabilityResult); Mockito.when( repositorySearchService.getElementInDependencies( Mockito.eq(IndexedCapabilityType.class), Mockito.eq("mytypes.mycapabilities.MyCapabilityTypeName"), Mockito.any(List.class))) .thenReturn(mockedCapabilityResult); Mockito.when( repositorySearchService.getElementInDependencies( Mockito.eq(IndexedCapabilityType.class), Mockito.eq("tosca.capabilities.Endpoint"), Mockito.any(List.class))) .thenReturn(mockedCapabilityResult); IndexedRelationshipType hostedOn = new IndexedRelationshipType(); Mockito.when( repositorySearchService.getElementInDependencies( Mockito.eq(IndexedRelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(List.class))) .thenReturn(hostedOn); ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-node-type.yml")); 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. Entry<String, IndexedNodeType> entry = archiveRoot.getNodeTypes().entrySet().iterator().next(); Assert.assertEquals("my_company.my_types.MyAppNodeType", entry.getKey()); IndexedNodeType nodeType = entry.getValue(); 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()); // validate attributes parsing // nodeType.getAttributes() // nodeType.getInterfaces() // nodeType.getCapabilities() // nodeType.get }
private ToscaProcessor parsingApplicationTopology(File definitionFilePath) throws TopologyTemplateFormatException, NodeTemplateTypeNotSupportedException { toscaParser.parsingApplicationTopology(definitionFilePath); return this; }