use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class TemplateBuilder method fillCapabilitiesMap.
private static void fillCapabilitiesMap(Map<String, Capability> map, List<CapabilityDefinition> elements, Map<String, Capability> mapToMerge, boolean adaptToType) {
if (elements == null) {
return;
}
for (CapabilityDefinition capa : elements) {
Capability toAddCapa = MapUtils.getObject(mapToMerge, capa.getId());
Map<String, AbstractPropertyValue> capaProperties = null;
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capa.getType());
if (capabilityType != null && capabilityType.getProperties() != null) {
// Inject all default values from the type.
capaProperties = PropertyUtil.getDefaultPropertyValuesFromPropertyDefinitions(capabilityType.getProperties());
// Override them with values as defined in the actual Capability Definition of the node type.
if (capa.getProperties() != null) {
capaProperties.putAll(capa.getProperties());
}
}
// only merge if the types are equals
if (toAddCapa == null || (StringUtils.isNotBlank(toAddCapa.getType()) && !Objects.equals(toAddCapa.getType(), capa.getType()))) {
toAddCapa = new Capability();
toAddCapa.setType(capa.getType());
toAddCapa.setProperties(capaProperties);
} else {
if (StringUtils.isBlank(toAddCapa.getType())) {
toAddCapa.setType(capa.getType());
}
if (MapUtils.isNotEmpty(capaProperties)) {
Map<String, AbstractPropertyValue> nodeCapaProperties = safe(toAddCapa.getProperties());
capaProperties.putAll(nodeCapaProperties);
toAddCapa.setProperties(capaProperties);
}
}
Map<String, AbstractPropertyValue> properties = Maps.newLinkedHashMap();
fillProperties(properties, capabilityType != null ? capabilityType.getProperties() : null, toAddCapa.getProperties(), adaptToType);
toAddCapa.setProperties(properties);
map.put(capa.getId(), toAddCapa);
}
}
use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class DanglingRequirementService method addDanglingNodes.
private void addDanglingNodes(Topology topology, TopologyContext topologyContext, NodeTemplate nodeTemplate, RequirementDefinition requirementDefinition, int count) {
// TODO If the TOSCA context does not has the TOSCA normative types then add it automatically
String danglingTemplateType = requirementDefinition.getNodeType() == null ? NormativeTypesConstant.ROOT_NODE_TYPE : requirementDefinition.getNodeType();
NodeType danglingNodeType = ToscaContext.get(NodeType.class, danglingTemplateType);
List<CapabilityDefinition> compatibleCapabilityByType = capabilityMatcherService.getCompatibleCapabilityByType(danglingNodeType, requirementDefinition.getType());
CapabilityDefinition targetCapabilityDefinition = compatibleCapabilityByType.size() == 0 ? null : compatibleCapabilityByType.get(0);
RelationshipType danglingRelationshipType = fetchValidRelationshipType(requirementDefinition, targetCapabilityDefinition);
// check if the type is scalable (then count is used as a scalability parameter) or if we should add multiple instances
CapabilityDefinition scalable = NodeTypeUtils.getCapabilityByType(danglingNodeType, NormativeCapabilityTypes.SCALABLE);
if (scalable == null) {
scalable = NodeTypeUtils.getCapabilityByType(danglingNodeType, AlienCapabilityTypes.CLUSTER_CONTROLLER);
}
List<NodeTemplate> addedNodes = Lists.newArrayList();
if (scalable == null) {
for (int i = 0; i < count; i++) {
NodeTemplate addedNode = addDanglingNode(topology, topologyContext, nodeTemplate, requirementDefinition, danglingNodeType, danglingRelationshipType, targetCapabilityDefinition);
addedNodes.add(addedNode);
}
} else {
NodeTemplate danglingTemplate = addDanglingNode(topology, topologyContext, nodeTemplate, requirementDefinition, danglingNodeType, danglingRelationshipType, targetCapabilityDefinition);
Capability scalableCapability = danglingTemplate.getCapabilities().get(scalable.getId());
TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, count, scalableCapability);
TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_MAX_INSTANCES, requirementDefinition.getUpperBound(), scalableCapability);
addedNodes.add(danglingTemplate);
}
// Recursively add dangling nodes.
for (NodeTemplate addedNode : addedNodes) {
addDanglingRequirements(topology, topologyContext, addedNode, null);
}
}
use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition 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);
}
use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class NodeFilterValidationService method validateNodeFilterCapabilities.
private void validateNodeFilterCapabilities(NodeFilter nodeFilter, NodeTemplate target, NodeType targetType, Map<String, CapabilityType> capabilityTypes, NodeFilterToSatisfy nodeFilterToSatisfy, boolean skipInputs) {
if (nodeFilter.getCapabilities() == null || nodeFilter.getCapabilities().isEmpty()) {
return;
}
Map<String, FilterDefinition> capabilities = nodeFilter.getCapabilities();
for (Map.Entry<String, FilterDefinition> filterDefinitionEntry : capabilities.entrySet()) {
String capabilityName = filterDefinitionEntry.getKey();
CapabilityDefinition definition = getCapabilityDefinition(targetType, capabilityName);
if (definition == null) {
nodeFilterToSatisfy.getMissingCapabilities().add(capabilityName);
continue;
}
CapabilityType capabilityType = capabilityTypes.get(definition.getType());
List<Violations> violations = validatePropertyFilters(filterDefinitionEntry.getValue().getProperties(), target.getCapabilities().get(definition.getId()).getProperties(), capabilityType.getProperties(), skipInputs);
violations.forEach(violation -> violation.capabilityName = capabilityName);
if (nodeFilterToSatisfy.getViolations() == null) {
nodeFilterToSatisfy.setViolations(violations);
} else {
nodeFilterToSatisfy.getViolations().addAll(violations);
}
}
}
use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.
the class DefineAsDefaultForCapabilityDefinitionsSteps method I_have_a_node_type_with_id_and_an_archive_version_with_capability.
@Given("^I have a node type with id \"([^\"]*)\" and an archive version \"([^\"]*)\" with capability \"([^\"]*)\"$")
public void I_have_a_node_type_with_id_and_an_archive_version_with_capability(String elementId, String archiveVersion, String capability) throws Throwable {
List<CapabilityDefinition> capabilities = Lists.newArrayList(new CapabilityDefinition(capability, capability, 1));
createOneIndexNodeType(elementId, archiveVersion, capabilities, true);
}
Aggregations