Search in sources :

Example 1 with ServiceUsageRequestEvent

use of org.alien4cloud.alm.service.events.ServiceUsageRequestEvent 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 2 with ServiceUsageRequestEvent

use of org.alien4cloud.alm.service.events.ServiceUsageRequestEvent in project alien4cloud by alien4cloud.

the class ServiceResourceService method failIdUsed.

private void failIdUsed(String id) {
    ServiceUsageRequestEvent serviceUsageRequestEvent = new ServiceUsageRequestEvent(this, id);
    publisher.publishEvent(serviceUsageRequestEvent);
    Usage[] usages = serviceUsageRequestEvent.getUsages();
    if (usages.length > 0) {
        throw new ServiceUsageException("Used services cannot be updated or deleted.", usages);
    }
}
Also used : ServiceUsageException(org.alien4cloud.alm.service.exceptions.ServiceUsageException) Usage(alien4cloud.model.common.Usage) ServiceUsageRequestEvent(org.alien4cloud.alm.service.events.ServiceUsageRequestEvent)

Aggregations

Usage (alien4cloud.model.common.Usage)2 ServiceUsageRequestEvent (org.alien4cloud.alm.service.events.ServiceUsageRequestEvent)2 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)1 FilterUtil.fromKeyValueCouples (alien4cloud.dao.FilterUtil.fromKeyValueCouples)1 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)1 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)1 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 Deployment (alien4cloud.model.deployment.Deployment)1 Arrays (java.util.Arrays)1 Resource (javax.annotation.Resource)1 Inject (javax.inject.Inject)1 ServiceUsageException (org.alien4cloud.alm.service.exceptions.ServiceUsageException)1 EventListener (org.springframework.context.event.EventListener)1 Service (org.springframework.stereotype.Service)1