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");
}
}
}
}
}
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);
}
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()));
}
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;
}
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;
}
Aggregations