use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class InputService method setInputValues.
public void setInputValues(ApplicationEnvironment environment, Topology topology, Map<String, Object> inputProperties) {
if (safe(inputProperties).isEmpty()) {
return;
}
// Get the configuration object
DeploymentInputs configuration = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(environment.getTopologyVersion(), environment.getId()));
if (configuration == null) {
configuration = new DeploymentInputs(environment.getTopologyVersion(), environment.getId());
}
for (Map.Entry<String, Object> inputPropertyValue : inputProperties.entrySet()) {
if (topology.getInputs() == null || topology.getInputs().get(inputPropertyValue.getKey()) == null) {
throw new NotFoundException("Input", inputPropertyValue.getKey(), "Input <" + inputPropertyValue.getKey() + "> cannot be found on topology for application <" + environment.getApplicationId() + "> environement <" + environment.getId() + ">");
}
try {
propertyService.setPropertyValue(configuration.getInputs(), topology.getInputs().get(inputPropertyValue.getKey()), inputPropertyValue.getKey(), inputPropertyValue.getValue());
} catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) {
throw new ConstraintTechnicalException("Dispatching constraint violation.", e);
}
}
// Save configuration
deploymentConfigurationDao.save(configuration);
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class MetaPropertiesService method upsertMetaProperty.
/**
* Add or update a meta-property to a {{IMetaProperties}} resource.
*
* @param resource The resource for which to add or update the given meta-property.
* @param key The id of the meta-property.
* @param value The value of the meta-property.
* @return
* @throws ConstraintValueDoNotMatchPropertyTypeException
* @throws ConstraintViolationException
*/
public ConstraintInformation upsertMetaProperty(IMetaProperties resource, String key, String value) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
MetaPropConfiguration propertyDefinition = alienDAO.findById(MetaPropConfiguration.class, key);
if (propertyDefinition == null) {
throw new NotFoundException("Property update operation failed. Could not find property definition with id <" + propertyDefinition + ">.");
}
if (value != null) {
// by convention updateproperty with null value => reset to default if exists
ConstraintPropertyService.checkPropertyConstraint(key, value, propertyDefinition);
}
if (resource.getMetaProperties() == null) {
resource.setMetaProperties(Maps.<String, String>newHashMap());
} else if (resource.getMetaProperties().containsKey(key)) {
resource.getMetaProperties().remove(key);
}
resource.getMetaProperties().put(key, value);
alienDAO.save(resource);
return null;
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class LocationModifierService method move.
/**
* Move a location modifier from a position to another
*
* @param location
* @param from
* @param to
*/
public void move(Location location, int from, int to) {
if (from == to) {
return;
}
if (from < 0 || to < 0 || location.getModifiers() == null || from > location.getModifiers().size() || to > location.getModifiers().size()) {
throw new NotFoundException("Cannot move location modifier from " + from + "to index " + to);
}
LocationModifierReference modifier = location.getModifiers().remove(from);
location.getModifiers().add(to, modifier);
sort(location);
alienDAO.save(location);
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class LocationResourceService method setTemplateProperty.
/*
* (non-Javadoc)
*
* @see alien4cloud.orchestrators.locations.services.ILocationResourceService#setTemplateProperty(java.lang.String, java.lang.String,
* java.lang.Object)
*/
@Override
public void setTemplateProperty(String resourceId, String propertyName, Object propertyValue) throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException {
AbstractLocationResourceTemplate resourceTemplate = getOrFail(resourceId);
Location location = locationService.getOrFail(resourceTemplate.getLocationId());
AbstractInheritableToscaType resourceType = (AbstractInheritableToscaType) csarRepoSearchService.getRequiredElementInDependencies(AbstractToscaType.class, resourceTemplate.getTemplate().getType(), location.getDependencies());
if (!safe(resourceType.getProperties()).containsKey(propertyName)) {
throw new NotFoundException("Property [" + propertyName + "] is not found in type [" + resourceType.getElementId() + "]");
}
propertyService.setPropertyValue(location.getDependencies(), resourceTemplate.getTemplate(), resourceType.getProperties().get(propertyName), propertyName, propertyValue);
saveResource(resourceTemplate);
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class LocationResourceGeneratorService method buildComputeContext.
public ComputeContext buildComputeContext(String elementType, String namePefix, String imageIdPropertyName, String flavorIdPropertyName, ILocationResourceAccessor resourceAccessor) {
ComputeContext context = new ComputeContext();
context.setFlavorIdPropertyName(flavorIdPropertyName);
context.setImageIdPropertyName(imageIdPropertyName);
context.setGeneratedNamePrefix(namePefix);
try {
NodeType nodeType = resourceAccessor.getIndexedToscaElement(elementType);
context.getNodeTypes().add(nodeType);
} catch (NotFoundException e) {
log.warn("No compute found with the element id: " + elementType, e);
}
return context;
}
Aggregations