use of alien4cloud.rest.application.model.ApplicationEnvironmentDTO in project alien4cloud by alien4cloud.
the class ApplicationEnvironmentDTOBuilder method getApplicationEnvironmentDTO.
/**
* Creates an ApplicationEnvironmentDTO from an ApplicationEnvironment adding the deployment status informations.
*
* @param env The environment for which to create DTO
* @return The application environement DTO matching the given application environement.
*/
public ApplicationEnvironmentDTO getApplicationEnvironmentDTO(ApplicationEnvironment env) {
ApplicationEnvironmentDTO tempEnvDTO = new ApplicationEnvironmentDTO();
tempEnvDTO.setApplicationId(env.getApplicationId());
tempEnvDTO.setDescription(env.getDescription());
tempEnvDTO.setEnvironmentType(env.getEnvironmentType());
tempEnvDTO.setId(env.getId());
tempEnvDTO.setName(env.getName());
tempEnvDTO.setUserRoles(env.getUserRoles());
tempEnvDTO.setGroupRoles(env.getGroupRoles());
tempEnvDTO.setCurrentVersionName(env.getTopologyVersion());
try {
Deployment deployment = applicationEnvironmentService.getActiveDeployment(env.getId());
tempEnvDTO.setStatus(applicationEnvironmentService.getStatus(deployment));
if (!DeploymentStatus.UNDEPLOYED.equals(tempEnvDTO.getStatus())) {
tempEnvDTO.setDeployedVersion(deployment.getVersionId());
}
} catch (Exception e) {
log.debug("Getting status for the environment <" + env.getId() + "> failed because the associated orchestrator cannot be reached. Returned status is UNKNOWN.", e);
tempEnvDTO.setStatus(DeploymentStatus.UNKNOWN);
}
return tempEnvDTO;
}
use of alien4cloud.rest.application.model.ApplicationEnvironmentDTO in project alien4cloud by alien4cloud.
the class ApplicationStepDefinitions method I_get_the_application_environment_named.
@When("^I get the application environment named \"([^\"]*)\"$")
public void I_get_the_application_environment_named(String applicationEnvironmentName) throws Throwable {
Assert.assertNotNull(CURRENT_APPLICATION);
String applicationEnvId = Context.getInstance().getApplicationEnvironmentId(CURRENT_APPLICATION.getName(), applicationEnvironmentName);
Context.getInstance().registerRestResponse(getRestClientInstance().get("/rest/v1/applications/" + CURRENT_APPLICATION.getId() + "/environments/" + applicationEnvId));
RestResponse<ApplicationEnvironmentDTO> appEnvironment = JsonUtil.read(Context.getInstance().getRestResponse(), ApplicationEnvironmentDTO.class);
Assert.assertNotNull(appEnvironment.getData());
Assert.assertEquals(appEnvironment.getData().getId(), applicationEnvId);
}
use of alien4cloud.rest.application.model.ApplicationEnvironmentDTO in project alien4cloud by alien4cloud.
the class ApplicationStepDefinitions method setAppEnvironmentIdToContext.
@SuppressWarnings("rawtypes")
public void setAppEnvironmentIdToContext(String applicationName) throws IOException {
String applicationId = Context.getInstance().getApplicationId(applicationName);
FilteredSearchRequest request = new FilteredSearchRequest();
request.setFrom(0);
request.setSize(10);
String applicationEnvironmentsJson = getRestClientInstance().postJSon("/rest/v1/applications/" + applicationId + "/environments/search", JsonUtil.toString(request));
RestResponse<GetMultipleDataResult> restResponse = JsonUtil.read(applicationEnvironmentsJson, GetMultipleDataResult.class);
GetMultipleDataResult searchResp = restResponse.getData();
ApplicationEnvironmentDTO appEnvDTO = JsonUtil.readObject(JsonUtil.toString(searchResp.getData()[0]), ApplicationEnvironmentDTO.class);
Context.getInstance().registerApplicationEnvironmentId(applicationName, appEnvDTO.getName(), appEnvDTO.getId());
}
use of alien4cloud.rest.application.model.ApplicationEnvironmentDTO in project alien4cloud by alien4cloud.
the class ApplicationDeploymentController method getApplicationsEnvironments.
@ApiOperation(value = "Get all environments including their current deployment status for a list of applications.", notes = "Return the environements for all given applications. Note that only environments the user is authorized to see are returned.")
@RequestMapping(value = "/environments", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Deprecated
public RestResponse<Map<String, ApplicationEnvironmentDTO[]>> getApplicationsEnvironments(@RequestBody List<String> applicationIds) {
Map<String, ApplicationEnvironmentDTO[]> envsByApplicationId = Maps.newHashMap();
for (String applicationId : applicationIds) {
Application application = applicationService.checkAndGetApplication(applicationId);
// get all environments status for the current application
ApplicationEnvironment[] environments = applicationEnvironmentService.getByApplicationId(application.getId());
List<ApplicationEnvironmentDTO> userEnvironmentList = new ArrayList<>(environments.length);
for (ApplicationEnvironment env : environments) {
if (AuthorizationUtil.hasAuthorizationForEnvironment(application, env, ApplicationEnvironmentRole.values())) {
userEnvironmentList.add(dtoBuilder.getApplicationEnvironmentDTO(env));
}
}
envsByApplicationId.put(applicationId, userEnvironmentList.toArray(new ApplicationEnvironmentDTO[userEnvironmentList.size()]));
}
return RestResponseBuilder.<Map<String, ApplicationEnvironmentDTO[]>>builder().data(envsByApplicationId).build();
}
Aggregations