|
|
|
@ -46,6 +46,7 @@ import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
|
import org.gcube.documentstore.records.AggregatedRecord;
|
|
|
|
|
import org.gcube.documentstore.records.Record;
|
|
|
|
|
import org.gcube.documentstore.records.RecordUtility;
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
@ -55,6 +56,7 @@ import com.couchbase.client.java.Bucket;
|
|
|
|
|
import com.couchbase.client.java.Cluster;
|
|
|
|
|
import com.couchbase.client.java.CouchbaseCluster;
|
|
|
|
|
import com.couchbase.client.java.bucket.BucketManager;
|
|
|
|
|
import com.couchbase.client.java.document.JsonDocument;
|
|
|
|
|
import com.couchbase.client.java.document.json.JsonArray;
|
|
|
|
|
import com.couchbase.client.java.document.json.JsonObject;
|
|
|
|
|
import com.couchbase.client.java.env.CouchbaseEnvironment;
|
|
|
|
@ -149,27 +151,23 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
|
|
|
|
|
String url = configuration.getProperty(URL_PROPERTY_KEY);
|
|
|
|
|
String password = configuration.getProperty(PASSWORD_PROPERTY_KEY);
|
|
|
|
|
|
|
|
|
|
cluster = CouchbaseCluster.create(ENV, url);
|
|
|
|
|
bucketNameStorage = configuration.getProperty(BUCKET_STORAGE_NAME_PROPERTY_KEY);
|
|
|
|
|
|
|
|
|
|
bucketNameStorageStatus = configuration.getProperty(BUCKET_STORAGESTATUS_NAME_PROPERTY_KEY);
|
|
|
|
|
|
|
|
|
|
bucketNameService = configuration.getProperty(BUCKET_SERVICE_NAME_PROPERTY_KEY);
|
|
|
|
|
bucketNameJob = configuration.getProperty(BUCKET_JOB_NAME_PROPERTY_KEY);
|
|
|
|
|
bucketNamePortlet = configuration.getProperty(BUCKET_PORTLET_NAME_PROPERTY_KEY);
|
|
|
|
|
bucketNameTask = configuration.getProperty(BUCKET_TASK_NAME_PROPERTY_KEY);
|
|
|
|
|
|
|
|
|
|
connectionMap = new HashMap<String, Bucket>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//bucketStorage = cluster.openBucket(bucketNameStorage, password);
|
|
|
|
|
bucketStorage = cluster.openBucket(bucketNameStorage, password);
|
|
|
|
|
connectionMap.put(BUCKET_STORAGE_NAME_PROPERTY_KEY, bucketStorage);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bucketStorageStatus = cluster.openBucket( bucketNameStorageStatus,password);
|
|
|
|
|
connectionMap.put(BUCKET_STORAGESTATUS_NAME_PROPERTY_KEY, bucketStorageStatus);
|
|
|
|
|
|
|
|
|
|
logger.debug("connectionMap"+connectionMap.toString());
|
|
|
|
|
|
|
|
|
|
bucketService = cluster.openBucket(bucketNameService, password);
|
|
|
|
|
connectionMap.put(BUCKET_SERVICE_NAME_PROPERTY_KEY, bucketService);
|
|
|
|
|
|
|
|
|
@ -417,7 +415,6 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
|
|
|
|
|
if (!collection.isEmpty()){
|
|
|
|
|
reduceFunction = top;
|
|
|
|
|
//reduceFunction = null;
|
|
|
|
|
for (String property : collection) {
|
|
|
|
|
if (!property.equals(top)){
|
|
|
|
|
|
|
|
|
@ -466,6 +463,7 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
*Return:
|
|
|
|
|
* List of service class used by alessandro in the required period
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
public SortedMap<String,Integer> getListUsage(Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,String context,List<String> parameters)throws Exception{
|
|
|
|
|
//TODO
|
|
|
|
@ -520,13 +518,7 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
int scopeDateGroupLevel = aggregationMode.ordinal() + 1 + 1;
|
|
|
|
|
int groupLevel = scopeDateGroupLevel;
|
|
|
|
|
if (filters != null) {
|
|
|
|
|
groupLevel += keys.size();
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
for (Object temporal: temporalStartKey.toList()){
|
|
|
|
|
if (!temporal.toString().isEmpty())
|
|
|
|
|
startKey.add(temporal);
|
|
|
|
@ -587,7 +579,7 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
protected SortedMap<Calendar, Info> mapReduceQuery(
|
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
@ -1499,7 +1491,7 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SPERIMENTAL
|
|
|
|
|
*
|
|
|
|
|
* Used for calculate a usage value for each element of list
|
|
|
|
|
* (QUOTA)
|
|
|
|
|
* @param listUsage
|
|
|
|
@ -1518,14 +1510,6 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
for (UsageValue totalFilters:listUsage){
|
|
|
|
|
|
|
|
|
|
logger.debug("-----------------/ init for totalFilters");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
UsageValue totalfilter=
|
|
|
|
|
new UsageServiceValue(context,"lucio.lelii",AggregatedServiceUsageRecord.class,temporalConstraint,filters);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String currentScope = totalFilters.getContext();
|
|
|
|
|
|
|
|
|
|
Collection<String> keys= new TreeSet<>();
|
|
|
|
@ -1547,13 +1531,15 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
temporalConstraint =
|
|
|
|
|
new TemporalConstraint(startTime.getTimeInMillis(),
|
|
|
|
|
endTime.getTimeInMillis(), AggregationMode.DAILY);
|
|
|
|
|
//if type=storage then bucket =accounting_storage_status and designDocId = quotaTotal
|
|
|
|
|
//logger.trace("totalFilters.getClass().getSimpleName():{}",totalFilters.getClass().getSimpleName());
|
|
|
|
|
//logger.trace("totalFilters.getClz().getSimpleName():{}",totalFilters.getClz().getSimpleName());
|
|
|
|
|
if (totalFilters.getClz().getSimpleName().equals(AggregatedStorageStatusRecord.class.getSimpleName())){
|
|
|
|
|
if (totalFilters instanceof UsageStorageValue){
|
|
|
|
|
|
|
|
|
|
// if (totalFilters.getClz().getSimpleName().equals(AggregatedStorageStatusRecord.class.getSimpleName())){
|
|
|
|
|
//TODO sarebbe possibile invece con il nome verificare che getClz e' un istanza di AggregatedStorageStatusRecord?
|
|
|
|
|
designDocId = "QuotaTotal";
|
|
|
|
|
//designDocId = "QuotaTotal";
|
|
|
|
|
|
|
|
|
|
//TEST
|
|
|
|
|
designDocId="QuotaTotalSeparated";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -1628,6 +1614,7 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
ViewQuery query = ViewQuery.from(designDocId, viewNameTmp);
|
|
|
|
|
//if storage
|
|
|
|
|
query.inclusiveEnd();
|
|
|
|
|
/*
|
|
|
|
|
if (designDocId == "QuotaTotal"){
|
|
|
|
|
|
|
|
|
|
query.startKey(endKeyTmp);
|
|
|
|
@ -1638,13 +1625,13 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
query.groupLevel(groupLevelTmp);
|
|
|
|
|
query.startKey(startKeyTmp);
|
|
|
|
|
query.endKey(endKeyTmp);
|
|
|
|
|
query.descending(false);
|
|
|
|
|
query.onError(OnError.STOP);
|
|
|
|
|
}
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
logger.trace("query row:{}",query.toString());
|
|
|
|
|
ViewResult viewResult;
|
|
|
|
@ -1666,55 +1653,34 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
Iterator<?> iterateJosn = objJson.keys();
|
|
|
|
|
while( iterateJosn.hasNext() ) {
|
|
|
|
|
String key = (String)iterateJosn.next();
|
|
|
|
|
|
|
|
|
|
Float valuetmp=Float.parseFloat(objJson.get(key).toString());
|
|
|
|
|
|
|
|
|
|
//logger.debug("totalFilters.getClass().getSimpleName():{} UsageStorageValue.class.getSimpleName():{}", totalFilters.getClass().getSimpleName(),UsageStorageValue.class.getSimpleName());
|
|
|
|
|
|
|
|
|
|
if (key.equals("operationCount") || key.equals("dataVolume")){
|
|
|
|
|
|
|
|
|
|
if (map.containsKey(key)) {
|
|
|
|
|
map.put(key, valuetmp + map.get(key));
|
|
|
|
|
|
|
|
|
|
// TODO verify a better method
|
|
|
|
|
if (totalFilters instanceof UsageStorageValue){
|
|
|
|
|
logger.debug("storageUsageRecord -designDocId:{}",designDocId);
|
|
|
|
|
if (key.equals("dataVolume")){
|
|
|
|
|
keyOrderingProperty=key;
|
|
|
|
|
totalQuota+=totalFilters.getD()+valuetmp.doubleValue();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
|
|
if (totalFilters instanceof UsageStorageValue){
|
|
|
|
|
JSONArray valueStorage=(JSONArray) objJson.get(key);
|
|
|
|
|
logger.debug("--storageUsageRecord -key:{} value:{}",key,valueStorage.get(0));
|
|
|
|
|
totalQuota+=Float.parseFloat(valueStorage.get(0).toString());
|
|
|
|
|
keyOrderingProperty="dataVolume";
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
if (key.equals("operationCount") || key.equals("dataVolume")){
|
|
|
|
|
Float valuetmp=Float.parseFloat(objJson.get(key).toString());
|
|
|
|
|
|
|
|
|
|
if (map.containsKey(key)) {
|
|
|
|
|
map.put(key, valuetmp + map.get(key));
|
|
|
|
|
logger.debug("?UsageRecord -designDocId:{}",designDocId);
|
|
|
|
|
keyOrderingProperty=key;
|
|
|
|
|
totalQuota+=totalFilters.getD()+valuetmp.doubleValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
map.put(key, valuetmp);
|
|
|
|
|
|
|
|
|
|
// TODO verify a better method
|
|
|
|
|
if (totalFilters instanceof UsageStorageValue){
|
|
|
|
|
logger.debug("storageUsageRecord -designDocId:{}",designDocId);
|
|
|
|
|
if (key.equals("dataVolume")){
|
|
|
|
|
keyOrderingProperty=key;
|
|
|
|
|
|
|
|
|
|
totalQuota+=valuetmp.doubleValue();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
map.put(key, valuetmp);
|
|
|
|
|
logger.debug("?UsageRecord -designDocId:{}",designDocId);
|
|
|
|
|
keyOrderingProperty=key;
|
|
|
|
|
|
|
|
|
|
totalQuota+=valuetmp.doubleValue();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//i++;
|
|
|
|
|
//} while (i <countFilters );
|
|
|
|
|
|
|
|
|
|
//convert usage from byte to Mb
|
|
|
|
|
if (totalFilters instanceof UsageStorageValue){
|
|
|
|
|
totalQuota=totalQuota/1024/1024;
|
|
|
|
@ -1732,7 +1698,252 @@ AccountingPersistenceBackendQuery {
|
|
|
|
|
return listUsage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getRecord(String recordId, String type )
|
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
String recordType=null;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case "service": recordType = BUCKET_SERVICE_NAME_PROPERTY_KEY;
|
|
|
|
|
break;
|
|
|
|
|
case "storage": recordType = BUCKET_STORAGE_NAME_PROPERTY_KEY;
|
|
|
|
|
break;
|
|
|
|
|
case "storageStatus": recordType = BUCKET_STORAGESTATUS_NAME_PROPERTY_KEY;
|
|
|
|
|
break;
|
|
|
|
|
case "task": recordType = BUCKET_TASK_NAME_PROPERTY_KEY;
|
|
|
|
|
break;
|
|
|
|
|
case "portlet": recordType = BUCKET_PORTLET_NAME_PROPERTY_KEY;
|
|
|
|
|
break;
|
|
|
|
|
case "job": recordType = BUCKET_JOB_NAME_PROPERTY_KEY;
|
|
|
|
|
break;
|
|
|
|
|
default: recordType = BUCKET_SERVICE_NAME_PROPERTY_KEY;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JsonDocument recordJson=connectionMap.get(recordType).get(recordId);
|
|
|
|
|
|
|
|
|
|
return recordJson.content().toString();
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Used for storage status aka tab Space (into portlet accounting) and popolate a list combobox used
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public SortedSet<String> getSpaceProvidersIds() {
|
|
|
|
|
String currentScope = ScopeProvider.instance.get();
|
|
|
|
|
|
|
|
|
|
JsonArray startKey = JsonArray.create();
|
|
|
|
|
startKey.add(currentScope);
|
|
|
|
|
|
|
|
|
|
int scopeDateGroupLevel = 2;
|
|
|
|
|
int groupLevel = scopeDateGroupLevel;
|
|
|
|
|
String designDocId = "StorageStatusRecordValue";
|
|
|
|
|
String viewName = "providerId";
|
|
|
|
|
logger.trace("designDocId:{} view:{} startKey:{} groupLevel:{}",designDocId,viewName,startKey,groupLevel);
|
|
|
|
|
ViewQuery query = ViewQuery.from(designDocId, viewName);
|
|
|
|
|
|
|
|
|
|
query.inclusiveEnd();
|
|
|
|
|
query.groupLevel(groupLevel);
|
|
|
|
|
query.startKey(startKey);
|
|
|
|
|
query.descending(false);
|
|
|
|
|
SortedSet ret = new TreeSet();
|
|
|
|
|
ViewResult viewResult;
|
|
|
|
|
try {
|
|
|
|
|
//execute query in a specify bucket
|
|
|
|
|
viewResult = connectionMap.get("AggregatedStorageStatusRecord").query(query);
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("error executing the query",e);
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
for (ViewRow row : viewResult) {
|
|
|
|
|
String value =(String) row.value();
|
|
|
|
|
ret.add(value);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* used for accounting portlet section storage status
|
|
|
|
|
* @param clz
|
|
|
|
|
* @param temporalConstraint
|
|
|
|
|
* @param filters
|
|
|
|
|
* @param context
|
|
|
|
|
* @return
|
|
|
|
|
* @throws JSONException
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public SortedMap<Filter, SortedMap<Calendar, Long>> getSpaceTimeSeries(
|
|
|
|
|
Class<? extends AggregatedRecord<?, ?>> clz,
|
|
|
|
|
TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
|
|
|
List<String> providersId) throws Exception {
|
|
|
|
|
|
|
|
|
|
String currentScope=null;
|
|
|
|
|
currentScope = ScopeProvider.instance.get();
|
|
|
|
|
|
|
|
|
|
JsonArray startKey = JsonArray.create();
|
|
|
|
|
|
|
|
|
|
JsonArray endKey = JsonArray.create();
|
|
|
|
|
startKey.add(currentScope);
|
|
|
|
|
endKey.add(currentScope);
|
|
|
|
|
|
|
|
|
|
AggregationMode aggregationMode = temporalConstraint
|
|
|
|
|
.getAggregationMode();
|
|
|
|
|
|
|
|
|
|
JsonArray temporalStartKey = getRangeKey(
|
|
|
|
|
temporalConstraint.getStartTime(),
|
|
|
|
|
aggregationMode, false, false);
|
|
|
|
|
|
|
|
|
|
JsonArray temporalEndKey = getRangeKey(
|
|
|
|
|
temporalConstraint.getEndTime(),
|
|
|
|
|
aggregationMode, false, false);
|
|
|
|
|
Collection<String> keys = new TreeSet<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String designDocId = "StorageStatusUsage";
|
|
|
|
|
String viewName;
|
|
|
|
|
int groupLevel=5;
|
|
|
|
|
if (temporalConstraint.getAggregationMode().equals(AggregationMode.MONTHLY)){
|
|
|
|
|
groupLevel= 4;
|
|
|
|
|
}
|
|
|
|
|
viewName= temporalConstraint.getAggregationMode().name().toLowerCase();
|
|
|
|
|
|
|
|
|
|
if (filters != null && filters.size() != 0) {
|
|
|
|
|
// Sorting filter for call a mapreduce
|
|
|
|
|
Collections.sort(filters, new Comparator<Filter>() {
|
|
|
|
|
@Override
|
|
|
|
|
public int compare(Filter filter1, Filter filter2)
|
|
|
|
|
{
|
|
|
|
|
int result =filter1.getKey().compareTo(filter2.getKey());
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
for (Filter filter : filters) {
|
|
|
|
|
String filterKey = filter.getKey();
|
|
|
|
|
String filterValue = filter.getValue();
|
|
|
|
|
|
|
|
|
|
if (filterKey != null && filterKey.compareTo("") != 0) {
|
|
|
|
|
if (filterValue != null && filterValue.compareTo("") != 0) {
|
|
|
|
|
if (keys.contains(filterKey)) {
|
|
|
|
|
throw new DuplicatedKeyFilterException(
|
|
|
|
|
"Only one value per Filter key is allowed");
|
|
|
|
|
}
|
|
|
|
|
startKey.add(filterValue);
|
|
|
|
|
endKey.add(filterValue);
|
|
|
|
|
keys.add(filterKey);
|
|
|
|
|
viewName=viewName+"_"+filterKey;
|
|
|
|
|
if (filterKey!="consumerId"){
|
|
|
|
|
groupLevel= groupLevel+1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new KeyException(
|
|
|
|
|
String.format("Invalid %s : %s",Filter.class.getSimpleName(), filter.toString()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
throw new ValueException(String.format("Invalid %s : %s",Filter.class.getSimpleName(), filter.toString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (Object temporal: temporalStartKey.toList()){
|
|
|
|
|
if (!temporal.toString().isEmpty())
|
|
|
|
|
startKey.add(temporal);
|
|
|
|
|
}
|
|
|
|
|
int count =1;
|
|
|
|
|
for (Object temporal: temporalEndKey.toList()){
|
|
|
|
|
if (!temporal.toString().isEmpty()){
|
|
|
|
|
//couchbase exclude last value
|
|
|
|
|
if (count==temporalEndKey.size())
|
|
|
|
|
temporal=(int)temporal+1;
|
|
|
|
|
endKey.add(temporal);
|
|
|
|
|
}
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ViewQuery query = ViewQuery.from(designDocId, viewName);
|
|
|
|
|
query.inclusiveEnd();
|
|
|
|
|
query.groupLevel(groupLevel);
|
|
|
|
|
query.startKey(startKey);
|
|
|
|
|
query.endKey(endKey);
|
|
|
|
|
query.descending(false);
|
|
|
|
|
|
|
|
|
|
logger.trace("Bucket :{}, Design Doc ID : {}, View Name : {}, "
|
|
|
|
|
+ "Group Level : {}, Start Key : {}, End Key : {},"
|
|
|
|
|
+ "temporalStartKey :{}, temporalEndKey :{}",
|
|
|
|
|
clz.getSimpleName(),designDocId, viewName, groupLevel, startKey, endKey,temporalStartKey.toString(), temporalEndKey.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ViewResult viewResult;
|
|
|
|
|
try {
|
|
|
|
|
//execute query in a specify bucket
|
|
|
|
|
viewResult = connectionMap.get(clz.getSimpleName()).query(query);
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error(e.getLocalizedMessage());
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SortedMap<Filter, SortedMap<Calendar, Long>> ret = new TreeMap<>();
|
|
|
|
|
|
|
|
|
|
for (ViewRow row : viewResult) {
|
|
|
|
|
|
|
|
|
|
JsonArray array = (JsonArray) row.key();
|
|
|
|
|
Calendar calendar = getCalendarFromArray(array);
|
|
|
|
|
|
|
|
|
|
JsonObject value = (JsonObject) row.value();
|
|
|
|
|
JSONObject obj = new JSONObject(value.toString());
|
|
|
|
|
|
|
|
|
|
//logger.trace("row: {}, value: {}, obj: {}",row.toString(),value.toString(),obj.toString());
|
|
|
|
|
for(Iterator iterator = obj.keys(); iterator.hasNext();) {
|
|
|
|
|
String key = (String) iterator.next();
|
|
|
|
|
String[] tmp=key.split("-");
|
|
|
|
|
String providerId=tmp[0];
|
|
|
|
|
|
|
|
|
|
if (providersId.contains(providerId)){
|
|
|
|
|
Long valueProvider=Long.parseLong(obj.get(key).toString().split(",")[0].replace("[",""));
|
|
|
|
|
//convert into kb
|
|
|
|
|
valueProvider=valueProvider/1024;
|
|
|
|
|
|
|
|
|
|
Filter filter= new Filter("providerId",providerId );
|
|
|
|
|
if (!ret.containsKey(filter) ){
|
|
|
|
|
SortedMap<Calendar, Long> infos = new TreeMap<>();
|
|
|
|
|
infos.put(calendar, valueProvider);
|
|
|
|
|
ret.put(filter, infos);
|
|
|
|
|
}else{
|
|
|
|
|
SortedMap<Calendar, Long> singleValue=ret.get(filter);
|
|
|
|
|
if (!singleValue.containsKey(calendar)){
|
|
|
|
|
//if not exist put
|
|
|
|
|
singleValue.put(calendar, valueProvider);
|
|
|
|
|
}else{
|
|
|
|
|
//if exist, update
|
|
|
|
|
singleValue.put(calendar, singleValue.get(calendar)+valueProvider);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//logger.trace("return map:{}",map.toString());
|
|
|
|
|
logger.trace("return ret:{}",ret.toString());
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|