Alessandro Pieve 2016-11-15 10:41:07 +00:00
parent 5e3e88741b
commit 3fcc59c6ae
2 changed files with 220 additions and 352 deletions

View File

@ -24,13 +24,14 @@ import java.util.TreeMap;
import java.util.TreeSet; import java.util.TreeSet;
import org.gcube.accounting.analytics.Filter; import org.gcube.accounting.analytics.Filter;
import org.gcube.accounting.analytics.Filters; import org.gcube.accounting.analytics.FiltersValue;
import org.gcube.accounting.analytics.Info; import org.gcube.accounting.analytics.Info;
import org.gcube.accounting.analytics.NumberedFilter; import org.gcube.accounting.analytics.NumberedFilter;
import org.gcube.accounting.analytics.TemporalConstraint; import org.gcube.accounting.analytics.TemporalConstraint;
import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode; import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode;
import org.gcube.accounting.analytics.TemporalConstraint.CalendarEnum; import org.gcube.accounting.analytics.TemporalConstraint.CalendarEnum;
import org.gcube.accounting.analytics.TotalFilters; import org.gcube.accounting.analytics.UsageServiceValue;
import org.gcube.accounting.analytics.UsageValue;
import org.gcube.accounting.analytics.exception.DuplicatedKeyFilterException; import org.gcube.accounting.analytics.exception.DuplicatedKeyFilterException;
import org.gcube.accounting.analytics.exception.ValueException; import org.gcube.accounting.analytics.exception.ValueException;
import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQuery; import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQuery;
@ -38,6 +39,7 @@ import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQu
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery; import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
import org.gcube.accounting.datamodel.BasicUsageRecord; import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.datamodel.UsageRecord; import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
import org.gcube.accounting.persistence.AccountingPersistenceConfiguration; import org.gcube.accounting.persistence.AccountingPersistenceConfiguration;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.documentstore.records.AggregatedRecord; import org.gcube.documentstore.records.AggregatedRecord;
@ -75,10 +77,7 @@ AccountingPersistenceBackendQuery {
private static final Logger logger = LoggerFactory private static final Logger logger = LoggerFactory
.getLogger(AccountingPersistenceQueryCouchBase.class); .getLogger(AccountingPersistenceQueryCouchBase.class);
public static final String URL_PROPERTY_KEY = AccountingPersistenceConfiguration.URL_PROPERTY_KEY; public static final String URL_PROPERTY_KEY = AccountingPersistenceConfiguration.URL_PROPERTY_KEY;
// public static final String USERNAME_PROPERTY_KEY =
// AccountingPersistenceConfiguration.USERNAME_PROPERTY_KEY;
public static final String PASSWORD_PROPERTY_KEY = AccountingPersistenceConfiguration.PASSWORD_PROPERTY_KEY; public static final String PASSWORD_PROPERTY_KEY = AccountingPersistenceConfiguration.PASSWORD_PROPERTY_KEY;
public static final String BUCKET_STORAGE_NAME_PROPERTY_KEY="AggregatedStorageUsageRecord"; public static final String BUCKET_STORAGE_NAME_PROPERTY_KEY="AggregatedStorageUsageRecord";
@ -127,8 +126,6 @@ AccountingPersistenceBackendQuery {
String password = configuration.getProperty(PASSWORD_PROPERTY_KEY); String password = configuration.getProperty(PASSWORD_PROPERTY_KEY);
cluster = CouchbaseCluster.create(ENV, url); cluster = CouchbaseCluster.create(ENV, url);
logger.trace("env"+ENV.toString());
bucketNameStorage = configuration.getProperty(BUCKET_STORAGE_NAME_PROPERTY_KEY); bucketNameStorage = configuration.getProperty(BUCKET_STORAGE_NAME_PROPERTY_KEY);
bucketNameService = configuration.getProperty(BUCKET_SERVICE_NAME_PROPERTY_KEY); bucketNameService = configuration.getProperty(BUCKET_SERVICE_NAME_PROPERTY_KEY);
bucketNameJob = configuration.getProperty(BUCKET_JOB_NAME_PROPERTY_KEY); bucketNameJob = configuration.getProperty(BUCKET_JOB_NAME_PROPERTY_KEY);
@ -152,8 +149,7 @@ AccountingPersistenceBackendQuery {
bucketTask= cluster.openBucket(bucketNameTask, password); bucketTask= cluster.openBucket(bucketNameTask, password);
connectionMap.put(BUCKET_TASK_NAME_PROPERTY_KEY, bucketTask); connectionMap.put(BUCKET_TASK_NAME_PROPERTY_KEY, bucketTask);
logger.trace("Open cluster Service Bucket Url:"+url+" Pwd:"+configuration.getProperty(PASSWORD_PROPERTY_KEY)+ logger.trace("Open cluster Service Bucket Url:"+url+" BucketName:"+configuration.getProperty(BUCKET_SERVICE_NAME_PROPERTY_KEY));
" BucketName "+configuration.getProperty(BUCKET_SERVICE_NAME_PROPERTY_KEY));
} }
/** /**
@ -190,7 +186,6 @@ AccountingPersistenceBackendQuery {
TemporalConstraint temporalConstraint, List<Filter> filters) TemporalConstraint temporalConstraint, List<Filter> filters)
throws Exception { throws Exception {
String currentScope = ScopeProvider.instance.get(); String currentScope = ScopeProvider.instance.get();
String recordType = clz.newInstance().getRecordType(); String recordType = clz.newInstance().getRecordType();
Expression expression = x(BasicUsageRecord.SCOPE).eq(s(currentScope)); Expression expression = x(BasicUsageRecord.SCOPE).eq(s(currentScope));
@ -221,9 +216,7 @@ AccountingPersistenceBackendQuery {
.where(expression); .where(expression);
Map<Calendar, Info> map = new HashMap<Calendar, Info>(); Map<Calendar, Info> map = new HashMap<Calendar, Info>();
//logger.info("result"+result.toString());
N1qlQueryResult result = connectionMap.get(clz.getSimpleName()).query(groupByPath); N1qlQueryResult result = connectionMap.get(clz.getSimpleName()).query(groupByPath);
if (!result.finalSuccess()) { if (!result.finalSuccess()) {
logger.debug("{} failed : {}", logger.debug("{} failed : {}",
N1qlQueryResult.class.getSimpleName(), result.errors()); N1qlQueryResult.class.getSimpleName(), result.errors());
@ -278,17 +271,13 @@ AccountingPersistenceBackendQuery {
count++; count++;
startFound = true; startFound = true;
} catch (Exception e) { } catch (Exception e) {
/* //logger.trace("The provide value is not an int. {}", array.get(i).toString());
logger.trace("The provide value is not an int. {}", array
.get(i).toString());
*/
if (startFound) { if (startFound) {
break; break;
} }
} }
} }
for (int j = count; j < calendarValues.length; j++) { for (int j = count; j < calendarValues.length; j++) {
if (calendarValues[j].getCalendarValue() == Calendar.DAY_OF_MONTH) { if (calendarValues[j].getCalendarValue() == Calendar.DAY_OF_MONTH) {
calendar.set(calendarValues[j].getCalendarValue(), 1); calendar.set(calendarValues[j].getCalendarValue(), 1);
@ -296,9 +285,7 @@ AccountingPersistenceBackendQuery {
calendar.set(calendarValues[j].getCalendarValue(), 0); calendar.set(calendarValues[j].getCalendarValue(), 0);
} }
} }
return calendar; return calendar;
} }
protected JsonArray getRangeKey(long time, AggregationMode aggregationMode, protected JsonArray getRangeKey(long time, AggregationMode aggregationMode,
@ -308,26 +295,19 @@ AccountingPersistenceBackendQuery {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time); calendar.setTimeInMillis(time);
CalendarEnum[] values = CalendarEnum.values(); CalendarEnum[] values = CalendarEnum.values();
if (endKey) { if (endKey) {
calendar.add(values[aggregationMode.ordinal()].getCalendarValue(), calendar.add(values[aggregationMode.ordinal()].getCalendarValue(),1);
1);
} }
for (int i = 0; i <= aggregationMode.ordinal(); i++) { for (int i = 0; i <= aggregationMode.ordinal(); i++) {
int value = calendar.get(values[i].getCalendarValue()); int value = calendar.get(values[i].getCalendarValue());
if (values[i].getCalendarValue() == Calendar.MONTH) { if (values[i].getCalendarValue() == Calendar.MONTH) {
value = value + 1; value = value + 1;
} }
array.add(value); array.add(value);
} }
if (wildCard) { if (wildCard) {
array.add("{}"); array.add("{}");
} }
return array; return array;
} }
@ -339,33 +319,31 @@ AccountingPersistenceBackendQuery {
* Used in the name of map reduce to separate keys used as filter * Used in the name of map reduce to separate keys used as filter
*/ */
protected static final String KEYS_SEPARATOR = "__"; protected static final String KEYS_SEPARATOR = "__";
protected String getDesignDocId( protected String getDesignDocId(
Class<? extends AggregatedRecord<?,?>> recordClass) Class<? extends AggregatedRecord<?,?>> recordClass)
throws InstantiationException, IllegalAccessException { throws InstantiationException, IllegalAccessException {
String getDesigndocid=String.format("%s%s", MAP_REDUCE__DESIGN, recordClass
.newInstance().getRecordType());
//logger.debug("use a designDocID:{}",getDesigndocid);
return String.format("%s%s", MAP_REDUCE__DESIGN, recordClass return String.format("%s%s", MAP_REDUCE__DESIGN, recordClass
.newInstance().getRecordType()); .newInstance().getRecordType());
} }
/**
*
* @param recordClass
* @param keys
* @return
* @throws InstantiationException
* @throws IllegalAccessException
*/
protected String getDesignDocIdSpecific( protected String getDesignDocIdSpecific(
Class<? extends AggregatedRecord<?,?>> recordClass, Class<? extends AggregatedRecord<?,?>> recordClass,
Collection<String> keys) Collection<String> keys)
throws InstantiationException, IllegalAccessException { throws InstantiationException, IllegalAccessException {
String getDesigndocId=String.format("%s%s", MAP_REDUCE__DESIGN, recordClass
.newInstance().getRecordType());
String specific="all"; String specific="all";
if (!keys.isEmpty()){ if (!keys.isEmpty()){
specific = keys.iterator().next(); specific = keys.iterator().next();
} }
String getDesigndocIdSpecific=getDesigndocId+SEPARATOR_DESIGN_DOC+specific; String getDesigndocIdSpecific=specific;
logger.debug("use a designDocIDSpecific:{}",getDesigndocIdSpecific); logger.trace("Use a designDocIDSpecific:{}",getDesigndocIdSpecific);
return getDesigndocIdSpecific; return getDesigndocIdSpecific;
} }
@ -464,10 +442,9 @@ AccountingPersistenceBackendQuery {
groupLevel += keys.size(); groupLevel += keys.size();
} }
String designDocId = getDesignDocId(clz); //String designDocId = getDesignDocId(clz);
//ADD A SPECIFY DESIGN DOC FAMILY String designDocId = getDesignDocIdSpecific(clz,keys);
String designDocIdNew = getDesignDocIdSpecific(clz,keys); logger.trace("designDocIdNew :{}",designDocId);
logger.trace("designDocIdNew :{}",designDocIdNew);
for (Object temporal: temporalStartKey.toList()){ for (Object temporal: temporalStartKey.toList()){
if (!temporal.toString().isEmpty()) if (!temporal.toString().isEmpty())
startKey.add(temporal); startKey.add(temporal);
@ -509,7 +486,6 @@ AccountingPersistenceBackendQuery {
JsonArray array = (JsonArray) row.key(); JsonArray array = (JsonArray) row.key();
Calendar calendar = getCalendarFromArray(array); Calendar calendar = getCalendarFromArray(array);
JsonObject value = (JsonObject) row.value(); JsonObject value = (JsonObject) row.value();
JSONObject obj = new JSONObject(value.toString()); JSONObject obj = new JSONObject(value.toString());
Info info = new Info(calendar, obj); Info info = new Info(calendar, obj);
@ -518,8 +494,6 @@ AccountingPersistenceBackendQuery {
} }
if (infos.isEmpty()){ if (infos.isEmpty()){
//exec a map reduce for found name key
query = ViewQuery.from(designDocId, viewName); query = ViewQuery.from(designDocId, viewName);
query.groupLevel(groupLevel); query.groupLevel(groupLevel);
query.descending(false); query.descending(false);
@ -556,10 +530,10 @@ AccountingPersistenceBackendQuery {
return infos; return infos;
} }
@Override @Override
public SortedMap<Calendar, Info> getTimeSeries( public SortedMap<Calendar, Info> getTimeSeries(
Class<? extends AggregatedRecord<?, ?>> clz, Class<? extends AggregatedRecord<?, ?>> clz,
@ -570,7 +544,7 @@ AccountingPersistenceBackendQuery {
return map; return map;
} }
@Override @Override
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues( public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
Class<? extends AggregatedRecord<?, ?>> clz, Class<? extends AggregatedRecord<?, ?>> clz,
@ -610,18 +584,16 @@ AccountingPersistenceBackendQuery {
@Override @Override
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries( public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
Class<? extends AggregatedRecord<?, ?>> clz, Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters,List<String> contexts) TemporalConstraint temporalConstraint, List<Filter> filters,List<String> contexts)
throws Exception { throws Exception {
logger.trace("getContextTimeSeries"); logger.trace("getContextTimeSeries for contexts:{}",contexts.toString());
SortedSet<Filter> listContexts = new TreeSet(); SortedSet<Filter> listContexts = new TreeSet();
for (String context:contexts){ for (String context:contexts){
Filter contextLabel= new Filter("context",context); Filter contextLabel= new Filter("context",context);
listContexts.add(contextLabel); listContexts.add(contextLabel);
} }
SortedMap<Filter, SortedMap<Calendar, Info>> ret = new TreeMap<>(); SortedMap<Filter, SortedMap<Calendar, Info>> ret = new TreeMap<>();
for(Filter nf : listContexts){
for(Filter nf : listContexts){
//filters.add(nf);
logger.debug("detail time series :{}",nf.toString()); logger.debug("detail time series :{}",nf.toString());
SortedMap<Calendar, Info> map = SortedMap<Calendar, Info> map =
mapReduceQuery(clz, temporalConstraint, filters,nf.getValue()); mapReduceQuery(clz, temporalConstraint, filters,nf.getValue());
@ -629,7 +601,7 @@ AccountingPersistenceBackendQuery {
filters.remove(nf); filters.remove(nf);
} }
return ret; return ret;
} }
protected String getQualifiedProperty(String property){ protected String getQualifiedProperty(String property){
@ -651,7 +623,7 @@ AccountingPersistenceBackendQuery {
String key, String orderingProperty) throws Exception { String key, String orderingProperty) throws Exception {
String currentScope = ScopeProvider.instance.get(); String currentScope = ScopeProvider.instance.get();
String recordType = clz.newInstance().getRecordType(); //String recordType = clz.newInstance().getRecordType();
if(orderingProperty==null){ if(orderingProperty==null){
orderingProperty = AccountingPersistenceQuery. orderingProperty = AccountingPersistenceQuery.
@ -659,19 +631,12 @@ AccountingPersistenceBackendQuery {
} }
Collection<Expression> selectExpressions = new ArrayList<>(); Collection<Expression> selectExpressions = new ArrayList<>();
//add select expression //add select expression
/* //selectExpressions.add(x("SUM(" + getSpecializedProperty(clz,orderingProperty) + ")").as(orderingProperty));
selectExpressions.add(x("SUM(" + getSpecializedProperty(clz,orderingProperty) + ")").
as(orderingProperty));
*/
//add select expression and check if exist //add select expression and check if exist
selectExpressions.add(x("SUM(CASE WHEN " + getSpecializedProperty(clz,orderingProperty) + selectExpressions.add(x("SUM(CASE WHEN " + getSpecializedProperty(clz,orderingProperty) +
" IS NOT NULL THEN "+getSpecializedProperty(clz,orderingProperty)+" ELSE 1 END )"). " IS NOT NULL THEN "+getSpecializedProperty(clz,orderingProperty)+" ELSE 1 END )").
as(orderingProperty)); as(orderingProperty));
//selectExpressions.add(x(getSpecializedProperty(clz,key)).as(key)); //selectExpressions.add(x(getSpecializedProperty(clz,key)).as(key));
selectExpressions.add(x("(CASE WHEN " + getSpecializedProperty(clz,key) + selectExpressions.add(x("(CASE WHEN " + getSpecializedProperty(clz,key) +
" IS NOT NULL THEN "+getSpecializedProperty(clz,key)+" ELSE 'UNKNOWN' END )").as(key)); " IS NOT NULL THEN "+getSpecializedProperty(clz,key)+" ELSE 'UNKNOWN' END )").as(key));
@ -686,7 +651,6 @@ AccountingPersistenceBackendQuery {
x(getSpecializedProperty(clz,AggregatedRecord.START_TIME)).gt(startTime) x(getSpecializedProperty(clz,AggregatedRecord.START_TIME)).gt(startTime)
); );
//long endTime = temporalConstraint.getAlignedEndTime().getTimeInMillis(); //long endTime = temporalConstraint.getAlignedEndTime().getTimeInMillis();
//if (startTime==endTime)
long endTime = temporalConstraint.getEndTime(); long endTime = temporalConstraint.getEndTime();
whereExpression = whereExpression.and( whereExpression = whereExpression.and(
@ -739,7 +703,7 @@ AccountingPersistenceBackendQuery {
OffsetPath path = select(selectExpressionArray).from(connectionMap.get(clz.getSimpleName()).name()) OffsetPath path = select(selectExpressionArray).from(connectionMap.get(clz.getSimpleName()).name())
.where(whereExpression).groupBy(key).orderBy(sort); .where(whereExpression).groupBy(key).orderBy(sort);
logger.debug("Query for top"+path.toString()); logger.debug("Query for top:"+path.toString());
Comparator<NumberedFilter> comparator = new Comparator<NumberedFilter>() { Comparator<NumberedFilter> comparator = new Comparator<NumberedFilter>() {
@Override @Override
public int compare(NumberedFilter o1, NumberedFilter o2) { public int compare(NumberedFilter o1, NumberedFilter o2) {
@ -803,15 +767,12 @@ AccountingPersistenceBackendQuery {
int groupLevel = scopeDateGroupLevel; int groupLevel = scopeDateGroupLevel;
//NO ADD A SPECIFIY DESIGN DOC ID FAMILY //NO ADD A SPECIFIY DESIGN DOC ID FAMILY
String designDocId = getDesignDocId(clz)+"Value"; String designDocId = getDesignDocId(clz)+"Value";
String viewName = key; String viewName = key;
logger.trace("designDocId:{} view:{} ",designDocId,key); logger.trace("designDocId:{} view:{} startKey:{} groupLevel:{}",designDocId,key,startKey,groupLevel);
logger.trace("startKey:{}",startKey);
logger.trace("groupLevel"+groupLevel);
ViewQuery query = ViewQuery.from(designDocId, viewName); ViewQuery query = ViewQuery.from(designDocId, viewName);
query.inclusiveEnd(); query.inclusiveEnd();
query.groupLevel(groupLevel); query.groupLevel(groupLevel);
query.startKey(startKey); query.startKey(startKey);
query.descending(false); query.descending(false);
@ -859,7 +820,6 @@ AccountingPersistenceBackendQuery {
Class<? extends AggregatedRecord<?, ?>> clz, Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, Filter applicant) throws Exception { TemporalConstraint temporalConstraint, Filter applicant) throws Exception {
String currentScope = ScopeProvider.instance.get(); String currentScope = ScopeProvider.instance.get();
JsonArray startKey = JsonArray.create(); JsonArray startKey = JsonArray.create();
@ -868,7 +828,6 @@ AccountingPersistenceBackendQuery {
JsonArray endKey = JsonArray.create(); JsonArray endKey = JsonArray.create();
endKey.add(currentScope); endKey.add(currentScope);
AggregationMode aggregationMode = temporalConstraint AggregationMode aggregationMode = temporalConstraint
.getAggregationMode(); .getAggregationMode();
@ -882,13 +841,13 @@ AccountingPersistenceBackendQuery {
startKey.add(applicant.getValue()); startKey.add(applicant.getValue());
for (Object temporal: temporalStartKey.toList()){ for (Object temporal: temporalStartKey.toList()){
if (!temporal.toString().isEmpty()) if (!temporal.toString().isEmpty())
startKey.add(temporal); startKey.add(temporal);
} }
endKey.add(applicant.getValue()); endKey.add(applicant.getValue());
int count =1; int count =1;
for (Object temporal: temporalEndKey.toList()){ for (Object temporal: temporalEndKey.toList()){
if (!temporal.toString().isEmpty()){ if (!temporal.toString().isEmpty()){
@ -906,12 +865,16 @@ AccountingPersistenceBackendQuery {
int scopeDateGroupLevel = aggregationMode.ordinal() + 1 + 1 +1; int scopeDateGroupLevel = aggregationMode.ordinal() + 1 + 1 +1;
int groupLevel = scopeDateGroupLevel; int groupLevel = scopeDateGroupLevel;
String designDocId = getDesignDocId(clz);
Collection<String> keys = new TreeSet<>();
keys.add(applicant.getKey());
//String designDocId = getDesignDocId(clz);
//ADD A SPECIFIY DESIGN DOC ID FAMILY //ADD A SPECIFIY DESIGN DOC ID FAMILY
String designDocId = getDesignDocIdSpecific(clz,keys);
String viewName = applicant.getKey(); String viewName = applicant.getKey();
ViewQuery query = ViewQuery.from(designDocId, viewName); ViewQuery query = ViewQuery.from(designDocId, viewName);
query.inclusiveEnd(); query.inclusiveEnd();
query.groupLevel(groupLevel); query.groupLevel(groupLevel);
query.startKey(startKey); query.startKey(startKey);
@ -958,173 +921,55 @@ AccountingPersistenceBackendQuery {
return result; return result;
} }
@Override
public List<Filters> getUsageValueQuota(
Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint,
List<Filters> filterPackageQuota) throws Exception {
String currentScope = ScopeProvider.instance.get();
AggregationMode aggregationMode = temporalConstraint
.getAggregationMode();
JsonArray temporalStartKey = getRangeKey(
temporalConstraint.getStartTime(),
aggregationMode, false, false);
JsonArray temporalEndKey = getRangeKey(
temporalConstraint.getEndTime(),
aggregationMode, false, false);
String designDocId = getDesignDocId(clz);
//ADD A SPECIFIY DESIGN DOC ID FAMILY
for (Filters singleFilter:filterPackageQuota){
String viewNameTmp=null;
JsonArray startKeyTmp=JsonArray.create();
startKeyTmp.add(currentScope);
JsonArray endKeyTmp=JsonArray.create();
endKeyTmp.add(currentScope);
int groupLevelTmp= 2;
for (Filter filter:singleFilter.getFilters()){
if (groupLevelTmp==2)
viewNameTmp=filter.getKey();
else
viewNameTmp=viewNameTmp+"__"+filter.getKey();
startKeyTmp.add(filter.getValue());
endKeyTmp.add(filter.getValue());
groupLevelTmp++;
}
for (Object temporal: temporalStartKey.toList()){
if (!temporal.toString().isEmpty())
startKeyTmp.add(temporal);
}
int count =1;
for (Object temporal: temporalEndKey.toList()){
if (!temporal.toString().isEmpty()){
//couchbase exclude last value
if (count==temporalEndKey.size())
temporal=(int)temporal+1;
endKeyTmp.add(temporal);
}
count++;
}
ViewQuery query = ViewQuery.from(designDocId, viewNameTmp);
query.inclusiveEnd();
query.groupLevel(groupLevelTmp);
query.startKey(startKeyTmp);
query.endKey(endKeyTmp);
query.descending(false);
logger.trace("Bucket :{}, Design Doc ID : {}, View Name : {}, "
+ "Group Level : {}, Start Key : {}, End Key : {},"
+ "temporalStartKey :{}, temporalEndKey :{}",
clz.getSimpleName(),designDocId, viewNameTmp, groupLevelTmp, startKeyTmp, endKeyTmp,temporalStartKey.toString(), temporalEndKey.toString());
ViewResult viewResult;
try {
//execute query in a specify bucket
viewResult = connectionMap.get(clz.getSimpleName()).query(query);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
throw e;
}
Map<String, Float> map = new HashMap<String, Float>();
for (ViewRow row : viewResult) {
JsonObject jsnobject = (JsonObject) row.value();
JSONObject objJson = new JSONObject(jsnobject.toString());
Iterator<?> iterateJosn = objJson.keys();
while( iterateJosn.hasNext() ) {
String key = (String)iterateJosn.next();
Float valuetmp=Float.parseFloat(objJson.get(key).toString());
if (key.equals("operationCount") || key.equals("dataVolume")){
if (map.containsKey(key)) {
map.put(key, valuetmp + map.get(key));
// TODO verify a better method
if (designDocId.equals("StorageUsageRecord")){
if (key.equals("dataVolume")){
singleFilter.setOrderingProperty(key);
singleFilter.setD(singleFilter.getD()+valuetmp.doubleValue());
}
}
else{
singleFilter.setOrderingProperty(key);
singleFilter.setD(singleFilter.getD()+valuetmp.doubleValue());
}
}
else{
map.put(key, valuetmp);
// TODO verify a better method
if (designDocId.equals("StorageUsageRecord")){
if (key.equals("dataVolume")){
singleFilter.setOrderingProperty(key);
singleFilter.setD(valuetmp.doubleValue());
}
}
else{
singleFilter.setOrderingProperty(key);
singleFilter.setD(valuetmp.doubleValue());
}
}
}
}
}
}
return filterPackageQuota;
}
/** /**
* *
*/ */
@Override @Override
public List<TotalFilters> getUsageValueQuotaTotal( public List<UsageValue> getUsageValueQuotaTotal(
Class<? extends AggregatedRecord<?, ?>> clz, List<UsageValue> listUsage)
TemporalConstraint temporalConstraint, List<TotalFilters> listUsage) throws Exception {
throws Exception {
//String currentScope = ScopeProvider.instance.get();
String keyOrderingProperty = null;
for (UsageValue totalFilters:listUsage){
String currentScope = ScopeProvider.instance.get(); String currentScope = totalFilters.getContext();
AggregationMode aggregationMode = temporalConstraint
.getAggregationMode();
JsonArray temporalStartKey = getRangeKey( Collection<String> keys= new TreeSet<>();
temporalConstraint.getStartTime(), keys.add("consumerId");
aggregationMode, false, false); String designDocId = getDesignDocIdSpecific(totalFilters.getClz(), keys);
JsonArray temporalEndKey = getRangeKey( JsonArray temporalStartKey=null;
temporalConstraint.getEndTime(), JsonArray temporalEndKey=null;
aggregationMode, false, false); TemporalConstraint temporalConstraint=totalFilters.getTemporalConstraint();
if (temporalConstraint==(null)){
logger.trace("Not found temporalConstraint");
Calendar startTime = Calendar.getInstance();
startTime.set(1970, Calendar.JANUARY, 1);
Calendar endTime = Calendar.getInstance();
temporalConstraint =
new TemporalConstraint(startTime.getTimeInMillis(),
endTime.getTimeInMillis(), AggregationMode.DAILY);
}
String designDocId = getDesignDocId(clz); AggregationMode aggregationMode = temporalConstraint.getAggregationMode();
//ADD A SPECIFIC DESIGN DOC ID FAMILY temporalStartKey = getRangeKey(
temporalConstraint.getStartTime(),
for (TotalFilters totalfilters:listUsage){ aggregationMode, false, false);
temporalEndKey = getRangeKey(
temporalConstraint.getEndTime(),
aggregationMode, false, false);
Double totalQuota=0.00; Double totalQuota=0.00;
int i = 0;
for (Filters singleFilter:totalfilters.getTotalFilters()){ int countFilters=0;
String viewNameTmp=null;
if (totalFilters.getClass().getSimpleName().equals(UsageServiceValue.class.getSimpleName())){
UsageServiceValue totalFiltersService = (UsageServiceValue)totalFilters;
countFilters =totalFiltersService.getFiltersValue().size();
}
do {
String viewNameTmp=null;
JsonArray startKeyTmp=JsonArray.create(); JsonArray startKeyTmp=JsonArray.create();
startKeyTmp.add(currentScope); startKeyTmp.add(currentScope);
@ -1132,18 +977,22 @@ AccountingPersistenceBackendQuery {
endKeyTmp.add(currentScope); endKeyTmp.add(currentScope);
int groupLevelTmp= 2; int groupLevelTmp= 2;
//FiltersValue singleFilter=null;
for (Filter filter:singleFilter.getFilters()){ viewNameTmp=AggregatedServiceUsageRecord.CONSUMER_ID;
if (groupLevelTmp==2) startKeyTmp.add(totalFilters.getIdentifier());
viewNameTmp=filter.getKey(); endKeyTmp.add(totalFilters.getIdentifier());
else FiltersValue singleFilter=null;
if (totalFilters.getClass().getSimpleName().equals(UsageServiceValue.class.getSimpleName())){
UsageServiceValue totalFiltersService = (UsageServiceValue)totalFilters;
singleFilter=totalFiltersService.getFiltersValue().get(i);
for (Filter filter:singleFilter.getFiltersValue()){
viewNameTmp=viewNameTmp+"__"+filter.getKey(); viewNameTmp=viewNameTmp+"__"+filter.getKey();
startKeyTmp.add(filter.getValue()); startKeyTmp.add(filter.getValue());
endKeyTmp.add(filter.getValue()); endKeyTmp.add(filter.getValue());
groupLevelTmp++; groupLevelTmp++;
}
} }
//not defined temporal constraint
for (Object temporal: temporalStartKey.toList()){ for (Object temporal: temporalStartKey.toList()){
if (!temporal.toString().isEmpty()) if (!temporal.toString().isEmpty())
startKeyTmp.add(temporal); startKeyTmp.add(temporal);
@ -1151,13 +1000,17 @@ AccountingPersistenceBackendQuery {
int count =1; int count =1;
for (Object temporal: temporalEndKey.toList()){ for (Object temporal: temporalEndKey.toList()){
if (!temporal.toString().isEmpty()){ if (!temporal.toString().isEmpty()){
//couchbase exclude last value //couchbase excludes last value
if (count==temporalEndKey.size()) if (count==temporalEndKey.size())
temporal=(int)temporal+1; temporal=(int)temporal+1;
endKeyTmp.add(temporal); endKeyTmp.add(temporal);
} }
count++; count++;
} }
logger.trace("Bucket :{}, Design Doc ID : {}, View Name : {}, "
+ "Group Level : {}, Start Key : {}, End Key : {},"
+ "temporalStartKey :{}, temporalEndKey :{}",
totalFilters.getClz().getSimpleName(),designDocId, viewNameTmp, groupLevelTmp, startKeyTmp, endKeyTmp,temporalStartKey.toString(), temporalEndKey.toString());
ViewQuery query = ViewQuery.from(designDocId, viewNameTmp); ViewQuery query = ViewQuery.from(designDocId, viewNameTmp);
query.inclusiveEnd(); query.inclusiveEnd();
@ -1166,16 +1019,9 @@ AccountingPersistenceBackendQuery {
query.endKey(endKeyTmp); query.endKey(endKeyTmp);
query.descending(false); query.descending(false);
logger.trace("Bucket :{}, Design Doc ID : {}, View Name : {}, "
+ "Group Level : {}, Start Key : {}, End Key : {},"
+ "temporalStartKey :{}, temporalEndKey :{}",
clz.getSimpleName(),designDocId, viewNameTmp, groupLevelTmp, startKeyTmp, endKeyTmp,temporalStartKey.toString(), temporalEndKey.toString());
ViewResult viewResult; ViewResult viewResult;
try { try {
//execute query in a specify bucket viewResult = connectionMap.get(totalFilters.getClz().getSimpleName()).query(query);
viewResult = connectionMap.get(clz.getSimpleName()).query(query);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
throw e; throw e;
@ -1191,23 +1037,31 @@ AccountingPersistenceBackendQuery {
Iterator<?> iterateJosn = objJson.keys(); Iterator<?> iterateJosn = objJson.keys();
while( iterateJosn.hasNext() ) { while( iterateJosn.hasNext() ) {
String key = (String)iterateJosn.next(); String key = (String)iterateJosn.next();
Float valuetmp=Float.parseFloat(objJson.get(key).toString()); Float valuetmp=Float.parseFloat(objJson.get(key).toString());
if (key.equals("operationCount") || key.equals("dataVolume")){ if (key.equals("operationCount") || key.equals("dataVolume")){
if (map.containsKey(key)) { if (map.containsKey(key)) {
map.put(key, valuetmp + map.get(key)); map.put(key, valuetmp + map.get(key));
// TODO verify a better method // TODO verify a better method
if (designDocId.equals("StorageUsageRecord")){ if (designDocId.equals("StorageUsageRecord")){
if (key.equals("dataVolume")){ if (key.equals("dataVolume")){
singleFilter.setOrderingProperty(key); if (totalFilters.getClass().getSimpleName().equals(UsageServiceValue.class.getSimpleName())){
singleFilter.setD(singleFilter.getD()+valuetmp.doubleValue()); singleFilter.setOrderingProperty(key);
singleFilter.setD(singleFilter.getD()+valuetmp.doubleValue());
}
keyOrderingProperty=key;
totalQuota+=singleFilter.getD()+valuetmp.doubleValue(); totalQuota+=singleFilter.getD()+valuetmp.doubleValue();
} }
} }
else{ else{
singleFilter.setOrderingProperty(key); if (totalFilters.getClass().getSimpleName().equals(UsageServiceValue.class.getSimpleName())){
singleFilter.setD(singleFilter.getD()+valuetmp.doubleValue()); singleFilter.setOrderingProperty(key);
singleFilter.setD(singleFilter.getD()+valuetmp.doubleValue());
}
keyOrderingProperty=key;
totalQuota+=singleFilter.getD()+valuetmp.doubleValue(); totalQuota+=singleFilter.getD()+valuetmp.doubleValue();
} }
@ -1218,36 +1072,32 @@ AccountingPersistenceBackendQuery {
// TODO verify a better method // TODO verify a better method
if (designDocId.equals("StorageUsageRecord")){ if (designDocId.equals("StorageUsageRecord")){
if (key.equals("dataVolume")){ if (key.equals("dataVolume")){
singleFilter.setOrderingProperty(key); keyOrderingProperty=key;
singleFilter.setD(valuetmp.doubleValue()); if (totalFilters.getClass().getSimpleName().equals(UsageServiceValue.class.getSimpleName())){
singleFilter.setOrderingProperty(key);
singleFilter.setD(valuetmp.doubleValue());
}
totalQuota+=valuetmp.doubleValue(); totalQuota+=valuetmp.doubleValue();
} }
} }
else{ else{
singleFilter.setOrderingProperty(key); keyOrderingProperty=key;
singleFilter.setD(valuetmp.doubleValue()); if (totalFilters.getClass().getSimpleName().equals(UsageServiceValue.class.getSimpleName())){
singleFilter.setOrderingProperty(key);
singleFilter.setD(valuetmp.doubleValue());
}
totalQuota+=valuetmp.doubleValue(); totalQuota+=valuetmp.doubleValue();
} }
} }
} }
} }
} }
} i++;
totalfilters.setD(totalQuota); } while (i <countFilters );
totalFilters.setOrderingProperty(keyOrderingProperty);
totalFilters.setD(totalQuota);
} }
return listUsage; return listUsage;
} }
} }

View File

@ -14,16 +14,19 @@ import java.util.SortedMap;
import java.util.SortedSet; import java.util.SortedSet;
import org.gcube.accounting.analytics.Filter; import org.gcube.accounting.analytics.Filter;
import org.gcube.accounting.analytics.Filters; import org.gcube.accounting.analytics.FiltersValue;
import org.gcube.accounting.analytics.Info; import org.gcube.accounting.analytics.Info;
import org.gcube.accounting.analytics.NumberedFilter; import org.gcube.accounting.analytics.NumberedFilter;
import org.gcube.accounting.analytics.TemporalConstraint; import org.gcube.accounting.analytics.TemporalConstraint;
import org.gcube.accounting.analytics.TotalFilters; import org.gcube.accounting.analytics.UsageServiceValue;
import org.gcube.accounting.analytics.UsageStorageValue;
import org.gcube.accounting.analytics.UsageValue;
import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode; import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode;
import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQueryConfiguration; import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQueryConfiguration;
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery; import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord; import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.json.JSONException; import org.json.JSONException;
@ -183,47 +186,41 @@ public class AccountingPersistenceQueryCouchBaseTest {
} }
@Test
public void getUsageValueQuota() throws Exception{
Calendar startTime = Calendar.getInstance();
startTime.set(2015, Calendar.MAY, 1);
Calendar endTime = Calendar.getInstance();
ScopeProvider.instance.set("/gcube");
TemporalConstraint temporalConstraint =
new TemporalConstraint(startTime.getTimeInMillis(),
endTime.getTimeInMillis(), AggregationMode.DAILY);
List<Filters> filterPackageQuota =new ArrayList<Filters>();
Filters simpleFilter = new Filters();
List<Filter> filters=new ArrayList<Filter>();
filters.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "alessandro.pieve"));
filters.add(new Filter("serviceClass", "DataAccess"));
filters.add(new Filter("serviceName", "CkanConnector"));
simpleFilter.setFilters(filters);
filterPackageQuota.add(simpleFilter);
Filters simpleFilter1 = new Filters();
List<Filter> filters1=new ArrayList<Filter>();
filters1.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "alessandro.pieve"));
filters1.add(new Filter("serviceClass", "VREManagement"));
simpleFilter1.setFilters(filters1);
filterPackageQuota.add(simpleFilter1);
logger.info("filterPackageQuota:"+filterPackageQuota);
List<Filters> filterValue =
accountingPersistenceQueryCouchBase.getUsageValueQuota(AggregatedServiceUsageRecord.class, temporalConstraint, filterPackageQuota);
logger.info("result:"+filterValue.toString());
}
/**
* utilizzato per effettuare una singola chiamata ad accounting analytics in modo che ritorni una lista di quote riempite
*
* OUTPUT:
* result:[
*
* [
* UsageServiceValue [
* clz=class org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord,
* temporalConstraint=StartTime : 2015-05-01 10:25:49:238 UTC (1430475949238 millis), EndTime : 2016-11-11 10:25:49:238 UTC (1478859949238 millis),
* Aggregated DAILY,
* filtersValue=[
* FiltersValue [
* filters=[{ "serviceClass" : "DataAccess" }, { "serviceName" : "CkanConnector" }], d=1.0, orderingProperty=operationCount],
* FiltersValue [
* filters=[{ "serviceClass" : "VREManagement" }], d=1.0, orderingProperty=operationCount]
* ],
* identifier=lucio.lelii,
* d=2.0,
* orderingProperty=operationCount
* ],
*
* UsageStorageValue [
* clz=class org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord,
* temporalConstraint=StartTime : 2015-05-01 10:25:49:238 UTC (1430475949238 millis), EndTime : 2016-11-11 10:25:49:238 UTC (1478859949238 millis),
* Aggregated DAILY,
* identifier=alessandro.pieve,
* d=714216.0,
* orderingProperty=dataVolume
* ]
* ]
*/
@Test @Test
public void getUsageValueQuotaTotal() throws Exception{ public void getUsageValueQuotaTotal() throws Exception{
Calendar startTime = Calendar.getInstance(); Calendar startTime = Calendar.getInstance();
@ -232,64 +229,97 @@ public class AccountingPersistenceQueryCouchBaseTest {
ScopeProvider.instance.set("/gcube"); ScopeProvider.instance.set("/gcube");
String context="/gcube";
TemporalConstraint temporalConstraint = TemporalConstraint temporalConstraint =
new TemporalConstraint(startTime.getTimeInMillis(), new TemporalConstraint(startTime.getTimeInMillis(),
endTime.getTimeInMillis(), AggregationMode.DAILY); endTime.getTimeInMillis(), AggregationMode.DAILY);
/*ask quota for user alessandro pieve*/ /*ask quota for user alessandro pieve
List<Filters> filterPackageQuota =new ArrayList<Filters>(); *
* SERVICE
* */
List<FiltersValue> filterPackageQuota =new ArrayList<FiltersValue>();
Filters simpleFilter = new Filters(); FiltersValue simpleFilter = new FiltersValue();
List<Filter> filters=new ArrayList<Filter>(); List<Filter> filters=new ArrayList<Filter>();
filters.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "alessandro.pieve")); filters.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "alessandro.pieve"));
filters.add(new Filter("serviceClass", "DataAccess")); filters.add(new Filter("serviceClass", "DataAccess"));
filters.add(new Filter("serviceName", "CkanConnector")); filters.add(new Filter("serviceName", "CkanConnector"));
simpleFilter.setFilters(filters); simpleFilter.setFiltersValue(filters);
filterPackageQuota.add(simpleFilter); filterPackageQuota.add(simpleFilter);
Filters simpleFilter1 = new Filters(); FiltersValue simpleFilter1 = new FiltersValue();
List<Filter> filters1=new ArrayList<Filter>(); List<Filter> filters1=new ArrayList<Filter>();
filters1.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "alessandro.pieve")); filters1.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "alessandro.pieve"));
filters1.add(new Filter("serviceClass", "VREManagement")); filters1.add(new Filter("serviceClass", "VREManagement"));
simpleFilter1.setFilters(filters1); simpleFilter1.setFiltersValue(filters1);
filterPackageQuota.add(simpleFilter1); filterPackageQuota.add(simpleFilter1);
TotalFilters totalfilter=new TotalFilters(); UsageValue totalfilter=new UsageServiceValue(context,"lucio.lelii",AggregatedServiceUsageRecord.class,temporalConstraint,filterPackageQuota);
totalfilter.setTotalFilters(filterPackageQuota);
/*ask quota for user lucio lelii*/
List<Filters> filterPackageQuota1 =new ArrayList<Filters>();
Filters simpleFilter2 = new Filters(); /*ask quota for user lucio lelii
* SERVICE
* */
List<FiltersValue> filterPackageQuota1 =new ArrayList<FiltersValue>();
FiltersValue simpleFilter2 = new FiltersValue();
List<Filter> filters2=new ArrayList<Filter>(); List<Filter> filters2=new ArrayList<Filter>();
filters2.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "lucio.lelii")); //filters2.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "lucio.lelii"));
filters2.add(new Filter("serviceClass", "DataAccess")); filters2.add(new Filter("serviceClass", "DataAccess"));
filters2.add(new Filter("serviceName", "CkanConnector")); filters2.add(new Filter("serviceName", "CkanConnector"));
simpleFilter2.setFilters(filters2); simpleFilter2.setFiltersValue(filters2);
filterPackageQuota1.add(simpleFilter2); filterPackageQuota1.add(simpleFilter2);
Filters simpleFilter3 = new Filters(); FiltersValue simpleFilter3 = new FiltersValue();
List<Filter> filters3=new ArrayList<Filter>(); List<Filter> filters3=new ArrayList<Filter>();
filters3.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "lucio.lelii")); //filters3.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "lucio.lelii"));
filters3.add(new Filter("serviceClass", "VREManagement")); filters3.add(new Filter("serviceClass", "VREManagement"));
simpleFilter3.setFilters(filters3); simpleFilter3.setFiltersValue(filters3);
filterPackageQuota1.add(simpleFilter3); filterPackageQuota1.add(simpleFilter3);
TotalFilters totalfilter1=new TotalFilters(); UsageValue totalfilter1=new UsageServiceValue("gcube","lucio.lelii",AggregatedServiceUsageRecord.class,temporalConstraint,filterPackageQuota1);
totalfilter1.setTotalFilters(filterPackageQuota1); //totalfilter1.setTotalFilters(filterPackageQuota1);
/*ask quota for alessandro pieve
*STORAGE
**/
List<FiltersValue> filterPackageQuota2 =new ArrayList<FiltersValue>();
FiltersValue simpleFilter4 = new FiltersValue();
List<Filter> filters4=new ArrayList<Filter>();
filters4.add(new Filter(AggregatedStorageUsageRecord.CONSUMER_ID, "alessandro.pieve"));
simpleFilter4.setFiltersValue(filters4);
filterPackageQuota2.add(simpleFilter4);
//TotalFilters totalfilter2=new TotalFilters("alessandro.pieve",AggregatedStorageUsageRecord.class,temporalConstraint,filterPackageQuota2);
List<FiltersValue> filtersList=new ArrayList<FiltersValue>();
//UsageValue totalfilter2=new UsageStorageValue("alessandro.pieve",AggregatedStorageUsageRecord.class,temporalConstraint);
UsageValue totalfilter2=new UsageStorageValue(context,"alessandro.pieve",AggregatedStorageUsageRecord.class);
List<UsageValue> listTotalFilter=new ArrayList<UsageValue>();
// listTotalFilter.add(totalfilter);
listTotalFilter.add(totalfilter1);
listTotalFilter.add(totalfilter2);
List<TotalFilters> listTotalFilter=new ArrayList<TotalFilters>();
listTotalFilter.add(totalfilter);
listTotalFilter.add(totalfilter1);
logger.info("filterPackageQuota:"+listTotalFilter); logger.info("filterPackageQuota:"+listTotalFilter);
List<TotalFilters> filterValue = List<UsageValue> filterValue =
accountingPersistenceQueryCouchBase.getUsageValueQuotaTotal(AggregatedServiceUsageRecord.class, temporalConstraint, listTotalFilter); accountingPersistenceQueryCouchBase.getUsageValueQuotaTotal(listTotalFilter);
logger.info("result:"+filterValue.toString()); logger.info("result:"+filterValue.toString());
} }
@ -447,11 +477,8 @@ public class AccountingPersistenceQueryCouchBaseTest {
startTime.set(2016, Calendar.SEPTEMBER, 1); startTime.set(2016, Calendar.SEPTEMBER, 1);
Calendar endTime = Calendar.getInstance(); Calendar endTime = Calendar.getInstance();
endTime.set(2016, Calendar.OCTOBER, 20,23,59); endTime.set(2016, Calendar.OCTOBER, 20,23,59);
List<Filter> filters = new ArrayList<Filter>(); List<Filter> filters = new ArrayList<Filter>();
//filters.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "alessandro.pieve")); //filters.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "alessandro.pieve"));
TemporalConstraint temporalConstraint = TemporalConstraint temporalConstraint =
new TemporalConstraint(startTime.getTimeInMillis(), new TemporalConstraint(startTime.getTimeInMillis(),
endTime.getTimeInMillis(), AggregationMode.DAILY); endTime.getTimeInMillis(), AggregationMode.DAILY);
@ -460,27 +487,18 @@ public class AccountingPersistenceQueryCouchBaseTest {
AggregatedServiceUsageRecord.class; AggregatedServiceUsageRecord.class;
List<String> context=new ArrayList<String>(); List<String> context=new ArrayList<String>();
context.add("/gcube"); context.add("/gcube");
context.add("/gcube/devNext"); context.add("/gcube/devNext");
context.add("/gcube/devNext/nextNext"); context.add("/gcube/devNext/nextNext");
context.add("/gcube/devsec"); context.add("/gcube/devsec");
context.add("/gcube/devsec/devVRE"); context.add("/gcube/devsec/devVRE");
context.add("/gcube/devsec/preVRE"); context.add("/gcube/devsec/preVRE");
context.add("/gcube/preprod/preVRE"); context.add("/gcube/preprod/preVRE");
context.add("/gcube/preprod"); context.add("/gcube/preprod");
SortedMap<Filter, SortedMap<Calendar, Info>> setContext = SortedMap<Filter, SortedMap<Calendar, Info>> setContext =
accountingPersistenceQueryCouchBase.getContextTimeSeries( accountingPersistenceQueryCouchBase.getContextTimeSeries(
clz, temporalConstraint, filters, clz, temporalConstraint, filters,
context); context);
logger.debug("Result final{}", setContext); logger.debug("Result final{}", setContext);
} }