use of org.alien4cloud.tosca.model.types.CapabilityType 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);
}
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class SetNodeCapabilityPropertyAsInputProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, SetNodeCapabilityPropertyAsInputOperation operation, NodeTemplate nodeTemplate) {
Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} does not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
PropertyDefinition inputPropertyDefinition = getOrFail(topology.getInputs(), operation.getInputName(), "Input {} not found in topology", operation.getInputName());
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType());
PropertyDefinition capabilityPropertyDefinition = getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName());
// Check that the property definition of the input is indeed compatible with the property definition of the capability.
inputPropertyDefinition.checkIfCompatibleOrFail(capabilityPropertyDefinition);
FunctionPropertyValue getInput = new FunctionPropertyValue();
getInput.setFunction(ToscaFunctionConstants.GET_INPUT);
getInput.setParameters(Arrays.asList(operation.getInputName()));
capabilityTemplate.getProperties().put(operation.getPropertyName(), getInput);
log.debug("Associate the property [ {} ] of capability template [ {} ] of node [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class SetNodeCapabilityPropertyAsOutputProcessor method check.
private void check(SetNodeCapabilityPropertyAsOutputOperation operation, Topology topology, NodeTemplate nodeTemplate) {
if (nodeTemplate.getCapabilities() == null || nodeTemplate.getCapabilities().get(operation.getCapabilityName()) == null) {
throw new NotFoundException("Capability " + operation.getCapabilityName() + " not found in node template " + operation.getNodeName());
}
Capability capabilityTemplate = nodeTemplate.getCapabilities().get(operation.getCapabilityName());
CapabilityType indexedCapabilityType = EditionContextManager.get().getToscaContext().getElement(CapabilityType.class, capabilityTemplate.getType(), true);
if (indexedCapabilityType.getProperties() == null || !indexedCapabilityType.getProperties().containsKey(operation.getPropertyName())) {
throw new NotFoundException("Property " + operation.getPropertyName() + " not found in capability " + operation.getCapabilityName() + " of node " + operation.getNodeName());
}
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class UnsetNodeCapabilityPropertyAsInputProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodeCapabilityPropertyAsInputOperation operation, NodeTemplate nodeTemplate) {
Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} do not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
// check if the node property value is a get_input
AbstractPropertyValue currentValue = capabilityTemplate.getProperties().get(operation.getPropertyName());
if (!isGetInput(currentValue)) {
throw new NotFoundException("Property {} of node {} is not associated to an input.", operation.getPropertyName(), operation.getNodeName());
}
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType());
PropertyDefinition capabilityPropertyDefinition = getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName());
AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(capabilityPropertyDefinition);
capabilityTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
log.debug("Remove association from property [ {} ] of capability template [ {} ] of node [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
use of org.alien4cloud.tosca.model.types.CapabilityType 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);
}
}
}
Aggregations