Search in sources :

Example 11 with DeploymentStatus

use of alien4cloud.paas.model.DeploymentStatus in project alien4cloud by alien4cloud.

the class ApplicationsDeploymentStepDefinitions method doUndeployApplication.

private void doUndeployApplication(String applicationName, String environmentName, boolean failsafe) throws Throwable {
    String applicationId = Context.getInstance().getApplicationId(applicationName);
    String envId = environmentName == null ? Context.getInstance().getDefaultApplicationEnvironmentId(applicationName) : Context.getInstance().getApplicationEnvironmentId(applicationName, environmentName);
    String statusRequest = "/rest/v1/applications/" + applicationId + "/environments/" + envId + "/status";
    RestResponse<String> statusResponse = JsonUtil.read(Context.getRestClientInstance().get(statusRequest), String.class);
    if (failsafe) {
        if (statusResponse.getError() != null) {
            log.warn("Error was supposed to be null but was : ", statusResponse.getError());
        }
    } else {
        assertNull(statusResponse.getError());
    }
    DeploymentStatus deploymentStatus = DeploymentStatus.valueOf(statusResponse.getData());
    if (!DeploymentStatus.UNDEPLOYED.equals(deploymentStatus) || !DeploymentStatus.UNDEPLOYMENT_IN_PROGRESS.equals(deploymentStatus)) {
        Context.getInstance().registerRestResponse(Context.getRestClientInstance().delete("/rest/v1/applications/" + applicationId + "/environments/" + envId + "/deployment"));
    }
    assertStatus(applicationName, DeploymentStatus.UNDEPLOYED, Sets.newHashSet(DeploymentStatus.UNDEPLOYMENT_IN_PROGRESS), 10 * 60L * 1000L, null, failsafe);
}
Also used : DeploymentStatus(alien4cloud.paas.model.DeploymentStatus)

Example 12 with DeploymentStatus

use of alien4cloud.paas.model.DeploymentStatus in project alien4cloud by alien4cloud.

the class ApplicationDeploymentController method getApplicationsStatuses.

@ApiOperation(value = "Deprecated Get the deployment status for the environements that the current user is allowed to see for a given application.", notes = "Returns the current status of an application list from the PaaS it is deployed on for all environments.")
@RequestMapping(value = "/statuses", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Deprecated
public RestResponse<Map<String, Map<String, EnvironmentStatusDTO>>> getApplicationsStatuses(@RequestBody List<String> applicationIds) {
    Map<String, Map<String, EnvironmentStatusDTO>> statuses = Maps.newHashMap();
    for (String applicationId : applicationIds) {
        Map<String, EnvironmentStatusDTO> environmentStatuses = Maps.newHashMap();
        Application application = applicationService.checkAndGetApplication(applicationId);
        // get all environments status for the current application
        ApplicationEnvironment[] environments = applicationEnvironmentService.getByApplicationId(application.getId());
        for (ApplicationEnvironment env : environments) {
            if (AuthorizationUtil.hasAuthorizationForEnvironment(application, env, ApplicationEnvironmentRole.values())) {
                DeploymentStatus status = DeploymentStatus.UNKNOWN;
                try {
                    status = applicationEnvironmentService.getStatus(env);
                } catch (Exception e) {
                    log.debug("Getting status for the environment <" + env.getId() + "> failed because the associated orchestrator seems disabled. Returned status is UNKNOWN.", e);
                }
                // TODO: include environment roles in the DTO to help display on ui
                environmentStatuses.put(env.getId(), new EnvironmentStatusDTO(env.getName(), status));
            }
        }
        statuses.put(applicationId, environmentStatuses);
    }
    return RestResponseBuilder.<Map<String, Map<String, EnvironmentStatusDTO>>>builder().data(statuses).build();
}
Also used : EnvironmentStatusDTO(alien4cloud.rest.application.model.EnvironmentStatusDTO) Map(java.util.Map) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus) PaaSDeploymentException(alien4cloud.paas.exception.PaaSDeploymentException) MaintenanceModeException(alien4cloud.paas.exception.MaintenanceModeException) OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) NotFoundException(alien4cloud.exception.NotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with DeploymentStatus

use of alien4cloud.paas.model.DeploymentStatus in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentController method getApplicationEnvironmentStatus.

/**
 * Get the current status of the environment for the given application.
 *
 * @param applicationId the id of the application to be deployed.
 * @param applicationEnvironmentId the environment for which to get the status
 * @return A {@link RestResponse} that contains the application's current {@link DeploymentStatus}.
 * @throws Exception
 */
@ApiOperation(value = "Get an application environment from its id", notes = "Returns the application environment. Application role required [ APPLICATION_USER | DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/{applicationEnvironmentId:.+}/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<DeploymentStatus> getApplicationEnvironmentStatus(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId) throws ExecutionException, InterruptedException {
    Application application = applicationService.checkAndGetApplication(applicationId);
    ApplicationEnvironment environment = applicationEnvironmentService.getOrFail(applicationEnvironmentId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.values());
    DeploymentStatus status = applicationEnvironmentService.getStatus(environment);
    return RestResponseBuilder.<DeploymentStatus>builder().data(status).build();
}
Also used : Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 14 with DeploymentStatus

use of alien4cloud.paas.model.DeploymentStatus in project yorc-a4c-plugin by ystia.

the class YorcPaaSProvider method doChangeStatus.

/**
 * Actually change the status of the deployment in YorcRuntimeDeploymentInfo
 * Must be called with lock on jrdi
 * @param paasId
 * @param status
 */
public void doChangeStatus(String paasId, DeploymentStatus status) {
    YorcRuntimeDeploymentInfo jrdi = runtimeDeploymentInfos.get(paasId);
    if (jrdi == null) {
        log.error("YorcRuntimeDeploymentInfo is null for paasId " + paasId);
        return;
    }
    if (status.equals(DeploymentStatus.UNDEPLOYED)) {
        try {
            log.debug("send deployment purge request to yorc");
            restClient.undeploy("/deployments/" + paasId, true);
        } catch (YorcRestException jre) {
            // If 400 code (bad request)  is returned, we retry requesting purge during at most 5 minutes
            if (jre.getHttpStatusCode() == 400) {
                long timeout = System.currentTimeMillis() + 1000 * 60 * 5;
                long timetowait = timeout - System.currentTimeMillis();
                boolean retry = true;
                while (retry && timetowait > 0) {
                    retry = retryDeploymentPurge(paasId);
                }
            } else // 404 status code is ignored for purge failure
            if (jre.getHttpStatusCode() != 404) {
                log.error("undeploy purge returned an exception: " + jre.getMessage());
                changeStatus(paasId, DeploymentStatus.FAILURE);
                return;
            }
        } catch (Exception e) {
            log.error("undeploy purge returned an exception: " + e.getMessage());
            changeStatus(paasId, DeploymentStatus.FAILURE);
            return;
        }
    }
    DeploymentStatus oldDeploymentStatus = jrdi.getStatus();
    log.debug("Deployment [" + paasId + "] moved from status [" + oldDeploymentStatus + "] to [" + status + "]");
    jrdi.setStatus(status);
    PaaSDeploymentStatusMonitorEvent event = new PaaSDeploymentStatusMonitorEvent();
    event.setDeploymentStatus(status);
    postEvent(event, paasId);
}
Also used : PaaSDeploymentStatusMonitorEvent(alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent) MaintenanceModeException(alien4cloud.paas.exception.MaintenanceModeException) OperationExecutionException(alien4cloud.paas.exception.OperationExecutionException) YorcRestException(org.ystia.yorc.alien4cloud.plugin.rest.YorcRestException) PluginConfigurationException(alien4cloud.paas.exception.PluginConfigurationException) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus) YorcRestException(org.ystia.yorc.alien4cloud.plugin.rest.YorcRestException)

Aggregations

DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)14 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)3 MaintenanceModeException (alien4cloud.paas.exception.MaintenanceModeException)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Map (java.util.Map)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 AlreadyExistException (alien4cloud.exception.AlreadyExistException)2 Application (alien4cloud.model.application.Application)2 Deployment (alien4cloud.model.deployment.Deployment)2 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)2 IllegalDeploymentStateException (alien4cloud.paas.exception.IllegalDeploymentStateException)2 OperationExecutionException (alien4cloud.paas.exception.OperationExecutionException)2 OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)2 PluginConfigurationException (alien4cloud.paas.exception.PluginConfigurationException)2 PaaSDeploymentStatusMonitorEvent (alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 YorcRestException (org.ystia.yorc.alien4cloud.plugin.rest.YorcRestException)2 NotFoundException (alien4cloud.exception.NotFoundException)1 ITException (alien4cloud.it.exception.ITException)1 ServiceResource (alien4cloud.model.service.ServiceResource)1