add getContextTimeSeries

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-analytics-persistence-couchbase@133949 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Alessandro Pieve 2016-11-08 09:00:47 +00:00
parent 882d1e116e
commit 5e3e88741b
3 changed files with 100 additions and 19 deletions

View File

@ -8,7 +8,7 @@
</parent>
<groupId>org.gcube.accounting</groupId>
<artifactId>accounting-analytics-persistence-couchbase</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<name>Accounting Analytics Persistence CouchBase</name>
<description>Accounting Analytics Persistence CouchBase Implementation</description>

View File

@ -387,11 +387,13 @@ AccountingPersistenceBackendQuery {
protected SortedMap<Calendar, Info> mapReduceQuery(
Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters)
TemporalConstraint temporalConstraint, List<Filter> filters,String context)
throws Exception {
String currentScope = ScopeProvider.instance.get();
String currentScope=null;
if (context==null)
currentScope = ScopeProvider.instance.get();
else
currentScope = context;
JsonArray startKey = JsonArray.create();
startKey.add(currentScope);
JsonArray endKey = JsonArray.create();
@ -463,8 +465,9 @@ AccountingPersistenceBackendQuery {
}
String designDocId = getDesignDocId(clz);
//ADD A SPECIFY DESIGN DOC FAMILY
String designDocIdNew = getDesignDocIdSpecific(clz,keys);
logger.trace("designDocIdNew :{}",designDocIdNew);
for (Object temporal: temporalStartKey.toList()){
if (!temporal.toString().isEmpty())
startKey.add(temporal);
@ -553,16 +556,21 @@ AccountingPersistenceBackendQuery {
return infos;
}
@Override
public SortedMap<Calendar, Info> getTimeSeries(
Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters)
throws Exception {
SortedMap<Calendar, Info> map = mapReduceQuery(clz, temporalConstraint, filters);
SortedMap<Calendar, Info> map = mapReduceQuery(clz, temporalConstraint, filters,null);
return map;
}
@Override
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
Class<? extends AggregatedRecord<?, ?>> clz,
@ -590,7 +598,7 @@ AccountingPersistenceBackendQuery {
for(NumberedFilter nf : top){
filters.add(nf);
SortedMap<Calendar, Info> map =
mapReduceQuery(clz, temporalConstraint, filters);
mapReduceQuery(clz, temporalConstraint, filters,null);
ret.put(nf, map);
filters.remove(nf);
@ -599,6 +607,30 @@ AccountingPersistenceBackendQuery {
}
@Override
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters,List<String> contexts)
throws Exception {
logger.trace("getContextTimeSeries");
SortedSet<Filter> listContexts = new TreeSet();
for (String context:contexts){
Filter contextLabel= new Filter("context",context);
listContexts.add(contextLabel);
}
SortedMap<Filter, SortedMap<Calendar, Info>> ret = new TreeMap<>();
for(Filter nf : listContexts){
//filters.add(nf);
logger.debug("detail time series :{}",nf.toString());
SortedMap<Calendar, Info> map =
mapReduceQuery(clz, temporalConstraint, filters,nf.getValue());
ret.put(nf, map);
filters.remove(nf);
}
return ret;
}
protected String getQualifiedProperty(String property){
//DEVELOPING
@ -769,9 +801,9 @@ AccountingPersistenceBackendQuery {
int scopeDateGroupLevel = 2;
int groupLevel = scopeDateGroupLevel;
//NO ADD A SPECIFIY DESIGN DOC ID FAMILY
String designDocId = getDesignDocId(clz)+"Value";
String viewName = key;
logger.trace("designDocId:{} view:{} ",designDocId,key);
logger.trace("startKey:{}",startKey);
@ -875,7 +907,7 @@ AccountingPersistenceBackendQuery {
int groupLevel = scopeDateGroupLevel;
String designDocId = getDesignDocId(clz);
//ADD A SPECIFIY DESIGN DOC ID FAMILY
String viewName = applicant.getKey();
ViewQuery query = ViewQuery.from(designDocId, viewName);
@ -946,7 +978,7 @@ AccountingPersistenceBackendQuery {
aggregationMode, false, false);
String designDocId = getDesignDocId(clz);
//ADD A SPECIFIY DESIGN DOC ID FAMILY
for (Filters singleFilter:filterPackageQuota){
String viewNameTmp=null;
@ -1084,6 +1116,8 @@ AccountingPersistenceBackendQuery {
aggregationMode, false, false);
String designDocId = getDesignDocId(clz);
//ADD A SPECIFIC DESIGN DOC ID FAMILY
for (TotalFilters totalfilters:listUsage){
Double totalQuota=0.00;
@ -1214,4 +1248,6 @@ AccountingPersistenceBackendQuery {
}

View File

@ -272,8 +272,7 @@ public class AccountingPersistenceQueryCouchBaseTest {
filters2.add(new Filter("serviceName", "CkanConnector"));
simpleFilter2.setFilters(filters2);
filterPackageQuota1.add(simpleFilter2);
filterPackageQuota1.add(simpleFilter2);
Filters simpleFilter3 = new Filters();
List<Filter> filters3=new ArrayList<Filter>();
@ -285,9 +284,6 @@ public class AccountingPersistenceQueryCouchBaseTest {
TotalFilters totalfilter1=new TotalFilters();
totalfilter1.setTotalFilters(filterPackageQuota1);
List<TotalFilters> listTotalFilter=new ArrayList<TotalFilters>();
listTotalFilter.add(totalfilter);
listTotalFilter.add(totalfilter1);
@ -317,7 +313,7 @@ public class AccountingPersistenceQueryCouchBaseTest {
@Test
public void testTopService() throws Exception {
Calendar startTime = Calendar.getInstance();
startTime.set(2016, Calendar.AUGUST, 29);
startTime.set(2016, Calendar.SEPTEMBER, 27);
Calendar endTime = Calendar.getInstance();
endTime.set(2016, Calendar.SEPTEMBER, 28,23,59);
@ -334,11 +330,12 @@ public class AccountingPersistenceQueryCouchBaseTest {
SortedMap<NumberedFilter, SortedMap<Calendar, Info>> set =
accountingPersistenceQueryCouchBase.getTopValues(
clz, temporalConstraint, filters,
AggregatedServiceUsageRecord.CALLERQUALIFIER, null);
AggregatedServiceUsageRecord.CALLED_METHOD, null);
logger.debug("Result final{}", set);
}
@Test
public void getQuerableKeyService() throws Exception{
SortedSet<String> keys;
@ -442,4 +439,52 @@ public class AccountingPersistenceQueryCouchBaseTest {
e.printStackTrace();
}
}
@Test
public void testContextService() throws Exception {
Calendar startTime = Calendar.getInstance();
startTime.set(2016, Calendar.SEPTEMBER, 1);
Calendar endTime = Calendar.getInstance();
endTime.set(2016, Calendar.OCTOBER, 20,23,59);
List<Filter> filters = new ArrayList<Filter>();
//filters.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "alessandro.pieve"));
TemporalConstraint temporalConstraint =
new TemporalConstraint(startTime.getTimeInMillis(),
endTime.getTimeInMillis(), AggregationMode.DAILY);
Class<AggregatedServiceUsageRecord> clz =
AggregatedServiceUsageRecord.class;
List<String> context=new ArrayList<String>();
context.add("/gcube");
context.add("/gcube/devNext");
context.add("/gcube/devNext/nextNext");
context.add("/gcube/devsec");
context.add("/gcube/devsec/devVRE");
context.add("/gcube/devsec/preVRE");
context.add("/gcube/preprod/preVRE");
context.add("/gcube/preprod");
SortedMap<Filter, SortedMap<Calendar, Info>> setContext =
accountingPersistenceQueryCouchBase.getContextTimeSeries(
clz, temporalConstraint, filters,
context);
logger.debug("Result final{}", setContext);
}
}