304 lines
15 KiB
Java
304 lines
15 KiB
Java
package org.gcube.accounting.aggregator.plugin;
|
|
|
|
import java.util.Calendar;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
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.JobUsageRecord;
|
|
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
|
import org.gcube.accounting.datamodel.usagerecords.StorageStatusRecord;
|
|
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
|
import org.junit.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
public class AccountingAggregatorPluginTest extends ContextTest {
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(AccountingAggregatorPluginTest.class);
|
|
|
|
public static final String ROOT_PROD = "/d4science.research-infrastructures.eu";
|
|
|
|
@Test
|
|
public void aggregateJob() throws Exception {
|
|
//ContextTest.setContextByName(ROOT_DEV_SCOPE);
|
|
ContextTest.setContextByName(ROOT_PROD);
|
|
|
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
|
|
|
|
|
AggregationType aggregationType = AggregationType.MONTHLY;
|
|
//type aggregation
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_TYPE_INPUT_PARAMETER, aggregationType.name());
|
|
|
|
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.AGGREGATE.name());
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_START_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(0, 10));
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(23, 59));
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.RECORD_TYPE_INPUT_PARAMETER, JobUsageRecord.class.newInstance().getRecordType());
|
|
|
|
inputs.put(AccountingAggregatorPlugin.RESTART_FROM_LAST_AGGREGATION_DATE_INPUT_PARAMETER, false);
|
|
|
|
inputs.put(AccountingAggregatorPlugin.FORCE_EARLY_AGGREGATION, true);
|
|
inputs.put(AccountingAggregatorPlugin.FORCE_RERUN, true);
|
|
inputs.put(AccountingAggregatorPlugin.FORCE_RESTART, true);
|
|
|
|
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2017, Calendar.NOVEMBER, 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.getEndCalendarFromStartCalendar(AggregationType.MONTHLY, aggregationStartCalendar, 1);
|
|
Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2017, Calendar.DECEMBER, 1);
|
|
/*
|
|
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);
|
|
*/
|
|
|
|
AccountingAggregatorPlugin plugin = new AccountingAggregatorPlugin();
|
|
logger.debug("Going to launch {} with inputs {}", plugin.getName(), inputs);
|
|
|
|
while(aggregationStartCalendar.before(aggregationEndCalendar)) {
|
|
|
|
plugin.launch(inputs);
|
|
Thread.sleep(TimeUnit.SECONDS.toMillis(20));
|
|
plugin = new AccountingAggregatorPlugin();
|
|
aggregationStartCalendar.add(aggregationType.getCalendarField(), 1);
|
|
aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationStartCalendar.getTime());
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
|
}
|
|
|
|
}
|
|
|
|
@Test
|
|
public void aggregateStorageStatus() throws Exception {
|
|
//ContextTest.setContextByName(ROOT_DEV_SCOPE);
|
|
ContextTest.setContextByName(ROOT_PROD);
|
|
|
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
|
|
|
|
|
AggregationType aggregationType = AggregationType.MONTHLY;
|
|
//type aggregation
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_TYPE_INPUT_PARAMETER, aggregationType.name());
|
|
|
|
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.AGGREGATE.name());
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_START_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(0, 10));
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(23, 59));
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.RECORD_TYPE_INPUT_PARAMETER, StorageStatusRecord.class.newInstance().getRecordType());
|
|
|
|
inputs.put(AccountingAggregatorPlugin.RESTART_FROM_LAST_AGGREGATION_DATE_INPUT_PARAMETER, false);
|
|
|
|
inputs.put(AccountingAggregatorPlugin.FORCE_EARLY_AGGREGATION, true);
|
|
inputs.put(AccountingAggregatorPlugin.FORCE_RERUN, true);
|
|
inputs.put(AccountingAggregatorPlugin.FORCE_RESTART, true);
|
|
|
|
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2021, Calendar.MAY, 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.getEndCalendarFromStartCalendar(AggregationType.MONTHLY, aggregationStartCalendar, 1);
|
|
Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2021, Calendar.JULY, 1);
|
|
/*
|
|
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);
|
|
*/
|
|
|
|
AccountingAggregatorPlugin plugin = new AccountingAggregatorPlugin();
|
|
logger.debug("Going to launch {} with inputs {}", plugin.getName(), inputs);
|
|
|
|
while(aggregationStartCalendar.before(aggregationEndCalendar)) {
|
|
|
|
plugin.launch(inputs);
|
|
Thread.sleep(TimeUnit.SECONDS.toMillis(20));
|
|
plugin = new AccountingAggregatorPlugin();
|
|
aggregationStartCalendar.add(aggregationType.getCalendarField(), 1);
|
|
aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationStartCalendar.getTime());
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
@Test
|
|
public void aggregateStorageUsage() throws Exception {
|
|
//ContextTest.setContextByName(ROOT_DEV_SCOPE);
|
|
ContextTest.setContextByName(ROOT_PROD);
|
|
|
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
|
|
|
|
|
AggregationType aggregationType = AggregationType.MONTHLY;
|
|
//type aggregation51170
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_TYPE_INPUT_PARAMETER, aggregationType.name());
|
|
|
|
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.AGGREGATE.name());
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_START_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(0, 10));
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(23, 59));
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.RECORD_TYPE_INPUT_PARAMETER, StorageUsageRecord.class.newInstance().getRecordType());
|
|
|
|
inputs.put(AccountingAggregatorPlugin.RESTART_FROM_LAST_AGGREGATION_DATE_INPUT_PARAMETER, false);
|
|
|
|
inputs.put(AccountingAggregatorPlugin.FORCE_EARLY_AGGREGATION, true);
|
|
inputs.put(AccountingAggregatorPlugin.FORCE_RERUN, true);
|
|
inputs.put(AccountingAggregatorPlugin.FORCE_RESTART, true);
|
|
|
|
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2021, Calendar.APRIL, 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.getEndCalendarFromStartCalendar(AggregationType.MONTHLY, aggregationStartCalendar, 1);
|
|
Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2021, Calendar.MAY, 1);
|
|
/*
|
|
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);
|
|
*/
|
|
|
|
AccountingAggregatorPlugin plugin = new AccountingAggregatorPlugin();
|
|
logger.debug("Going to launch {} with inputs {}", plugin.getName(), inputs);
|
|
|
|
|
|
|
|
while(aggregationStartCalendar.before(aggregationEndCalendar)) {
|
|
plugin.launch(inputs);
|
|
//Thread.sleep(TimeUnit.MINUTES.toMillis(1));
|
|
aggregationStartCalendar.add(aggregationType.getCalendarField(), 1);
|
|
aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationStartCalendar.getTime());
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
@Test
|
|
public void aggregateService() throws Exception {
|
|
//ContextTest.setContextByName(ROOT_DEV_SCOPE);
|
|
ContextTest.setContextByName(ROOT_PROD);
|
|
|
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
|
|
|
|
|
AggregationType aggregationType = AggregationType.MONTHLY;
|
|
//type aggregation
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_TYPE_INPUT_PARAMETER, aggregationType.name());
|
|
|
|
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.AGGREGATE.name());
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_START_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(0, 10));
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(23, 59));
|
|
|
|
|
|
inputs.put(AccountingAggregatorPlugin.RECORD_TYPE_INPUT_PARAMETER, ServiceUsageRecord.class.newInstance().getRecordType());
|
|
|
|
inputs.put(AccountingAggregatorPlugin.RESTART_FROM_LAST_AGGREGATION_DATE_INPUT_PARAMETER, false);
|
|
|
|
inputs.put(AccountingAggregatorPlugin.FORCE_EARLY_AGGREGATION, true);
|
|
inputs.put(AccountingAggregatorPlugin.FORCE_RERUN, true);
|
|
inputs.put(AccountingAggregatorPlugin.FORCE_RESTART, true);
|
|
|
|
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2021, Calendar.JUNE, 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.getEndCalendarFromStartCalendar(AggregationType.MONTHLY, aggregationStartCalendar, 1);
|
|
Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2021, Calendar.JULY, 1);
|
|
/*
|
|
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);
|
|
*/
|
|
|
|
AccountingAggregatorPlugin plugin = new AccountingAggregatorPlugin();
|
|
logger.debug("Going to launch {} with inputs {}", plugin.getName(), inputs);
|
|
|
|
|
|
|
|
while(aggregationStartCalendar.before(aggregationEndCalendar)) {
|
|
plugin.launch(inputs);
|
|
//Thread.sleep(TimeUnit.MINUTES.toMillis(1));
|
|
aggregationStartCalendar.add(aggregationType.getCalendarField(), 1);
|
|
aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationStartCalendar.getTime());
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
@Test
|
|
public void cycle() throws Exception {
|
|
for(int i=0; i<20; i++) {
|
|
aggregate();
|
|
logger.debug("---------------------------------------------\n\n");
|
|
}
|
|
}
|
|
*/
|
|
|
|
@Test
|
|
public void testRecovery() throws Exception {
|
|
ContextTest.setContextByName(ROOT_DEV_SCOPE);
|
|
// ContextTest.setContextByName(ROOT_PROD);
|
|
|
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
|
|
|
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.RECOVERY.name());
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_TYPE_INPUT_PARAMETER, AggregationType.MONTHLY.name());
|
|
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_START_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(0, 0));
|
|
inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(24, 00));
|
|
|
|
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2017, Calendar.MAY, 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);
|
|
|
|
inputs.put(AccountingAggregatorPlugin.FORCE_EARLY_AGGREGATION, true);
|
|
inputs.put(AccountingAggregatorPlugin.FORCE_RESTART, true);
|
|
|
|
|
|
// Calendar aggregationEndCalendar = Utility.getEndCalendarFromStartCalendar(AggregationType.MONTHLY, aggregationStartCalendar, 1);
|
|
Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2017, Calendar.JUNE, 1);
|
|
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);
|
|
|
|
|
|
AccountingAggregatorPlugin plugin = new AccountingAggregatorPlugin();
|
|
logger.debug("Going to launch {} with inputs {}",plugin.getName(), inputs);
|
|
|
|
|
|
/*
|
|
while(aggregationStartCalendar.before(aggregationEndCalendar)) {
|
|
plugin.launch(inputs);
|
|
aggregationStartCalendar.add(Calendar.MONTH, 1);
|
|
aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationStartCalendar.getTime());
|
|
inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
|
}
|
|
*/
|
|
plugin.launch(inputs);
|
|
|
|
}
|
|
|
|
}
|