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