Fixed integration of CoreServicesAccessesHarvester

This commit is contained in:
Luca Frosini 2020-06-05 10:05:45 +02:00
parent a6cf5c09a4
commit 9d2b2e5010
2 changed files with 29 additions and 20 deletions

View File

@ -20,6 +20,7 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type; import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.dataharvest.harvester.CatalogueAccessesHarvester; import org.gcube.dataharvest.harvester.CatalogueAccessesHarvester;
import org.gcube.dataharvest.harvester.CoreServicesAccessesHarvester;
import org.gcube.dataharvest.harvester.MethodInvocationHarvester; import org.gcube.dataharvest.harvester.MethodInvocationHarvester;
import org.gcube.dataharvest.harvester.SocialInteractionsHarvester; import org.gcube.dataharvest.harvester.SocialInteractionsHarvester;
import org.gcube.dataharvest.harvester.VREAccessesHarvester; import org.gcube.dataharvest.harvester.VREAccessesHarvester;
@ -258,9 +259,15 @@ public class AccountingDashboardHarvesterPlugin extends Plugin<AccountingDashboa
if(scopeBean.is(Type.INFRASTRUCTURE)) { if(scopeBean.is(Type.INFRASTRUCTURE)) {
try { try {
CatalogueAccessesHarvester catalogueHarvester = new CatalogueAccessesHarvester(start, end); CatalogueAccessesHarvester catalogueHarvester = new CatalogueAccessesHarvester(start, end);
List<AccountingRecord> harvested = catalogueHarvester.getAccountingRecords(); List<AccountingRecord> harvested = catalogueHarvester.getAccountingRecords();
accountingRecords.addAll(harvested); accountingRecords.addAll(harvested);
CoreServicesAccessesHarvester coreServicesHarvester = new CoreServicesAccessesHarvester(start, end);
List<AccountingRecord> records = coreServicesHarvester.getAccountingRecords();
accountingRecords.addAll(records);
}catch (Exception e) { }catch (Exception e) {
logger.error("Error harvesting {} for {}", CatalogueAccessesHarvester.class.getSimpleName(), context, e); logger.error("Error harvesting {} for {}", CatalogueAccessesHarvester.class.getSimpleName(), context, e);
} }

View File

@ -90,7 +90,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
} }
} }
// @Test @Test
public void launch() { public void launch() {
try { try {
@ -109,13 +109,13 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
inputs.put(AccountingDashboardHarvesterPlugin.GET_VRE_USERS_INPUT_PARAMETER, true); inputs.put(AccountingDashboardHarvesterPlugin.GET_VRE_USERS_INPUT_PARAMETER, true);
inputs.put(AccountingDashboardHarvesterPlugin.RERUN_INPUT_PARAMETER, true); inputs.put(AccountingDashboardHarvesterPlugin.RERUN_INPUT_PARAMETER, true);
inputs.put(AccountingDashboardHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, false); inputs.put(AccountingDashboardHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, false);
inputs.put(AccountingDashboardHarvesterPlugin.PARTIAL_HARVESTING, true); inputs.put(AccountingDashboardHarvesterPlugin.PARTIAL_HARVESTING, false);
/* /*
Calendar from = DateUtils.getStartCalendar(2016, Calendar.SEPTEMBER, 1); Calendar from = DateUtils.getStartCalendar(2020, Calendar.MAY, 1);
String fromDate = DateUtils.LAUNCH_DATE_FORMAT.format(from.getTime()); String fromDate = DateUtils.LAUNCH_DATE_FORMAT.format(from.getTime());
logger.trace("{} is {}", AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate); logger.trace("{} is {}", AccountingDashboardHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
inputs.put(AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate); inputs.put(AccountingDashboardHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
*/ */
accountingDataHarvesterPlugin.launch(inputs); accountingDataHarvesterPlugin.launch(inputs);
@ -738,27 +738,29 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
String context = ROOT; //"/gcube"; String context = ROOT; //"/gcube";
ContextTest.setContextByName(context); ContextTest.setContextByName(context);
//AccountingDao dao = getAccountingDao(); AccountingDao dao = getAccountingDao();
Date start = DateUtils.getStartCalendar(2020, Calendar.JANUARY, 1).getTime(); Date start = DateUtils.getStartCalendar(2017, Calendar.MAY, 1).getTime();
Date end = DateUtils.getStartCalendar(2020, Calendar.FEBRUARY, 1).getTime(); Date finalEnd = DateUtils.getStartCalendar(2020, Calendar.MAY, 1).getTime();
/* Date end = DateUtils.getEndDateFromStartDate(AggregationType.MONTHLY, start, 1, false);
* Date start = DateUtils.getPreviousPeriod(measureType, false).getTime();
* Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
*/
ScopeBean scopeBean = new ScopeBean(context); ScopeBean scopeBean = new ScopeBean(context);
logger.debug("FullName {} - Name {}", scopeBean.toString(), scopeBean.name()); logger.debug("FullName {} - Name {}", scopeBean.toString(), scopeBean.name());
CoreServicesAccessesHarvester coreServicesHarvester = new CoreServicesAccessesHarvester(start, end); while(end.before(finalEnd)) {
List<AccountingRecord> accountingRecords = coreServicesHarvester.getAccountingRecords(); CoreServicesAccessesHarvester coreServicesHarvester = new CoreServicesAccessesHarvester(start, end);
for (AccountingRecord accountingRecord : accountingRecords) { List<AccountingRecord> accountingRecords = coreServicesHarvester.getAccountingRecords();
logger.debug("{}", accountingRecord); dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
logger.debug("{} -> {} Data Inserted", DateUtils.format(start), DateUtils.format(end));
logger.debug("---------------------------------------------------------------------------------------");
Thread.sleep(TimeUnit.SECONDS.toMillis(90));
start = end;
end = DateUtils.getEndDateFromStartDate(AggregationType.MONTHLY, start, 1, false);
} }
logger.debug("{}", accountingRecords);
//dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
} catch(Exception e) { } catch(Exception e) {
logger.error("", e); logger.error("", e);