Merge branch 'feature/21353'
Conflicts: CHANGELOG.md pom.xml src/main/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQuery.java
This commit is contained in:
commit
7cc25cd68e
|
@ -2,7 +2,16 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
# Changelog for Accounting Analytics
|
||||
|
||||
<<<<<<< HEAD
|
||||
## [v3.0.1]
|
||||
=======
|
||||
## [v4.0.0-SNAPSHOT]
|
||||
|
||||
- Supporting zero or multiple contexts in all queries [#21353]
|
||||
- Query parameters are now provided via setter and not as functions parameters [#21353]
|
||||
- Removed getSpaceProvidersIds() and added getDataType() [#21353]
|
||||
|
||||
>>>>>>> refs/heads/feature/21353
|
||||
|
||||
- Aligned model
|
||||
|
||||
|
|
13
pom.xml
13
pom.xml
|
@ -9,7 +9,11 @@
|
|||
|
||||
<groupId>org.gcube.accounting</groupId>
|
||||
<artifactId>accounting-analytics</artifactId>
|
||||
<<<<<<< HEAD
|
||||
<version>3.0.1</version>
|
||||
=======
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
>>>>>>> refs/heads/feature/21353
|
||||
<name>Accounting Analytics</name>
|
||||
<description>
|
||||
Accounting Analytics allows querying accounting data. It
|
||||
|
@ -44,27 +48,18 @@
|
|||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.accounting</groupId>
|
||||
<artifactId>accounting-lib</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.data.publishing</groupId>
|
||||
<artifactId>document-store-lib</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20090211</version>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
package org.gcube.accounting.analytics;
|
||||
|
||||
import java.util.List;
|
||||
/**
|
||||
* @author Alessandro Pieve (ISTI - CNR) alessandro.pieve@isti.cnr.it
|
||||
*
|
||||
*/
|
||||
public class FiltersValue {
|
||||
|
||||
|
||||
protected List<Filter> filters;
|
||||
protected Double d;
|
||||
protected String orderingProperty;
|
||||
|
||||
public FiltersValue(){}
|
||||
|
||||
public FiltersValue(List<Filter> filters, Number n, String orderingProperty) {
|
||||
super();
|
||||
this.filters=filters;
|
||||
this.d = n.doubleValue();
|
||||
this.orderingProperty = orderingProperty;
|
||||
}
|
||||
|
||||
public List<Filter> getFiltersValue() {
|
||||
return filters;
|
||||
}
|
||||
|
||||
public void setFiltersValue(List<Filter> filters) {
|
||||
this.filters = filters;
|
||||
}
|
||||
|
||||
public Double getD() {
|
||||
return d;
|
||||
}
|
||||
|
||||
public void setD(Double d) {
|
||||
this.d = d;
|
||||
}
|
||||
|
||||
public String getOrderingProperty() {
|
||||
return orderingProperty;
|
||||
}
|
||||
|
||||
public void setOrderingProperty(String orderingProperty) {
|
||||
this.orderingProperty = orderingProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((d == null) ? 0 : d.hashCode());
|
||||
result = prime * result + ((filters == null) ? 0 : filters.hashCode());
|
||||
result = prime
|
||||
* result
|
||||
+ ((orderingProperty == null) ? 0 : orderingProperty.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
FiltersValue other = (FiltersValue) obj;
|
||||
if (d == null) {
|
||||
if (other.d != null)
|
||||
return false;
|
||||
} else if (!d.equals(other.d))
|
||||
return false;
|
||||
if (filters == null) {
|
||||
if (other.filters != null)
|
||||
return false;
|
||||
} else if (!filters.equals(other.filters))
|
||||
return false;
|
||||
if (orderingProperty == null) {
|
||||
if (other.orderingProperty != null)
|
||||
return false;
|
||||
} else if (!orderingProperty.equals(other.orderingProperty))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FiltersValue [filters=" + filters + ", d=" + d
|
||||
+ ", orderingProperty=" + orderingProperty + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@ package org.gcube.accounting.analytics;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -16,13 +16,13 @@ import org.json.JSONObject;
|
|||
public class Info {
|
||||
|
||||
protected Calendar calendar;
|
||||
protected JSONObject value;
|
||||
protected JsonNode value;
|
||||
|
||||
/**
|
||||
* @param calendar the date
|
||||
* @param value the JSON value
|
||||
*/
|
||||
public Info(Calendar calendar, JSONObject value) {
|
||||
public Info(Calendar calendar, JsonNode value) {
|
||||
super();
|
||||
this.calendar = calendar;
|
||||
this.value = value;
|
||||
|
@ -45,14 +45,14 @@ public class Info {
|
|||
/**
|
||||
* @return the value
|
||||
*/
|
||||
public JSONObject getValue() {
|
||||
public JsonNode getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value the value to set
|
||||
*/
|
||||
public void setValue(JSONObject value) {
|
||||
public void setValue(JsonNode value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ package org.gcube.accounting.analytics;
|
|||
import java.util.Calendar;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -34,11 +34,11 @@ public class NumberedFilter extends Filter {
|
|||
this.orderingProperty = orderingProperty;
|
||||
|
||||
for(Info info : timeSeries.values()){
|
||||
JSONObject value = info.getValue();
|
||||
JsonNode value = info.getValue();
|
||||
if(this.d == null){
|
||||
this.d = value.getDouble(orderingProperty);
|
||||
this.d = value.get(orderingProperty).asDouble();
|
||||
}else{
|
||||
this.d = this.d + value.getDouble(orderingProperty);
|
||||
this.d = this.d + value.get(orderingProperty).asDouble();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,101 +0,0 @@
|
|||
package org.gcube.accounting.analytics;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.accounting.datamodel.AggregatedUsageRecord;
|
||||
|
||||
public class UsageServiceValue extends UsageValue {
|
||||
|
||||
|
||||
protected Class<? extends AggregatedUsageRecord<?, ?>> clz;
|
||||
protected TemporalConstraint temporalConstraint;
|
||||
|
||||
//USED for a list service for each identifier (package service )
|
||||
//protected List<FiltersValue> filtersValue;
|
||||
|
||||
protected List<Filter> filters;
|
||||
protected String identifier;
|
||||
protected Double d;
|
||||
protected String orderingProperty;
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public Double getD() {
|
||||
return d;
|
||||
}
|
||||
|
||||
public void setD(Double d) {
|
||||
this.d = d;
|
||||
}
|
||||
public TemporalConstraint getTemporalConstraint() {
|
||||
if (temporalConstraint!=null)
|
||||
return temporalConstraint;
|
||||
else
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public String getOrderingProperty() {
|
||||
return orderingProperty;
|
||||
}
|
||||
|
||||
public void setOrderingProperty(String orderingProperty) {
|
||||
this.orderingProperty = orderingProperty;
|
||||
}
|
||||
public void setTemporalConstraint(TemporalConstraint temporalConstraint) {
|
||||
this.temporalConstraint = temporalConstraint;
|
||||
}
|
||||
|
||||
public Class<? extends AggregatedUsageRecord<?, ?>> getClz() {
|
||||
return clz;
|
||||
}
|
||||
|
||||
public void setClz(String context,Class<? extends AggregatedUsageRecord<?, ?>> clz) {
|
||||
this.clz = clz;
|
||||
}
|
||||
|
||||
public UsageServiceValue(){}
|
||||
|
||||
public UsageServiceValue(String context,String identifier,Class<? extends AggregatedUsageRecord<?, ?>> clz,TemporalConstraint temporalConstraint,List<Filter> filters){
|
||||
super();
|
||||
this.context=context;
|
||||
this.filters=filters;
|
||||
this.clz=clz;
|
||||
this.temporalConstraint=temporalConstraint;
|
||||
this.identifier=identifier;
|
||||
|
||||
}
|
||||
|
||||
public List<Filter> getFilters() {
|
||||
return filters;
|
||||
}
|
||||
|
||||
public void setFilters(List<Filter> filters) {
|
||||
this.filters = filters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContext() {
|
||||
return this.context;
|
||||
}
|
||||
@Override
|
||||
public void setContext(String context) {
|
||||
this.context=context;
|
||||
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UsageServiceValue [clz=" + clz + ", temporalConstraint="
|
||||
+ temporalConstraint + ", filters=" + filters + ", identifier="
|
||||
+ identifier + ", d=" + d + ", orderingProperty="
|
||||
+ orderingProperty + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
package org.gcube.accounting.analytics;
|
||||
|
||||
import org.gcube.accounting.datamodel.AggregatedUsageRecord;
|
||||
|
||||
public class UsageStorageValue extends UsageValue {
|
||||
protected Class<? extends AggregatedUsageRecord<?, ?>> clz;
|
||||
protected TemporalConstraint temporalConstraint;
|
||||
protected String identifier;
|
||||
protected Double d;
|
||||
protected String orderingProperty;
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public Double getD() {
|
||||
return d;
|
||||
}
|
||||
|
||||
public void setD(Double d) {
|
||||
this.d = d;
|
||||
}
|
||||
public String getOrderingProperty() {
|
||||
return orderingProperty;
|
||||
}
|
||||
|
||||
public void setOrderingProperty(String orderingProperty) {
|
||||
this.orderingProperty = orderingProperty;
|
||||
}
|
||||
public TemporalConstraint getTemporalConstraint() {
|
||||
if (temporalConstraint!=null)
|
||||
return temporalConstraint;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setTemporalConstraint(TemporalConstraint temporalConstraint) {
|
||||
this.temporalConstraint = temporalConstraint;
|
||||
}
|
||||
|
||||
public Class<? extends AggregatedUsageRecord<?, ?>> getClz() {
|
||||
return clz;
|
||||
}
|
||||
|
||||
public void setClz(Class<? extends AggregatedUsageRecord<?, ?>> clz) {
|
||||
this.clz = clz;
|
||||
}
|
||||
|
||||
public UsageStorageValue(){}
|
||||
|
||||
|
||||
public UsageStorageValue(String context,String identifier,Class<? extends AggregatedUsageRecord<?, ?>> clz){
|
||||
super();
|
||||
this.context=context;
|
||||
this.clz=clz;
|
||||
this.identifier=identifier;
|
||||
|
||||
}
|
||||
|
||||
public UsageStorageValue(String context,String identifier,Class<? extends AggregatedUsageRecord<?, ?>> clz,TemporalConstraint temporalConstraint){
|
||||
super();
|
||||
this.context=context;
|
||||
this.identifier=identifier;
|
||||
this.clz=clz;
|
||||
this.temporalConstraint=temporalConstraint;
|
||||
|
||||
}
|
||||
@Override
|
||||
public String getContext() {
|
||||
return this.context;
|
||||
}
|
||||
@Override
|
||||
public void setContext(String context) {
|
||||
this.context=context;
|
||||
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UsageStorageValue [clz=" + clz + ", temporalConstraint="
|
||||
+ temporalConstraint + ", identifier=" + identifier + ", d="
|
||||
+ d + ", orderingProperty=" + orderingProperty
|
||||
+ ", context=" + context
|
||||
+ "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ package org.gcube.accounting.analytics.persistence;
|
|||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
|
||||
|
@ -13,9 +14,6 @@ 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;
|
||||
|
@ -39,98 +37,72 @@ public interface AccountingPersistenceBackendQuery {
|
|||
AccountingPersistenceBackendQueryConfiguration configuration)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* @param clz the Usage Record Class of interest
|
||||
*
|
||||
* Required
|
||||
*
|
||||
*/
|
||||
public void setRequestedRecords(Class<? extends AggregatedRecord<?, ?>> clz);
|
||||
|
||||
/**
|
||||
* @param temporalConstraint the TemporalConstraint (interval and aggregation)
|
||||
*
|
||||
* Required
|
||||
*/
|
||||
public void setTemporalConstraint(TemporalConstraint temporalConstraint);
|
||||
|
||||
|
||||
/**
|
||||
* @param contexts the list of context to use as filter
|
||||
*
|
||||
* If null or empty list get all data for the interested Record Class
|
||||
* with the applying temporal constraint with no contexts constraint.
|
||||
* 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.
|
||||
*/
|
||||
public void setFilters(Set<Filter> filters);
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return the Map containing for each date in the required interval the requested data
|
||||
* @throws Exception
|
||||
*/
|
||||
public SortedMap<Calendar, Info> getTimeSeries(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception;
|
||||
|
||||
public SortedMap<Calendar, Info> getTimeSeries() 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.
|
||||
* 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
|
||||
* Return a SortedMap containing the TimeSeries for each context.
|
||||
* @return a SortedMap containing the TimeSeries for each context.
|
||||
*/
|
||||
public SortedMap<Calendar, Info> getNoContextTimeSeries(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception;
|
||||
|
||||
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries() throws 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.
|
||||
* key taking in account all Filters.
|
||||
*
|
||||
* @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
|
||||
* The values are ordered from the most occurred value.
|
||||
*
|
||||
* @param topKey the key to obtain top values
|
||||
* @param orderingProperty
|
||||
* @return a SortedMap
|
||||
* @throws DuplicatedKeyFilterException
|
||||
* @throws KeyException
|
||||
* @throws ValueException
|
||||
|
||||
* @throws Exception
|
||||
*/
|
||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>>
|
||||
getTopValues(Class<? extends AggregatedRecord<?,?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String topKey, String orderingProperty)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException,
|
||||
Exception;
|
||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(String topKey, String orderingProperty) throws Exception;
|
||||
|
||||
/**
|
||||
* Close the connection to persistence
|
||||
|
@ -140,20 +112,20 @@ public interface AccountingPersistenceBackendQuery {
|
|||
*/
|
||||
public void close() throws Exception;
|
||||
|
||||
public SortedSet<NumberedFilter> getFilterValues(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String key) throws Exception;
|
||||
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;
|
||||
|
||||
public SortedSet<NumberedFilter> getFilterValues(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String key, Integer limit) throws Exception;
|
||||
|
||||
/**
|
||||
* getUsageValueQuotaTotal
|
||||
*
|
||||
* Example for crequire 2 different quota (lucio.lelii for service and alessandro.pieve for storage)
|
||||
* Example to require 2 different quota (lucio.lelii for service and alessandro.pieve for storage)
|
||||
* Input:
|
||||
* [
|
||||
* TotalFilters [
|
||||
|
@ -194,32 +166,10 @@ public interface AccountingPersistenceBackendQuery {
|
|||
* @return List<UsageValue>
|
||||
* @throws Exception
|
||||
*/
|
||||
public List<UsageValue> getUsageValueQuotaTotal(
|
||||
List<UsageValue> listUsage)
|
||||
public List<UsageValue> getUsageValueQuotaTotal(List<UsageValue> 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<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,List<String> contexts)
|
||||
throws Exception;
|
||||
|
||||
public Record getRecord(String recordId, String type) throws Exception;
|
||||
|
||||
public SortedSet<String> getSpaceProvidersIds() throws Exception;
|
||||
|
||||
public SortedMap<Filter, SortedMap<Calendar, Long>> getSpaceTimeSeries(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
List<String> providersId) throws Exception;
|
||||
|
||||
boolean isConnectionActive() throws Exception;
|
||||
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ import java.util.Calendar;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeMap;
|
||||
|
@ -25,10 +26,12 @@ import org.gcube.accounting.analytics.exception.KeyException;
|
|||
import org.gcube.accounting.analytics.exception.ValueException;
|
||||
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageStatusRecord;
|
||||
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.DataType;
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.documentstore.records.AggregatedRecord;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -40,17 +43,58 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
|
||||
public static final int DEFAULT_LIMIT_RESULT_NUMBER = 5;
|
||||
|
||||
private AccountingPersistenceQuery() {
|
||||
}
|
||||
|
||||
static {
|
||||
accountingPersistenceQuery = new AccountingPersistenceQuery();
|
||||
try {
|
||||
accountingPersistenceQuery = new AccountingPersistenceQuery();
|
||||
}catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static synchronized AccountingPersistenceQuery getInstance() {
|
||||
return accountingPersistenceQuery;
|
||||
}
|
||||
|
||||
|
||||
protected Class<? extends AggregatedRecord<?, ?>> clz;
|
||||
protected TemporalConstraint temporalConstraint;
|
||||
|
||||
protected Set<String> contexts;
|
||||
protected Set<Filter> filters;
|
||||
|
||||
protected ObjectMapper objectMapper;
|
||||
|
||||
protected AccountingPersistenceBackendQuery accountingPersistenceBackendQuery;
|
||||
|
||||
private AccountingPersistenceQuery() throws Exception {
|
||||
accountingPersistenceBackendQuery = AccountingPersistenceBackendQueryFactory.getInstance();
|
||||
objectMapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRequestedRecords(Class<? extends AggregatedRecord<?, ?>> clz) {
|
||||
this.clz = clz;
|
||||
accountingPersistenceBackendQuery.setRequestedRecords(clz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemporalConstraint(TemporalConstraint temporalConstraint) {
|
||||
this.temporalConstraint = temporalConstraint;
|
||||
accountingPersistenceBackendQuery.setTemporalConstraint(temporalConstraint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContexts(Set<String> contexts) {
|
||||
this.contexts = contexts;
|
||||
accountingPersistenceBackendQuery.setContexts(this.contexts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFilters(Set<Filter> filters) {
|
||||
this.filters = filters;
|
||||
accountingPersistenceBackendQuery.setFilters(filters);
|
||||
}
|
||||
|
||||
public static SortedSet<String> getQuerableKeys(Class<? extends AggregatedRecord<?, ?>> clz) throws Exception {
|
||||
AggregatedRecord<?, ?> instance = clz.newInstance();
|
||||
|
||||
|
@ -59,7 +103,11 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
if (clz.equals(AggregatedStorageStatusRecord.class)) {
|
||||
SortedSet<String> storageStatus = new TreeSet<>();
|
||||
storageStatus.add(AggregatedStorageStatusRecord.CONSUMER_ID);
|
||||
<<<<<<< HEAD
|
||||
storageStatus.add(AggregatedStorageStatusRecord.PROVIDER_URI);
|
||||
=======
|
||||
// storageStatus.add(AggregatedStorageStatusRecord.DATA_SERVICEID);
|
||||
>>>>>>> refs/heads/feature/21353
|
||||
return storageStatus;
|
||||
} else {
|
||||
return instance.getQuerableKeys();
|
||||
|
@ -74,21 +122,19 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
return AggregatedRecord.OPERATION_COUNT;
|
||||
}
|
||||
|
||||
protected static JSONObject getPaddingJSONObject(Map<Calendar, Info> unpaddedResults) throws JSONException {
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
protected JsonNode getPaddingJsonNode(Map<Calendar, Info> unpaddedResults) throws Exception {
|
||||
ObjectNode objectNode = objectMapper.createObjectNode();
|
||||
// verify data consistency
|
||||
if (unpaddedResults.size() != 0) {
|
||||
Info auxInfo = new ArrayList<Info>(unpaddedResults.values()).get(0);
|
||||
JSONObject auxJsonObject = auxInfo.getValue();
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterator<String> keys = auxJsonObject.keys();
|
||||
JsonNode auxJsonNode = auxInfo.getValue();
|
||||
Iterator<String> keys = auxJsonNode.fieldNames();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
jsonObject.put(key, 0);
|
||||
objectNode.put(key, 0);
|
||||
}
|
||||
}
|
||||
return jsonObject;
|
||||
return objectNode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,15 +149,13 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
* @throws Exception
|
||||
* if fails
|
||||
*/
|
||||
protected static SortedMap<Calendar, Info> padMap(SortedMap<Calendar, Info> unpaddedData,
|
||||
TemporalConstraint temporalConstraint) throws Exception {
|
||||
|
||||
JSONObject jsonObject = getPaddingJSONObject(unpaddedData);
|
||||
protected SortedMap<Calendar, Info> padMap(SortedMap<Calendar, Info> unpaddedData) throws Exception {
|
||||
JsonNode jsonNode = getPaddingJsonNode(unpaddedData);
|
||||
SortedSet<Calendar> sequence = temporalConstraint.getCalendarSequence();
|
||||
for (Calendar progressTime : sequence) {
|
||||
Info info = unpaddedData.get(progressTime);
|
||||
if (info == null) {
|
||||
info = new Info(progressTime, jsonObject);
|
||||
info = new Info(progressTime, jsonNode);
|
||||
unpaddedData.put(progressTime, info);
|
||||
}
|
||||
}
|
||||
|
@ -119,74 +163,43 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Calendar, Info> getTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||
public SortedMap<Calendar, Info> getTimeSeries()
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||
|
||||
return this.getTimeSeries(clz, temporalConstraint, filters, false);
|
||||
return this.getTimeSeries(true);
|
||||
}
|
||||
|
||||
public SortedMap<Calendar, Info> getTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters, boolean pad)
|
||||
public SortedMap<Calendar, Info> getTimeSeries(boolean pad)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||
SortedMap<Calendar, Info> ret = AccountingPersistenceBackendQueryFactory.getInstance().getTimeSeries(clz,
|
||||
temporalConstraint, filters);
|
||||
|
||||
SortedMap<Calendar, Info> ret = accountingPersistenceBackendQuery.getTimeSeries();
|
||||
|
||||
if (ret == null) {
|
||||
ret = new TreeMap<>();
|
||||
}
|
||||
|
||||
if (pad) {
|
||||
ret = padMap(ret, temporalConstraint);
|
||||
ret = padMap(ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Calendar, Info> getNoContextTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||
|
||||
return this.getNoContextTimeSeries(clz, temporalConstraint, filters, false);
|
||||
}
|
||||
|
||||
public SortedMap<Calendar, Info> getNoContextTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters, boolean pad)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||
SortedMap<Calendar, Info> ret = AccountingPersistenceBackendQueryFactory.getInstance()
|
||||
.getNoContextTimeSeries(clz, temporalConstraint, filters);
|
||||
|
||||
if (ret == null) {
|
||||
ret = new TreeMap<>();
|
||||
}
|
||||
|
||||
if (pad) {
|
||||
ret = padMap(ret, temporalConstraint);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String topKey, String orderingProperty, boolean pad, int limit)
|
||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(String topKey, String orderingProperty, boolean pad, int limit)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||
SortedMap<NumberedFilter, SortedMap<Calendar, Info>> got;
|
||||
|
||||
if (orderingProperty == null) {
|
||||
orderingProperty = getDefaultOrderingProperties(clz);
|
||||
}
|
||||
|
||||
got = AccountingPersistenceBackendQueryFactory.getInstance().getTopValues(clz, temporalConstraint, filters,
|
||||
topKey, orderingProperty);
|
||||
|
||||
got = accountingPersistenceBackendQuery.getTopValues(topKey, orderingProperty);
|
||||
|
||||
int count = got.size() > limit ? limit : got.size();
|
||||
NumberedFilter firstRemovalKey = null;
|
||||
for (NumberedFilter nf : got.keySet()) {
|
||||
if (--count >= 0 || limit <= 0) {
|
||||
if (pad) {
|
||||
padMap(got.get(nf), temporalConstraint);
|
||||
padMap(got.get(nf));
|
||||
|
||||
}
|
||||
} else {
|
||||
|
@ -203,20 +216,15 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
return got;
|
||||
}
|
||||
|
||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String topKey) throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(String topKey) throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||
String orderingProperty = AccountingPersistenceQuery.getDefaultOrderingProperties(clz);
|
||||
|
||||
return this.getTopValues(clz, temporalConstraint, filters, topKey, orderingProperty, false, 0);
|
||||
return this.getTopValues(topKey, orderingProperty, false, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String topKey, String orderingProperty)
|
||||
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||
return this.getTopValues(clz, temporalConstraint, filters, topKey, orderingProperty, false, 0);
|
||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(String topKey, String orderingProperty)
|
||||
throws Exception {
|
||||
return this.getTopValues(topKey, orderingProperty, false, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -230,46 +238,35 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<NumberedFilter> getFilterValues(Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters, String key) throws Exception {
|
||||
return getFilterValues(clz, temporalConstraint, filters, key, null);
|
||||
public SortedSet<NumberedFilter> getFilterValues(String key) throws Exception {
|
||||
return getFilterValues(key, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<NumberedFilter> getFilterValues(Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters, String key, Integer limit) throws Exception {
|
||||
|
||||
return AccountingPersistenceBackendQueryFactory.getInstance().getFilterValues(clz, temporalConstraint, filters,
|
||||
key, limit);
|
||||
public SortedSet<NumberedFilter> getFilterValues(String key, Integer limit) throws Exception {
|
||||
return accountingPersistenceBackendQuery.getFilterValues(key, limit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UsageValue> getUsageValueQuotaTotal(List<UsageValue> listUsage) throws Exception {
|
||||
|
||||
return AccountingPersistenceBackendQueryFactory.getInstance().getUsageValueQuotaTotal(listUsage);
|
||||
return accountingPersistenceBackendQuery.getUsageValueQuotaTotal(listUsage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
List<String> contexts) throws Exception {
|
||||
|
||||
return AccountingPersistenceBackendQueryFactory.getInstance().getContextTimeSeries(clz, temporalConstraint,
|
||||
filters, contexts);
|
||||
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries() throws Exception {
|
||||
return getContextTimeSeries(true);
|
||||
}
|
||||
|
||||
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
|
||||
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
List<String> contexts, boolean pad) throws DuplicatedKeyFilterException, Exception {
|
||||
|
||||
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(boolean pad) throws DuplicatedKeyFilterException, Exception {
|
||||
SortedMap<Filter, SortedMap<Calendar, Info>> got;
|
||||
got = AccountingPersistenceBackendQueryFactory.getInstance().getContextTimeSeries(clz, temporalConstraint,
|
||||
filters, contexts);
|
||||
|
||||
got = accountingPersistenceBackendQuery.getContextTimeSeries();
|
||||
int count = got.size();
|
||||
Filter firstRemovalKey = null;
|
||||
for (Filter nf : got.keySet()) {
|
||||
if (--count >= 0) {
|
||||
if (pad) {
|
||||
padMap(got.get(nf), temporalConstraint);
|
||||
padMap(got.get(nf));
|
||||
|
||||
}
|
||||
} else {
|
||||
|
@ -285,31 +282,31 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
}
|
||||
return got;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Record getRecord(String recordId, String type) throws Exception {
|
||||
Record record = AccountingPersistenceBackendQueryFactory.getInstance().getRecord(recordId, type);
|
||||
return record;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<String> getSpaceProvidersIds() throws Exception {
|
||||
SortedSet<String> providersId = AccountingPersistenceBackendQueryFactory.getInstance().getSpaceProvidersIds();
|
||||
return providersId;
|
||||
public SortedSet<String> getDataType() throws Exception {
|
||||
SortedSet<String> dataTypes = new TreeSet<String>();
|
||||
for(DataType dataType : DataType.values()) {
|
||||
dataTypes.add(dataType.name());
|
||||
}
|
||||
return dataTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedMap<Filter, SortedMap<Calendar, Long>> getSpaceTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters, List<String> providersId) throws Exception {
|
||||
public SortedMap<Filter, SortedMap<Calendar, Info>> getSpaceTimeSeries(Set<String> dataTypes) throws Exception {
|
||||
|
||||
SortedMap<Filter, SortedMap<Calendar, Long>> spaceTimeSeries = AccountingPersistenceBackendQueryFactory
|
||||
.getInstance().getSpaceTimeSeries(clz, temporalConstraint, filters, providersId);
|
||||
SortedMap<Filter, SortedMap<Calendar, Info>> spaceTimeSeries = accountingPersistenceBackendQuery.getSpaceTimeSeries(dataTypes);
|
||||
|
||||
int count = spaceTimeSeries.size();
|
||||
Filter firstRemovalKey = null;
|
||||
for (Filter nf : spaceTimeSeries.keySet()) {
|
||||
if (--count >= 0) {
|
||||
padMapStorage(spaceTimeSeries.get(nf), temporalConstraint);
|
||||
padMapStorage(spaceTimeSeries.get(nf));
|
||||
} else {
|
||||
if (firstRemovalKey == null) {
|
||||
firstRemovalKey = nf;
|
||||
|
@ -325,20 +322,20 @@ public class AccountingPersistenceQuery implements AccountingPersistenceBackendQ
|
|||
|
||||
}
|
||||
|
||||
protected SortedMap<Calendar, Long> padMapStorage(SortedMap<Calendar, Long> unpaddedData,
|
||||
TemporalConstraint temporalConstraint) throws Exception {
|
||||
protected SortedMap<Calendar, Info> padMapStorage(SortedMap<Calendar, Info> unpaddedData) throws Exception {
|
||||
SortedSet<Calendar> sequence = temporalConstraint.getCalendarSequence();
|
||||
Long longValuePre = null;
|
||||
|
||||
Info previuosInfo = null;
|
||||
for (Calendar progressTime : sequence) {
|
||||
Long longValue = unpaddedData.get(progressTime);
|
||||
Info info = unpaddedData.get(progressTime);
|
||||
|
||||
if (longValue == null) {
|
||||
unpaddedData.put(progressTime, longValuePre);
|
||||
if (info == null) {
|
||||
unpaddedData.put(progressTime, previuosInfo);
|
||||
} else {
|
||||
longValuePre = longValue;
|
||||
previuosInfo = info;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return unpaddedData;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue