2017-07-07 12:51:20 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2017-08-03 15:13:57 +02:00
|
|
|
package org.gcube.accounting.aggregator.plugin;
|
2017-07-07 12:51:20 +02:00
|
|
|
|
2017-08-01 15:56:08 +02:00
|
|
|
import java.util.Calendar;
|
2017-07-07 12:51:20 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2017-08-01 15:56:08 +02:00
|
|
|
import org.gcube.accounting.aggregator.aggregation.AggregationType;
|
|
|
|
import org.gcube.accounting.aggregator.plugin.AccountingAggregatorPlugin;
|
|
|
|
import org.gcube.accounting.aggregator.plugin.AccountingAggregatorPlugin.ElaborationType;
|
2017-07-31 15:39:45 +02:00
|
|
|
import org.gcube.accounting.aggregator.plugin.AccountingAggregatorPluginDeclaration;
|
2017-08-01 15:56:08 +02:00
|
|
|
import org.gcube.accounting.aggregator.utility.Utility;
|
|
|
|
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
2017-07-07 12:51:20 +02:00
|
|
|
import org.gcube.testutility.ScopedTest;
|
|
|
|
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
|
|
|
import org.gcube.vremanagement.executor.api.types.Scheduling;
|
|
|
|
import org.gcube.vremanagement.executor.client.plugins.ExecutorPlugin;
|
|
|
|
import org.gcube.vremanagement.executor.client.proxies.SmartExecutorProxy;
|
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.quartz.CronExpression;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
public class AggregatorAccountingPluginSmartExecutorSchedulerTest extends ScopedTest {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(AggregatorAccountingPluginSmartExecutorSchedulerTest.class);
|
|
|
|
|
|
|
|
private SmartExecutorProxy proxy;
|
2017-08-01 15:56:08 +02:00
|
|
|
|
2017-07-07 12:51:20 +02:00
|
|
|
@Before
|
2017-08-01 15:56:08 +02:00
|
|
|
public void before() throws Exception {
|
|
|
|
proxy = ExecutorPlugin.getExecutorProxy(AccountingAggregatorPluginDeclaration.NAME).build();
|
2017-07-07 12:51:20 +02:00
|
|
|
Assert.assertNotNull(proxy);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-08-01 15:56:08 +02:00
|
|
|
private Map<String, Object> getRecoveryInputs() throws Exception {
|
2017-07-07 12:51:20 +02:00
|
|
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
2017-08-01 15:56:08 +02:00
|
|
|
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.RECOVERY.name());
|
|
|
|
|
2017-09-04 10:54:10 +02:00
|
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_START_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(8, 0));
|
|
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(18, 0));
|
2017-08-01 15:56:08 +02:00
|
|
|
|
2017-07-31 15:39:45 +02:00
|
|
|
return inputs;
|
2017-07-07 12:51:20 +02:00
|
|
|
}
|
2017-08-01 15:56:08 +02:00
|
|
|
|
|
|
|
private Map<String, Object> getAggregateInputs() throws Exception {
|
2017-07-07 12:51:20 +02:00
|
|
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
2017-08-01 15:56:08 +02:00
|
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_TYPE_INPUT_PARAMETER, AggregationType.DAILY.name());
|
|
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.AGGREGATE.name());
|
|
|
|
|
2017-09-04 10:54:10 +02:00
|
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_START_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(8, 0));
|
|
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(18, 0));
|
2017-08-01 15:56:08 +02:00
|
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.RECORD_TYPE_INPUT_PARAMETER,
|
|
|
|
ServiceUsageRecord.class.newInstance().getRecordType());
|
|
|
|
|
|
|
|
// Start Aggregation Date
|
|
|
|
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2017, Calendar.JUNE,
|
2017-08-03 14:31:45 +02:00
|
|
|
1);
|
2017-08-01 15:56:08 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.RESTART_FROM_LAST_AGGREGATION_DATE_INPUT_PARAMETER, true);
|
|
|
|
|
|
|
|
return inputs;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void launch(Scheduling scheduling, Map<String, Object> inputs) throws Exception {
|
|
|
|
|
2017-07-31 15:39:45 +02:00
|
|
|
LaunchParameter launchParameter = new LaunchParameter(AccountingAggregatorPluginDeclaration.NAME, inputs);
|
|
|
|
launchParameter.setScheduling(scheduling);
|
2017-08-01 15:56:08 +02:00
|
|
|
|
2017-07-07 12:51:20 +02:00
|
|
|
try {
|
2017-07-31 15:39:45 +02:00
|
|
|
String uuidString = proxy.launch(launchParameter);
|
2017-07-07 12:51:20 +02:00
|
|
|
logger.debug("Launched with UUID : {}", uuidString);
|
2017-08-01 15:56:08 +02:00
|
|
|
} catch (Exception e) {
|
2017-07-31 15:39:45 +02:00
|
|
|
logger.error("Error while launching {}", e);
|
2017-07-07 12:51:20 +02:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
2017-08-01 15:56:08 +02:00
|
|
|
|
2017-07-07 12:51:20 +02:00
|
|
|
@Test
|
2017-09-04 10:54:10 +02:00
|
|
|
public void aggregate() throws Exception {
|
2017-08-01 15:56:08 +02:00
|
|
|
// Every 15 minutes
|
|
|
|
CronExpression cronExpression = new CronExpression("0 0/15 * 1/1 * ? *");
|
2017-08-03 15:13:07 +02:00
|
|
|
Scheduling scheduling = new Scheduling(cronExpression, false);
|
2017-08-04 11:09:55 +02:00
|
|
|
scheduling.setGlobal(false);
|
2017-08-01 15:56:08 +02:00
|
|
|
|
|
|
|
Map<String, Object> inputs = getAggregateInputs();
|
|
|
|
|
|
|
|
launch(scheduling, inputs);
|
|
|
|
|
2017-07-07 12:51:20 +02:00
|
|
|
}
|
|
|
|
|
2017-08-01 15:56:08 +02:00
|
|
|
@Test
|
|
|
|
public void recovery() throws Exception {
|
|
|
|
// Every Day at 8:00
|
2017-08-04 11:09:55 +02:00
|
|
|
CronExpression cronExpression = new CronExpression("0 0 8,12,16 1/1 * ? *");
|
|
|
|
Scheduling scheduling = new Scheduling(cronExpression, true);
|
|
|
|
scheduling.setGlobal(false);
|
2017-08-01 15:56:08 +02:00
|
|
|
|
|
|
|
Map<String, Object> inputs = getRecoveryInputs();
|
|
|
|
|
|
|
|
launch(scheduling, inputs);
|
|
|
|
|
|
|
|
}
|
2017-07-07 12:51:20 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void unSchedule() throws Exception {
|
2017-08-01 15:56:08 +02:00
|
|
|
// proxy.unSchedule("", true);
|
2017-07-07 12:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void stop() throws Exception {
|
2017-07-31 15:39:45 +02:00
|
|
|
proxy.stop(AccountingAggregatorPluginDeclaration.NAME);
|
2017-07-07 12:51:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|