|
|
|
@ -11,6 +11,7 @@ import org.gcube.accounting.aggregator.aggregation.AggregationType;
|
|
|
|
|
import org.gcube.accounting.aggregator.plugin.AccountingAggregatorPlugin.ElaborationType;
|
|
|
|
|
import org.gcube.accounting.aggregator.utility.Utility;
|
|
|
|
|
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
|
|
|
|
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
|
|
|
|
import org.gcube.testutility.ScopedTest;
|
|
|
|
|
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
|
|
|
|
import org.gcube.vremanagement.executor.api.types.Scheduling;
|
|
|
|
@ -31,21 +32,26 @@ public class AggregatorAccountingPluginSmartExecutorSchedulerTest extends Scoped
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
public void before() throws Exception {
|
|
|
|
|
setContext(ROOT);
|
|
|
|
|
proxy = ExecutorPlugin.getExecutorProxy(AccountingAggregatorPluginDeclaration.NAME).build();
|
|
|
|
|
Assert.assertNotNull(proxy);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void launch(Scheduling scheduling, Map<String, Object> inputs) throws Exception {
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> getRecoveryInputs() throws Exception {
|
|
|
|
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.RECOVERY.name());
|
|
|
|
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_START_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(4, 0));
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(20, 0));
|
|
|
|
|
LaunchParameter launchParameter = new LaunchParameter(AccountingAggregatorPluginDeclaration.NAME, inputs);
|
|
|
|
|
launchParameter.setScheduling(scheduling);
|
|
|
|
|
|
|
|
|
|
return inputs;
|
|
|
|
|
try {
|
|
|
|
|
String uuidString = proxy.launch(launchParameter);
|
|
|
|
|
logger.debug("Launched with UUID : {}", uuidString);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("Error while launching {}", e);
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> getAggregateInputs() throws Exception {
|
|
|
|
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_TYPE_INPUT_PARAMETER, AggregationType.DAILY.name());
|
|
|
|
@ -58,34 +64,23 @@ public class AggregatorAccountingPluginSmartExecutorSchedulerTest extends Scoped
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.RECORD_TYPE_INPUT_PARAMETER,
|
|
|
|
|
ServiceUsageRecord.class.newInstance().getRecordType());
|
|
|
|
|
|
|
|
|
|
// Start Aggregation Date
|
|
|
|
|
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2017, Calendar.APRIL,
|
|
|
|
|
17);
|
|
|
|
|
String aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT
|
|
|
|
|
.format(aggregationStartCalendar.getTime());
|
|
|
|
|
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER,
|
|
|
|
|
aggregationStartDate);
|
|
|
|
|
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2017, Calendar.SEPTEMBER, 22);
|
|
|
|
|
String aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationStartCalendar.getTime());
|
|
|
|
|
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2017, Calendar.SEPTEMBER, 23);
|
|
|
|
|
String aggregationEndDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationEndCalendar.getTime());
|
|
|
|
|
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationEndDate);
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_END_DATE_INPUT_PARAMETER, aggregationEndDate);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.RESTART_FROM_LAST_AGGREGATION_DATE_INPUT_PARAMETER, false);
|
|
|
|
|
|
|
|
|
|
return inputs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void launch(Scheduling scheduling, Map<String, Object> inputs) throws Exception {
|
|
|
|
|
|
|
|
|
|
LaunchParameter launchParameter = new LaunchParameter(AccountingAggregatorPluginDeclaration.NAME, inputs);
|
|
|
|
|
launchParameter.setScheduling(scheduling);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
String uuidString = proxy.launch(launchParameter);
|
|
|
|
|
logger.debug("Launched with UUID : {}", uuidString);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("Error while launching {}", e);
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void aggregate() throws Exception {
|
|
|
|
|
// Every 5 minutes
|
|
|
|
@ -98,17 +93,84 @@ public class AggregatorAccountingPluginSmartExecutorSchedulerTest extends Scoped
|
|
|
|
|
launch(null, inputs);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> getMonthlyAggregateInputs() throws Exception {
|
|
|
|
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_TYPE_INPUT_PARAMETER, AggregationType.MONTHLY.name());
|
|
|
|
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.AGGREGATE.name());
|
|
|
|
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_START_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(3, 0));
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(19, 00));
|
|
|
|
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.RECORD_TYPE_INPUT_PARAMETER,
|
|
|
|
|
StorageUsageRecord.class.newInstance().getRecordType());
|
|
|
|
|
|
|
|
|
|
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2016, Calendar.JANUARY, 1);
|
|
|
|
|
String aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationStartCalendar.getTime());
|
|
|
|
|
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
|
|
|
|
/*
|
|
|
|
|
Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2017, Calendar.JUNE, 30);
|
|
|
|
|
String aggregationEndDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationEndCalendar.getTime());
|
|
|
|
|
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationEndDate);
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_END_DATE_INPUT_PARAMETER, aggregationEndDate);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.RESTART_FROM_LAST_AGGREGATION_DATE_INPUT_PARAMETER, true);
|
|
|
|
|
|
|
|
|
|
return inputs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void aggregateMonthly() throws Exception {
|
|
|
|
|
CronExpression cronExpression = new CronExpression("0 0/5 * 1/1 * ? *");
|
|
|
|
|
Scheduling scheduling = new Scheduling(cronExpression, true);
|
|
|
|
|
scheduling.setGlobal(false);
|
|
|
|
|
|
|
|
|
|
Map<String, Object> inputs = getMonthlyAggregateInputs();
|
|
|
|
|
launch(scheduling, inputs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> getRecoveryInputs() throws Exception {
|
|
|
|
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.RECOVERY.name());
|
|
|
|
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_START_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(3, 0));
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(19, 0));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2017, Calendar.AUGUST, 1);
|
|
|
|
|
String aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationStartCalendar.getTime());
|
|
|
|
|
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2017, Calendar.JUNE, 22);
|
|
|
|
|
String aggregationEndDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationEndCalendar.getTime());
|
|
|
|
|
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationEndDate);
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_END_DATE_INPUT_PARAMETER, aggregationEndDate);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
return inputs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void recovery() throws Exception {
|
|
|
|
|
// Every Day at 8:00
|
|
|
|
|
CronExpression cronExpression = new CronExpression("0 0/15 4-19 1/1 * ? *");
|
|
|
|
|
CronExpression cronExpression = new CronExpression("0 0/5 3-19 1/1 * ? *");
|
|
|
|
|
Scheduling scheduling = new Scheduling(cronExpression, true);
|
|
|
|
|
scheduling.setGlobal(false);
|
|
|
|
|
|
|
|
|
|
Map<String, Object> inputs = getRecoveryInputs();
|
|
|
|
|
|
|
|
|
|
launch(null, inputs);
|
|
|
|
|
launch(scheduling, inputs);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|