git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-analytics-persistence-couchbase@141948 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
4f09feec06
commit
ed86d266ff
|
@ -98,12 +98,13 @@ AccountingPersistenceBackendQuery {
|
||||||
public static final String DESIGN_DOC_ID_LIST_USAGE="ListUsage";
|
public static final String DESIGN_DOC_ID_LIST_USAGE="ListUsage";
|
||||||
|
|
||||||
public static final long ENV_TIME_OUT=240000;
|
public static final long ENV_TIME_OUT=240000;
|
||||||
|
//public static final long ENV_TIME_OUT_VIEW=30000;
|
||||||
/* The environment configuration */
|
/* The environment configuration */
|
||||||
protected static final CouchbaseEnvironment ENV = DefaultCouchbaseEnvironment
|
protected static final CouchbaseEnvironment ENV = DefaultCouchbaseEnvironment
|
||||||
.builder()
|
.builder()
|
||||||
.connectTimeout(ENV_TIME_OUT)
|
.connectTimeout(ENV_TIME_OUT)
|
||||||
.maxRequestLifetime(ENV_TIME_OUT)
|
.maxRequestLifetime(ENV_TIME_OUT)
|
||||||
.viewTimeout(ENV_TIME_OUT)
|
//.viewTimeout(ENV_TIME_OUT_VIEW)
|
||||||
.queryTimeout(ENV_TIME_OUT).build();
|
.queryTimeout(ENV_TIME_OUT).build();
|
||||||
|
|
||||||
|
|
||||||
|
@ -550,9 +551,7 @@ AccountingPersistenceBackendQuery {
|
||||||
//infos.put(info);
|
//infos.put(info);
|
||||||
|
|
||||||
}
|
}
|
||||||
//TODO DA Completare per la richiesta utente e servizi/altro utilizzati nel periodo
|
//TODO complete the request from user/service usage into period
|
||||||
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|
||||||
|
@ -561,7 +560,7 @@ AccountingPersistenceBackendQuery {
|
||||||
|
|
||||||
protected SortedMap<Calendar, Info> mapReduceQuery(
|
protected SortedMap<Calendar, Info> mapReduceQuery(
|
||||||
Class<? extends AggregatedRecord<?, ?>> clz,
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters,String context)
|
TemporalConstraint temporalConstraint, List<Filter> filters,String context,Boolean valueEmpty)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
String currentScope=null;
|
String currentScope=null;
|
||||||
if (context==null)
|
if (context==null)
|
||||||
|
@ -680,29 +679,31 @@ AccountingPersistenceBackendQuery {
|
||||||
infos.put(calendar, info);
|
infos.put(calendar, info);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
logger.trace("valueEmpty not permitted:{}",valueEmpty);
|
||||||
|
//infos not empity is permitted only for getTimeSeries and Top
|
||||||
|
if (valueEmpty){
|
||||||
if (infos.isEmpty()){
|
if (infos.isEmpty()){
|
||||||
|
logger.trace("infos is empity");
|
||||||
query = ViewQuery.from(designDocId, viewName);
|
query = ViewQuery.from(designDocId, viewName);
|
||||||
query.groupLevel(groupLevel);
|
query.groupLevel(groupLevel);
|
||||||
query.descending(false);
|
query.descending(false);
|
||||||
try {
|
try {
|
||||||
//execute query in a specify bucket
|
//execute query in a specify bucket
|
||||||
viewResult = connectionMap.get(clz.getSimpleName()).query(query);
|
viewResult = connectionMap.get(clz.getSimpleName()).query(query);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e.getLocalizedMessage());
|
logger.warn("not execute query",e.getLocalizedMessage());
|
||||||
throw e;
|
//throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(viewResult.totalRows()!=0){
|
||||||
ViewRow row=viewResult.allRows().get(0);
|
ViewRow row=viewResult.allRows().get(0);
|
||||||
|
|
||||||
JsonArray array = getRangeKey(
|
JsonArray array = getRangeKey(
|
||||||
temporalConstraint.getStartTime(),
|
temporalConstraint.getStartTime(),
|
||||||
aggregationMode, false, false);
|
aggregationMode, false, false);
|
||||||
Calendar calendar = getCalendarFromArray(array);
|
Calendar calendar = getCalendarFromArray(array);
|
||||||
|
|
||||||
JsonObject value = (JsonObject) row.value();
|
JsonObject value = (JsonObject) row.value();
|
||||||
|
|
||||||
JSONObject objJson= new JSONObject(value.toString());
|
JSONObject objJson= new JSONObject(value.toString());
|
||||||
JSONObject objJsontemplate=new JSONObject();
|
JSONObject objJsontemplate=new JSONObject();
|
||||||
Iterator<?> iterateJson = objJson.keys();
|
Iterator<?> iterateJson = objJson.keys();
|
||||||
|
@ -713,8 +714,14 @@ AccountingPersistenceBackendQuery {
|
||||||
//generate an example object for json
|
//generate an example object for json
|
||||||
Info info = new Info(calendar, objJsontemplate);
|
Info info = new Info(calendar, objJsontemplate);
|
||||||
infos.put(calendar, info);
|
infos.put(calendar, info);
|
||||||
//break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warn("error :{}",e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger.trace("infos:{}",infos.toString());
|
||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -728,7 +735,7 @@ AccountingPersistenceBackendQuery {
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
SortedMap<Calendar, Info> map = mapReduceQuery(clz, temporalConstraint, filters,null);
|
SortedMap<Calendar, Info> map = mapReduceQuery(clz, temporalConstraint, filters,null,true);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -780,7 +787,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,null);
|
mapReduceQuery(clz, temporalConstraint, filters,null,true);
|
||||||
ret.put(nf, map);
|
ret.put(nf, map);
|
||||||
filters.remove(nf);
|
filters.remove(nf);
|
||||||
}
|
}
|
||||||
|
@ -1207,8 +1214,11 @@ AccountingPersistenceBackendQuery {
|
||||||
for(Filter nf : listContexts){
|
for(Filter nf : listContexts){
|
||||||
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(),false);
|
||||||
|
if (!map.isEmpty()){
|
||||||
ret.put(nf, map);
|
ret.put(nf, map);
|
||||||
|
}
|
||||||
|
|
||||||
filters.remove(nf);
|
filters.remove(nf);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -537,6 +537,7 @@ public class AccountingPersistenceQueryCouchBaseTest {
|
||||||
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.CALLED_METHOD, "WebProcessingService"));
|
||||||
//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(),
|
||||||
|
@ -546,10 +547,18 @@ public class AccountingPersistenceQueryCouchBaseTest {
|
||||||
AggregatedServiceUsageRecord.class;
|
AggregatedServiceUsageRecord.class;
|
||||||
|
|
||||||
List<String> context=new ArrayList<String>();
|
List<String> context=new ArrayList<String>();
|
||||||
|
|
||||||
|
|
||||||
|
// , /gcube/devsec/TestCreation12, /gcube/devsec/TestCreation13, /gcube/devsec/TestCreation14, /gcube/devsec/TestCreation15, /gcube/devsec/TestCreation16, /gcube/devsec/TestCreation17, /gcube/devsec/TestCreation7, /gcube/devsec/TestCreation8, /gcube/devsec/TestCreation9, /gcube/devsec/TestLucio2]]
|
||||||
context.add("/gcube");
|
context.add("/gcube");
|
||||||
context.add("/gcube/devNext");
|
context.add("/gcube/devNext");
|
||||||
context.add("/gcube/devNext/nextNext");
|
context.add("/gcube/devNext/Luciotest");
|
||||||
|
context.add("/gcube/devNext/NextNext");
|
||||||
context.add("/gcube/devsec");
|
context.add("/gcube/devsec");
|
||||||
|
context.add("/gcube/devsec/SmartCamera");
|
||||||
|
context.add("/gcube/devsec/statVRE");
|
||||||
|
context.add("/gcube/devsec/TestAddLast");
|
||||||
|
|
||||||
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");
|
||||||
|
|
Reference in New Issue