Search in sources :

Example 6 with Usage

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

Example 7 with 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);
    }
}
Also used : Usage(alien4cloud.model.common.Usage) Deployment(alien4cloud.model.deployment.Deployment)

Example 8 with Usage

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);
    }
}
Also used : Usage(alien4cloud.model.common.Usage) ServiceResource(alien4cloud.model.service.ServiceResource) Application(alien4cloud.model.application.Application)

Example 9 with Usage

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;
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) LocationArchiveDeleteRequested(alien4cloud.events.LocationArchiveDeleteRequested) Usage(alien4cloud.model.common.Usage) ILocationConfiguratorPlugin(alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin) PluginArchive(alien4cloud.orchestrators.plugin.model.PluginArchive) IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) ArrayList(java.util.ArrayList) List(java.util.List) Location(alien4cloud.model.orchestrators.locations.Location)

Example 10 with Usage

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

Aggregations

Usage (alien4cloud.model.common.Usage)16 Csar (org.alien4cloud.tosca.model.Csar)7 Application (alien4cloud.model.application.Application)4 Deployment (alien4cloud.model.deployment.Deployment)3 Location (alien4cloud.model.orchestrators.locations.Location)3 ApiOperation (io.swagger.annotations.ApiOperation)3 List (java.util.List)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ServiceResource (alien4cloud.model.service.ServiceResource)2 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)2 PluginArchive (alien4cloud.orchestrators.plugin.model.PluginArchive)2 ServiceUsageRequestEvent (org.alien4cloud.alm.service.events.ServiceUsageRequestEvent)2 EventListener (org.springframework.context.event.EventListener)2 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)1 Audit (alien4cloud.audit.annotation.Audit)1 FilterUtil.fromKeyValueCouples (alien4cloud.dao.FilterUtil.fromKeyValueCouples)1 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)1 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)1 LocationArchiveDeleteRequested (alien4cloud.events.LocationArchiveDeleteRequested)1