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