Search in sources :

Example 1 with ApplicationEnvironmentDTO

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;
}
Also used : ApplicationEnvironmentDTO(alien4cloud.rest.application.model.ApplicationEnvironmentDTO) Deployment(alien4cloud.model.deployment.Deployment)

Example 2 with ApplicationEnvironmentDTO

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);
}
Also used : ApplicationEnvironmentDTO(alien4cloud.rest.application.model.ApplicationEnvironmentDTO) TestUtils.nullAsString(alien4cloud.it.utils.TestUtils.nullAsString) When(cucumber.api.java.en.When)

Example 3 with ApplicationEnvironmentDTO

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());
}
Also used : FilteredSearchRequest(alien4cloud.rest.model.FilteredSearchRequest) ApplicationEnvironmentDTO(alien4cloud.rest.application.model.ApplicationEnvironmentDTO) TestUtils.nullAsString(alien4cloud.it.utils.TestUtils.nullAsString) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult)

Example 4 with ApplicationEnvironmentDTO

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

Aggregations

ApplicationEnvironmentDTO (alien4cloud.rest.application.model.ApplicationEnvironmentDTO)4 TestUtils.nullAsString (alien4cloud.it.utils.TestUtils.nullAsString)2 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)1 Application (alien4cloud.model.application.Application)1 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 Deployment (alien4cloud.model.deployment.Deployment)1 FilteredSearchRequest (alien4cloud.rest.model.FilteredSearchRequest)1 When (cucumber.api.java.en.When)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1