Refs #10188: Add a way to esplicitly set the scope in accounting-analytics
Task-Url: https://support.d4science.org/issues/10188 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-analytics-persistence-couchbase@161933 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
407f5d1d17
commit
2edcb5a076
File diff suppressed because it is too large
Load Diff
|
@ -1,8 +1,4 @@
|
|||
package org.gcube.accounting.analytics.persistence.couchbase;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
@ -63,34 +59,29 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
this.key = key;
|
||||
}
|
||||
|
||||
public ExtendedInfo(String key, Calendar calendar, JSONObject value){
|
||||
public ExtendedInfo(String key, Calendar calendar, JSONObject value) {
|
||||
super(calendar, value);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
String info = String .format("Key : %s, %s ", key, super.toString());
|
||||
public String toString() {
|
||||
String info = String.format("Key : %s, %s ", key, super.toString());
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
AccountingPersistenceBackendQueryConfiguration configuration = new
|
||||
AccountingPersistenceBackendQueryConfiguration(AccountingPersistenceQueryCouchBase.class);
|
||||
public void before() throws Exception {
|
||||
AccountingPersistenceBackendQueryConfiguration configuration = new AccountingPersistenceBackendQueryConfiguration(
|
||||
AccountingPersistenceQueryCouchBase.class);
|
||||
|
||||
accountingPersistenceQueryCouchBase = new AccountingPersistenceQueryCouchBase();
|
||||
accountingPersistenceQueryCouchBase.prepareConnection(configuration);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void printMap(Map<Calendar, Info> map){
|
||||
for(Info info : map.values()){
|
||||
public void printMap(Map<Calendar,Info> map) {
|
||||
for(Info info : map.values()) {
|
||||
logger.debug("{}", info);
|
||||
}
|
||||
}
|
||||
|
@ -113,24 +104,21 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
|
||||
logger.debug("EndTime {}", endTime.getTimeInMillis());
|
||||
|
||||
TemporalConstraint temporalConstraint =
|
||||
new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
endTime.getTimeInMillis(), AggregationMode.MONTHLY);
|
||||
|
||||
Class<AggregatedServiceUsageRecord> clz =
|
||||
AggregatedServiceUsageRecord.class;
|
||||
|
||||
Class<AggregatedServiceUsageRecord> clz = AggregatedServiceUsageRecord.class;
|
||||
|
||||
List<Filter> filters = new ArrayList<Filter>();
|
||||
//Filter filter = new Filter(ServiceUsageRecord.SERVICE_NAME, "DataMiner");
|
||||
Filter filter = new Filter(ServiceUsageRecord.SERVICE_NAME, "RConnector");
|
||||
filters.add(filter);
|
||||
|
||||
|
||||
for(String context : contexts){
|
||||
for(String context : contexts) {
|
||||
ScopeProvider.instance.set(context);
|
||||
|
||||
SortedSet<NumberedFilter> top = accountingPersistenceQueryCouchBase.getNextPossibleValuesWithMap(clz, temporalConstraint, filters, ServiceUsageRecord.CONSUMER_ID, null);
|
||||
SortedSet<NumberedFilter> top = accountingPersistenceQueryCouchBase.getNextPossibleValuesWithMap(clz,
|
||||
temporalConstraint, filters, ServiceUsageRecord.CONSUMER_ID, null);
|
||||
|
||||
logger.info("Context : {} - Users [{}] : {}", context, top.size(), top);
|
||||
|
||||
|
@ -150,56 +138,48 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
|
||||
logger.debug("EndTime {}", endTime.getTimeInMillis());
|
||||
|
||||
|
||||
List<Filter> filters = new ArrayList<Filter>();
|
||||
Filter filter = new Filter(ServiceUsageRecord.SERVICE_NAME, "DataMiner");
|
||||
//Filter filter = new Filter(ServiceUsageRecord.SERVICE_NAME, "RConnector");
|
||||
filters.add(filter);
|
||||
|
||||
|
||||
TemporalConstraint temporalConstraint =
|
||||
new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
endTime.getTimeInMillis(), AggregationMode.MONTHLY);
|
||||
|
||||
Class<AggregatedServiceUsageRecord> clz =
|
||||
AggregatedServiceUsageRecord.class;
|
||||
|
||||
SortedMap<NumberedFilter, SortedMap<Calendar, Info>> set =
|
||||
accountingPersistenceQueryCouchBase.getTopValues(
|
||||
clz, temporalConstraint, filters,
|
||||
ServiceUsageRecord.CONSUMER_ID, null);
|
||||
Class<AggregatedServiceUsageRecord> clz = AggregatedServiceUsageRecord.class;
|
||||
|
||||
SortedMap<NumberedFilter,SortedMap<Calendar,Info>> set = accountingPersistenceQueryCouchBase.getTopValues(clz,
|
||||
temporalConstraint, filters, ServiceUsageRecord.CONSUMER_ID, null);
|
||||
|
||||
logger.debug("Result {}", set);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeSeries() throws Exception{
|
||||
public void testTimeSeries() throws Exception {
|
||||
|
||||
//AccountingPersistenceQueryFactory.getForcedScope().set("/gcube/devNext/NextNext");
|
||||
|
||||
Calendar startTime = Calendar.getInstance();
|
||||
startTime.set(2015, Calendar.AUGUST, 20);
|
||||
startTime.set(2017, Calendar.NOVEMBER, 29);
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
endTime.set(2016, Calendar.SEPTEMBER, 29,23,59);
|
||||
endTime.set(2017, Calendar.DECEMBER, 29);
|
||||
List<Filter> filters = new ArrayList<Filter>();
|
||||
|
||||
TemporalConstraint temporalConstraint =
|
||||
new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
endTime.getTimeInMillis(), AggregationMode.DAILY);
|
||||
Class<AggregatedJobUsageRecord> clz =
|
||||
AggregatedJobUsageRecord.class;
|
||||
SortedMap<Calendar, Info> set =
|
||||
accountingPersistenceQueryCouchBase.getTimeSeries(
|
||||
clz, temporalConstraint, filters);
|
||||
Class<AggregatedJobUsageRecord> clz = AggregatedJobUsageRecord.class;
|
||||
SortedMap<Calendar,Info> set = accountingPersistenceQueryCouchBase.getTimeSeries(clz, temporalConstraint,
|
||||
filters);
|
||||
logger.debug("Result final{}", set);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeSeriesNoContext() throws Exception{
|
||||
public void testTimeSeriesNoContext() throws Exception {
|
||||
|
||||
Calendar startTime = Calendar.getInstance();
|
||||
startTime.set(2017, Calendar.APRIL, 20);
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
endTime.set(2017, Calendar.APRIL, 29,23,59);
|
||||
endTime.set(2017, Calendar.APRIL, 29, 23, 59);
|
||||
List<Filter> filters = new ArrayList<Filter>();
|
||||
|
||||
/*
|
||||
|
@ -207,44 +187,32 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
new Filter(AggregatedServiceUsageRecord.CALLED_METHOD, "WebProcessingService");
|
||||
filters.add(filter);
|
||||
*/
|
||||
TemporalConstraint temporalConstraint =
|
||||
new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
endTime.getTimeInMillis(), AggregationMode.DAILY);
|
||||
Class<AggregatedServiceUsageRecord> clz =
|
||||
AggregatedServiceUsageRecord.class;
|
||||
SortedMap<Calendar, Info> set =
|
||||
accountingPersistenceQueryCouchBase.getNoContextTimeSeries(
|
||||
clz, temporalConstraint, filters);
|
||||
Class<AggregatedServiceUsageRecord> clz = AggregatedServiceUsageRecord.class;
|
||||
SortedMap<Calendar,Info> set = accountingPersistenceQueryCouchBase.getNoContextTimeSeries(clz,
|
||||
temporalConstraint, filters);
|
||||
logger.debug("Result final{}", set);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void getUsageValue() throws Exception{
|
||||
public void getUsageValue() throws Exception {
|
||||
Calendar startTime = Calendar.getInstance();
|
||||
startTime.set(2015, Calendar.MAY, 1);
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
ScopeProvider.instance.set("/gcube");
|
||||
Filter filter =
|
||||
new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "alessandro.pieve");
|
||||
Filter filter = new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "alessandro.pieve");
|
||||
|
||||
TemporalConstraint temporalConstraint =
|
||||
new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
endTime.getTimeInMillis(), AggregationMode.DAILY);
|
||||
|
||||
JSONObject filterValue =
|
||||
accountingPersistenceQueryCouchBase.getUsageValue(AggregatedServiceUsageRecord.class,
|
||||
JSONObject filterValue = accountingPersistenceQueryCouchBase.getUsageValue(AggregatedServiceUsageRecord.class,
|
||||
temporalConstraint, filter);
|
||||
|
||||
logger.info("result:"+filterValue.toString());
|
||||
logger.info("result:" + filterValue.toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* utilizzato per effettuare una singola chiamata ad accounting analytics in modo che ritorni una lista di quote riempite
|
||||
*
|
||||
|
@ -278,7 +246,7 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
* ]
|
||||
*/
|
||||
@Test
|
||||
public void getUsageValueQuotaTotal() throws Exception{
|
||||
public void getUsageValueQuotaTotal() throws Exception {
|
||||
|
||||
String context = ScopedTest.getCurrentScope(DEFAULT_TEST_SCOPE);
|
||||
|
||||
|
@ -286,36 +254,31 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
startTime.set(2017, Calendar.MAY, 1);
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
|
||||
TemporalConstraint temporalConstraint =
|
||||
new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
endTime.getTimeInMillis(), AggregationMode.DAILY);
|
||||
|
||||
|
||||
/*ask quota for user alessandro pieve
|
||||
*
|
||||
* SERVICE
|
||||
* */
|
||||
List<Filter> filters=new ArrayList<Filter>();
|
||||
List<Filter> filters = new ArrayList<Filter>();
|
||||
filters.add(new Filter("serviceClass", "DataAccess"));
|
||||
filters.add(new Filter("serviceName", "CkanConnector"));
|
||||
UsageValue totalfilter=new UsageServiceValue(context,"lucio.lelii",AggregatedServiceUsageRecord.class,temporalConstraint,filters);
|
||||
|
||||
|
||||
|
||||
|
||||
UsageValue totalfilter = new UsageServiceValue(context, "lucio.lelii", AggregatedServiceUsageRecord.class,
|
||||
temporalConstraint, filters);
|
||||
|
||||
/****
|
||||
*Example call storage status for each consumer id (quota total used )
|
||||
*/
|
||||
//Call quota total for consumerID
|
||||
UsageValue totalfilterStorageStatus=new UsageStorageValue(context,"name.surname",AggregatedStorageStatusRecord.class);
|
||||
UsageValue totalfilterStorageStatus_2=new UsageStorageValue(context,"lucio.lelii",AggregatedStorageStatusRecord.class);
|
||||
UsageValue totalfilterStorageStatus_3=new UsageStorageValue(context,"alessandro.pieve",AggregatedStorageStatusRecord.class);
|
||||
UsageValue totalfilterStorageStatus_4=new UsageStorageValue(context,"giancarlo.panichi",AggregatedStorageStatusRecord.class);
|
||||
|
||||
|
||||
|
||||
|
||||
UsageValue totalfilterStorageStatus = new UsageStorageValue(context, "name.surname",
|
||||
AggregatedStorageStatusRecord.class);
|
||||
UsageValue totalfilterStorageStatus_2 = new UsageStorageValue(context, "lucio.lelii",
|
||||
AggregatedStorageStatusRecord.class);
|
||||
UsageValue totalfilterStorageStatus_3 = new UsageStorageValue(context, "alessandro.pieve",
|
||||
AggregatedStorageStatusRecord.class);
|
||||
UsageValue totalfilterStorageStatus_4 = new UsageStorageValue(context, "giancarlo.panichi",
|
||||
AggregatedStorageStatusRecord.class);
|
||||
|
||||
/****
|
||||
*Example call storage status for each consumer id( quota into period)
|
||||
|
@ -327,14 +290,12 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
endTimeStorage.set(2017, Calendar.APRIL, 13);
|
||||
/*TemporalConstraint temporalConstraintStorage =new TemporalConstraint(startTimeStorage.getTimeInMillis(),
|
||||
endTimeStorage.getTimeInMillis(), AggregationMode.DAILY);*/
|
||||
TemporalConstraint temporalConstraintStorage =null;
|
||||
UsageValue totalfilterStorageStatusPeriod=new UsageStorageValue(context,"alessandro.pieve",AggregatedStorageStatusRecord.class,temporalConstraintStorage);
|
||||
|
||||
|
||||
|
||||
TemporalConstraint temporalConstraintStorage = null;
|
||||
UsageValue totalfilterStorageStatusPeriod = new UsageStorageValue(context, "alessandro.pieve",
|
||||
AggregatedStorageStatusRecord.class, temporalConstraintStorage);
|
||||
|
||||
//richiedo la lista di dati usati totali
|
||||
List<UsageValue> listTotalFilter=new ArrayList<UsageValue>();
|
||||
List<UsageValue> listTotalFilter = new ArrayList<UsageValue>();
|
||||
listTotalFilter.add(totalfilter);
|
||||
listTotalFilter.add(totalfilterStorageStatus);
|
||||
listTotalFilter.add(totalfilterStorageStatus_2);
|
||||
|
@ -342,25 +303,19 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
listTotalFilter.add(totalfilterStorageStatus_4);
|
||||
listTotalFilter.add(totalfilterStorageStatusPeriod);
|
||||
|
||||
|
||||
logger.info("filterPackageQuota:"+listTotalFilter);
|
||||
List<UsageValue> filterValue =
|
||||
accountingPersistenceQueryCouchBase.getUsageValueQuotaTotal(listTotalFilter);
|
||||
logger.info("result:"+filterValue.toString());
|
||||
logger.info("filterPackageQuota:" + listTotalFilter);
|
||||
List<UsageValue> filterValue = accountingPersistenceQueryCouchBase.getUsageValueQuotaTotal(listTotalFilter);
|
||||
logger.info("result:" + filterValue.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void getQuerableKeyJob() throws Exception{
|
||||
public void getQuerableKeyJob() throws Exception {
|
||||
SortedSet<String> keys;
|
||||
|
||||
keys = AccountingPersistenceQuery.getQuerableKeys(AggregatedJobUsageRecord.class);
|
||||
for (String key : keys) {
|
||||
if (key != null && !key.isEmpty()) {
|
||||
logger.debug("key:" +key);
|
||||
for(String key : keys) {
|
||||
if(key != null && !key.isEmpty()) {
|
||||
logger.debug("key:" + key);
|
||||
}
|
||||
}
|
||||
logger.debug("List FilterKeys:" + keys.toString());
|
||||
|
@ -371,22 +326,18 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
Calendar startTime = Calendar.getInstance();
|
||||
startTime.set(2016, Calendar.AUGUST, 27);
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
endTime.set(2016, Calendar.SEPTEMBER, 28,23,59);
|
||||
endTime.set(2016, Calendar.SEPTEMBER, 28, 23, 59);
|
||||
|
||||
List<Filter> filters = new ArrayList<Filter>();
|
||||
//filters.add(new Filter(AggregatedServiceUsageRecord.SERVICE_NAME, "IS-Registry"));
|
||||
//filters.add(new Filter(AggregatedServiceUsageRecord.SERVICE_CLASS, "Common"));
|
||||
TemporalConstraint temporalConstraint =
|
||||
new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
endTime.getTimeInMillis(), AggregationMode.DAILY);
|
||||
|
||||
Class<AggregatedServiceUsageRecord> clz =
|
||||
AggregatedServiceUsageRecord.class;
|
||||
Class<AggregatedServiceUsageRecord> clz = AggregatedServiceUsageRecord.class;
|
||||
|
||||
SortedMap<NumberedFilter, SortedMap<Calendar, Info>> set =
|
||||
accountingPersistenceQueryCouchBase.getTopValues(
|
||||
clz, temporalConstraint, filters,
|
||||
AggregatedServiceUsageRecord.OPERATION_RESULT, null);
|
||||
SortedMap<NumberedFilter,SortedMap<Calendar,Info>> set = accountingPersistenceQueryCouchBase.getTopValues(clz,
|
||||
temporalConstraint, filters, AggregatedServiceUsageRecord.OPERATION_RESULT, null);
|
||||
|
||||
logger.debug("Result final{}", set);
|
||||
|
||||
|
@ -397,75 +348,60 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
Calendar startTime = Calendar.getInstance();
|
||||
startTime.set(2017, Calendar.FEBRUARY, 1);
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
endTime.set(2017, Calendar.FEBRUARY, 28,23,59);
|
||||
|
||||
endTime.set(2017, Calendar.FEBRUARY, 28, 23, 59);
|
||||
|
||||
List<Filter> filters = new ArrayList<Filter>();
|
||||
filters.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "scarponi"));
|
||||
TemporalConstraint temporalConstraint =
|
||||
new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
endTime.getTimeInMillis(), AggregationMode.DAILY);
|
||||
|
||||
Class<AggregatedStorageUsageRecord> clz =
|
||||
AggregatedStorageUsageRecord.class;
|
||||
Class<AggregatedStorageUsageRecord> clz = AggregatedStorageUsageRecord.class;
|
||||
|
||||
SortedMap<NumberedFilter, SortedMap<Calendar, Info>> set =
|
||||
accountingPersistenceQueryCouchBase.getTopValues(
|
||||
clz, temporalConstraint, filters,
|
||||
AggregatedStorageUsageRecord.OPERATION_TYPE, null);
|
||||
SortedMap<NumberedFilter,SortedMap<Calendar,Info>> set = accountingPersistenceQueryCouchBase.getTopValues(clz,
|
||||
temporalConstraint, filters, AggregatedStorageUsageRecord.OPERATION_TYPE, null);
|
||||
|
||||
logger.debug("Result final{}", set);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void getQuerableKeyService() throws Exception{
|
||||
public void getQuerableKeyService() throws Exception {
|
||||
SortedSet<String> keys;
|
||||
|
||||
keys = AccountingPersistenceQuery.getQuerableKeys(AggregatedServiceUsageRecord.class);
|
||||
for (String key : keys) {
|
||||
if (key != null && !key.isEmpty()) {
|
||||
logger.debug("key:" +key);
|
||||
for(String key : keys) {
|
||||
if(key != null && !key.isEmpty()) {
|
||||
logger.debug("key:" + key);
|
||||
}
|
||||
}
|
||||
logger.debug("List FilterKeys:" + keys.toString());
|
||||
}
|
||||
|
||||
public static SortedMap<Calendar, Info> padMap(
|
||||
SortedMap<Calendar, Info> unpaddedData,
|
||||
public static SortedMap<Calendar,Info> padMap(SortedMap<Calendar,Info> unpaddedData,
|
||||
TemporalConstraint temporalConstraint) throws Exception {
|
||||
JSONObject jsonObject = getPaddingJSONObject(unpaddedData);
|
||||
SortedSet<Calendar> sequence = temporalConstraint.getCalendarSequence();
|
||||
for (Calendar progressTime : sequence) {
|
||||
for(Calendar progressTime : sequence) {
|
||||
Info info = unpaddedData.get(progressTime);
|
||||
if (info == null) {
|
||||
if(info == null) {
|
||||
info = new Info(progressTime, jsonObject);
|
||||
unpaddedData.put(progressTime, info);
|
||||
}
|
||||
}
|
||||
return unpaddedData;
|
||||
}
|
||||
public static JSONObject getPaddingJSONObject(
|
||||
Map<Calendar, Info> unpaddedResults) throws JSONException {
|
||||
|
||||
public static JSONObject getPaddingJSONObject(Map<Calendar,Info> unpaddedResults) throws JSONException {
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//verify data consistency
|
||||
|
||||
if (unpaddedResults.size()!=0){
|
||||
if(unpaddedResults.size() != 0) {
|
||||
Info auxInfo = new ArrayList<Info>(unpaddedResults.values()).get(0);
|
||||
JSONObject auxJsonObject = auxInfo.getValue();
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterator<String> keys = auxJsonObject.keys();
|
||||
while (keys.hasNext()) {
|
||||
while(keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
jsonObject.put(key, 0);
|
||||
}
|
||||
|
@ -477,79 +413,68 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
@Test
|
||||
public void testFull() throws Exception {
|
||||
logger.debug("test full ");
|
||||
try{
|
||||
try {
|
||||
Calendar startTime = Calendar.getInstance();
|
||||
//startTime.set(2016, Calendar.AUGUST, 20, 00, 00);
|
||||
startTime.set(2016, Calendar.AUGUST, 29,00,00);
|
||||
startTime.set(2016, Calendar.AUGUST, 29, 00, 00);
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
//endTime.set(2016, Calendar.AUGUST, 29, 23, 59);
|
||||
endTime.set(2016, Calendar.AUGUST, 31,23,59);
|
||||
|
||||
endTime.set(2016, Calendar.AUGUST, 31, 23, 59);
|
||||
|
||||
List<Filter> filters = new ArrayList<Filter>();
|
||||
|
||||
TemporalConstraint temporalConstraint =
|
||||
new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
endTime.getTimeInMillis(), AggregationMode.DAILY);
|
||||
|
||||
Class<AggregatedServiceUsageRecord> clz =
|
||||
AggregatedServiceUsageRecord.class;
|
||||
Class<AggregatedServiceUsageRecord> clz = AggregatedServiceUsageRecord.class;
|
||||
|
||||
SortedMap<NumberedFilter, SortedMap<Calendar, Info>> set =
|
||||
accountingPersistenceQueryCouchBase.getTopValues(
|
||||
clz, temporalConstraint, filters,
|
||||
AggregatedServiceUsageRecord.CALLED_METHOD, null);
|
||||
SortedMap<NumberedFilter,SortedMap<Calendar,Info>> set = accountingPersistenceQueryCouchBase
|
||||
.getTopValues(clz, temporalConstraint, filters, AggregatedServiceUsageRecord.CALLED_METHOD, null);
|
||||
/**pad*/
|
||||
int limit=0;
|
||||
boolean pad=true;
|
||||
int limit = 0;
|
||||
boolean pad = true;
|
||||
int count = set.size() > limit ? limit : set.size();
|
||||
NumberedFilter firstRemovalKey = null;
|
||||
logger.debug("set completo"+set.toString());
|
||||
for(NumberedFilter nf : set.keySet()){
|
||||
if(--count>=0 || limit<=0){
|
||||
if(pad){
|
||||
logger.debug("set completo" + set.toString());
|
||||
for(NumberedFilter nf : set.keySet()) {
|
||||
if(--count >= 0 || limit <= 0) {
|
||||
if(pad) {
|
||||
padMap(set.get(nf), temporalConstraint);
|
||||
}
|
||||
}else{
|
||||
if(firstRemovalKey==null){
|
||||
} else {
|
||||
if(firstRemovalKey == null) {
|
||||
firstRemovalKey = nf;
|
||||
}else{
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(firstRemovalKey!=null){
|
||||
logger.debug("First removal key set:"+set.subMap(set.firstKey(), firstRemovalKey));
|
||||
if(firstRemovalKey != null) {
|
||||
logger.debug("First removal key set:" + set.subMap(set.firstKey(), firstRemovalKey));
|
||||
}
|
||||
|
||||
logger.debug("set: " + set);
|
||||
|
||||
logger.debug("set: "+set);
|
||||
|
||||
|
||||
}catch(Exception e){
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testContextService() throws Exception {
|
||||
Calendar startTime = Calendar.getInstance();
|
||||
startTime.set(2017, Calendar.APRIL, 20);
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
endTime.set(2017, Calendar.APRIL, 28,23,59);
|
||||
endTime.set(2017, Calendar.APRIL, 28, 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(),
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
endTime.getTimeInMillis(), AggregationMode.DAILY);
|
||||
|
||||
Class<AggregatedServiceUsageRecord> clz =
|
||||
AggregatedServiceUsageRecord.class;
|
||||
|
||||
List<String> context=new ArrayList<String>();
|
||||
Class<AggregatedServiceUsageRecord> clz = 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");
|
||||
|
@ -567,28 +492,24 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
context.add("/gcube/preprod/preVRE");
|
||||
context.add("/gcube/preprod");
|
||||
*/
|
||||
SortedMap<Filter, SortedMap<Calendar, Info>> setContext =
|
||||
accountingPersistenceQueryCouchBase.getContextTimeSeries(
|
||||
clz, temporalConstraint, filters,
|
||||
context);
|
||||
SortedMap<Filter,SortedMap<Calendar,Info>> setContext = accountingPersistenceQueryCouchBase
|
||||
.getContextTimeSeries(clz, temporalConstraint, filters, context);
|
||||
logger.debug("Result final{}", setContext);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getListUsage() throws Exception{
|
||||
public void getListUsage() throws Exception {
|
||||
Calendar startTime = Calendar.getInstance();
|
||||
startTime.set(2015, Calendar.SEPTEMBER, 1);
|
||||
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>();
|
||||
filters.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "valentina.marioli"));
|
||||
////TemporalConstraint temporalConstraint =
|
||||
new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
endTime.getTimeInMillis(), AggregationMode.DAILY);
|
||||
new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.DAILY);
|
||||
//String context="/gcube/devNext";
|
||||
List <String>parameters=new ArrayList<String>();
|
||||
List<String> parameters = new ArrayList<String>();
|
||||
parameters.add("serviceClass");
|
||||
parameters.add("serviceName");
|
||||
//Class<AggregatedServiceUsageRecord> clz =
|
||||
|
@ -597,98 +518,80 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void getRecord() throws Exception{
|
||||
String recordId="91e1c339-d811-45d7-a13f-7385af59e3c8";
|
||||
String type="service";
|
||||
|
||||
String document=accountingPersistenceQueryCouchBase.getRecord(recordId, type);
|
||||
logger.debug("document:{}",document);
|
||||
public void getRecord() throws Exception {
|
||||
String recordId = "91e1c339-d811-45d7-a13f-7385af59e3c8";
|
||||
String type = "service";
|
||||
|
||||
String document = accountingPersistenceQueryCouchBase.getRecord(recordId, type);
|
||||
logger.debug("document:{}", document);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getQuerableKeyStorageStatus() throws Exception{
|
||||
public void getQuerableKeyStorageStatus() throws Exception {
|
||||
SortedSet<String> keys;
|
||||
keys = AccountingPersistenceQuery.getQuerableKeys(AggregatedStorageStatusRecord.class);
|
||||
for (String key : keys) {
|
||||
if (key != null && !key.isEmpty()) {
|
||||
logger.debug("key:" +key);
|
||||
for(String key : keys) {
|
||||
if(key != null && !key.isEmpty()) {
|
||||
logger.debug("key:" + key);
|
||||
}
|
||||
}
|
||||
logger.debug("List FilterKeys:" + keys.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSpaceProvidersIds() throws Exception{
|
||||
SortedSet<String> listProvidersId =
|
||||
accountingPersistenceQueryCouchBase.getSpaceProvidersIds();
|
||||
public void testGetSpaceProvidersIds() throws Exception {
|
||||
SortedSet<String> listProvidersId = accountingPersistenceQueryCouchBase.getSpaceProvidersIds();
|
||||
logger.debug("Result final{}", listProvidersId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetFilterValue() throws Exception{
|
||||
public void testGetFilterValue() throws Exception {
|
||||
|
||||
//String key="consumerId";
|
||||
String key="dataServiceId";
|
||||
String key = "dataServiceId";
|
||||
|
||||
SortedSet<NumberedFilter> listFilterValue =
|
||||
accountingPersistenceQueryCouchBase.getFilterValues(AggregatedStorageStatusRecord.class, null, null, key, null);
|
||||
SortedSet<NumberedFilter> listFilterValue = accountingPersistenceQueryCouchBase
|
||||
.getFilterValues(AggregatedStorageStatusRecord.class, null, null, key, null);
|
||||
logger.debug("Result final{}", listFilterValue);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUsageStorage() throws Exception {
|
||||
Calendar startTime = Calendar.getInstance();
|
||||
startTime.set(2017, Calendar.APRIL, 13);
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
endTime.set(2017, Calendar.APRIL, 26,23,59);
|
||||
endTime.set(2017, Calendar.APRIL, 26, 23, 59);
|
||||
List<Filter> filters = new ArrayList<Filter>();
|
||||
//filters.add(new Filter(AggregatedStorageStatusRecord.DATA_SERVICEID, "identifier"));
|
||||
filters.add(new Filter(AggregatedServiceUsageRecord.CONSUMER_ID, "alessandro.pieve"));
|
||||
TemporalConstraint temporalConstraint =
|
||||
new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
endTime.getTimeInMillis(), AggregationMode.YEARLY);
|
||||
|
||||
|
||||
List<String> providerId=new ArrayList<String>();
|
||||
Class<AggregatedStorageStatusRecord> clz =
|
||||
AggregatedStorageStatusRecord.class;
|
||||
List<String> providerId = new ArrayList<String>();
|
||||
Class<AggregatedStorageStatusRecord> clz = AggregatedStorageStatusRecord.class;
|
||||
|
||||
//providerId.add("Rstudio");
|
||||
providerId.add("MongoDb");
|
||||
|
||||
SortedMap<Filter, SortedMap<Calendar, Long>> setContext =
|
||||
accountingPersistenceQueryCouchBase.getSpaceTimeSeries(
|
||||
clz,
|
||||
temporalConstraint, filters,
|
||||
providerId);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SortedMap<Filter,SortedMap<Calendar,Long>> setContext = accountingPersistenceQueryCouchBase
|
||||
.getSpaceTimeSeries(clz, temporalConstraint, filters, providerId);
|
||||
|
||||
int count = setContext.size();
|
||||
Filter firstRemovalKey = null;
|
||||
for(Filter nf : setContext.keySet()){
|
||||
if(--count>=0){
|
||||
for(Filter nf : setContext.keySet()) {
|
||||
if(--count >= 0) {
|
||||
//if(pad){
|
||||
padMapStorage(setContext.get(nf), temporalConstraint);
|
||||
|
||||
//}
|
||||
}else{
|
||||
if(firstRemovalKey==null){
|
||||
} else {
|
||||
if(firstRemovalKey == null) {
|
||||
firstRemovalKey = nf;
|
||||
}else{
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -700,32 +603,27 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
logger.debug("Result final{}", setContext);
|
||||
|
||||
}
|
||||
|
||||
public SortedMap<Calendar, Long> padMapStorage(
|
||||
SortedMap<Calendar, Long> unpaddedData,
|
||||
public SortedMap<Calendar,Long> padMapStorage(SortedMap<Calendar,Long> unpaddedData,
|
||||
TemporalConstraint temporalConstraint) throws Exception {
|
||||
|
||||
//JSONObject jsonObject = getPaddingJSONObject(unpaddedData);
|
||||
SortedSet<Calendar> sequence = temporalConstraint.getCalendarSequence();
|
||||
Long longValuePre = null;
|
||||
for (Calendar progressTime : sequence) {
|
||||
for(Calendar progressTime : sequence) {
|
||||
Long longValue = unpaddedData.get(progressTime);
|
||||
|
||||
if (longValue == null) {
|
||||
if(longValue == null) {
|
||||
unpaddedData.put(progressTime, longValuePre);
|
||||
}else{
|
||||
longValuePre=longValue;
|
||||
} else {
|
||||
longValuePre = longValue;
|
||||
}
|
||||
|
||||
}
|
||||
return unpaddedData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.accounting.analytics.persistence.couchbase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -23,9 +20,6 @@ import org.slf4j.LoggerFactory;
|
|||
*/
|
||||
public class ScopedTest {
|
||||
|
||||
|
||||
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ScopedTest.class);
|
||||
|
||||
protected static final String PROPERTIES_FILENAME = "token.properties";
|
||||
|
@ -45,7 +39,6 @@ public class ScopedTest {
|
|||
public static final String SA_VARNAME = "SA";
|
||||
public static final String SA;
|
||||
|
||||
|
||||
public static final String DEFAULT_TEST_SCOPE;
|
||||
public static final String ALTERNATIVE_TEST_SCOPE;
|
||||
|
||||
|
@ -56,7 +49,7 @@ public class ScopedTest {
|
|||
try {
|
||||
// load the properties file
|
||||
properties.load(input);
|
||||
} catch (IOException e) {
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
@ -68,30 +61,29 @@ public class ScopedTest {
|
|||
|
||||
SA = properties.getProperty(SA_VARNAME);
|
||||
|
||||
DEFAULT_TEST_SCOPE = SA;
|
||||
DEFAULT_TEST_SCOPE = GCUBE_DEVNEXT;
|
||||
ALTERNATIVE_TEST_SCOPE = GCUBE_DEVSEC;
|
||||
}
|
||||
|
||||
public static String getCurrentScope(String token) throws ObjectNotFound, Exception{
|
||||
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
String context = authorizationEntry.getContext();
|
||||
logger.info("Context of token {} is {}", token, context);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
public static void setContext(String token) throws ObjectNotFound, Exception{
|
||||
public static void setContext(String token) throws ObjectNotFound, Exception {
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
ScopeProvider.instance.set(getCurrentScope(token));
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception{
|
||||
public static void beforeClass() throws Exception {
|
||||
setContext(DEFAULT_TEST_SCOPE);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception{
|
||||
public static void afterClass() throws Exception {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
|
Reference in New Issue