2015-10-14 15:10:06 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.accounting.analytics.persistence;
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.List;
|
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;
|
2016-03-24 18:59:34 +01:00
|
|
|
import org.gcube.accounting.analytics.exception.DuplicatedKeyFilterException;
|
|
|
|
import org.gcube.accounting.analytics.exception.KeyException;
|
|
|
|
import org.gcube.accounting.analytics.exception.ValueException;
|
2015-12-18 17:13:22 +01:00
|
|
|
import org.gcube.documentstore.records.AggregatedRecord;
|
2016-06-28 15:00:55 +02:00
|
|
|
import org.json.JSONObject;
|
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
|
|
|
|
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
|
|
|
|
2015-10-14 15:10:06 +02:00
|
|
|
/**
|
2016-03-16 15:53:59 +01:00
|
|
|
* Query the persistence obtaining a Map where the date is the key and the
|
|
|
|
* #Info is the value. The result is relative to an Usage Record Type,
|
2015-10-14 15:10:06 +02:00
|
|
|
* respect a TemporalConstraint and can be applied one or more filters.
|
2016-03-16 15:53:59 +01:00
|
|
|
*
|
2016-03-17 12:16:30 +01:00
|
|
|
* @param clz
|
2016-03-16 15:53:59 +01:00
|
|
|
* the Record Class of interest
|
|
|
|
* @param temporalConstraint
|
|
|
|
* the TemporalConstraint (interval and aggregation)
|
|
|
|
* @param filters
|
|
|
|
* list of filter to obtain the time series. 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 are 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.
|
2015-10-14 15:10:06 +02:00
|
|
|
* @return the Map containing for each date in the required interval the
|
2016-03-16 15:53:59 +01:00
|
|
|
* requested data
|
2016-03-24 18:59:34 +01:00
|
|
|
* @throws DuplicatedKeyFilterException
|
|
|
|
* @throws KeyException
|
|
|
|
* @throws ValueException
|
2016-03-16 15:53:59 +01:00
|
|
|
* @throws Exception
|
2015-10-14 15:10:06 +02:00
|
|
|
*/
|
2016-03-24 18:59:34 +01:00
|
|
|
public SortedMap<Calendar, Info> getTimeSeries(
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
2016-06-28 15:00:55 +02:00
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
|
|
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
|
|
|
Exception;
|
|
|
|
|
2017-02-03 12:18:14 +01:00
|
|
|
/**
|
|
|
|
* Query the persistence obtaining a Map where the date is the key and the
|
|
|
|
* #Info is the value. The result is relative to an Usage Record Type,
|
|
|
|
* respect a TemporalConstraint and can be applied one or more filters.
|
|
|
|
* Used for no context call
|
|
|
|
*
|
|
|
|
* @param clz
|
|
|
|
* the Record Class of interest
|
|
|
|
* @param temporalConstraint
|
|
|
|
* the TemporalConstraint (interval and aggregation)
|
|
|
|
* @param filters
|
|
|
|
* list of filter to obtain the time series. 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 are 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.
|
|
|
|
* @return the Map containing for each date in the required interval the
|
|
|
|
* requested data
|
|
|
|
* @throws DuplicatedKeyFilterException
|
|
|
|
* @throws KeyException
|
|
|
|
* @throws ValueException
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public SortedMap<Calendar, Info> getNoContextTimeSeries(
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
|
|
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
|
|
|
Exception;
|
2016-03-16 15:53:59 +01:00
|
|
|
|
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
|
|
|
|
* key taking in account all Filters. The key is identified adding a Filter
|
|
|
|
* with a null value. Only one Filter with null value is allowed otherwise
|
|
|
|
* an Exception is thrown. The values are ordered from the most occurred
|
|
|
|
* value.
|
|
|
|
*
|
2016-03-17 12:16:30 +01:00
|
|
|
* @param clz
|
2016-03-16 15:53:59 +01:00
|
|
|
* the Usage Record Class of interest
|
|
|
|
* @param temporalConstraint
|
|
|
|
* the TemporalConstraint (interval and aggregation)
|
|
|
|
* @param filters
|
2016-03-24 18:59:34 +01:00
|
|
|
* list of filter to obtain the time series of top values. 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 are
|
|
|
|
* 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.
|
|
|
|
* @param topKey
|
|
|
|
* @param orderingProperty
|
2016-03-16 15:53:59 +01:00
|
|
|
* @return a SortedMap
|
2016-03-24 18:59:34 +01:00
|
|
|
* @throws DuplicatedKeyFilterException
|
|
|
|
* @throws KeyException
|
|
|
|
* @throws ValueException
|
2016-03-16 15:53:59 +01:00
|
|
|
* @throws Exception
|
2015-10-14 15:10:06 +02:00
|
|
|
*/
|
2016-03-24 18:59:34 +01:00
|
|
|
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>>
|
2016-06-28 15:00:55 +02:00
|
|
|
getTopValues(Class<? extends AggregatedRecord<?,?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
String topKey, String orderingProperty)
|
|
|
|
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
|
|
|
Exception;
|
2016-03-16 15:53:59 +01:00
|
|
|
|
2016-01-15 17:48:22 +01:00
|
|
|
/**
|
2016-03-16 15:53:59 +01:00
|
|
|
*
|
2016-03-17 12:16:30 +01:00
|
|
|
* @param clz
|
2016-03-16 15:53:59 +01:00
|
|
|
* @param temporalConstraint
|
|
|
|
* @param filters
|
2016-03-30 09:42:48 +02:00
|
|
|
* @param key
|
2016-03-24 18:59:34 +01:00
|
|
|
* @param orderingProperty
|
|
|
|
* @return
|
|
|
|
* @throws DuplicatedKeyFilterException
|
|
|
|
* @throws KeyException
|
|
|
|
* @throws ValueException
|
2016-03-16 15:53:59 +01:00
|
|
|
* @throws Exception
|
2016-01-15 17:48:22 +01:00
|
|
|
*/
|
2016-03-16 15:53:59 +01:00
|
|
|
public SortedSet<NumberedFilter> getNextPossibleValues(
|
2016-03-17 12:16:30 +01:00
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
2016-06-28 15:00:55 +02:00
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
String key, String orderingProperty) throws
|
|
|
|
DuplicatedKeyFilterException, KeyException, ValueException,
|
|
|
|
Exception;
|
2017-01-19 11:42:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Same method but use if possible a map-reduce
|
|
|
|
* @param clz
|
|
|
|
* @param temporalConstraint
|
|
|
|
* @param filters
|
|
|
|
* @param key
|
|
|
|
* @param orderingProperty
|
|
|
|
* @return
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public SortedSet<NumberedFilter> getNextPossibleValuesWithMap(
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
String key, String orderingProperty) throws Exception;
|
2016-03-16 15:53:59 +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
|
|
|
|
2017-10-12 15:49:25 +02:00
|
|
|
|
|
|
|
|
2016-06-28 15:00:55 +02:00
|
|
|
/**
|
|
|
|
* Return a sortedSet filter value
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param clz
|
|
|
|
* @param temporalConstraint
|
|
|
|
* @param filters
|
|
|
|
* @param key
|
|
|
|
* @param orderingProperty
|
|
|
|
* @return
|
|
|
|
* @throws DuplicatedKeyFilterException
|
|
|
|
* @throws KeyException
|
|
|
|
* @throws ValueException
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public SortedSet<NumberedFilter> getFilterValues(
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
String key) throws Exception;
|
|
|
|
|
2017-10-12 15:49:25 +02:00
|
|
|
/**
|
|
|
|
* Return a sortedSet filter value
|
|
|
|
*
|
|
|
|
* @param clz
|
|
|
|
* @param temporalConstraint
|
|
|
|
* @param filters
|
|
|
|
* @param key
|
|
|
|
* @param limit
|
|
|
|
* @return
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public SortedSet<NumberedFilter> getFilterValues(
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
String key, int limit) throws Exception;
|
|
|
|
|
2016-06-28 15:00:55 +02:00
|
|
|
/**
|
|
|
|
* Return a JsonObject with value
|
|
|
|
* e.g.for StorageUsageRecord {"dataVolume":1860328,"operationCount":4115}
|
|
|
|
* e.g. for ServiceUsageRcord {"operationCount":1651624}
|
|
|
|
*
|
|
|
|
* @param clz
|
|
|
|
* the Usage Record Class of interest
|
|
|
|
* @param temporalConstraint
|
|
|
|
* the TemporalConstraint (interval and aggregation)
|
|
|
|
* @param applicant
|
|
|
|
* the type field and value
|
|
|
|
* @return
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public JSONObject getUsageValue(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, Filter applicant)
|
|
|
|
throws Exception;
|
|
|
|
|
2017-09-06 16:12:15 +02:00
|
|
|
/* *
|
2016-11-11 10:03:09 +01:00
|
|
|
*
|
|
|
|
* getUsageValueQuota
|
|
|
|
* use for a specifiy consumer id and for single quota
|
|
|
|
*
|
2016-10-13 18:18:19 +02:00
|
|
|
* in:[{ "consumerId" : "alessandro.pieve" }, { "serviceClass" : "DataAccess" }, { "serviceName" : "CkanConnector" }], d=null, orderingProperty=null]
|
|
|
|
* out:[{ "consumerId" : "alessandro.pieve" }, { "serviceClass" : "DataAccess" }, { "serviceName" : "CkanConnector" }], d=88.0, orderingProperty=operationCount]
|
2016-10-13 09:42:47 +02:00
|
|
|
* @param clz
|
|
|
|
* the Usage Record Class of interest
|
|
|
|
* @param temporalConstraint
|
|
|
|
* the TemporalConstraint (interval and aggregation)
|
|
|
|
* @param applicant
|
|
|
|
* the type field and value
|
|
|
|
* @parm list
|
|
|
|
* the list of service or task what you want
|
|
|
|
* @return
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2016-11-11 10:03:09 +01:00
|
|
|
/*
|
2016-10-13 09:42:47 +02:00
|
|
|
public List<Filters> getUsageValueQuota(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint,
|
|
|
|
List<Filters> filterPackageQuota) throws Exception;
|
2016-11-11 10:03:09 +01:00
|
|
|
*/
|
2016-10-13 09:42:47 +02:00
|
|
|
|
2016-10-13 18:18:19 +02:00
|
|
|
/**
|
2016-11-11 10:03:09 +01:00
|
|
|
* getUsageValueQuotaTotal
|
|
|
|
*
|
|
|
|
* Example for crequire 2 different quota (lucio.lelii for service and alessandro.pieve for storage)
|
|
|
|
* 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
|
|
|
|
* @return
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2016-11-15 11:21:51 +01:00
|
|
|
public List<UsageValue> getUsageValueQuotaTotal(
|
|
|
|
List<UsageValue> listUsage)
|
2016-10-13 18:18:19 +02:00
|
|
|
throws Exception;
|
|
|
|
|
2016-11-08 10:00:15 +01:00
|
|
|
/**
|
|
|
|
* Return a SortedMap containing the TimeSeries for each context.
|
|
|
|
* @param clz
|
|
|
|
* @param temporalConstraint
|
|
|
|
* @param filters
|
|
|
|
* @param contexts
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,List<String> contexts)
|
|
|
|
throws Exception;
|
2016-06-28 15:00:55 +02:00
|
|
|
|
2017-05-05 17:01:23 +02:00
|
|
|
/**
|
|
|
|
* Return a record
|
|
|
|
* @param recordId
|
|
|
|
* @param recordType
|
|
|
|
* @return
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public String getRecord(String recordId, String type ) throws Exception;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a list of type storage usage
|
|
|
|
* @return
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public SortedSet<String> getSpaceProvidersIds() throws Exception;
|
|
|
|
|
2017-09-06 16:12:15 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param clz
|
|
|
|
* @param temporalConstraint
|
|
|
|
* @param filters
|
|
|
|
* @param providersId
|
|
|
|
* @return
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2017-05-05 17:01:23 +02:00
|
|
|
public SortedMap<Filter, SortedMap<Calendar, Long>> getSpaceTimeSeries(
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
List<String> providersId) throws Exception;
|
|
|
|
|
2017-09-06 16:12:15 +02:00
|
|
|
/**
|
|
|
|
* @return
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
boolean isConnectionActive() throws Exception;
|
|
|
|
|
2017-02-03 12:18:14 +01:00
|
|
|
|
2015-10-14 15:10:06 +02:00
|
|
|
}
|