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:
parent
882d1e116e
commit
5e3e88741b
2
pom.xml
2
pom.xml
|
@ -8,7 +8,7 @@
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>org.gcube.accounting</groupId>
|
<groupId>org.gcube.accounting</groupId>
|
||||||
<artifactId>accounting-analytics-persistence-couchbase</artifactId>
|
<artifactId>accounting-analytics-persistence-couchbase</artifactId>
|
||||||
<version>1.1.0-SNAPSHOT</version>
|
<version>1.2.0-SNAPSHOT</version>
|
||||||
<name>Accounting Analytics Persistence CouchBase</name>
|
<name>Accounting Analytics Persistence CouchBase</name>
|
||||||
<description>Accounting Analytics Persistence CouchBase Implementation</description>
|
<description>Accounting Analytics Persistence CouchBase Implementation</description>
|
||||||
|
|
||||||
|
|
|
@ -387,11 +387,13 @@ AccountingPersistenceBackendQuery {
|
||||||
|
|
||||||
protected SortedMap<Calendar, Info> mapReduceQuery(
|
protected SortedMap<Calendar, Info> mapReduceQuery(
|
||||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
TemporalConstraint temporalConstraint, List<Filter> filters,String context)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
String currentScope=null;
|
||||||
String currentScope = ScopeProvider.instance.get();
|
if (context==null)
|
||||||
|
currentScope = ScopeProvider.instance.get();
|
||||||
|
else
|
||||||
|
currentScope = context;
|
||||||
JsonArray startKey = JsonArray.create();
|
JsonArray startKey = JsonArray.create();
|
||||||
startKey.add(currentScope);
|
startKey.add(currentScope);
|
||||||
JsonArray endKey = JsonArray.create();
|
JsonArray endKey = JsonArray.create();
|
||||||
|
@ -463,8 +465,9 @@ AccountingPersistenceBackendQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
String designDocId = getDesignDocId(clz);
|
String designDocId = getDesignDocId(clz);
|
||||||
|
//ADD A SPECIFY DESIGN DOC FAMILY
|
||||||
String designDocIdNew = getDesignDocIdSpecific(clz,keys);
|
String designDocIdNew = getDesignDocIdSpecific(clz,keys);
|
||||||
|
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);
|
||||||
|
@ -553,16 +556,21 @@ 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,
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
SortedMap<Calendar, Info> map = mapReduceQuery(clz, temporalConstraint, filters);
|
SortedMap<Calendar, Info> map = mapReduceQuery(clz, temporalConstraint, filters,null);
|
||||||
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,
|
||||||
|
@ -590,7 +598,7 @@ AccountingPersistenceBackendQuery {
|
||||||
for(NumberedFilter nf : top){
|
for(NumberedFilter nf : top){
|
||||||
filters.add(nf);
|
filters.add(nf);
|
||||||
SortedMap<Calendar, Info> map =
|
SortedMap<Calendar, Info> map =
|
||||||
mapReduceQuery(clz, temporalConstraint, filters);
|
mapReduceQuery(clz, temporalConstraint, filters,null);
|
||||||
ret.put(nf, map);
|
ret.put(nf, map);
|
||||||
|
|
||||||
filters.remove(nf);
|
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){
|
protected String getQualifiedProperty(String property){
|
||||||
//DEVELOPING
|
//DEVELOPING
|
||||||
|
@ -769,9 +801,9 @@ AccountingPersistenceBackendQuery {
|
||||||
|
|
||||||
int scopeDateGroupLevel = 2;
|
int scopeDateGroupLevel = 2;
|
||||||
int groupLevel = scopeDateGroupLevel;
|
int groupLevel = scopeDateGroupLevel;
|
||||||
|
//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:{} ",designDocId,key);
|
||||||
logger.trace("startKey:{}",startKey);
|
logger.trace("startKey:{}",startKey);
|
||||||
|
@ -875,7 +907,7 @@ AccountingPersistenceBackendQuery {
|
||||||
int groupLevel = scopeDateGroupLevel;
|
int groupLevel = scopeDateGroupLevel;
|
||||||
|
|
||||||
String designDocId = getDesignDocId(clz);
|
String designDocId = getDesignDocId(clz);
|
||||||
|
//ADD A SPECIFIY DESIGN DOC ID FAMILY
|
||||||
String viewName = applicant.getKey();
|
String viewName = applicant.getKey();
|
||||||
|
|
||||||
ViewQuery query = ViewQuery.from(designDocId, viewName);
|
ViewQuery query = ViewQuery.from(designDocId, viewName);
|
||||||
|
@ -946,7 +978,7 @@ AccountingPersistenceBackendQuery {
|
||||||
aggregationMode, false, false);
|
aggregationMode, false, false);
|
||||||
|
|
||||||
String designDocId = getDesignDocId(clz);
|
String designDocId = getDesignDocId(clz);
|
||||||
|
//ADD A SPECIFIY DESIGN DOC ID FAMILY
|
||||||
for (Filters singleFilter:filterPackageQuota){
|
for (Filters singleFilter:filterPackageQuota){
|
||||||
String viewNameTmp=null;
|
String viewNameTmp=null;
|
||||||
|
|
||||||
|
@ -1084,6 +1116,8 @@ AccountingPersistenceBackendQuery {
|
||||||
aggregationMode, false, false);
|
aggregationMode, false, false);
|
||||||
|
|
||||||
String designDocId = getDesignDocId(clz);
|
String designDocId = getDesignDocId(clz);
|
||||||
|
//ADD A SPECIFIC DESIGN DOC ID FAMILY
|
||||||
|
|
||||||
for (TotalFilters totalfilters:listUsage){
|
for (TotalFilters totalfilters:listUsage){
|
||||||
|
|
||||||
Double totalQuota=0.00;
|
Double totalQuota=0.00;
|
||||||
|
@ -1214,4 +1248,6 @@ AccountingPersistenceBackendQuery {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,8 +272,7 @@ public class AccountingPersistenceQueryCouchBaseTest {
|
||||||
filters2.add(new Filter("serviceName", "CkanConnector"));
|
filters2.add(new Filter("serviceName", "CkanConnector"));
|
||||||
simpleFilter2.setFilters(filters2);
|
simpleFilter2.setFilters(filters2);
|
||||||
|
|
||||||
filterPackageQuota1.add(simpleFilter2);
|
filterPackageQuota1.add(simpleFilter2);
|
||||||
|
|
||||||
|
|
||||||
Filters simpleFilter3 = new Filters();
|
Filters simpleFilter3 = new Filters();
|
||||||
List<Filter> filters3=new ArrayList<Filter>();
|
List<Filter> filters3=new ArrayList<Filter>();
|
||||||
|
@ -285,9 +284,6 @@ public class AccountingPersistenceQueryCouchBaseTest {
|
||||||
TotalFilters totalfilter1=new TotalFilters();
|
TotalFilters totalfilter1=new TotalFilters();
|
||||||
totalfilter1.setTotalFilters(filterPackageQuota1);
|
totalfilter1.setTotalFilters(filterPackageQuota1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<TotalFilters> listTotalFilter=new ArrayList<TotalFilters>();
|
List<TotalFilters> listTotalFilter=new ArrayList<TotalFilters>();
|
||||||
listTotalFilter.add(totalfilter);
|
listTotalFilter.add(totalfilter);
|
||||||
listTotalFilter.add(totalfilter1);
|
listTotalFilter.add(totalfilter1);
|
||||||
|
@ -317,7 +313,7 @@ public class AccountingPersistenceQueryCouchBaseTest {
|
||||||
@Test
|
@Test
|
||||||
public void testTopService() throws Exception {
|
public void testTopService() throws Exception {
|
||||||
Calendar startTime = Calendar.getInstance();
|
Calendar startTime = Calendar.getInstance();
|
||||||
startTime.set(2016, Calendar.AUGUST, 29);
|
startTime.set(2016, Calendar.SEPTEMBER, 27);
|
||||||
Calendar endTime = Calendar.getInstance();
|
Calendar endTime = Calendar.getInstance();
|
||||||
endTime.set(2016, Calendar.SEPTEMBER, 28,23,59);
|
endTime.set(2016, Calendar.SEPTEMBER, 28,23,59);
|
||||||
|
|
||||||
|
@ -334,11 +330,12 @@ public class AccountingPersistenceQueryCouchBaseTest {
|
||||||
SortedMap<NumberedFilter, SortedMap<Calendar, Info>> set =
|
SortedMap<NumberedFilter, SortedMap<Calendar, Info>> set =
|
||||||
accountingPersistenceQueryCouchBase.getTopValues(
|
accountingPersistenceQueryCouchBase.getTopValues(
|
||||||
clz, temporalConstraint, filters,
|
clz, temporalConstraint, filters,
|
||||||
AggregatedServiceUsageRecord.CALLERQUALIFIER, null);
|
AggregatedServiceUsageRecord.CALLED_METHOD, null);
|
||||||
|
|
||||||
logger.debug("Result final{}", set);
|
logger.debug("Result final{}", set);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getQuerableKeyService() throws Exception{
|
public void getQuerableKeyService() throws Exception{
|
||||||
SortedSet<String> keys;
|
SortedSet<String> keys;
|
||||||
|
@ -442,4 +439,52 @@ public class AccountingPersistenceQueryCouchBaseTest {
|
||||||
e.printStackTrace();
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue