Search in sources :

Example 56 with NotFoundException

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);
        }
    }
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 57 with NotFoundException

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);
        }
    }
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 58 with NotFoundException

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.");
}
Also used : Set(java.util.Set) LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) NotFoundException(alien4cloud.exception.NotFoundException) NodeMatchingConfigAutoSelectModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.NodeMatchingConfigAutoSelectModifier)

Example 59 with NotFoundException

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);
    }
}
Also used : ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) NotFoundException(alien4cloud.exception.NotFoundException) LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException) NodeMatchingConfigAutoSelectModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.NodeMatchingConfigAutoSelectModifier) NodePropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodePropsOverride)

Example 60 with NotFoundException

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);
}
Also used : NodePropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodePropsOverride) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) NotFoundException(alien4cloud.exception.NotFoundException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

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