Search in sources :

Example 11 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationDeploymentController method getRuntimeTopology.

/**
 * Get runtime topology of an application on a specific environment or the current deployment topology if no deployment is active.
 * This method is necessary for example to compute output properties / attributes on the client side.
 *
 * @param applicationId application id for which to get the topology
 * @param applicationEnvironmentId application environment for which to get the topology
 * @return {@link RestResponse}<{@link TopologyDTO}> containing the requested runtime {@link Topology} and the
 *         {@link NodeType} related to its {@link NodeTemplate}s
 */
@ApiOperation(value = "Get last runtime (deployed) topology of an application or else get the current deployment topology for the environment.")
@RequestMapping(value = "/{applicationId:.+?}/environments/{applicationEnvironmentId:.+?}/runtime-topology", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<TopologyDTO> getRuntimeTopology(@ApiParam(value = "Id of the application for which to get deployed topology.", required = true) @PathVariable String applicationId, @ApiParam(value = "Id of the environment for which to get deployed topology.", required = true) @PathVariable String applicationEnvironmentId) {
    ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(applicationId, applicationEnvironmentId);
    if (!environment.getApplicationId().equals(applicationId)) {
        throw new NotFoundException("Unable to find environment with id <" + applicationEnvironmentId + "> for application <" + applicationId + ">");
    }
    AuthorizationUtil.checkAuthorizationForEnvironment(applicationService.getOrFail(applicationId), environment, ApplicationEnvironmentRole.APPLICATION_USER);
    Deployment deployment = deploymentService.getActiveDeployment(environment.getId());
    DeploymentTopology deploymentTopology = null;
    if (deployment != null) {
        deploymentTopology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
    }
    return RestResponseBuilder.<TopologyDTO>builder().data(topologyDTOBuilder.initTopologyDTO(deploymentTopology, new TopologyDTO())).build();
}
Also used : TopologyDTO(alien4cloud.topology.TopologyDTO) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) NotFoundException(alien4cloud.exception.NotFoundException) Deployment(alien4cloud.model.deployment.Deployment) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentController method getTopologyId.

@Deprecated
@ApiOperation(value = "Deprecated: Get the id of the topology linked to the environment", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ]")
@RequestMapping(value = "/{applicationEnvironmentId:.+}/topology", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<String> getTopologyId(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId) {
    Application application = applicationService.getOrFail(applicationId);
    ApplicationEnvironment environment = applicationEnvironmentService.getOrFail(applicationEnvironmentId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.values());
    String topologyId = applicationEnvironmentService.getTopologyId(applicationEnvironmentId);
    if (topologyId == null) {
        throw new ApplicationVersionNotFoundException("An application version is required by an application environment.");
    }
    return RestResponseBuilder.<String>builder().data(topologyId).build();
}
Also used : ApplicationVersionNotFoundException(alien4cloud.exception.ApplicationVersionNotFoundException) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 13 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentController method getApplicationEnvironment.

/**
 * Get application environment from its id
 *
 * @param applicationId The application id
 * @param applicationEnvironmentId the environment for which to get the status
 * @return A {@link RestResponse} that contains the application environment {@link ApplicationEnvironment}.
 */
@ApiOperation(value = "Get an application environment from its id", notes = "Returns the application environment. Roles required: Application environment [ APPLICATION_USER | DEPLOYMENT_MANAGER ], or application [APPLICATION_MANAGER]")
@RequestMapping(value = "/{applicationEnvironmentId:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<ApplicationEnvironmentDTO> getApplicationEnvironment(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId) {
    Application application = applicationService.checkAndGetApplication(applicationId);
    ApplicationEnvironment environment = applicationEnvironmentService.getOrFail(applicationEnvironmentId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.values());
    return RestResponseBuilder.<ApplicationEnvironmentDTO>builder().data(dtoBuilder.getApplicationEnvironmentDTO(environment)).build();
}
Also used : Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 14 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentController method create.

/**
 * Create the application environment for an application
 *
 * @param request data to create an application environment
 * @return application environment id
 */
@ApiOperation(value = "Create a new application environment", notes = "If successfull returns a rest response with the id of the created application environment in data. If not successful a rest response with an error content is returned. Role required [ APPLICATIONS_MANAGER ]" + "By default the application environment 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(@PathVariable String applicationId, @RequestBody ApplicationEnvironmentRequest request) throws OrchestratorDisabledException {
    // User should be APPLICATION_MANAGER to create an environment
    applicationService.checkAndGetApplication(applicationId, ApplicationRole.APPLICATION_MANAGER);
    final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    ApplicationEnvironment appEnvironment = applicationEnvironmentService.createApplicationEnvironment(auth.getName(), applicationId, request.getName(), request.getDescription(), request.getEnvironmentType(), request.getVersionId());
    alienDAO.save(appEnvironment);
    if (StringUtils.isNotBlank(request.getInputCandidate())) {
        // Client ask to copy inputs from other environment
        ApplicationEnvironment environmentToCopyInputs = applicationEnvironmentService.checkAndGetApplicationEnvironment(request.getInputCandidate(), ApplicationRole.APPLICATION_MANAGER);
        applicationEnvironmentService.synchronizeEnvironmentInputs(environmentToCopyInputs, appEnvironment);
    }
    return RestResponseBuilder.<String>builder().data(appEnvironment.getId()).build();
}
Also used : Authentication(org.springframework.security.core.Authentication) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 15 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentGitController method checkEnvironmentAuthorization.

private void checkEnvironmentAuthorization(String applicationId, String environmentId) {
    ApplicationEnvironment environment = environmentService.getOrFail(environmentId);
    if (!environment.getApplicationId().equals(applicationId)) {
        throw new NotFoundException("Cannot find environement <" + environmentId + "> for application <" + applicationId + ">.");
    }
    Application application = applicationService.getOrFail(applicationId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Application(alien4cloud.model.application.Application)

Aggregations

ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)82 ApiOperation (io.swagger.annotations.ApiOperation)42 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 Application (alien4cloud.model.application.Application)40 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)35 Audit (alien4cloud.audit.annotation.Audit)27 List (java.util.List)17 Collectors (java.util.stream.Collectors)16 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)15 RestResponse (alien4cloud.rest.model.RestResponse)15 Topology (org.alien4cloud.tosca.model.templates.Topology)15 Set (java.util.Set)14 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)13 NotFoundException (alien4cloud.exception.NotFoundException)13 Map (java.util.Map)13 Resource (javax.annotation.Resource)12 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)11 Deployment (alien4cloud.model.deployment.Deployment)11 Arrays (java.util.Arrays)11 Location (alien4cloud.model.orchestrators.locations.Location)10