use of alien4cloud.model.application.ApplicationVersion in project alien4cloud by alien4cloud.
the class ApplicationStepDefinitions method setAppVersionIdToContext.
private void setAppVersionIdToContext(String appId) throws IOException {
String applicationVersionJson = getRestClientInstance().get("/rest/v1/applications/" + appId + "/versions");
RestResponse<ApplicationVersion> appVersion = JsonUtil.read(applicationVersionJson, ApplicationVersion.class);
Context.getInstance().registerApplicationVersionId(appVersion.getData().getVersion(), appVersion.getData().getId());
}
use of alien4cloud.model.application.ApplicationVersion 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.model.application.ApplicationVersion in project alien4cloud by alien4cloud.
the class ApplicationEnvironmentController method updateTopologyVersion.
/**
* Use new topology version for environment
*
* @param applicationEnvironmentId environment's id
* @param applicationId application's id
* @param request request for new topology's version
*/
@ApiOperation(value = "Use new topology version for the given application environment", notes = "The logged-in user must have the application manager role for this application. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/{applicationEnvironmentId:.+}/topology-version", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Void> updateTopologyVersion(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId, @RequestBody UpdateTopologyVersionForEnvironmentRequest request) throws OrchestratorDisabledException {
// Only APPLICATION_MANAGER & DEPLOYMENT_MANAGER on the underlying application can update an application environment
ApplicationEnvironment applicationEnvironment = applicationEnvironmentService.checkAndGetApplicationEnvironment(applicationEnvironmentId, ApplicationRole.APPLICATION_MANAGER, ApplicationEnvironmentRole.DEPLOYMENT_MANAGER);
if (applicationEnvironment == null) {
return RestResponseBuilder.<Void>builder().data(null).error(RestErrorBuilder.builder(RestErrorCode.APPLICATION_ENVIRONMENT_ERROR).message("Application environment with id <" + applicationEnvironmentId + "> does not exist").build()).build();
}
// update the version of the environment
ApplicationVersion newApplicationVersion = applicationVersionService.getOrFailByArchiveId(Csar.createId(applicationEnvironment.getApplicationId(), request.getNewTopologyVersion()));
String oldVersion = applicationEnvironment.getVersion();
String oldTopologyVersion = applicationEnvironment.getTopologyVersion();
String newVersion = newApplicationVersion.getVersion();
String newTopologyVersion = request.getNewTopologyVersion();
if (!Objects.equals(newVersion, oldVersion) || !Objects.equals(newTopologyVersion, oldTopologyVersion)) {
// Only process if something has changed
applicationEnvironmentService.updateTopologyVersion(applicationEnvironment, oldTopologyVersion, newVersion, newTopologyVersion, request.getEnvironmentToCopyInput());
}
return RestResponseBuilder.<Void>builder().build();
}
use of alien4cloud.model.application.ApplicationVersion in project alien4cloud by alien4cloud.
the class ApplicationEnvironmentController method update.
/**
* Update application environment
*
* @param applicationEnvironmentId
* @param request
* @return
*/
@ApiOperation(value = "Updates by merging the given request into the given application environment", notes = "The logged-in user must have the application manager role for this application. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/{applicationEnvironmentId:.+}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Void> update(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId, @RequestBody UpdateApplicationEnvironmentRequest request) throws OrchestratorDisabledException {
// Only APPLICATION_MANAGER on the underlying application can update an application environment
ApplicationEnvironment applicationEnvironment = applicationEnvironmentService.checkAndGetApplicationEnvironment(applicationEnvironmentId, ApplicationRole.APPLICATION_MANAGER);
if (applicationEnvironment == null) {
return RestResponseBuilder.<Void>builder().data(null).error(RestErrorBuilder.builder(RestErrorCode.APPLICATION_ENVIRONMENT_ERROR).message("Application environment with id <" + applicationEnvironmentId + "> does not exist").build()).build();
}
applicationEnvironmentService.ensureNameUnicity(applicationEnvironment.getApplicationId(), request.getName());
ReflectionUtil.mergeObject(request, applicationEnvironment);
if (applicationEnvironment.getName() == null || applicationEnvironment.getName().isEmpty()) {
throw new UnsupportedOperationException("Application environment name cannot be set to null or empty");
}
if (request.getCurrentVersionId() != null) {
// update the version of the environment
ApplicationVersion applicationVersion = applicationVersionService.getOrFailByArchiveId(Csar.createId(applicationEnvironment.getApplicationId(), request.getCurrentVersionId()));
applicationEnvironment.setVersion(applicationVersion.getVersion());
applicationEnvironment.setTopologyVersion(request.getCurrentVersionId());
}
alienDAO.save(applicationEnvironment);
return RestResponseBuilder.<Void>builder().build();
}
Aggregations