Search in sources :

Example 16 with ApplicationVersion

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());
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) TestUtils.nullAsString(alien4cloud.it.utils.TestUtils.nullAsString)

Example 17 with ApplicationVersion

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();
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) Authentication(org.springframework.security.core.Authentication) AlreadyExistException(alien4cloud.exception.AlreadyExistException) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 18 with ApplicationVersion

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

Example 19 with ApplicationVersion

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

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