|
|
|
@ -9,6 +9,7 @@ import java.util.Calendar;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.SortedMap;
|
|
|
|
|
import java.util.SortedSet;
|
|
|
|
|
|
|
|
|
@ -18,7 +19,10 @@ import org.gcube.accounting.analytics.NumberedFilter;
|
|
|
|
|
import org.gcube.accounting.analytics.TemporalConstraint;
|
|
|
|
|
import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode;
|
|
|
|
|
import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQueryConfiguration;
|
|
|
|
|
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
|
|
|
|
|
import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord;
|
|
|
|
|
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
|
|
|
|
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
@ -74,7 +78,7 @@ public class AccountingPersistenceQueryCouchBaseTest {
|
|
|
|
|
@Before
|
|
|
|
|
public void before() throws Exception{
|
|
|
|
|
|
|
|
|
|
ScopeProvider.instance.set("/gcube/devNext");
|
|
|
|
|
ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
|
|
|
|
|
|
|
|
|
AccountingPersistenceBackendQueryConfiguration configuration = new
|
|
|
|
|
AccountingPersistenceBackendQueryConfiguration(AccountingPersistenceQueryCouchBase.class);
|
|
|
|
@ -96,11 +100,47 @@ public class AccountingPersistenceQueryCouchBaseTest {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void test() throws Exception {
|
|
|
|
|
public void testTopJob() throws Exception {
|
|
|
|
|
Calendar startTime = Calendar.getInstance();
|
|
|
|
|
startTime.set(2016, Calendar.AUGUST, 29);
|
|
|
|
|
startTime.set(2015, Calendar.AUGUST, 20);
|
|
|
|
|
Calendar endTime = Calendar.getInstance();
|
|
|
|
|
endTime.set(2016, Calendar.AUGUST, 29,23,59);
|
|
|
|
|
endTime.set(2016, Calendar.SEPTEMBER, 29,23,59);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Filter> filters = new ArrayList<Filter>();
|
|
|
|
|
|
|
|
|
|
TemporalConstraint temporalConstraint =
|
|
|
|
|
new TemporalConstraint(startTime.getTimeInMillis(),
|
|
|
|
|
endTime.getTimeInMillis(), AggregationMode.DAILY);
|
|
|
|
|
|
|
|
|
|
Class<AggregatedJobUsageRecord> clz =
|
|
|
|
|
AggregatedJobUsageRecord.class;
|
|
|
|
|
|
|
|
|
|
SortedMap<NumberedFilter, SortedMap<Calendar, Info>> set =
|
|
|
|
|
accountingPersistenceQueryCouchBase.getTopValues(
|
|
|
|
|
clz, temporalConstraint, filters,
|
|
|
|
|
AggregatedJobUsageRecord.CONSUMER_ID, null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JobUsageRecord record =new JobUsageRecord();
|
|
|
|
|
Set<String> result=record.getRequiredFields();
|
|
|
|
|
logger.debug("result"+result.toString());
|
|
|
|
|
logger.debug("Result final{}", set);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void getQuerableKey() throws Exception{
|
|
|
|
|
SortedSet<String> keys = AccountingPersistenceQuery.getQuerableKeys(AggregatedJobUsageRecord.class);
|
|
|
|
|
logger.debug("keys:"+keys);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTopService() throws Exception {
|
|
|
|
|
Calendar startTime = Calendar.getInstance();
|
|
|
|
|
startTime.set(2016, Calendar.AUGUST, 25);
|
|
|
|
|
Calendar endTime = Calendar.getInstance();
|
|
|
|
|
endTime.set(2016, Calendar.AUGUST, 28,23,59);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Filter> filters = new ArrayList<Filter>();
|
|
|
|
@ -115,11 +155,13 @@ public class AccountingPersistenceQueryCouchBaseTest {
|
|
|
|
|
SortedMap<NumberedFilter, SortedMap<Calendar, Info>> set =
|
|
|
|
|
accountingPersistenceQueryCouchBase.getTopValues(
|
|
|
|
|
clz, temporalConstraint, filters,
|
|
|
|
|
AggregatedServiceUsageRecord.CALLED_METHOD, null);
|
|
|
|
|
AggregatedServiceUsageRecord.HOST, null);
|
|
|
|
|
|
|
|
|
|
logger.debug("Result final{}", set);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static SortedMap<Calendar, Info> padMap(
|
|
|
|
|
SortedMap<Calendar, Info> unpaddedData,
|
|
|
|
|
TemporalConstraint temporalConstraint) throws Exception {
|
|
|
|
|