|
|
|
@ -558,7 +558,7 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
|
|
|
|
|
protected SortedMap<Calendar, Info> mapReduceQuery(
|
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,String context,Boolean valueEmpty)
|
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,String context,Boolean valueEmpty,Boolean noScope)
|
|
|
|
|
throws Exception {
|
|
|
|
|
String currentScope=null;
|
|
|
|
|
if (context==null)
|
|
|
|
@ -566,9 +566,13 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
else
|
|
|
|
|
currentScope = context;
|
|
|
|
|
JsonArray startKey = JsonArray.create();
|
|
|
|
|
startKey.add(currentScope);
|
|
|
|
|
|
|
|
|
|
JsonArray endKey = JsonArray.create();
|
|
|
|
|
endKey.add(currentScope);
|
|
|
|
|
//no scope call a map reduce without scope in startkey and endkey
|
|
|
|
|
if (!noScope){
|
|
|
|
|
startKey.add(currentScope);
|
|
|
|
|
endKey.add(currentScope);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AggregationMode aggregationMode = temporalConstraint
|
|
|
|
|
.getAggregationMode();
|
|
|
|
@ -629,6 +633,10 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
}
|
|
|
|
|
//String designDocId = getDesignDocId(clz);
|
|
|
|
|
String designDocId = getDesignDocIdSpecific(clz,keys);
|
|
|
|
|
if (noScope){
|
|
|
|
|
designDocId="noContext";
|
|
|
|
|
groupLevel=groupLevel-1;
|
|
|
|
|
}
|
|
|
|
|
//logger.trace("designDocIdNew :{}",designDocId);
|
|
|
|
|
for (Object temporal: temporalStartKey.toList()){
|
|
|
|
|
if (!temporal.toString().isEmpty())
|
|
|
|
@ -733,10 +741,20 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
|
|
SortedMap<Calendar, Info> map = mapReduceQuery(clz, temporalConstraint, filters,null,true);
|
|
|
|
|
SortedMap<Calendar, Info> map = mapReduceQuery(clz, temporalConstraint, filters,null,true,false);
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public SortedMap<Calendar, Info> getNoContextTimeSeries(
|
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
|
|
SortedMap<Calendar, Info> map = mapReduceQuery(clz, temporalConstraint, filters,null,true,true);
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Used for calculate a top value
|
|
|
|
|
* @param clz
|
|
|
|
@ -785,7 +803,7 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
for(NumberedFilter nf : top){
|
|
|
|
|
filters.add(nf);
|
|
|
|
|
SortedMap<Calendar, Info> map =
|
|
|
|
|
mapReduceQuery(clz, temporalConstraint, filters,null,true);
|
|
|
|
|
mapReduceQuery(clz, temporalConstraint, filters,null,true,false);
|
|
|
|
|
ret.put(nf, map);
|
|
|
|
|
filters.remove(nf);
|
|
|
|
|
}
|
|
|
|
@ -1212,7 +1230,7 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
for(Filter nf : listContexts){
|
|
|
|
|
logger.debug("detail time series :{}",nf.toString());
|
|
|
|
|
SortedMap<Calendar, Info> map =
|
|
|
|
|
mapReduceQuery(clz, temporalConstraint, filters,nf.getValue(),false);
|
|
|
|
|
mapReduceQuery(clz, temporalConstraint, filters,nf.getValue(),false,false);
|
|
|
|
|
if (!map.isEmpty()){
|
|
|
|
|
ret.put(nf, map);
|
|
|
|
|
}
|
|
|
|
@ -1441,25 +1459,13 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
for (UsageValue totalFilters:listUsage){
|
|
|
|
|
|
|
|
|
|
logger.debug("----------------- init for totalFilters");
|
|
|
|
|
/*
|
|
|
|
|
gli arriva una lista di usage value da verificare...
|
|
|
|
|
gli usage value possono essere di diversi macro tipi:
|
|
|
|
|
storage
|
|
|
|
|
storage senza limite temporale (richiesta da per una quota totale )
|
|
|
|
|
utilizzo identifier come consumer id
|
|
|
|
|
utilizzo accounting_storage_status come bucket !
|
|
|
|
|
utilizzo quotaTotal come design
|
|
|
|
|
ed il nome della view sara composto da consumerid ed eventuali filtri (al momento non previsti)
|
|
|
|
|
storage con limiti temporali (richiesto per una quota parziale)
|
|
|
|
|
utilizzo identifier come consumer id
|
|
|
|
|
utilizzo accounting_storage_status come bucket !
|
|
|
|
|
utilizzo quota come design
|
|
|
|
|
ed il nome della view sara composto da consumerid ed eventuali filtri (al momento non previsti)
|
|
|
|
|
service
|
|
|
|
|
lista service con limite temporali
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
UsageValue totalfilter=
|
|
|
|
|
new UsageServiceValue(context,"lucio.lelii",AggregatedServiceUsageRecord.class,temporalConstraint,filters);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String currentScope = totalFilters.getContext();
|
|
|
|
|
|
|
|
|
@ -1494,6 +1500,7 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
logger.trace("AggregatedStorageStatusRecord with temporalConstraint");
|
|
|
|
|
designDocId = "Quota";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AggregationMode aggregationMode = temporalConstraint.getAggregationMode();
|
|
|
|
|
temporalStartKey = getRangeKey(
|
|
|
|
@ -1504,14 +1511,14 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
aggregationMode, false, false);
|
|
|
|
|
|
|
|
|
|
Double totalQuota=0.00;
|
|
|
|
|
int i = 0;
|
|
|
|
|
int countFilters=0;
|
|
|
|
|
//int i = 0;
|
|
|
|
|
//int countFilters=0;
|
|
|
|
|
|
|
|
|
|
if (totalFilters.getClass().getSimpleName().equals(UsageServiceValue.class.getSimpleName())){
|
|
|
|
|
UsageServiceValue totalFiltersService = (UsageServiceValue)totalFilters;
|
|
|
|
|
countFilters =totalFiltersService.getFiltersValue().size();
|
|
|
|
|
//countFilters =totalFiltersService.getFiltersValue().size();
|
|
|
|
|
}
|
|
|
|
|
do {
|
|
|
|
|
//do {
|
|
|
|
|
String viewNameTmp=null;
|
|
|
|
|
JsonArray startKeyTmp=JsonArray.create();
|
|
|
|
|
startKeyTmp.add(currentScope);
|
|
|
|
@ -1524,11 +1531,11 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
viewNameTmp=AggregatedServiceUsageRecord.CONSUMER_ID;
|
|
|
|
|
startKeyTmp.add(totalFilters.getIdentifier());
|
|
|
|
|
endKeyTmp.add(totalFilters.getIdentifier());
|
|
|
|
|
FiltersValue singleFilter=null;
|
|
|
|
|
//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()){
|
|
|
|
|
//singleFilter=totalFiltersService.getFiltersValue().get(i);
|
|
|
|
|
for (Filter filter:totalFiltersService.getFilters()){
|
|
|
|
|
viewNameTmp=viewNameTmp+"__"+filter.getKey();
|
|
|
|
|
startKeyTmp.add(filter.getValue());
|
|
|
|
|
endKeyTmp.add(filter.getValue());
|
|
|
|
@ -1595,21 +1602,21 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
logger.debug("storageUsageRecord -designDocId:{}",designDocId);
|
|
|
|
|
if (key.equals("dataVolume")){
|
|
|
|
|
if (totalFilters.getClass().getSimpleName().equals(UsageServiceValue.class.getSimpleName())){
|
|
|
|
|
singleFilter.setOrderingProperty(key);
|
|
|
|
|
singleFilter.setD(singleFilter.getD()+valuetmp.doubleValue());
|
|
|
|
|
totalFilters.setOrderingProperty(key);
|
|
|
|
|
totalFilters.setD(totalFilters.getD()+valuetmp.doubleValue());
|
|
|
|
|
}
|
|
|
|
|
keyOrderingProperty=key;
|
|
|
|
|
totalQuota+=singleFilter.getD()+valuetmp.doubleValue();
|
|
|
|
|
totalQuota+=totalFilters.getD()+valuetmp.doubleValue();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
logger.debug("?UsageRecord -designDocId:{}",designDocId);
|
|
|
|
|
if (totalFilters.getClass().getSimpleName().equals(UsageServiceValue.class.getSimpleName())){
|
|
|
|
|
singleFilter.setOrderingProperty(key);
|
|
|
|
|
singleFilter.setD(singleFilter.getD()+valuetmp.doubleValue());
|
|
|
|
|
totalFilters.setOrderingProperty(key);
|
|
|
|
|
totalFilters.setD(totalFilters.getD()+valuetmp.doubleValue());
|
|
|
|
|
}
|
|
|
|
|
keyOrderingProperty=key;
|
|
|
|
|
totalQuota+=singleFilter.getD()+valuetmp.doubleValue();
|
|
|
|
|
totalQuota+=totalFilters.getD()+valuetmp.doubleValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -1622,18 +1629,18 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
if (key.equals("dataVolume")){
|
|
|
|
|
keyOrderingProperty=key;
|
|
|
|
|
if (totalFilters.getClass().getSimpleName().equals(UsageServiceValue.class.getSimpleName())){
|
|
|
|
|
singleFilter.setOrderingProperty(key);
|
|
|
|
|
singleFilter.setD(valuetmp.doubleValue());
|
|
|
|
|
totalFilters.setOrderingProperty(key);
|
|
|
|
|
totalFilters.setD(valuetmp.doubleValue());
|
|
|
|
|
}
|
|
|
|
|
totalQuota+=valuetmp.doubleValue();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
logger.debug("?UsageRecord -designDocId:{}",designDocId);
|
|
|
|
|
logger.debug("UsageRecord -designDocId:{}",designDocId);
|
|
|
|
|
keyOrderingProperty=key;
|
|
|
|
|
if (totalFilters.getClass().getSimpleName().equals(UsageServiceValue.class.getSimpleName())){
|
|
|
|
|
singleFilter.setOrderingProperty(key);
|
|
|
|
|
singleFilter.setD(valuetmp.doubleValue());
|
|
|
|
|
totalFilters.setOrderingProperty(key);
|
|
|
|
|
totalFilters.setD(valuetmp.doubleValue());
|
|
|
|
|
}
|
|
|
|
|
totalQuota+=valuetmp.doubleValue();
|
|
|
|
|
}
|
|
|
|
@ -1641,8 +1648,8 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
} while (i <countFilters );
|
|
|
|
|
//i++;
|
|
|
|
|
//} while (i <countFilters );
|
|
|
|
|
totalFilters.setOrderingProperty(keyOrderingProperty);
|
|
|
|
|
totalFilters.setD(totalQuota);
|
|
|
|
|
}
|
|
|
|
|