Search in sources :

Example 11 with ApplicationVersion

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));
}
Also used : AfterApplicationTopologyVersionDeleted(org.alien4cloud.alm.events.AfterApplicationTopologyVersionDeleted) ApplicationVersion(alien4cloud.model.application.ApplicationVersion) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) BeforeApplicationTopologyVersionDeleted(org.alien4cloud.alm.events.BeforeApplicationTopologyVersionDeleted) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion)

Example 12 with ApplicationVersion

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));
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) Deployment(alien4cloud.model.deployment.Deployment) Test(org.junit.Test)

Example 13 with 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();
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Application(alien4cloud.model.application.Application) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with ApplicationVersion

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();
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) Application(alien4cloud.model.application.Application) Audit(alien4cloud.audit.annotation.Audit) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with ApplicationVersion

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();
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) Application(alien4cloud.model.application.Application) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ApplicationVersion (alien4cloud.model.application.ApplicationVersion)19 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)6 ApiOperation (io.swagger.annotations.ApiOperation)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)5 Audit (alien4cloud.audit.annotation.Audit)4 Test (org.junit.Test)4 Application (alien4cloud.model.application.Application)3 Deployment (alien4cloud.model.deployment.Deployment)3 AuthorizationServiceException (org.springframework.security.access.AuthorizationServiceException)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Topology (org.alien4cloud.tosca.model.templates.Topology)2 TopologyVersionUpdated (alien4cloud.common.ResourceUpdateInterceptor.TopologyVersionUpdated)1 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)1 AlreadyExistException (alien4cloud.exception.AlreadyExistException)1 TestUtils.nullAsString (alien4cloud.it.utils.TestUtils.nullAsString)1 UpdateApplicationVersionException (alien4cloud.utils.version.UpdateApplicationVersionException)1 Date (java.util.Date)1 Set (java.util.Set)1 AfterApplicationTopologyVersionDeleted (org.alien4cloud.alm.events.AfterApplicationTopologyVersionDeleted)1