use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class SetNodePropertyAsInputProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, SetNodePropertyAsInputOperation operation, NodeTemplate nodeTemplate) {
PropertyDefinition inputPropertyDefinition = getOrFail(topology.getInputs(), operation.getInputName(), "Input {} not found in topology", operation.getInputName());
NodeType indexedNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
PropertyDefinition nodePropertyDefinition = getOrFail(indexedNodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName());
// Check that the property definition of the input is indeed compatible with the property definition of the capability.
inputPropertyDefinition.checkIfCompatibleOrFail(nodePropertyDefinition);
FunctionPropertyValue getInput = new FunctionPropertyValue();
getInput.setFunction(ToscaFunctionConstants.GET_INPUT);
getInput.setParameters(Arrays.asList(operation.getInputName()));
nodeTemplate.getProperties().put(operation.getPropertyName(), getInput);
log.debug("Associate the property [ {} ] of the node template [ {} ] to input [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), operation.getInputName(), topology.getId());
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition 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.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class TopologyPropertiesValidationService method addRequiredPropertyIdToTaskProperties.
private void addRequiredPropertyIdToTaskProperties(String prefix, Map<String, AbstractPropertyValue> properties, Map<String, PropertyDefinition> relatedProperties, PropertiesTask task, boolean skipInputProperties) {
for (Map.Entry<String, AbstractPropertyValue> propertyEntry : properties.entrySet()) {
PropertyDefinition propertyDef = relatedProperties.get(propertyEntry.getKey());
String propertyErrorKey = prefix == null ? propertyEntry.getKey() : prefix + "." + propertyEntry.getKey();
AbstractPropertyValue value = propertyEntry.getValue();
if (propertyDef != null && propertyDef.isRequired()) {
if (value == null) {
addRequiredPropertyError(task, propertyErrorKey);
} else if (value instanceof ScalarPropertyValue) {
String propertyValue = ((ScalarPropertyValue) value).getValue();
if (StringUtils.isBlank(propertyValue)) {
addRequiredPropertyError(task, propertyErrorKey);
}
} else if (value instanceof ComplexPropertyValue) {
Map<String, Object> mapValue = ((ComplexPropertyValue) value).getValue();
if (MapUtils.isEmpty(mapValue)) {
addRequiredPropertyError(task, propertyErrorKey);
}
} else if (value instanceof ListPropertyValue) {
List<Object> listValue = ((ListPropertyValue) value).getValue();
if (listValue.isEmpty()) {
addRequiredPropertyError(task, propertyErrorKey);
}
} else if (FunctionEvaluator.containGetSecretFunction(value)) {
// this is a get_secret function, we should not validate the get_secret here
continue;
} else if (skipInputProperties) {
// get_input Will be validated later on
continue;
} else {
addRequiredPropertyError(task, propertyErrorKey);
}
}
}
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class SetMatchedNodePropertyModifier method setNodeCapabilityProperty.
private void setNodeCapabilityProperty(FlowExecutionContext context, LocationResourceTemplate locationResourceTemplate, NodeTemplate nodeTemplate, String capabilityName, DeploymentMatchingConfiguration matchingConfiguration) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
Capability locationResourceCapability = locationResourceTemplate.getTemplate().getCapabilities().get(capabilityName);
if (locationResourceCapability == null) {
throw new NotFoundException("The capability <" + capabilityName + "> cannot be found on node template <" + templateId + "> of type <" + locationResourceTemplate.getTemplate().getType() + ">");
}
PropertyDefinition propertyDefinition = ToscaContext.getOrFail(CapabilityType.class, locationResourceCapability.getType()).getProperties().get(propertyName);
if (propertyDefinition == null) {
throw new NotFoundException("No property with name <" + propertyName + "> can be found on capability <" + capabilityName + "> of type <" + locationResourceCapability.getType() + ">");
}
AbstractPropertyValue locationResourcePropertyValue = locationResourceTemplate.getTemplate().getCapabilities().get(capabilityName).getProperties().get(propertyName);
ensureNotSet(locationResourcePropertyValue, "by the admin in the Location Resource Template", propertyName, propertyValue);
AbstractPropertyValue originalNodePropertyValue = safe(nodeTemplate.getCapabilities().get(capabilityName).getProperties()).get(propertyName);
ensureNotSet(originalNodePropertyValue, "in the portable topology", propertyName, propertyValue);
// Update the configuration
NodePropsOverride nodePropsOverride = getTemplatePropsOverride(matchingConfiguration);
if (propertyValue == null && nodePropsOverride.getCapabilities().get(capabilityName) != null) {
nodePropsOverride.getCapabilities().get(capabilityName).getProperties().remove(propertyName);
} else {
// Set check constraints
ConstraintPropertyService.checkPropertyConstraint(propertyName, propertyValue, propertyDefinition);
NodeCapabilitiesPropsOverride nodeCapabilitiesPropsOverride = nodePropsOverride.getCapabilities().computeIfAbsent(capabilityName, k -> new NodeCapabilitiesPropsOverride());
nodeCapabilitiesPropsOverride.getProperties().put(propertyName, PropertyService.asPropertyValue(propertyValue));
}
context.saveConfiguration(matchingConfiguration);
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class PropertyDefinitionConverter method convert.
public PropertyDefinition convert(FormPropertyDefinition definitionAnnotation) {
if (definitionAnnotation == null) {
return null;
}
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType(definitionAnnotation.type());
// FIXME ? can be other than a scalar here ?
propertyDefinition.setDefault(new ScalarPropertyValue(definitionAnnotation.defaultValue()));
propertyDefinition.setDescription(definitionAnnotation.description());
propertyDefinition.setPassword(definitionAnnotation.isPassword());
propertyDefinition.setRequired(definitionAnnotation.isRequired());
List<PropertyConstraint> constraints = Lists.newArrayList();
if (!definitionAnnotation.constraints().equal().isEmpty()) {
EqualConstraint equalConstraint = new EqualConstraint();
equalConstraint.setEqual(definitionAnnotation.constraints().equal());
constraints.add(equalConstraint);
}
if (!definitionAnnotation.constraints().greaterOrEqual().isEmpty()) {
GreaterOrEqualConstraint greaterOrEqualConstraint = new GreaterOrEqualConstraint();
greaterOrEqualConstraint.setGreaterOrEqual(definitionAnnotation.constraints().greaterOrEqual());
constraints.add(greaterOrEqualConstraint);
}
if (!definitionAnnotation.constraints().greaterThan().isEmpty()) {
GreaterThanConstraint greaterThanConstraint = new GreaterThanConstraint();
greaterThanConstraint.setGreaterThan(definitionAnnotation.constraints().greaterThan());
constraints.add(greaterThanConstraint);
}
if (!definitionAnnotation.constraints().inRange().isEmpty()) {
String inRangeText = definitionAnnotation.constraints().inRange();
Matcher matcher = IN_RANGE_REGEXP.matcher(inRangeText);
if (matcher.matches()) {
InRangeConstraint inRangeConstraint = new InRangeConstraint();
inRangeConstraint.setRangeMinValue(matcher.group(1).trim());
inRangeConstraint.setRangeMaxValue(matcher.group(2).trim());
constraints.add(inRangeConstraint);
} else {
throw new FormDescriptorGenerationException("In range constraint definition must be in this format '[ $min - $max ]'");
}
}
if (definitionAnnotation.constraints().length() >= 0) {
LengthConstraint lengthConstraint = new LengthConstraint();
lengthConstraint.setLength(definitionAnnotation.constraints().length());
constraints.add(lengthConstraint);
}
if (!definitionAnnotation.constraints().lessOrEqual().isEmpty()) {
LessOrEqualConstraint lessOrEqualConstraint = new LessOrEqualConstraint();
lessOrEqualConstraint.setLessOrEqual(definitionAnnotation.constraints().lessOrEqual());
constraints.add(lessOrEqualConstraint);
}
if (!definitionAnnotation.constraints().lessThan().isEmpty()) {
LessThanConstraint lessThanConstraint = new LessThanConstraint();
lessThanConstraint.setLessThan(definitionAnnotation.constraints().lessThan());
constraints.add(lessThanConstraint);
}
if (definitionAnnotation.constraints().maxLength() >= 0) {
MaxLengthConstraint maxLengthConstraint = new MaxLengthConstraint();
maxLengthConstraint.setMaxLength(definitionAnnotation.constraints().maxLength());
constraints.add(maxLengthConstraint);
}
if (definitionAnnotation.constraints().minLength() >= 0) {
MinLengthConstraint minLengthConstraint = new MinLengthConstraint();
minLengthConstraint.setMinLength(definitionAnnotation.constraints().minLength());
constraints.add(minLengthConstraint);
}
if (!definitionAnnotation.constraints().pattern().isEmpty()) {
PatternConstraint patternConstraint = new PatternConstraint();
patternConstraint.setPattern(definitionAnnotation.constraints().pattern());
constraints.add(patternConstraint);
}
if (definitionAnnotation.constraints().validValues().length > 0) {
ValidValuesConstraint validValuesConstraint = new ValidValuesConstraint();
validValuesConstraint.setValidValues(Lists.newArrayList(definitionAnnotation.constraints().validValues()));
constraints.add(validValuesConstraint);
}
if (!constraints.isEmpty()) {
propertyDefinition.setConstraints(constraints);
}
return propertyDefinition;
}
Aggregations