Add new method for nocontext Graph

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-analytics-persistence-couchbase@142147 82a268e6-3cf1-43bd-a215-b396298e98cf
feature/19115
Alessandro Pieve 7 years ago
parent 4c54a6075a
commit 51cad72fb1

@ -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);
}

@ -24,6 +24,7 @@ import org.gcube.accounting.analytics.UsageStorageValue;
import org.gcube.accounting.analytics.UsageValue;
import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQueryConfiguration;
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
import org.gcube.accounting.datamodel.AggregatedUsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageStatusRecord;
@ -142,25 +143,40 @@ public class AccountingPersistenceQueryCouchBaseTest {
startTime.set(2015, Calendar.AUGUST, 20);
Calendar endTime = Calendar.getInstance();
endTime.set(2016, Calendar.SEPTEMBER, 29,23,59);
List<Filter> filters = new ArrayList<Filter>();
TemporalConstraint temporalConstraint =
new TemporalConstraint(startTime.getTimeInMillis(),
endTime.getTimeInMillis(), AggregationMode.DAILY);
Class<AggregatedJobUsageRecord> clz =
AggregatedJobUsageRecord.class;
SortedMap<Calendar, Info> set =
accountingPersistenceQueryCouchBase.getTimeSeries(
clz, temporalConstraint, filters);
logger.debug("Result final{}", set);
}
@Test
public void testTimeSeriesNoContext() throws Exception{
Calendar startTime = Calendar.getInstance();
startTime.set(2015, Calendar.AUGUST, 20);
Calendar endTime = Calendar.getInstance();
endTime.set(2016, Calendar.SEPTEMBER, 29,23,59);
List<Filter> filters = new ArrayList<Filter>();
Filter filter =
new Filter(AggregatedServiceUsageRecord.CALLED_METHOD, "WebProcessingService");
filters.add(filter);
TemporalConstraint temporalConstraint =
new TemporalConstraint(startTime.getTimeInMillis(),
endTime.getTimeInMillis(), AggregationMode.DAILY);
Class<AggregatedServiceUsageRecord> clz =
AggregatedServiceUsageRecord.class;
SortedMap<Calendar, Info> set =
accountingPersistenceQueryCouchBase.getNoContextTimeSeries(
clz, temporalConstraint, filters);
logger.debug("Result final{}", set);
}
@ -240,64 +256,11 @@ public class AccountingPersistenceQueryCouchBaseTest {
*
* SERVICE
* */
List<FiltersValue> filterPackageQuota =new ArrayList<FiltersValue>();
FiltersValue simpleFilter = new FiltersValue();
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.setFiltersValue(filters);
filterPackageQuota.add(simpleFilter);
FiltersValue simpleFilter1 = new FiltersValue();
List<Filter> filters1=new ArrayList<Filter>();
filters1.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "alessandro.pieve"));
filters1.add(new Filter("serviceClass", "VREManagement"));
simpleFilter1.setFiltersValue(filters1);
filterPackageQuota.add(simpleFilter1);
UsageValue totalfilter=new UsageServiceValue(context,"lucio.lelii",AggregatedServiceUsageRecord.class,temporalConstraint,filterPackageQuota);
/*ask quota for user lucio lelii
* SERVICE
* */
List<FiltersValue> filterPackageQuota1 =new ArrayList<FiltersValue>();
FiltersValue simpleFilter2 = new FiltersValue();
List<Filter> filters2=new ArrayList<Filter>();
//filters2.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "lucio.lelii"));
filters2.add(new Filter("serviceClass", "DataAccess"));
filters2.add(new Filter("serviceName", "CkanConnector"));
simpleFilter2.setFiltersValue(filters2);
filterPackageQuota1.add(simpleFilter2);
FiltersValue simpleFilter3 = new FiltersValue();
List<Filter> filters3=new ArrayList<Filter>();
//filters3.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "lucio.lelii"));
filters3.add(new Filter("serviceClass", "VREManagement"));
simpleFilter3.setFiltersValue(filters3);
filterPackageQuota1.add(simpleFilter3);
UsageValue totalfilter1=new UsageServiceValue("gcube","lucio.lelii",AggregatedServiceUsageRecord.class,temporalConstraint,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);
UsageValue totalfilter=new UsageServiceValue(context,"lucio.lelii",AggregatedServiceUsageRecord.class,temporalConstraint,filters);
//TotalFilters totalfilter2=new TotalFilters("alessandro.pieve",AggregatedStorageUsageRecord.class,temporalConstraint,filterPackageQuota2);
@ -332,8 +295,7 @@ public class AccountingPersistenceQueryCouchBaseTest {
//richiedo la lista di dati usati totali
List<UsageValue> listTotalFilter=new ArrayList<UsageValue>();
// listTotalFilter.add(totalfilter);
listTotalFilter.add(totalfilter1);
listTotalFilter.add(totalfilter);
listTotalFilter.add(totalfilterStorageStatus);
listTotalFilter.add(totalfilterStorageStatus_2);
listTotalFilter.add(totalfilterStorageStatus_3);