use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class NodeInstanceService method updateProperties.
private void updateProperties(NodeType nodeType, NodeTemplate nodeTemplate, Map<String, AbstractPropertyValue> nodeProperties) throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException {
for (Map.Entry<String, AbstractPropertyValue> propertyValueEntry : nodeProperties.entrySet()) {
if (propertyValueEntry.getValue() != null) {
AbstractPropertyValue value = PatchUtil.realValue(propertyValueEntry.getValue());
PropertyDefinition propertyDefinition = safe(nodeType.getProperties()).get(propertyValueEntry.getKey());
if (propertyDefinition == null) {
throw new NotFoundException("No property <" + propertyValueEntry.getKey() + "> can be found for node type <" + nodeType.getElementId() + "> in version <" + nodeType.getArchiveVersion() + ">");
}
propertyService.setPropertyValue(nodeTemplate, propertyDefinition, propertyValueEntry.getKey(), value);
}
}
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class NodeInstanceService method updateCapabilitiesProperties.
private void updateCapabilitiesProperties(CapabilityType capabilityType, Capability targetCapability, Capability patchCapability) throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException {
for (Map.Entry<String, AbstractPropertyValue> propertyValueEntry : patchCapability.getProperties().entrySet()) {
if (propertyValueEntry.getValue() != null) {
AbstractPropertyValue value = PatchUtil.realValue(propertyValueEntry.getValue());
PropertyDefinition propertyDefinition = safe(capabilityType.getProperties()).get(propertyValueEntry.getKey());
if (propertyDefinition == null) {
throw new NotFoundException("No property <" + propertyValueEntry.getKey() + "> can be found for capability <" + capabilityType.getElementId() + ">");
}
propertyService.setCapabilityPropertyValue(targetCapability, propertyDefinition, propertyValueEntry.getKey(), value);
}
}
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class AbstractSetMatchedModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
executed = true;
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 = getLastUserMatches(matchingConfiguration);
Map<String, Set<String>> templateIdToAvailableSubstitutions = getAvailableSubstitutions(context);
// Check the provided resourceTemplate is a valid substitution match and update matching configuration
Set<String> availableSubstitutions = templateIdToAvailableSubstitutions.get(templateId);
if (safe(availableSubstitutions).contains(resourceTemplateId)) {
lastUserSubstitutions.put(templateId, resourceTemplateId);
context.saveConfiguration(matchingConfiguration);
return;
}
throw new NotFoundException("Requested substitution <" + resourceTemplateId + "> for " + getSubject() + " <" + templateId + "> is not available as a match.");
}
use of alien4cloud.exception.NotFoundException 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 alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class AbstractSetMatchedPropertyModifier method setProperty.
protected void setProperty(FlowExecutionContext context, V resourceTemplate, U template, DeploymentMatchingConfiguration matchingConfiguration) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
PropertyDefinition propertyDefinition = ((T) ToscaContext.getOrFail(AbstractToscaType.class, resourceTemplate.getTemplate().getType())).getProperties().get(propertyName);
if (propertyDefinition == null) {
throw new NotFoundException("No property of name [" + propertyName + "] can be found on the " + getSubject() + " template [" + templateId + "] of type [" + resourceTemplate.getTemplate().getType() + "]");
}
AbstractPropertyValue locationResourcePropertyValue = resourceTemplate.getTemplate().getProperties().get(propertyName);
ensureNotSet(locationResourcePropertyValue, "by the admin in the Location Resource Template", propertyName, propertyValue);
ensureNotSet(template.getProperties().get(propertyName), "in the portable topology", propertyName, propertyValue);
// Update the configuration
NodePropsOverride nodePropsOverride = getTemplatePropsOverride(matchingConfiguration);
// Perform the update of the property
if (propertyValue == null) {
nodePropsOverride.getProperties().remove(propertyName);
} else {
AbstractPropertyValue abstractPropertyValue = PropertyService.asPropertyValue(propertyValue);
if (!(abstractPropertyValue instanceof FunctionPropertyValue)) {
ConstraintPropertyService.checkPropertyConstraint(propertyName, propertyValue, propertyDefinition);
}
nodePropsOverride.getProperties().put(propertyName, abstractPropertyValue);
}
context.saveConfiguration(matchingConfiguration);
}
Aggregations