Search in sources :

Example 46 with NotFoundException

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);
}
Also used : ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) NotFoundException(alien4cloud.exception.NotFoundException) ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) Map(java.util.Map) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException)

Example 47 with NotFoundException

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;
}
Also used : MetaPropConfiguration(alien4cloud.model.common.MetaPropConfiguration) NotFoundException(alien4cloud.exception.NotFoundException)

Example 48 with NotFoundException

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);
}
Also used : LocationModifierReference(alien4cloud.model.orchestrators.locations.LocationModifierReference) NotFoundException(alien4cloud.exception.NotFoundException)

Example 49 with NotFoundException

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);
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) NotFoundException(alien4cloud.exception.NotFoundException) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) AbstractInheritableToscaType(org.alien4cloud.tosca.model.types.AbstractInheritableToscaType) Location(alien4cloud.model.orchestrators.locations.Location)

Example 50 with NotFoundException

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;
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException)

Aggregations

NotFoundException (alien4cloud.exception.NotFoundException)88 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)17 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)12 Map (java.util.Map)10 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)10 AlreadyExistException (alien4cloud.exception.AlreadyExistException)9 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)9 Capability (org.alien4cloud.tosca.model.templates.Capability)9 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)8 SubstitutionTarget (org.alien4cloud.tosca.model.templates.SubstitutionTarget)8 Topology (org.alien4cloud.tosca.model.templates.Topology)7 Deployment (alien4cloud.model.deployment.Deployment)6 ApiOperation (io.swagger.annotations.ApiOperation)6 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)6 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)6 InvalidNameException (alien4cloud.exception.InvalidNameException)5 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5