Search in sources :

Example 51 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class SuggestionService method setSuggestionIdOnPropertyDefinition.

/**
 * Add the suggestion ID of the new suggestionEntry to the appropriate propertyDefinition.
 *
 * @param suggestionEntry entry of suggestion
 */
public void setSuggestionIdOnPropertyDefinition(SuggestionEntry suggestionEntry) {
    Class<? extends AbstractInheritableToscaType> targetClass = (Class<? extends AbstractInheritableToscaType>) alienDAO.getTypesToClasses().get(suggestionEntry.getEsType());
    // FIXME what if targetClass is null ?
    Object array = toscaTypeSearchService.findAll(targetClass, suggestionEntry.getTargetElementId());
    if (array != null) {
        int length = Array.getLength(array);
        for (int i = 0; i < length; i++) {
            AbstractInheritableToscaType targetElement = ((AbstractInheritableToscaType) Array.get(array, i));
            PropertyDefinition propertyDefinition = targetElement.getProperties().get(suggestionEntry.getTargetProperty());
            if (propertyDefinition == null) {
                throw new NotFoundException("Property [" + suggestionEntry.getTargetProperty() + "] not found for element [" + suggestionEntry.getTargetElementId() + "]");
            } else {
                switch(propertyDefinition.getType()) {
                    case ToscaTypes.VERSION:
                    case ToscaTypes.STRING:
                        propertyDefinition.setSuggestionId(suggestionEntry.getId());
                        alienDAO.save(targetElement);
                        break;
                    case ToscaTypes.LIST:
                    case ToscaTypes.MAP:
                        PropertyDefinition entrySchema = propertyDefinition.getEntrySchema();
                        if (entrySchema != null) {
                            entrySchema.setSuggestionId(suggestionEntry.getId());
                            alienDAO.save(targetElement);
                        } else {
                            throw new InvalidArgumentException("Cannot suggest a list / map type with no entry schema definition");
                        }
                        break;
                    default:
                        throw new InvalidArgumentException(propertyDefinition.getType() + " cannot be suggested, only property of type string list or map can be suggested");
                }
            }
        }
    }
}
Also used : InvalidArgumentException(alien4cloud.exception.InvalidArgumentException) NotFoundException(alien4cloud.exception.NotFoundException) AbstractInheritableToscaType(org.alien4cloud.tosca.model.types.AbstractInheritableToscaType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) ValidValuesConstraint(org.alien4cloud.tosca.model.definitions.constraints.ValidValuesConstraint) EqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint)

Example 52 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class SuggestionService method addSuggestionValueToSuggestionEntry.

public void addSuggestionValueToSuggestionEntry(String suggestionId, String newValue) {
    AbstractSuggestionEntry suggestion = alienDAO.findById(AbstractSuggestionEntry.class, suggestionId);
    if (suggestion == null) {
        throw new NotFoundException("Suggestion entry [" + suggestionId + "] cannot be found");
    }
    // TODO: should check the format of new value
    if (suggestion.getSuggestions().contains(newValue)) {
        return;
    }
    suggestion.getSuggestions().add(newValue);
    alienDAO.save(suggestion);
}
Also used : AbstractSuggestionEntry(alien4cloud.model.common.AbstractSuggestionEntry) NotFoundException(alien4cloud.exception.NotFoundException)

Example 53 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class TopologyService method updateDependencies.

public void updateDependencies(EditionContext context, CSARDependency newDependency) {
    final Set<CSARDependency> oldDependencies = new HashSet<>(context.getTopology().getDependencies());
    final Set<CSARDependency> newDependencies = csarDependencyLoader.getDependencies(newDependency.getName(), newDependency.getVersion());
    newDependencies.add(newDependency);
    // Update context with the new dependencies.
    newDependencies.forEach(csarDependency -> context.getToscaContext().updateDependency(csarDependency));
    // Validate that the dependency change does not induce missing types.
    try {
        this.checkForMissingTypes(context.getTopology());
    } catch (NotFoundException e) {
        // Revert changes made to the Context then throw.
        context.getToscaContext().resetDependencies(oldDependencies);
        context.getTopology().setDependencies(oldDependencies);
        throw new VersionConflictException("Changing the dependency [" + newDependency.getName() + "] to version [" + newDependency.getVersion() + "] induces missing types in the topology. Not found : [" + e.getMessage() + "].", e);
    }
    // Perform the dependency update on the topology.
    context.getTopology().setDependencies(new HashSet<>(context.getToscaContext().getDependencies()));
}
Also used : VersionConflictException(alien4cloud.exception.VersionConflictException) NotFoundException(alien4cloud.exception.NotFoundException) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) HashSet(java.util.HashSet)

Example 54 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class NodeMatchingSubstitutionService method updateSubstitution.

/**
 * Execute the deployment flow with a modification of changing the substitution for one of the nodes.
 *
 * @param application The application for which to execute the deployment flow.
 * @param environment The environment for which to execute the deployment flow.
 * @param topology The topology linked to the specified environment.
 * @param nodeId The id of the node to substitute at matching phase.
 * @param locationResourceTemplateId The id of the location resources to substitute.
 * @return The flow execution context.
 */
public FlowExecutionContext updateSubstitution(Application application, ApplicationEnvironment environment, Topology topology, String nodeId, String locationResourceTemplateId) {
    FlowExecutionContext executionContext = new FlowExecutionContext(deploymentConfigurationDao, topology, new EnvironmentContext(application, environment));
    // Load the actual configuration
    // add a modifier that will actually perform the configuration of a substitution from user request (after cleanup and prior to node matching
    // auto-selection).
    SetMatchedNodeModifier setMatchedNodeModifier = new SetMatchedNodeModifier(nodeId, locationResourceTemplateId);
    List<ITopologyModifier> modifierList = getModifierListWithSelectionAction(setMatchedNodeModifier);
    flowExecutor.execute(topology, modifierList, executionContext);
    if (!setMatchedNodeModifier.isExecuted()) {
        throw new NotFoundException("Requested substitution <" + locationResourceTemplateId + "> for node <" + nodeId + "> is not available as a match. Please check that inputs and location are configured and ask your admin to grant you access to requested resources on the location.");
    }
    return executionContext;
}
Also used : EnvironmentContext(org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) NotFoundException(alien4cloud.exception.NotFoundException) SetMatchedNodeModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.action.SetMatchedNodeModifier) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier)

Example 55 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class PolicyMatchingSubstitutionService method updateSubstitution.

/**
 * Execute the deployment flow with a modification of changing the substitution for one of the nodes.
 *
 * @param application The application for which to execute the deployment flow.
 * @param environment The environment for which to execute the deployment flow.
 * @param topology The topology linked to the specified environment.
 * @param nodeId The id of the node to substitute at matching phase.
 * @param resourceTemplateId The id of the location resource to substitute.
 * @return The flow execution context.
 */
public FlowExecutionContext updateSubstitution(Application application, ApplicationEnvironment environment, Topology topology, String nodeId, String resourceTemplateId) {
    FlowExecutionContext executionContext = new FlowExecutionContext(deploymentConfigurationDao, topology, new EnvironmentContext(application, environment));
    // Load the actual configuration
    // add a modifier that will actually perform the configuration of a substitution from user request (after cleanup and prior to node matching
    // auto-selection).
    SetMatchedPolicyModifier setMatchedPolicyModifier = new SetMatchedPolicyModifier(nodeId, resourceTemplateId);
    List<ITopologyModifier> modifierList = getModifierListWithSelectionAction(setMatchedPolicyModifier);
    flowExecutor.execute(topology, modifierList, executionContext);
    if (!setMatchedPolicyModifier.isExecuted()) {
        throw new NotFoundException("Requested substitution <" + resourceTemplateId + "> for node <" + nodeId + "> is not available as a match. Please check that inputs and location are configured and ask your admin to grant you access to requested resources on the location.");
    }
    return executionContext;
}
Also used : EnvironmentContext(org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext) SetMatchedPolicyModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.action.SetMatchedPolicyModifier) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) NotFoundException(alien4cloud.exception.NotFoundException) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier)

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