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);
}
}
}
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;
}
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;
}
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());
}
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);
}
Aggregations