/** * */ package org.gcube.accounting.analytics.persistence; import java.util.Calendar; import java.util.List; import java.util.SortedMap; import java.util.SortedSet; import org.gcube.accounting.analytics.Filter; import org.gcube.accounting.analytics.Info; import org.gcube.accounting.analytics.NumberedFilter; import org.gcube.accounting.analytics.TemporalConstraint; import org.gcube.accounting.analytics.UsageValue; import org.gcube.accounting.analytics.exception.DuplicatedKeyFilterException; import org.gcube.accounting.analytics.exception.KeyException; import org.gcube.accounting.analytics.exception.ValueException; import org.gcube.accounting.datamodel.BasicUsageRecord; import org.gcube.documentstore.records.AggregatedRecord; import org.gcube.documentstore.records.Record; /** * @author Luca Frosini (ISTI - CNR) */ public interface AccountingPersistenceBackendQuery { public static final int KEY_VALUES_LIMIT = 25; public static String getScopeToQuery() { String scope = AccountingPersistenceQueryFactory.getForcedQueryScope().get(); if(scope == null) { scope = BasicUsageRecord.getContextFromToken(); } return scope; } public void prepareConnection( AccountingPersistenceBackendQueryConfiguration configuration) throws Exception; /** * 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. * * @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 getTimeSeries( Class> clz, TemporalConstraint temporalConstraint, List filters) throws DuplicatedKeyFilterException, KeyException, ValueException, Exception; /** * 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 getNoContextTimeSeries( Class> clz, TemporalConstraint temporalConstraint, List filters) throws DuplicatedKeyFilterException, KeyException, ValueException, Exception; /** * 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. * * @param clz * the Usage Record Class of interest * @param temporalConstraint * the TemporalConstraint (interval and aggregation) * @param filters * 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 * @return a SortedMap * @throws DuplicatedKeyFilterException * @throws KeyException * @throws ValueException * @throws Exception */ public SortedMap> getTopValues(Class> clz, TemporalConstraint temporalConstraint, List filters, String topKey, String orderingProperty) throws DuplicatedKeyFilterException, KeyException, ValueException, Exception; /** * Close the connection to persistence * * @throws Exception * if the close fails */ public void close() throws Exception; public SortedSet getFilterValues( Class> clz, TemporalConstraint temporalConstraint, List filters, String key) throws Exception; public SortedSet getFilterValues( Class> clz, TemporalConstraint temporalConstraint, List filters, String key, Integer limit) throws Exception; /** * 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] * ] * @param listUsage * @return List * @throws Exception */ public List getUsageValueQuotaTotal( List listUsage) throws Exception; /** * Return a SortedMap containing the TimeSeries for each context. * @param clz * @param temporalConstraint * @param filters * @param contexts * @return a SortedMap containing the TimeSeries for each context. */ public SortedMap> getContextTimeSeries( Class> clz, TemporalConstraint temporalConstraint, List filters,List contexts) throws Exception; public Record getRecord(String recordId, String type) throws Exception; public SortedSet getSpaceProvidersIds() throws Exception; public SortedMap> getSpaceTimeSeries( Class> clz, TemporalConstraint temporalConstraint, List filters, List providersId) throws Exception; boolean isConnectionActive() throws Exception; }