use of alien4cloud.model.common.Usage in project alien4cloud by alien4cloud.
the class ServiceResourceService method reportArchiveUsage.
@EventListener
public void reportArchiveUsage(ArchiveUsageRequestEvent event) {
ServiceResource[] serviceResources = alienDAO.buildQuery(ServiceResource.class).setFilters(fromKeyValueCouples("dependency.name", event.getArchiveName(), "dependency.version", event.getArchiveVersion())).prepareSearch().search(0, Integer.MAX_VALUE).getData();
for (ServiceResource serviceResource : serviceResources) {
Usage usage = new Usage(serviceResource.getName(), ServiceResource.class.getSimpleName().toLowerCase(), serviceResource.getId(), "");
event.addUsage(usage);
}
}
use of alien4cloud.model.common.Usage in project alien4cloud by alien4cloud.
the class ApplicationVersionService method failIfAnyEnvironmentDeployed.
private void failIfAnyEnvironmentDeployed(ApplicationEnvironment[] relatedEnvironments) {
Usage[] usages = Arrays.stream(relatedEnvironments).map(environment -> {
Usage usage = null;
Deployment deployment = applicationEnvironmentService.getActiveDeployment(environment.getId());
if (deployment != null) {
String usageName = " App (" + deployment.getSourceName() + "), Env (" + environment.getName() + ")";
usage = new Usage(usageName, "Deployment", deployment.getId(), null);
}
return usage;
}).filter(Objects::nonNull).toArray(Usage[]::new);
if (ArrayUtils.isNotEmpty(usages)) {
throw new ReferencedResourceException("Application versions deployed cannot be updated", usages);
}
}
use of alien4cloud.model.common.Usage in project alien4cloud by alien4cloud.
the class ApplicationVersionService method failIfAnyEnvironmentExposedAsService.
private void failIfAnyEnvironmentExposedAsService(String applicationId, ApplicationEnvironment[] environments) {
Application application = applicationService.getOrFail(applicationId);
Usage[] usages = Arrays.stream(environments).map(environment -> {
Usage usage = null;
ServiceResource service = alienDAO.buildQuery(ServiceResource.class).setFilters(fromKeyValueCouples("environmentId", environment.getId())).prepareSearch().find();
if (service != null) {
String usageName = service.getName() + " [App (" + application.getName() + "), Env (" + environment.getName() + ")]";
usage = new Usage(usageName, "Service", service.getId(), null);
}
return usage;
}).filter(Objects::nonNull).toArray(Usage[]::new);
if (ArrayUtils.isNotEmpty(usages)) {
throw new ReferencedResourceException("Application versions exposed as a service cannot be updated", usages);
}
}
use of alien4cloud.model.common.Usage in project alien4cloud by alien4cloud.
the class PluginArchiveIndexer method deleteArchives.
/**
* Delete all archives related to a location, if not exposed or used by another location
*
* @param location
* @return Map of usages per archives if found (that means the deletion wasn't performed successfully), null if everything went well.
*/
public Map<Csar, List<Usage>> deleteArchives(Orchestrator orchestrator, Location location) {
ILocationConfiguratorPlugin configuratorPlugin = getConfiguratorPlugin(location);
IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
List<PluginArchive> pluginArchives = configuratorPlugin.pluginArchives();
// abort if no archive is exposed by this location
if (CollectionUtils.isEmpty(pluginArchives)) {
return null;
}
Map<String, List<Location>> allExposedArchivesIds = getAllExposedArchivesIdsExluding(location);
Map<Csar, List<Usage>> usages = Maps.newHashMap();
for (PluginArchive pluginArchive : pluginArchives) {
Csar csar = pluginArchive.getArchive().getArchive();
List<Location> locationsExposingArchive = allExposedArchivesIds.get(csar.getId());
LocationArchiveDeleteRequested e = new LocationArchiveDeleteRequested(this);
e.setCsar(csar);
e.setLocation(location);
e.setOrchestratorFactory(orchestratorFactory);
e.setLocationsExposingArchive(locationsExposingArchive);
// only delete if no other location exposed this archive
if (locationsExposingArchive == null) {
List<Usage> csarUsage = csarService.deleteCsarWithElements(csar);
if (CollectionUtils.isNotEmpty(csarUsage)) {
usages.put(csar, csarUsage);
}
e.setDeleted(true);
} else {
e.setDeleted(false);
}
applicationContext.publishEvent(e);
}
return usages.isEmpty() ? null : usages;
}
use of alien4cloud.model.common.Usage 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);
}
}
Aggregations