use of alien4cloud.model.application.ApplicationVersion in project alien4cloud by alien4cloud.
the class ApplicationVersionService method deleteTopologyVersion.
/**
* Delete an Application Topology version from a given application version.
*
* @param applicationId The application Id.
* @param versionId The version id of the application version.
* @param topologyVersion The version (not archive id) of the topology version.
*/
public void deleteTopologyVersion(String applicationId, String versionId, String topologyVersion) {
ApplicationVersion applicationVersion = getOrFail(versionId);
ApplicationTopologyVersion applicationTopologyVersion = applicationVersion.getTopologyVersions().get(topologyVersion);
if (applicationTopologyVersion == null) {
throw new NotFoundException("Topology version [" + topologyVersion + "] does not exist in the application version [" + versionId + "] for application [" + applicationId + "]");
}
if (applicationVersion.getTopologyVersions().size() == 1) {
throw new DeleteLastApplicationVersionException("Application topology version [" + topologyVersion + "] for application version [" + versionId + "] can't be be deleted as it is the last topology version for this application version.");
}
ApplicationEnvironment usage = findAnyApplicationTopologyVersionUsage(applicationId, topologyVersion);
if (usage != null) {
throw new DeleteReferencedObjectException("Application topology version with id [" + topologyVersion + "] could not be deleted as it is used by environment [" + usage.getName() + "]");
}
ApplicationTopologyVersion deleted = applicationVersion.getTopologyVersions().remove(topologyVersion);
publisher.publishEvent(new BeforeApplicationTopologyVersionDeleted(this, applicationVersion.getApplicationId(), applicationVersion.getId(), topologyVersion));
csarService.deleteCsar(deleted.getArchiveId());
alienDAO.save(applicationVersion);
publisher.publishEvent(new AfterApplicationTopologyVersionDeleted(this, applicationVersion.getApplicationId(), applicationVersion.getId(), topologyVersion));
}
use of alien4cloud.model.application.ApplicationVersion in project alien4cloud by alien4cloud.
the class ApplicationVersionServiceTest method versionShouldNotBeDeployedDeploymentOnOtherVersion.
@Test
public void versionShouldNotBeDeployedDeploymentOnOtherVersion() {
dao.delete(Deployment.class, QueryBuilders.matchAllQuery());
ApplicationVersion applicationVersion = createApplicationVersion();
Deployment deployment = new Deployment();
deployment.setId(UUID.randomUUID().toString());
deployment.setVersionId(UUID.randomUUID().toString());
deployment.setEndDate(null);
dao.save(deployment);
// this is supposed to find if a matching deployment object exists in ES.
Assert.assertFalse(appVersionSrv.isApplicationVersionDeployed(applicationVersion));
}
use of alien4cloud.model.application.ApplicationVersion in project alien4cloud by alien4cloud.
the class ApplicationVersionController method search.
/**
* Search application versions for a given application id
*
* @param applicationId the targeted application id
* @param searchRequest
* @return A rest response that contains a {@link FacetedSearchResult} containing application versions for an application id sorted by version
*/
@ApiOperation(value = "Search application versions", notes = "Returns a search result with that contains application versions matching the request. A application version is returned only if the connected user has at least one application role in [ APPLICATION_MANAGER | APPLICATION_USER | APPLICATION_DEVOPS | DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/search", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<GetMultipleDataResult<ApplicationVersion>> search(@PathVariable String applicationId, @RequestBody FilteredSearchRequest searchRequest) {
Application application = applicationService.getOrFail(applicationId);
AuthorizationUtil.checkAuthorizationForApplication(application, ApplicationRole.values());
GetMultipleDataResult<ApplicationVersion> searchResult = appVersionService.search(applicationId, searchRequest.getQuery(), searchRequest.getFrom(), searchRequest.getSize());
return RestResponseBuilder.<GetMultipleDataResult<ApplicationVersion>>builder().data(searchResult).build();
}
use of alien4cloud.model.application.ApplicationVersion in project alien4cloud by alien4cloud.
the class ApplicationVersionController method create.
/**
* Create a new application version for an application.
*
* @param request data to create an application environment
* @return application environment id
*/
@ApiOperation(value = "Create a new application version.", notes = "If successfull returns a rest response with the id of the created application version in data. If not successful a rest response with an error content is returned. Application role required [ APPLICATIONS_MANAGER ]. " + "By default the application version creator will have application roles [APPLICATION_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(@PathVariable String applicationId, @RequestBody CreateApplicationVersionRequest request) {
Application application = applicationService.getOrFail(applicationId);
AuthorizationUtil.checkAuthorizationForApplication(application, ApplicationRole.APPLICATION_MANAGER);
String originalId = request.getTopologyTemplateId();
boolean originalIsAppVersion = false;
if (originalId == null) {
originalId = request.getFromVersionId();
originalIsAppVersion = true;
} else if (request.getFromVersionId() != null) {
throw new IllegalArgumentException("topologyTemplateId and fromVersionId are mutually exclusive.");
}
ApplicationVersion appVersion = appVersionService.createApplicationVersion(applicationId, request.getVersion(), request.getDescription(), originalId, originalIsAppVersion);
return RestResponseBuilder.<String>builder().data(appVersion.getId()).build();
}
use of alien4cloud.model.application.ApplicationVersion in project alien4cloud by alien4cloud.
the class ApplicationVersionController method get.
/**
* Get most recent snapshot application version for an application
*
* @param applicationId The application id.
*/
@ApiOperation(value = "Get the first snapshot application version for an application.", notes = "Return the first snapshot application version for an application. Application role required [ APPLICATION_MANAGER | APPLICATION_USER | APPLICATION_DEVOPS | DEPLOYMENT_MANAGER ]")
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<ApplicationVersion> get(@PathVariable String applicationId) {
Application application = alienDAO.findById(Application.class, applicationId);
AuthorizationUtil.checkAuthorizationForApplication(application, ApplicationRole.values());
return RestResponseBuilder.<ApplicationVersion>builder().data(appVersionService.getLatestSnapshot(applicationId)).build();
}
Aggregations