use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class RelationshipPostProcessor method getCapabilityByType.
private Capability getCapabilityByType(NodeTemplate targetNodeTemplate, RelationshipTemplate relationshipTemplate, String capabilityType) {
Capability capability = null;
Map<String, Capability> compatibleCapabilityByType = capabilityMatcherService.getCompatibleCapabilityByType(targetNodeTemplate, capabilityType);
Entry<String, Capability> capabilityEntry = null;
if (compatibleCapabilityByType.size() == 1) {
capabilityEntry = compatibleCapabilityByType.entrySet().iterator().next();
} else if (compatibleCapabilityByType.size() > 1) {
capabilityEntry = compatibleCapabilityByType.entrySet().iterator().next();
Node node = ParsingContextExecution.getObjectToNodeMap().get(relationshipTemplate);
ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.REQUIREMENT_CAPABILITY_MULTIPLE_MATCH, null, node.getStartMark(), null, node.getEndMark(), relationshipTemplate.getRequirementName()));
}
if (capabilityEntry != null) {
capability = capabilityEntry.getValue();
relationshipTemplate.setTargetedCapabilityName(capabilityEntry.getKey());
}
return capability;
}
use of org.alien4cloud.tosca.model.templates.Capability 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.templates.Capability 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.templates.Capability in project alien4cloud by alien4cloud.
the class DeleteInputProcessor method processInputOperation.
@Override
protected void processInputOperation(Csar csar, Topology topology, DeleteInputOperation operation, Map<String, PropertyDefinition> inputs) {
if (!inputs.containsKey(operation.getInputName())) {
throw new NotFoundException("Input " + operation.getInputName() + "not found in topology");
}
for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
NodeType nodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
removeInputIdInProperties(nodeTemplate.getProperties(), nodeType.getProperties(), operation.getInputName());
if (nodeTemplate.getRelationships() != null) {
for (RelationshipTemplate relationshipTemplate : nodeTemplate.getRelationships().values()) {
RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
removeInputIdInProperties(relationshipTemplate.getProperties(), relationshipType.getProperties(), operation.getInputName());
}
}
if (nodeTemplate.getCapabilities() != null) {
for (Capability capability : nodeTemplate.getCapabilities().values()) {
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
removeInputIdInProperties(capability.getProperties(), capabilityType.getProperties(), operation.getInputName());
}
}
}
deletePreConfiguredInput(csar, topology, operation);
inputs.remove(operation.getInputName());
log.debug("Remove the input " + operation.getInputName() + " from the topology " + topology.getId());
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class UpdateCapabilityPropertyValueProcessor method process.
@Override
@SneakyThrows
public void process(Csar csar, Topology topology, UpdateCapabilityPropertyValueOperation operation) {
String propertyName = operation.getPropertyName();
Object propertyValue = operation.getPropertyValue();
Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates);
Capability capability = nodeTemplate.getCapabilities().get(operation.getCapabilityName());
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
if (!capabilityType.getProperties().containsKey(propertyName)) {
throw new NotFoundException("Property <" + propertyName + "> doesn't exists for node <" + operation.getNodeName() + "> of type <" + capabilityType + ">");
}
log.debug("Updating property [ {} ] of the capability [ {} ] for the Node template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", propertyName, capability.getType(), operation.getNodeName(), topology.getId(), capabilityType.getProperties().get(propertyName), propertyValue);
try {
propertyService.setCapabilityPropertyValue(capability, capabilityType.getProperties().get(propertyName), propertyName, propertyValue);
} catch (ConstraintFunctionalException e) {
throw new PropertyValueException("Error when setting node " + operation.getNodeName() + " property.", e, propertyName, propertyValue);
}
}
Aggregations