2015-10-14 15:10:06 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.accounting.analytics.persistence;
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
2021-11-22 13:37:18 +01:00
|
|
|
import java.util.Collection;
|
2015-10-14 15:10:06 +02:00
|
|
|
import java.util.List;
|
2021-05-07 14:05:31 +02:00
|
|
|
import java.util.Set;
|
2016-03-16 13:29:03 +01:00
|
|
|
import java.util.SortedMap;
|
|
|
|
import java.util.SortedSet;
|
2015-10-14 15:10:06 +02:00
|
|
|
|
|
|
|
import org.gcube.accounting.analytics.Filter;
|
|
|
|
import org.gcube.accounting.analytics.Info;
|
2016-03-16 15:53:59 +01:00
|
|
|
import org.gcube.accounting.analytics.NumberedFilter;
|
2015-10-14 15:10:06 +02:00
|
|
|
import org.gcube.accounting.analytics.TemporalConstraint;
|
2016-11-15 11:21:51 +01:00
|
|
|
import org.gcube.accounting.analytics.UsageValue;
|
2018-01-02 17:22:13 +01:00
|
|
|
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
2015-12-18 17:13:22 +01:00
|
|
|
import org.gcube.documentstore.records.AggregatedRecord;
|
2021-03-22 12:00:21 +01:00
|
|
|
import org.gcube.documentstore.records.Record;
|
2015-10-14 15:10:06 +02:00
|
|
|
|
|
|
|
/**
|
2016-10-12 14:09:44 +02:00
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
2015-10-14 15:10:06 +02:00
|
|
|
*/
|
2016-03-24 18:59:34 +01:00
|
|
|
public interface AccountingPersistenceBackendQuery {
|
2016-03-16 15:53:59 +01:00
|
|
|
|
2016-01-15 17:48:22 +01:00
|
|
|
public static final int KEY_VALUES_LIMIT = 25;
|
2016-03-16 15:53:59 +01:00
|
|
|
|
2018-01-02 17:22:13 +01:00
|
|
|
public static String getScopeToQuery() {
|
2018-01-02 17:26:12 +01:00
|
|
|
String scope = AccountingPersistenceQueryFactory.getForcedQueryScope().get();
|
2018-01-02 17:22:13 +01:00
|
|
|
if(scope == null) {
|
|
|
|
scope = BasicUsageRecord.getContextFromToken();
|
|
|
|
}
|
|
|
|
return scope;
|
|
|
|
}
|
|
|
|
|
2016-03-24 18:59:34 +01:00
|
|
|
public void prepareConnection(
|
2016-03-16 15:53:59 +01:00
|
|
|
AccountingPersistenceBackendQueryConfiguration configuration)
|
2016-06-28 15:00:55 +02:00
|
|
|
throws Exception;
|
2016-03-16 15:53:59 +01:00
|
|
|
|
2021-05-07 14:05:31 +02:00
|
|
|
/**
|
|
|
|
* @param clz the Usage Record Class of interest
|
|
|
|
*
|
|
|
|
* Required
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public void setRequestedRecords(Class<? extends AggregatedRecord<?, ?>> clz);
|
|
|
|
|
2015-10-14 15:10:06 +02:00
|
|
|
/**
|
2021-05-07 14:05:31 +02:00
|
|
|
* @param temporalConstraint the TemporalConstraint (interval and aggregation)
|
2016-03-16 15:53:59 +01:00
|
|
|
*
|
2021-05-07 14:05:31 +02:00
|
|
|
* Required
|
2015-10-14 15:10:06 +02:00
|
|
|
*/
|
2021-05-07 14:05:31 +02:00
|
|
|
public void setTemporalConstraint(TemporalConstraint temporalConstraint);
|
|
|
|
|
2017-02-03 12:18:14 +01:00
|
|
|
/**
|
2021-05-07 14:05:31 +02:00
|
|
|
* @param contexts the list of context to use as filter
|
|
|
|
*
|
|
|
|
* If null or empty list get all data for the interested Record Class
|
2021-10-29 18:26:34 +02:00
|
|
|
* with the applying temporal constraint with no contexts constraint.
|
2021-05-07 14:05:31 +02:00
|
|
|
* The contexts are evaluated in OR.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public void setContexts(Set<String> contexts);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param filters list of filter to obtain the results.
|
|
|
|
* If null or empty list get all data for the interested Record Class
|
|
|
|
* with the applying temporal constraint.
|
|
|
|
* All Filter must have not null and not empty key and value.
|
|
|
|
* The filters must be related to different keys and are in AND.
|
|
|
|
* If the list contains more than one filter with the same key an Exception is thrown
|
|
|
|
* when trying to query.
|
|
|
|
*/
|
2021-11-22 14:18:12 +01:00
|
|
|
public void setFilters(Collection<? extends Filter> filters);
|
2021-05-07 14:05:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Query the persistence obtaining a Map where the date is the key and the
|
2017-02-03 12:18:14 +01:00
|
|
|
* #Info is the value. The result is relative to an Usage Record Type,
|
|
|
|
* respect a TemporalConstraint and can be applied one or more filters.
|
|
|
|
*
|
2021-05-07 14:05:31 +02:00
|
|
|
* @return the Map containing for each date in the required interval the requested data
|
2017-02-03 12:18:14 +01:00
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-05-07 14:05:31 +02:00
|
|
|
public SortedMap<Calendar, Info> getTimeSeries() throws Exception;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a SortedMap containing the TimeSeries for each context.
|
|
|
|
* @return a SortedMap containing the TimeSeries for each context.
|
|
|
|
*/
|
|
|
|
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries() throws Exception;
|
|
|
|
|
2015-10-14 15:10:06 +02:00
|
|
|
/**
|
2016-03-16 15:53:59 +01:00
|
|
|
* Return a SortedMap containing the TimeSeries for top values for a certain
|
2021-05-07 14:05:31 +02:00
|
|
|
* key taking in account all Filters.
|
|
|
|
*
|
|
|
|
* The values are ordered from the most occurred value.
|
2016-03-16 15:53:59 +01:00
|
|
|
*
|
2021-05-07 14:05:31 +02:00
|
|
|
* @param topKey the key to obtain top values
|
2016-03-24 18:59:34 +01:00
|
|
|
* @param orderingProperty
|
2016-03-16 15:53:59 +01:00
|
|
|
* @return a SortedMap
|
2021-05-07 14:05:31 +02:00
|
|
|
|
2016-03-16 15:53:59 +01:00
|
|
|
* @throws Exception
|
2015-10-14 15:10:06 +02:00
|
|
|
*/
|
2021-05-07 14:05:31 +02:00
|
|
|
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(String topKey, String orderingProperty) throws Exception;
|
2021-03-19 18:18:30 +01:00
|
|
|
|
2015-10-14 15:10:06 +02:00
|
|
|
/**
|
|
|
|
* Close the connection to persistence
|
2016-03-16 15:53:59 +01:00
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
* if the close fails
|
2015-10-14 15:10:06 +02:00
|
|
|
*/
|
2016-03-24 18:59:34 +01:00
|
|
|
public void close() throws Exception;
|
2016-03-16 15:53:59 +01:00
|
|
|
|
2021-05-07 14:05:31 +02:00
|
|
|
public SortedSet<NumberedFilter> getFilterValues(String key) throws Exception;
|
|
|
|
|
|
|
|
public SortedSet<NumberedFilter> getFilterValues(String key, Integer limit) throws Exception;
|
|
|
|
|
|
|
|
public Record getRecord(String recordId, String type) throws Exception;
|
|
|
|
|
|
|
|
public SortedMap<Filter, SortedMap<Calendar, Info>> getSpaceTimeSeries(Set<String> dataTypes) throws Exception;
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2016-10-13 18:18:19 +02:00
|
|
|
/**
|
2016-11-11 10:03:09 +01:00
|
|
|
* getUsageValueQuotaTotal
|
|
|
|
*
|
2021-05-07 14:05:31 +02:00
|
|
|
* Example to require 2 different quota (lucio.lelii for service and alessandro.pieve for storage)
|
2016-11-11 10:03:09 +01:00
|
|
|
* Input:
|
|
|
|
* [
|
|
|
|
* TotalFilters [
|
|
|
|
* clz=class org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord,
|
|
|
|
* temporalConstraint=StartTime : 2015-05-01 11:42:34:515 UTC (1430480554515 millis), EndTime : 2016-11-09 11:42:34:515 UTC (1478691754515 millis),
|
|
|
|
* Aggregated DAILY,
|
|
|
|
* totalFilters=[
|
|
|
|
* Filters [filters=[
|
|
|
|
* { "consumerId" : "lucio.lelii" },
|
|
|
|
* { "serviceClass" : "DataAccess" },
|
|
|
|
* { "serviceName" : "CkanConnector" }
|
|
|
|
* ], d=null, orderingProperty=null],
|
|
|
|
* Filters [filters=[
|
|
|
|
* { "consumerId" : "lucio.lelii" },
|
|
|
|
* { "serviceClass" : "VREManagement" }
|
|
|
|
* ], d=null, orderingProperty=null]
|
|
|
|
* ], d=null, orderingProperty=null]
|
|
|
|
* ]
|
|
|
|
* Output:
|
|
|
|
* [
|
|
|
|
* TotalFilters [
|
|
|
|
* clz=class org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord,
|
|
|
|
* temporalConstraint=StartTime : 2015-05-01 11:42:34:515 UTC (1430480554515 millis), EndTime : 2016-11-09 11:42:34:515 UTC (1478691754515 millis),
|
|
|
|
* Aggregated DAILY,
|
|
|
|
* totalFilters=[
|
|
|
|
* Filters [filters=[
|
|
|
|
* { "consumerId" : "lucio.lelii" },
|
|
|
|
* { "serviceClass" : "DataAccess" },
|
|
|
|
* { "serviceName" : "CkanConnector" }
|
|
|
|
* ], d=1.0, orderingProperty=operationCount],
|
|
|
|
* Filters [filters=[
|
|
|
|
* { "consumerId" : "lucio.lelii" },
|
|
|
|
* { "serviceClass" : "VREManagement" }
|
|
|
|
* ], d=1.0, orderingProperty=operationCount]
|
|
|
|
* ], d=2.0, orderingProperty=null]
|
|
|
|
* ]
|
2016-10-13 18:18:19 +02:00
|
|
|
* @param listUsage
|
2017-10-27 17:36:13 +02:00
|
|
|
* @return List<UsageValue>
|
2016-10-13 18:18:19 +02:00
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-05-07 14:05:31 +02:00
|
|
|
public List<UsageValue> getUsageValueQuotaTotal(List<UsageValue> listUsage)
|
2016-11-08 10:00:15 +01:00
|
|
|
throws Exception;
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2017-09-06 16:12:15 +02:00
|
|
|
boolean isConnectionActive() throws Exception;
|
|
|
|
|
2021-05-07 14:05:31 +02:00
|
|
|
}
|