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:
Luca Frosini 2018-01-02 16:22:13 +00:00
parent 407f5d1d17
commit 2edcb5a076
3 changed files with 666 additions and 780 deletions

View File

@ -44,7 +44,6 @@ import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageStatusRecord;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.gcube.accounting.persistence.AccountingPersistenceConfiguration;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.documentstore.records.AggregatedRecord;
import org.gcube.documentstore.records.RecordUtility;
import org.json.JSONArray;
@ -326,8 +325,8 @@ public class AccountingPersistenceQueryCouchBase implements AccountingPersistenc
return String.format("%s%s", MAP_REDUCE__DESIGN, recordClass.newInstance().getRecordType());
}
protected String getDesignDocIdSpecific(Class<? extends AggregatedRecord<?, ?>> recordClass,
Collection<String> keys) throws InstantiationException, IllegalAccessException {
protected String getDesignDocIdSpecific(Class<? extends AggregatedRecord<?,?>> recordClass, Collection<String> keys)
throws InstantiationException, IllegalAccessException {
String specific = "all";
if(!keys.isEmpty()) {
specific = keys.iterator().next();
@ -484,11 +483,12 @@ public class AccountingPersistenceQueryCouchBase implements AccountingPersistenc
protected SortedMap<Calendar,Info> mapReduceQuery(Class<? extends AggregatedRecord<?,?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters, String context, Boolean valueEmpty,
Boolean noScope) throws Exception {
String currentScope = null;
if (context == null)
currentScope = ScopeProvider.instance.get();
else
String currentScope = AccountingPersistenceBackendQuery.getScopeToQuery();
if(context != null) {
currentScope = context;
}
JsonArray startKey = JsonArray.create();
JsonArray endKey = JsonArray.create();
@ -668,9 +668,9 @@ public class AccountingPersistenceQueryCouchBase implements AccountingPersistenc
}
@Override
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
String topKey, String orderingProperty) throws Exception {
public SortedMap<NumberedFilter,SortedMap<Calendar,Info>> getTopValues(Class<? extends AggregatedRecord<?,?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters, String topKey, String orderingProperty)
throws Exception {
Comparator<NumberedFilter> comparator = new Comparator<NumberedFilter>() {
@Override
@ -812,7 +812,7 @@ public class AccountingPersistenceQueryCouchBase implements AccountingPersistenc
throws Exception {
logger.debug("getNextPossibleValuesWithMap init");
String currentScope = ScopeProvider.instance.get();
String currentScope = AccountingPersistenceBackendQuery.getScopeToQuery();
if(orderingProperty == null) {
orderingProperty = AccountingPersistenceQuery.getDefaultOrderingProperties(clz);
@ -983,8 +983,7 @@ public class AccountingPersistenceQueryCouchBase implements AccountingPersistenc
TemporalConstraint temporalConstraint, List<Filter> filters, String key, String orderingProperty)
throws Exception {
String currentScope = ScopeProvider.instance.get();
// String recordType = clz.newInstance().getRecordType();
String currentScope = AccountingPersistenceBackendQuery.getScopeToQuery();
if(orderingProperty == null) {
orderingProperty = AccountingPersistenceQuery.getDefaultOrderingProperties(clz);
@ -1111,9 +1110,8 @@ public class AccountingPersistenceQueryCouchBase implements AccountingPersistenc
* @throws Exception
*/
@Override
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
List<String> contexts) throws Exception {
public SortedMap<Filter,SortedMap<Calendar,Info>> getContextTimeSeries(Class<? extends AggregatedRecord<?,?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters, List<String> contexts) throws Exception {
logger.trace("getContextTimeSeries for contexts:{}", contexts.toString());
SortedSet<Filter> listContexts = new TreeSet<Filter>();
for(String context : contexts) {
@ -1169,7 +1167,7 @@ public class AccountingPersistenceQueryCouchBase implements AccountingPersistenc
public SortedSet<NumberedFilter> getFilterValues(Class<? extends AggregatedRecord<?,?>> clz,
TemporalConstraint temporalConstraint, List<Filter> filters, String key, Integer limit) throws Exception {
String currentScope = ScopeProvider.instance.get();
String currentScope = AccountingPersistenceBackendQuery.getScopeToQuery();
JsonArray startKey = JsonArray.create();
startKey.add(currentScope);
@ -1242,7 +1240,7 @@ public class AccountingPersistenceQueryCouchBase implements AccountingPersistenc
public JSONObject getUsageValue(Class<? extends AggregatedRecord<?,?>> clz, TemporalConstraint temporalConstraint,
Filter applicant) throws Exception {
String currentScope = ScopeProvider.instance.get();
String currentScope = AccountingPersistenceBackendQuery.getScopeToQuery();
JsonArray startKey = JsonArray.create();
startKey.add(currentScope);
@ -1396,7 +1394,6 @@ public class AccountingPersistenceQueryCouchBase implements AccountingPersistenc
}
*/
// do {
String viewNameTmp = null;
JsonArray startKeyTmp = JsonArray.create();
@ -1535,7 +1532,7 @@ public class AccountingPersistenceQueryCouchBase implements AccountingPersistenc
*/
@Override
public SortedSet<String> getSpaceProvidersIds() throws Exception {
String currentScope = ScopeProvider.instance.get();
String currentScope = AccountingPersistenceBackendQuery.getScopeToQuery();
JsonArray startKey = JsonArray.create();
startKey.add(currentScope);
@ -1585,8 +1582,7 @@ public class AccountingPersistenceQueryCouchBase implements AccountingPersistenc
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();
String currentScope = AccountingPersistenceBackendQuery.getScopeToQuery();
JsonArray startKey = JsonArray.create();

View File

@ -1,8 +1,4 @@
package org.gcube.accounting.analytics.persistence.couchbase;
/**
*
*/
import java.util.ArrayList;
import java.util.Calendar;
@ -75,20 +71,15 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
}
@Before
public void before() throws Exception {
AccountingPersistenceBackendQueryConfiguration configuration = new
AccountingPersistenceBackendQueryConfiguration(AccountingPersistenceQueryCouchBase.class);
AccountingPersistenceBackendQueryConfiguration configuration = new AccountingPersistenceBackendQueryConfiguration(
AccountingPersistenceQueryCouchBase.class);
accountingPersistenceQueryCouchBase = new AccountingPersistenceQueryCouchBase();
accountingPersistenceQueryCouchBase.prepareConnection(configuration);
}
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) {
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,25 +138,18 @@ 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);
}
@ -176,20 +157,19 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
@Test
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);
}
@ -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 {
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());
}
/**
* utilizzato per effettuare una singola chiamata ad accounting analytics in modo che ritorni una lista di quote riempite
*
@ -286,11 +254,9 @@ 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
@ -298,24 +264,21 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
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)
@ -328,10 +291,8 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
/*TemporalConstraint temporalConstraintStorage =new TemporalConstraint(startTimeStorage.getTimeInMillis(),
endTimeStorage.getTimeInMillis(), AggregationMode.DAILY);*/
TemporalConstraint temporalConstraintStorage = null;
UsageValue totalfilterStorageStatusPeriod=new UsageStorageValue(context,"alessandro.pieve",AggregatedStorageStatusRecord.class,temporalConstraintStorage);
UsageValue totalfilterStorageStatusPeriod = new UsageStorageValue(context, "alessandro.pieve",
AggregatedStorageStatusRecord.class, temporalConstraintStorage);
//richiedo la lista di dati usati totali
List<UsageValue> listTotalFilter = new ArrayList<UsageValue>();
@ -342,17 +303,11 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
listTotalFilter.add(totalfilterStorageStatus_4);
listTotalFilter.add(totalfilterStorageStatusPeriod);
logger.info("filterPackageQuota:" + listTotalFilter);
List<UsageValue> filterValue =
accountingPersistenceQueryCouchBase.getUsageValueQuotaTotal(listTotalFilter);
List<UsageValue> filterValue = accountingPersistenceQueryCouchBase.getUsageValueQuotaTotal(listTotalFilter);
logger.info("result:" + filterValue.toString());
}
@Test
public void getQuerableKeyJob() throws Exception {
SortedSet<String> keys;
@ -376,17 +331,13 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
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);
@ -399,34 +350,20 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
Calendar endTime = Calendar.getInstance();
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 {
SortedSet<String> keys;
@ -440,8 +377,7 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
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();
@ -454,8 +390,8 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
}
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
@ -485,20 +421,15 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
//endTime.set(2016, Calendar.AUGUST, 29, 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;
@ -522,16 +453,13 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
logger.debug("First removal key set:" + set.subMap(set.firstKey(), firstRemovalKey));
}
logger.debug("set: " + set);
} catch(Exception e) {
e.printStackTrace();
}
}
@Test
public void testContextService() throws Exception {
Calendar startTime = Calendar.getInstance();
@ -541,16 +469,13 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
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;
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");
context.add("/gcube/devNext");
@ -567,15 +492,12 @@ 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 {
Calendar startTime = Calendar.getInstance();
@ -585,8 +507,7 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
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>();
parameters.add("serviceClass");
@ -597,8 +518,6 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
}
@Test
public void getRecord() throws Exception {
String recordId = "91e1c339-d811-45d7-a13f-7385af59e3c8";
@ -607,10 +526,8 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
String document = accountingPersistenceQueryCouchBase.getRecord(recordId, type);
logger.debug("document:{}", document);
}
@Test
public void getQuerableKeyStorageStatus() throws Exception {
SortedSet<String> keys;
@ -625,26 +542,23 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
@Test
public void testGetSpaceProvidersIds() throws Exception {
SortedSet<String> listProvidersId =
accountingPersistenceQueryCouchBase.getSpaceProvidersIds();
SortedSet<String> listProvidersId = accountingPersistenceQueryCouchBase.getSpaceProvidersIds();
logger.debug("Result final{}", listProvidersId);
}
@Test
public void testGetFilterValue() throws Exception {
//String key="consumerId";
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();
@ -654,28 +568,17 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
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;
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;
@ -700,14 +603,11 @@ 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);
@ -726,6 +626,4 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
return unpaddedData;
}
}

View File

@ -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;
@ -68,7 +61,7 @@ public class ScopedTest {
SA = properties.getProperty(SA_VARNAME);
DEFAULT_TEST_SCOPE = SA;
DEFAULT_TEST_SCOPE = GCUBE_DEVNEXT;
ALTERNATIVE_TEST_SCOPE = GCUBE_DEVSEC;
}
@ -79,7 +72,6 @@ public class ScopedTest {
return context;
}
public static void setContext(String token) throws ObjectNotFound, Exception {
SecurityTokenProvider.instance.set(token);
ScopeProvider.instance.set(getCurrentScope(token));