Alessandro Pieve 7 years ago
parent 4f09feec06
commit ed86d266ff

@ -98,12 +98,13 @@ AccountingPersistenceBackendQuery {
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_VIEW=30000;
/* The environment configuration */
protected static final CouchbaseEnvironment ENV = DefaultCouchbaseEnvironment
.builder()
.connectTimeout(ENV_TIME_OUT)
.maxRequestLifetime(ENV_TIME_OUT)
.viewTimeout(ENV_TIME_OUT)
//.viewTimeout(ENV_TIME_OUT_VIEW)
.queryTimeout(ENV_TIME_OUT).build();
@ -550,9 +551,7 @@ AccountingPersistenceBackendQuery {
//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;
@ -561,7 +560,7 @@ AccountingPersistenceBackendQuery {
protected SortedMap<Calendar, Info> mapReduceQuery(
Class<? extends AggregatedRecord<?, ?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters,String context)
TemporalConstraint temporalConstraint, List<Filter> filters,String context,Boolean valueEmpty)
throws Exception {
String currentScope=null;
if (context==null)
@ -680,41 +679,49 @@ AccountingPersistenceBackendQuery {
infos.put(calendar, info);
}
if (infos.isEmpty()){
query = ViewQuery.from(designDocId, viewName);
query.groupLevel(groupLevel);
query.descending(false);
try {
//execute query in a specify bucket
viewResult = connectionMap.get(clz.getSimpleName()).query(query);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
throw e;
}
ViewRow row=viewResult.allRows().get(0);
JsonArray array = getRangeKey(
temporalConstraint.getStartTime(),
aggregationMode, false, false);
Calendar calendar = getCalendarFromArray(array);
JsonObject value = (JsonObject) row.value();
JSONObject objJson = new JSONObject(value.toString());
JSONObject objJsontemplate = new JSONObject();
Iterator<?> iterateJson = objJson.keys();
while( iterateJson.hasNext() ) {
String key = (String)iterateJson.next();
objJsontemplate.put(key, 0);
logger.trace("valueEmpty not permitted:{}",valueEmpty);
//infos not empity is permitted only for getTimeSeries and Top
if (valueEmpty){
if (infos.isEmpty()){
logger.trace("infos is empity");
query = ViewQuery.from(designDocId, viewName);
query.groupLevel(groupLevel);
query.descending(false);
try {
//execute query in a specify bucket
viewResult = connectionMap.get(clz.getSimpleName()).query(query);
} catch (Exception e) {
logger.warn("not execute query",e.getLocalizedMessage());
//throw e;
}
try {
if(viewResult.totalRows()!=0){
ViewRow row=viewResult.allRows().get(0);
JsonArray array = getRangeKey(
temporalConstraint.getStartTime(),
aggregationMode, false, false);
Calendar calendar = getCalendarFromArray(array);
JsonObject value = (JsonObject) row.value();
JSONObject objJson= new JSONObject(value.toString());
JSONObject objJsontemplate=new JSONObject();
Iterator<?> iterateJson = objJson.keys();
while( iterateJson.hasNext() ) {
String key = (String)iterateJson.next();
objJsontemplate.put(key, 0);
}
//generate an example object for json
Info info = new Info(calendar, objJsontemplate);
infos.put(calendar, info);
}
} catch (Exception e) {
logger.warn("error :{}",e.getLocalizedMessage());
}
}
//generate an example object for json
Info info = new Info(calendar, objJsontemplate);
infos.put(calendar, info);
//break;
}
logger.trace("infos:{}",infos.toString());
return infos;
}
@ -728,7 +735,7 @@ AccountingPersistenceBackendQuery {
TemporalConstraint temporalConstraint, List<Filter> filters)
throws Exception {
SortedMap<Calendar, Info> map = mapReduceQuery(clz, temporalConstraint, filters,null);
SortedMap<Calendar, Info> map = mapReduceQuery(clz, temporalConstraint, filters,null,true);
return map;
}
@ -780,7 +787,7 @@ AccountingPersistenceBackendQuery {
for(NumberedFilter nf : top){
filters.add(nf);
SortedMap<Calendar, Info> map =
mapReduceQuery(clz, temporalConstraint, filters,null);
mapReduceQuery(clz, temporalConstraint, filters,null,true);
ret.put(nf, map);
filters.remove(nf);
}
@ -1207,8 +1214,11 @@ AccountingPersistenceBackendQuery {
for(Filter nf : listContexts){
logger.debug("detail time series :{}",nf.toString());
SortedMap<Calendar, Info> map =
mapReduceQuery(clz, temporalConstraint, filters,nf.getValue());
ret.put(nf, map);
mapReduceQuery(clz, temporalConstraint, filters,nf.getValue(),false);
if (!map.isEmpty()){
ret.put(nf, map);
}
filters.remove(nf);
}
return ret;

@ -537,6 +537,7 @@ public class AccountingPersistenceQueryCouchBaseTest {
Calendar endTime = Calendar.getInstance();
endTime.set(2016, Calendar.OCTOBER, 20,23,59);
List<Filter> filters = new ArrayList<Filter>();
filters.add(new Filter(AggregatedServiceUsageRecord.CALLED_METHOD, "WebProcessingService"));
//filters.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "alessandro.pieve"));
TemporalConstraint temporalConstraint =
new TemporalConstraint(startTime.getTimeInMillis(),
@ -546,10 +547,18 @@ public class AccountingPersistenceQueryCouchBaseTest {
AggregatedServiceUsageRecord.class;
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/devNext");
context.add("/gcube/devNext/nextNext");
context.add("/gcube/devNext/Luciotest");
context.add("/gcube/devNext/NextNext");
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/preVRE");
context.add("/gcube/preprod/preVRE");