@Override public boolean apply(LocationUsage input) { LocationUsage.LocationEvent first = input.getEvents().get(0); if (endDate.compareTo(first.getDate()) < 0) { return false; } LocationUsage.LocationEvent last = input.getEvents().get(input.getEvents().size() - 1); if (!WORKING_LIFECYCLES.contains(last.getState()) && startDate.compareTo(last.getDate()) > 0) { return false; } if (application != null) { for (LocationUsage.LocationEvent e : input.getEvents()) { if (Objects.equal(application, e.getApplicationId())) { return true; } } return false; } return true; } });
private List<UsageStatistic> retrieveApplicationUsage(ApplicationUsage usage, Date startDate, Date endDate) { log.debug("Determining application usage for application {}: dates {} -> {}", new Object[] {usage.getApplicationId(), startDate, endDate}); log.trace("Considering application usage events of {}: {}", usage.getApplicationId(), usage.getEvents()); for (int i = 0; i < usage.getEvents().size(); i++) { ApplicationEvent current = usage.getEvents().get(i); Date eventStartDate = current.getDate(); Date eventEndDate; if (i < usage.getEvents().size() - 1) { ApplicationEvent next = usage.getEvents().get(i + 1); eventEndDate = next.getDate(); } else if (current.getState() == Lifecycle.DESTROYED) { eventEndDate = eventStartDate; } else { UsageStatistic statistic = new UsageStatistic(ApplicationTransformer.statusFromLifecycle(current.getState()), usage.getApplicationId(), usage.getApplicationId(), format(eventStartDate), format(eventEndDate), duration, usage.getMetadata()); log.trace("Adding application usage statistic to response for app {}: {}", usage.getApplicationId(), statistic); result.add(statistic);
private List<UsageStatistic> retrieveMachineUsage(LocationUsage usage, Date startDate, Date endDate) { log.debug("Determining machine usage for location {}", usage.getLocationId()); log.trace("Considering machine usage events of {}: {}", usage.getLocationId(), usage.getEvents()); for (int i = 0; i < usage.getEvents().size(); i++) { LocationUsage.LocationEvent current = usage.getEvents().get(i); Date eventStartDate = current.getDate(); Date eventEndDate; if (i < usage.getEvents().size() - 1) { LocationUsage.LocationEvent next = usage.getEvents().get(i + 1); eventEndDate = next.getDate(); } else if (current.getState() == Lifecycle.DESTROYED || current.getState() == Lifecycle.STOPPED) { eventEndDate = eventStartDate; } else { UsageStatistic statistic = new UsageStatistic(ApplicationTransformer.statusFromLifecycle(current.getState()), usage.getLocationId(), current.getApplicationId(), format(eventStartDate), format(eventEndDate), duration, usage.getMetadata()); log.trace("Adding machine usage statistic to response for app {}: {}", usage.getLocationId(), statistic); result.add(statistic);
@Override public void recordApplicationEvent(Application app, Lifecycle state) { log.debug("Storing location lifecycle event: application {} in state {};", new Object[] {app, state}); ConcurrentMap<String, ApplicationUsage> eventMap = managementContext.getStorage().getMap(APPLICATION_USAGE_KEY); synchronized (mutex) { ApplicationUsage usage = eventMap.get(app.getId()); if (usage == null) { usage = new ApplicationUsage(app.getId(), app.getDisplayName(), app.getEntityType().getName(), ((EntityInternal)app).toMetadataRecord()); } usage.addEvent(new ApplicationUsage.ApplicationEvent(state)); eventMap.put(app.getId(), usage); } }
String entityTypeName = caller.getEntityType().getName(); String appId = caller.getApplicationId(); LocationUsage.LocationEvent event = new LocationUsage.LocationEvent(state, caller.getId(), entityTypeName, appId); LocationUsage usage = usageMap.get(loc.getId()); if (usage == null) { usage = new LocationUsage(loc.getId(), ((LocationInternal)loc).toMetadataRecord()); usage.addEvent(event); usageMap.put(loc.getId(), usage);