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();
}
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();
}
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();
}
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();
}
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);
}
Aggregations