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:
Luca Frosini 2018-05-29 09:08:24 +00:00
parent 67ae816424
commit 618f18e331
3 changed files with 15 additions and 8 deletions

View File

@ -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
VREUsersHarvester vreUsersHarvester = new VREUsersHarvester(start, end); if(!reRun) {
List<HarvestedData> harvested = vreUsersHarvester.getData(); VREUsersHarvester vreUsersHarvester = new VREUsersHarvester(start, end);
data.addAll(harvested); List<HarvestedData> harvested = vreUsersHarvester.getData();
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);
} }
@ -200,6 +206,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);

View File

@ -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());
} }
} }

View File

@ -62,12 +62,12 @@ 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);
*/ */
accountingDataHarvesterPlugin.launch(inputs); accountingDataHarvesterPlugin.launch(inputs);
logger.info("End."); logger.info("End.");