94 lines
3.0 KiB
Java
94 lines
3.0 KiB
Java
package org.gcube.dataharvest;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.SortedSet;
|
|
|
|
import org.gcube.accounting.accounting.summary.access.AccountingDao;
|
|
import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
|
|
import org.gcube.accounting.accounting.summary.access.model.internal.Dimension;
|
|
import org.gcube.accounting.accounting.summary.access.model.update.AccountingRecord;
|
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
|
import org.gcube.dataharvest.harvester.JupyterAccessesHarvester;
|
|
import org.gcube.dataharvest.utils.AggregationType;
|
|
import org.gcube.dataharvest.utils.ContextAuthorization;
|
|
import org.gcube.dataharvest.utils.ContextTest;
|
|
import org.gcube.dataharvest.utils.DateUtils;
|
|
import org.junit.Ignore;
|
|
import org.junit.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
*
|
|
* @author Giancarlo Panichi (ISTI CNR)
|
|
*
|
|
*/
|
|
public class AccountingDataHarvesterJupyterTest extends AccountingDataHarvesterPluginTest {
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(AccountingDataHarvesterJupyterTest.class);
|
|
|
|
@Ignore
|
|
@Test
|
|
public void testJupyterAccessesHarvester() throws Exception {
|
|
try {
|
|
|
|
ContextTest.set(ROOT);
|
|
AccountingDao dao = getAccountingDao();
|
|
|
|
List<Date> starts = new ArrayList<>();
|
|
starts.add(DateUtils.getStartCalendar(2021, Calendar.JANUARY, 1).getTime());
|
|
starts.add(DateUtils.getStartCalendar(2021, Calendar.FEBRUARY, 1).getTime());
|
|
starts.add(DateUtils.getStartCalendar(2021, Calendar.MARCH, 1).getTime());
|
|
starts.add(DateUtils.getStartCalendar(2021, Calendar.APRIL, 1).getTime());
|
|
starts.add(DateUtils.getStartCalendar(2021, Calendar.MAY, 1).getTime());
|
|
|
|
AggregationType measureType = AggregationType.MONTHLY;
|
|
|
|
SortedSet<String> contexts = contextAuthorization.getContexts();
|
|
/*
|
|
SortedSet<String> contexts = new TreeSet<>();
|
|
contexts.add("/d4science.research-infrastructures.eu/D4OS/Blue-CloudLab");
|
|
contexts.add("/d4science.research-infrastructures.eu/D4OS/Zoo-Phytoplankton_EOV");
|
|
contexts.add("/d4science.research-infrastructures.eu/D4OS/MarineEnvironmentalIndicators");
|
|
*/
|
|
|
|
List<AccountingRecord> accountingRecords = new ArrayList<>();
|
|
|
|
for (Date start : starts) {
|
|
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
|
|
|
|
ContextTest.set(ROOT);
|
|
JupyterAccessesHarvester jupyterAccessesHarvester = new JupyterAccessesHarvester(start, end);
|
|
|
|
for(String context : contexts) {
|
|
ContextTest.set(context);
|
|
|
|
List<AccountingRecord> harvested = jupyterAccessesHarvester.getAccountingRecords();
|
|
accountingRecords.addAll(harvested);
|
|
}
|
|
|
|
}
|
|
|
|
// logger.debug("{}", accountingRecords);
|
|
|
|
logger.debug("Going to insert {}", accountingRecords);
|
|
|
|
ContextTest.set(ROOT);
|
|
|
|
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
|
|
|
|
} catch (Throwable e) {
|
|
logger.error(e.getLocalizedMessage(), e);
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
|
|
}
|