Code redesign
Refs #11756: Refactor DataHArvesterPlugin to support scheduled execution from smart-executor Task-Url: https://support.d4science.org/issues/11756 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-dashboard-harvester-se-plugin@167820 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
67ae816424
commit
618f18e331
|
@ -9,6 +9,7 @@ import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.dataharvest.dao.DatabaseManager;
|
import org.gcube.dataharvest.dao.DatabaseManager;
|
||||||
import org.gcube.dataharvest.datamodel.HarvestedData;
|
import org.gcube.dataharvest.datamodel.HarvestedData;
|
||||||
import org.gcube.dataharvest.harvester.MethodInvocationHarvester;
|
import org.gcube.dataharvest.harvester.MethodInvocationHarvester;
|
||||||
|
@ -133,6 +134,9 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
||||||
|
|
||||||
ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
|
ArrayList<HarvestedData> data = new ArrayList<HarvestedData>();
|
||||||
|
|
||||||
|
|
||||||
|
String initialToken = SecurityTokenProvider.instance.get();
|
||||||
|
|
||||||
for(String context : contexts) {
|
for(String context : contexts) {
|
||||||
|
|
||||||
// Setting the token for the context
|
// Setting the token for the context
|
||||||
|
@ -149,9 +153,11 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Collecting info on VRE users
|
// Collecting info on VRE users
|
||||||
|
if(!reRun) {
|
||||||
VREUsersHarvester vreUsersHarvester = new VREUsersHarvester(start, end);
|
VREUsersHarvester vreUsersHarvester = new VREUsersHarvester(start, end);
|
||||||
List<HarvestedData> harvested = vreUsersHarvester.getData();
|
List<HarvestedData> harvested = vreUsersHarvester.getData();
|
||||||
data.addAll(harvested);
|
data.addAll(harvested);
|
||||||
|
}
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
logger.error("Error harvesting Context Users for {}", context, e);
|
logger.error("Error harvesting Context Users for {}", context, e);
|
||||||
}
|
}
|
||||||
|
@ -201,6 +207,8 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utils.setContext(initialToken);
|
||||||
|
|
||||||
if(!dryRun) {
|
if(!dryRun) {
|
||||||
dbaseManager.insertMonthlyData(start, end, data, reRun);
|
dbaseManager.insertMonthlyData(start, end, data, reRun);
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,9 +88,8 @@ public class DatabaseParameterRetriever {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch(Exception ex) {
|
} catch(Exception e) {
|
||||||
logger.error(ex.getLocalizedMessage());
|
throw new DaoException("Error retrieving database connection", e);
|
||||||
throw new DaoException(ex.getLocalizedMessage(), ex.getCause());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
||||||
inputs.put(AccountingDataHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, false);
|
inputs.put(AccountingDataHarvesterPlugin.DRY_RUN_INPUT_PARAMETER, false);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Calendar from = DateUtils.getStartCalendar(2018, Calendar.APRIL, 1);
|
Calendar from = DateUtils.getStartCalendar(2018, Calendar.MARCH, 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 {}", AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
||||||
inputs.put(AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
inputs.put(AccountingDataHarvesterPlugin.START_DATE_INPUT_PARAMETER, fromDate);
|
||||||
|
|
Loading…
Reference in New Issue