use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class DeploymentStatusEventHandler method eventHappened.
@Override
public void eventHappened(AbstractMonitorEvent aEvent) {
PaaSDeploymentStatusMonitorEvent event = (PaaSDeploymentStatusMonitorEvent) aEvent;
log.debug("Received a deployment status event for deployment {} with a new status to {}", event.getDeploymentId(), event.getDeploymentStatus());
if (DeploymentStatus.UNDEPLOYED.equals(event.getDeploymentStatus())) {
Deployment deployment = deploymentService.get(event.getDeploymentId());
if (deployment == null) {
log.error("No deployment with id {} can be found while processing status event with status update to {}.", event.getDeploymentId(), event.getDeploymentStatus());
return;
}
deploymentService.markUndeployed(deployment);
log.debug("Deployment {} end date has been updated to {} based on received UNDEPLOYED status event", event.getDeploymentId(), deployment.getEndDate());
}
}
use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class ServiceUsageReporter method reportServiceUsage.
@EventListener
private void reportServiceUsage(ServiceUsageRequestEvent serviceChangedEvent) {
GetMultipleDataResult<Deployment> usageResult = alienDAO.buildQuery(Deployment.class).setFilters(fromKeyValueCouples("endDate", null, "serviceResourceIds", serviceChangedEvent.getServiceId())).prepareSearch().search(0, Integer.MAX_VALUE);
if (usageResult.getTotalResults() > 0) {
Usage[] usages = Arrays.stream(usageResult.getData()).map(deployment -> {
ApplicationEnvironment environment = environmentService.getOrFail(deployment.getEnvironmentId());
String usageName = "App (" + deployment.getSourceName() + "), Env (" + environment.getName() + ")";
return new Usage(usageName, "Deployment", deployment.getId(), null);
}).toArray(Usage[]::new);
serviceChangedEvent.addUsages(usages);
}
}
use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class ManagedServiceResourceEventService method onDeploymentCreatedEvent.
/**
* On {@link DeploymentCreatedEvent}, eventually update the linked managed service
*
* @param event
*/
@EventListener
public void onDeploymentCreatedEvent(DeploymentCreatedEvent event) {
Deployment deployment = deploymentService.get(event.getDeploymentId());
if (deployment != null) {
ServiceResource serviceResource = managedServiceResourceService.get(deployment.getEnvironmentId());
if (serviceResource != null) {
serviceResource.setDeploymentId(event.getDeploymentId());
serviceResourceService.save(serviceResource);
}
}
}
use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class ApplicationVersionServiceTest method versionShouldNotBeDeployedDeploymentOnOtherVersion.
@Test
public void versionShouldNotBeDeployedDeploymentOnOtherVersion() {
dao.delete(Deployment.class, QueryBuilders.matchAllQuery());
ApplicationVersion applicationVersion = createApplicationVersion();
Deployment deployment = new Deployment();
deployment.setId(UUID.randomUUID().toString());
deployment.setVersionId(UUID.randomUUID().toString());
deployment.setEndDate(null);
dao.save(deployment);
// this is supposed to find if a matching deployment object exists in ES.
Assert.assertFalse(appVersionSrv.isApplicationVersionDeployed(applicationVersion));
}
use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class DeploymentController method getDeploymentStatus.
@ApiOperation(value = "Get deployment status from its id.", authorizations = { @Authorization("ADMIN"), @Authorization("APPLICATION_MANAGER") })
@RequestMapping(value = "/{deploymentId}/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<DeploymentStatus> getDeploymentStatus(@ApiParam(value = "Deployment id.", required = true) @Valid @NotBlank @PathVariable String deploymentId) {
Deployment deployment = alienDAO.findById(Deployment.class, deploymentId);
if (deployment != null) {
try {
return deploymentLockService.doWithDeploymentReadLock(deployment.getOrchestratorDeploymentId(), () -> {
final SettableFuture<DeploymentStatus> statusSettableFuture = SettableFuture.create();
deploymentRuntimeStateService.getDeploymentStatus(deployment, new IPaaSCallback<DeploymentStatus>() {
@Override
public void onSuccess(DeploymentStatus result) {
statusSettableFuture.set(result);
}
@Override
public void onFailure(Throwable t) {
statusSettableFuture.setException(t);
}
});
try {
DeploymentStatus currentStatus = statusSettableFuture.get();
if (DeploymentStatus.UNDEPLOYED.equals(currentStatus)) {
deploymentService.markUndeployed(deployment);
}
return RestResponseBuilder.<DeploymentStatus>builder().data(currentStatus).build();
} catch (Exception e) {
throw new PaaSTechnicalException("Could not retrieve status from PaaS", e);
}
});
} catch (OrchestratorDisabledException e) {
return RestResponseBuilder.<DeploymentStatus>builder().data(null).error(new RestError(RestErrorCode.CLOUD_DISABLED_ERROR.getCode(), e.getMessage())).build();
}
} else {
return RestResponseBuilder.<DeploymentStatus>builder().data(null).error(new RestError(RestErrorCode.NOT_FOUND_ERROR.getCode(), "Deployment with id <" + deploymentId + "> was not found.")).build();
}
}
Aggregations