Search in sources :

Example 31 with Deployment

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

Example 32 with Deployment

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);
    }
}
Also used : FilterUtil.fromKeyValueCouples(alien4cloud.dao.FilterUtil.fromKeyValueCouples) Arrays(java.util.Arrays) ApplicationEnvironmentService(alien4cloud.application.ApplicationEnvironmentService) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Usage(alien4cloud.model.common.Usage) Resource(javax.annotation.Resource) EventListener(org.springframework.context.event.EventListener) ServiceUsageRequestEvent(org.alien4cloud.alm.service.events.ServiceUsageRequestEvent) IGenericSearchDAO(alien4cloud.dao.IGenericSearchDAO) Inject(javax.inject.Inject) Deployment(alien4cloud.model.deployment.Deployment) Service(org.springframework.stereotype.Service) Usage(alien4cloud.model.common.Usage) Deployment(alien4cloud.model.deployment.Deployment) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) EventListener(org.springframework.context.event.EventListener)

Example 33 with Deployment

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);
        }
    }
}
Also used : Deployment(alien4cloud.model.deployment.Deployment) ServiceResource(alien4cloud.model.service.ServiceResource) IPaasEventListener(alien4cloud.paas.IPaasEventListener) EventListener(org.springframework.context.event.EventListener)

Example 34 with Deployment

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));
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) Deployment(alien4cloud.model.deployment.Deployment) Test(org.junit.Test)

Example 35 with Deployment

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();
    }
}
Also used : OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) PaaSTechnicalException(alien4cloud.paas.exception.PaaSTechnicalException) RestError(alien4cloud.rest.model.RestError) Deployment(alien4cloud.model.deployment.Deployment) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus) OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) PaaSTechnicalException(alien4cloud.paas.exception.PaaSTechnicalException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Deployment (alien4cloud.model.deployment.Deployment)43 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)13 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)11 ApiOperation (io.swagger.annotations.ApiOperation)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 NotFoundException (alien4cloud.exception.NotFoundException)6 Application (alien4cloud.model.application.Application)6 Location (alien4cloud.model.orchestrators.locations.Location)6 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)5 ApplicationVersion (alien4cloud.model.application.ApplicationVersion)3 Usage (alien4cloud.model.common.Usage)3 PaaSDeploymentContext (alien4cloud.paas.model.PaaSDeploymentContext)3 Date (java.util.Date)3 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)2 SecretProviderConfigurationAndCredentials (alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials)2 AlreadyExistException (alien4cloud.exception.AlreadyExistException)2 ServiceResource (alien4cloud.model.service.ServiceResource)2 OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)2 DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)2