use of alien4cloud.exception.AlreadyExistException in project alien4cloud by alien4cloud.
the class RenameInputProcessor method processInputOperation.
@Override
protected void processInputOperation(Csar csar, Topology topology, RenameInputOperation operation, Map<String, PropertyDefinition> inputs) {
if (!inputs.containsKey(operation.getInputName())) {
throw new NotFoundException("Input " + operation.getInputName() + " not found");
}
if (operation.getInputName().equals(operation.getNewInputName())) {
// nothing has changed.
return;
}
if (operation.getNewInputName() == null || operation.getNewInputName().isEmpty() || !operation.getNewInputName().matches("\\w+")) {
throw new InvalidNameException("newInputName", operation.getNewInputName(), "\\w+");
}
if (inputs.containsKey(operation.getNewInputName())) {
throw new AlreadyExistException("Input " + operation.getNewInputName() + " already existed");
}
PropertyDefinition propertyDefinition = inputs.remove(operation.getInputName());
inputs.put(operation.getNewInputName(), propertyDefinition);
Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
for (NodeTemplate nodeTemp : safe(nodeTemplates).values()) {
renameInputInProperties(nodeTemp.getProperties(), operation.getInputName(), operation.getNewInputName());
if (nodeTemp.getRelationships() != null) {
for (RelationshipTemplate relationshipTemplate : nodeTemp.getRelationships().values()) {
renameInputInProperties(relationshipTemplate.getProperties(), operation.getInputName(), operation.getNewInputName());
}
}
if (nodeTemp.getCapabilities() != null) {
for (Capability capability : nodeTemp.getCapabilities().values()) {
renameInputInProperties(capability.getProperties(), operation.getInputName(), operation.getNewInputName());
}
}
}
// rename preconfigured input
renamePreconfiguredInput(csar, topology, operation);
log.debug("Change the name of an input parameter [ {} ] to [ {} ] for the topology ", operation.getInputName(), operation.getNewInputName(), topology.getId());
}
use of alien4cloud.exception.AlreadyExistException in project alien4cloud by alien4cloud.
the class AddRequirementSubstitutionTypeProcessor method process.
@Override
public void process(Csar csar, Topology topology, AddRequirementSubstitutionTypeOperation operation) {
if (topology.getNodeTemplates() == null || !topology.getNodeTemplates().containsKey(operation.getNodeTemplateName())) {
throw new NotFoundException("Node " + operation.getNodeTemplateName() + " do not exist");
}
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(operation.getNodeTemplateName());
if (nodeTemplate.getRequirements() == null || !nodeTemplate.getRequirements().containsKey(operation.getRequirementId())) {
throw new NotFoundException("Requirement " + operation.getRequirementId() + " do not exist for node " + operation.getNodeTemplateName());
}
if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) {
throw new NotFoundException("No substitution type has been found");
}
Map<String, SubstitutionTarget> substitutionRequirements = topology.getSubstitutionMapping().getRequirements();
if (substitutionRequirements == null) {
substitutionRequirements = Maps.newHashMap();
topology.getSubstitutionMapping().setRequirements(substitutionRequirements);
} else if (substitutionRequirements.containsKey(operation.getSubstitutionRequirementId())) {
// ensure name unicity
throw new AlreadyExistException(String.format("The substitution requirement <%s> already exists", operation.getSubstitutionRequirementId()));
}
substitutionRequirements.put(operation.getSubstitutionRequirementId(), new SubstitutionTarget(operation.getNodeTemplateName(), operation.getRequirementId()));
}
use of alien4cloud.exception.AlreadyExistException in project alien4cloud by alien4cloud.
the class UpdateRequirementSubstitutionTypeProcessor method process.
@Override
public void process(Csar csar, Topology topology, UpdateRequirementSubstitutionTypeOperation operation) {
if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) {
throw new NotFoundException("No substitution type has been found");
}
Map<String, SubstitutionTarget> substitutionRequirements = topology.getSubstitutionMapping().getRequirements();
if (substitutionRequirements == null) {
throw new NotFoundException("No substitution requirement has been found");
}
SubstitutionTarget target = substitutionRequirements.remove(operation.getSubstitutionRequirementId());
if (target == null) {
throw new NotFoundException("No substitution requirement has been found for key " + operation.getSubstitutionRequirementId());
}
if (substitutionRequirements.containsKey(operation.getNewRequirementId())) {
throw new AlreadyExistException(String.format("Can not rename from <%s> to <%s> since requirement <%s> already exists", operation.getSubstitutionRequirementId(), operation.getNewRequirementId(), operation.getNewRequirementId()));
}
substitutionRequirements.put(operation.getNewRequirementId(), target);
}
use of alien4cloud.exception.AlreadyExistException in project alien4cloud by alien4cloud.
the class ApplicationController method create.
/**
* Create a new application in the system.
*
* @param request The new application to create.
*/
@ApiOperation(value = "Create a new application in the system.", notes = "If successfull returns a rest response with the id of the created application in data. If not successful a rest response with an error content is returned. Role required [ APPLICATIONS_MANAGER ]. " + "By default the application creator will have application roles [APPLICATION_MANAGER, DEPLOYMENT_MANAGER]")
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(value = HttpStatus.CREATED)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<String> create(@Valid @RequestBody CreateApplicationRequest request) {
AuthorizationUtil.checkHasOneRoleIn(Role.APPLICATIONS_MANAGER);
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
// check the topology template id to recover the related topology id
String topologyId = request.getTopologyTemplateVersionId();
if (topologyId != null) {
applicationVersionService.getTemplateTopology(topologyId);
}
// check unity of archive name
try {
archiveIndexer.ensureUniqueness(request.getArchiveName(), VersionUtil.DEFAULT_VERSION_NAME);
} catch (AlreadyExistException e) {
return RestResponseBuilder.<String>builder().error(RestErrorBuilder.builder(RestErrorCode.APPLICATION_CSAR_VERSION_ALREADY_EXIST).message("CSAR: " + request.getArchiveName() + ", Version: " + VersionUtil.DEFAULT_VERSION_NAME + " already exists in the repository.").build()).build();
}
// create the application with default environment and version
String applicationId = applicationService.create(auth.getName(), request.getArchiveName(), request.getName(), request.getDescription());
ApplicationVersion version = applicationVersionService.createInitialVersion(applicationId, topologyId);
applicationEnvironmentService.createApplicationEnvironment(auth.getName(), applicationId, version.getTopologyVersions().keySet().iterator().next());
return RestResponseBuilder.<String>builder().data(applicationId).build();
}
use of alien4cloud.exception.AlreadyExistException in project alien4cloud by alien4cloud.
the class ApplicationDeploymentController method deploy.
/**
* Trigger deployment of the application on the current configured PaaS.
*
* @param deployApplicationRequest application details for deployment (applicationId + deploymentProperties)
* @return An empty rest response.
*/
@ApiOperation(value = "Deploys the application on the configured Cloud.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/deployment", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit(bodyHiddenFields = { "secretProviderCredentials" })
public RestResponse<?> deploy(@Valid @RequestBody DeployApplicationRequest deployApplicationRequest) {
String applicationId = deployApplicationRequest.getApplicationId();
String environmentId = deployApplicationRequest.getApplicationEnvironmentId();
Application application = applicationService.checkAndGetApplication(applicationId);
ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(applicationId, environmentId);
if (!environment.getApplicationId().equals(applicationId)) {
throw new NotFoundException("Unable to find environment with id <" + environmentId + "> for application <" + applicationId + ">");
}
// Security check user must be authorized to deploy the environment (or be application manager)
AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
// ensure deployment status is sync with underlying orchestrator
applicationEnvironmentService.getStatus(environment);
// check that the environment is not already deployed
boolean isEnvironmentDeployed = applicationEnvironmentService.isDeployed(environment.getId());
if (isEnvironmentDeployed) {
throw new AlreadyExistException("Environment with id <" + environmentId + "> for application <" + applicationId + "> is already deployed");
}
// prepare the deployment
ApplicationTopologyVersion topologyVersion = applicationVersionService.getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion());
Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId());
return toscaContextualAspect.execInToscaContext(() -> doDeploy(deployApplicationRequest, application, environment, topology), false, topology);
}
Aggregations