use of org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException in project alien4cloud by alien4cloud.
the class OrchestratorPropertiesService method setOrchestratorProperties.
public void setOrchestratorProperties(ApplicationEnvironment environment, Map<String, String> providerDeploymentProperties) {
if (MapUtils.isNotEmpty(providerDeploymentProperties)) {
OrchestratorDeploymentProperties properties = deploymentConfigurationDao.findById(OrchestratorDeploymentProperties.class, AbstractDeploymentConfig.generateId(environment.getTopologyVersion(), environment.getId()));
try {
orchestratorPropertiesValidationService.checkConstraints(properties.getOrchestratorId(), providerDeploymentProperties);
} catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) {
throw new ConstraintTechnicalException("Error on deployer user orchestrator properties validation", e);
}
if (properties.getProviderDeploymentProperties() == null) {
properties.setProviderDeploymentProperties(providerDeploymentProperties);
} else {
properties.getProviderDeploymentProperties().putAll(providerDeploymentProperties);
}
deploymentConfigurationDao.save(properties);
}
}
use of org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException in project alien4cloud by alien4cloud.
the class AbstractTemplateMatcher method isValidTemplatePropertiesMatch.
/**
* Add filters ent/ICSARRepositorySearchService.java from the matching configuration to the node filter that will be applied for matching only if a value is
* specified on the configuration template.
*
* @param templatePropertyValues The properties values from the template to match.
* @param candidatePropertyValues The values defined on the Location Template.
* @param propertyDefinitions The properties definitions associated with the node.
* @param configuredFilters The filtering map (based on constraints) from matching configuration, other properties fall backs to an equal constraint/filter.
*/
protected boolean isValidTemplatePropertiesMatch(Map<String, AbstractPropertyValue> templatePropertyValues, Map<String, AbstractPropertyValue> candidatePropertyValues, Map<String, PropertyDefinition> propertyDefinitions, Map<String, List<IMatchPropertyConstraint>> configuredFilters) {
// We perform matching on every property that is defined on the candidate (admin node) and that has a value defined in the topology.
for (Map.Entry<String, AbstractPropertyValue> candidateValueEntry : safe(candidatePropertyValues).entrySet()) {
List<IMatchPropertyConstraint> filter = safe(configuredFilters).get(candidateValueEntry.getKey());
AbstractPropertyValue templatePropertyValue = templatePropertyValues.get(candidateValueEntry.getKey());
// For now we support matching only on scalar properties.
if (candidateValueEntry.getValue() != null && candidateValueEntry.getValue() instanceof ScalarPropertyValue && templatePropertyValue != null && templatePropertyValue instanceof ScalarPropertyValue) {
try {
IPropertyType<?> toscaType = ToscaTypes.fromYamlTypeName(propertyDefinitions.get(candidateValueEntry.getKey()).getType());
if (filter == null) {
// If no filter is defined then process matching using an equal constraint.
filter = Lists.newArrayList(new EqualConstraint());
}
// set the constraint value and add it to the node filter
for (IMatchPropertyConstraint constraint : filter) {
constraint.setConstraintValue(toscaType, ((ScalarPropertyValue) candidateValueEntry.getValue()).getValue());
try {
constraint.validate(toscaType, ((ScalarPropertyValue) templatePropertyValue).getValue());
} catch (ConstraintViolationException e) {
return false;
}
}
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
log.debug("The value of property for a constraint is not valid.", e);
}
}
}
return true;
}
use of org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException in project alien4cloud by alien4cloud.
the class PreconfiguredInputsModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
EnvironmentContext environmentContext = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Preconfigured input modifier requires an environment context."));
ApplicationEnvironment environment = environmentContext.getEnvironment();
Map<String, Location> locations = (Map<String, Location>) context.getExecutionCache().get(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY);
AlienContextVariables alienContextVariables = new AlienContextVariables();
alienContextVariables.setApplicationEnvironment(environment);
alienContextVariables.setLocation(locations.values().stream().findFirst().get());
alienContextVariables.setApplication(environmentContext.getApplication());
// TODO: avoid reloading every time - find a way to know the last update on files (git hash ?)
Properties appVarProps = quickFileStorageService.loadApplicationVariables(environmentContext.getApplication().getId());
Properties envTypeVarProps = quickFileStorageService.loadEnvironmentTypeVariables(topology.getId(), environment.getEnvironmentType());
Properties envVarProps = quickFileStorageService.loadEnvironmentVariables(topology.getId(), environment.getId());
Map<String, Object> inputsMappingsMap = quickFileStorageService.loadInputsMappingFile(topology.getId());
InputsMappingFileVariableResolver.InputsResolvingResult inputsResolvingResult = InputsMappingFileVariableResolver.configure(appVarProps, envTypeVarProps, envVarProps, alienContextVariables).resolve(inputsMappingsMap, topology.getInputs());
if (CollectionUtils.isNotEmpty(inputsResolvingResult.getMissingVariables())) {
context.log().error(new MissingVariablesTask(inputsResolvingResult.getMissingVariables()));
}
if (CollectionUtils.isNotEmpty(inputsResolvingResult.getUnresolved())) {
context.log().error(new UnresolvablePredefinedInputsTask(inputsResolvingResult.getUnresolved()));
}
// checking constraints
Map<String, ConstraintUtil.ConstraintInformation> violations = Maps.newHashMap();
Map<String, ConstraintUtil.ConstraintInformation> typesViolations = Maps.newHashMap();
for (Map.Entry<String, PropertyValue> entry : safe(inputsResolvingResult.getResolved()).entrySet()) {
try {
ConstraintPropertyService.checkPropertyConstraint(entry.getKey(), entry.getValue(), topology.getInputs().get(entry.getKey()));
} catch (ConstraintViolationException e) {
violations.put(entry.getKey(), getConstraintInformation(e.getMessage(), e.getConstraintInformation()));
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
typesViolations.put(entry.getKey(), getConstraintInformation(e.getMessage(), e.getConstraintInformation()));
}
}
if (MapUtils.isNotEmpty(violations)) {
context.log().error(new PredefinedInputsConstraintViolationTask(violations, TaskCode.PREDEFINED_INPUTS_CONSTRAINT_VIOLATION));
}
if (MapUtils.isNotEmpty(typesViolations)) {
context.log().error(new PredefinedInputsConstraintViolationTask(typesViolations, TaskCode.PREDEFINED_INPUTS_TYPE_VIOLATION));
}
PreconfiguredInputsConfiguration preconfiguredInputsConfiguration = new PreconfiguredInputsConfiguration(environment.getTopologyVersion(), environment.getId());
preconfiguredInputsConfiguration.setInputs(inputsResolvingResult.getResolved());
// add unresolved so that they are not considered as deployer input
inputsResolvingResult.getUnresolved().forEach(unresolved -> preconfiguredInputsConfiguration.getInputs().put(unresolved, null));
// TODO: improve me
preconfiguredInputsConfiguration.setLastUpdateDate(new Date());
preconfiguredInputsConfiguration.setCreationDate(new Date());
context.saveConfiguration(preconfiguredInputsConfiguration);
}
use of org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException in project alien4cloud by alien4cloud.
the class AbstractSetMatchedPropertyModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, NodeMatchingConfigAutoSelectModifier.class.getSimpleName());
if (!configurationOptional.isPresent()) {
// we should not end-up here as location matching should be processed first
context.log().error(new LocationPolicyTask());
return;
}
DeploymentMatchingConfiguration matchingConfiguration = configurationOptional.get();
Map<String, String> lastUserSubstitutions = getUserMatches(matchingConfiguration);
U template = getTemplates(topology).get(templateId);
if (template == null) {
throw new NotFoundException("Topology [" + topology.getId() + "] does not contains any " + getSubject() + " with id [" + templateId + "]");
}
String substitutionId = lastUserSubstitutions.get(templateId);
if (substitutionId == null) {
throw new NotFoundException("The " + getSubject() + " [" + templateId + "] from topology [" + topology.getId() + "] is not matched.");
}
Map<String, V> allAvailableResourceTemplates = getAvailableResourceTemplates(context);
V resourceTemplate = allAvailableResourceTemplates.get(substitutionId);
try {
setProperty(context, resourceTemplate, template, matchingConfiguration);
} catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) {
throw new ConstraintTechnicalException("Dispatching constraint violation.", e);
}
}
use of org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException in project alien4cloud by alien4cloud.
the class ToscaPropertyConstraintValidator method isValid.
@Override
public boolean isValid(PropertyDefinition value, ConstraintValidatorContext context) {
if (value.getConstraints() == null) {
return true;
}
IPropertyType<?> toscaType = ToscaTypes.fromYamlTypeName(value.getType());
if (toscaType == null) {
return false;
}
boolean isValid = true;
for (int i = 0; i < value.getConstraints().size(); i++) {
PropertyConstraint constraint = value.getConstraints().get(i);
try {
constraint.initialize(toscaType);
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
log.info("Constraint definition error", e);
context.buildConstraintViolationWithTemplate("CONSTRAINTS.VALIDATION.TYPE").addPropertyNode("constraints").addBeanNode().inIterable().atIndex(i).addConstraintViolation();
isValid = false;
}
}
return isValid;
}
Aggregations