2017-05-17 10:46:00 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.informationsystem.exporter;
|
|
|
|
|
2017-10-10 16:36:33 +02:00
|
|
|
import java.io.File;
|
2017-05-17 10:46:00 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2017-11-21 16:32:32 +01:00
|
|
|
import org.gcube.common.clients.ProxyBuilderImpl;
|
2017-05-17 10:46:00 +02:00
|
|
|
import org.gcube.testutility.ScopedTest;
|
2017-11-21 16:32:32 +01:00
|
|
|
import org.gcube.vremanagement.executor.api.SmartExecutor;
|
2017-05-17 10:46:00 +02:00
|
|
|
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
|
|
|
import org.gcube.vremanagement.executor.api.types.Scheduling;
|
|
|
|
import org.gcube.vremanagement.executor.client.plugins.ExecutorPlugin;
|
2017-11-21 16:32:32 +01:00
|
|
|
import org.gcube.vremanagement.executor.client.plugins.query.SmartExecutorPluginQuery;
|
|
|
|
import org.gcube.vremanagement.executor.client.plugins.query.filter.SpecificEndpointDiscoveryFilter;
|
2017-05-17 10:46:00 +02:00
|
|
|
import org.gcube.vremanagement.executor.client.proxies.SmartExecutorProxy;
|
2017-05-25 13:53:09 +02:00
|
|
|
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
|
2017-05-17 10:46:00 +02:00
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.quartz.CronExpression;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2017-10-10 16:36:33 +02:00
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
2017-05-17 10:46:00 +02:00
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
|
|
|
public class ISExporterPluginSmartExecutorSchedulerTest extends ScopedTest {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(ISExporterPluginSmartExecutorSchedulerTest.class);
|
2018-07-19 16:58:36 +02:00
|
|
|
/*
|
2017-05-17 10:46:00 +02:00
|
|
|
public UUID scheduleTest(Scheduling scheduling) throws Exception {
|
|
|
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
2017-05-22 12:05:18 +02:00
|
|
|
inputs.put(ISExporterPlugin.FILTERED_REPORT, true);
|
2017-05-17 10:46:00 +02:00
|
|
|
logger.debug("Inputs : {}", inputs);
|
|
|
|
|
|
|
|
|
|
|
|
LaunchParameter parameter = new LaunchParameter(ISExporterPluginDeclaration.NAME, inputs);
|
|
|
|
if(scheduling!=null){
|
|
|
|
parameter.setScheduling(scheduling);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2017-05-17 18:05:49 +02:00
|
|
|
SmartExecutorProxy proxy = ExecutorPlugin.getExecutorProxy(ISExporterPluginDeclaration.NAME).build();
|
|
|
|
Assert.assertNotNull(proxy);
|
2017-05-17 10:46:00 +02:00
|
|
|
String uuidString = proxy.launch(parameter);
|
|
|
|
return UUID.fromString(uuidString);
|
|
|
|
} catch(Exception e){
|
|
|
|
logger.error("Error launching sheduled task", e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-11 18:20:23 +02:00
|
|
|
//@Test
|
2017-10-10 16:36:33 +02:00
|
|
|
public void production() throws Exception {
|
|
|
|
File src = new File("src");
|
|
|
|
File test = new File(src, "test");
|
|
|
|
File resources = new File(test, "resources");
|
|
|
|
|
|
|
|
File tokenFile = new File(resources, "production-tokens-is-exporter.json");
|
|
|
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
JsonNode jsonNode = objectMapper.readTree(tokenFile);
|
|
|
|
|
|
|
|
Map<String, String> contextSecondMinutes = new HashMap<>();
|
|
|
|
contextSecondMinutes.put("/d4science.research-infrastructures.eu", "0 0");
|
|
|
|
contextSecondMinutes.put("/d4science.research-infrastructures.eu/ParthenosVO", "30 7");
|
|
|
|
contextSecondMinutes.put("/d4science.research-infrastructures.eu/ParthenosVO/RubRIcA", "0 15");
|
|
|
|
contextSecondMinutes.put("/d4science.research-infrastructures.eu/ParthenosVO/PARTHENOS_Registry", "30 22");
|
|
|
|
contextSecondMinutes.put("/d4science.research-infrastructures.eu/gCubeApps", "0 30");
|
|
|
|
contextSecondMinutes.put("/d4science.research-infrastructures.eu/gCubeApps/Parthenos", "30 37");
|
|
|
|
contextSecondMinutes.put("/d4science.research-infrastructures.eu/D4Research", "0 45");
|
|
|
|
contextSecondMinutes.put("/d4science.research-infrastructures.eu/D4Research/NERLiX", "30 52");
|
|
|
|
|
|
|
|
for(String context : contextSecondMinutes.keySet()){
|
|
|
|
logger.info("\n\n\n-------------------------------------------------------------------------");
|
|
|
|
|
|
|
|
String token = jsonNode.get(context).asText();
|
|
|
|
|
|
|
|
ScopedTest.setContext(token);
|
|
|
|
|
|
|
|
CronExpression cronExpression = new CronExpression(contextSecondMinutes.get(context) + " 0/1 * * ?"); // every hour at contextSecondMinutes.get(token)
|
|
|
|
Scheduling scheduling = new Scheduling(cronExpression, true);
|
|
|
|
scheduling.setGlobal(true);
|
|
|
|
|
|
|
|
logger.debug("{} : {} : {}", context, token, cronExpression.getCronExpression());
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-11 18:20:23 +02:00
|
|
|
UUID uuid = scheduleTest(scheduling);
|
|
|
|
logger.debug("Launched with UUID : {}", uuid);
|
2017-10-10 16:36:33 +02:00
|
|
|
|
|
|
|
logger.info("\n\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-17 10:46:00 +02:00
|
|
|
@Test
|
|
|
|
public void cronExpPreviousMustBeTerminated() throws Exception {
|
|
|
|
|
|
|
|
Map<String, String> tokenMinutes = new HashMap<>();
|
2017-05-17 18:05:49 +02:00
|
|
|
tokenMinutes.put(ScopedTest.GCUBE, "0");
|
|
|
|
tokenMinutes.put(ScopedTest.GCUBE_DEVSEC, "12");
|
|
|
|
tokenMinutes.put(ScopedTest.GCUBE_DEVSEC_DEVVRE, "24");
|
|
|
|
tokenMinutes.put(ScopedTest.GCUBE_DEVNEXT, "36");
|
|
|
|
tokenMinutes.put(ScopedTest.GCUBE_DEVNEXT_NEXTNEXT, "48");
|
2017-05-17 10:46:00 +02:00
|
|
|
|
|
|
|
for(String token : tokenMinutes.keySet()){
|
|
|
|
logger.info("\n\n\n-------------------------------------------------------------------------");
|
|
|
|
ScopedTest.setContext(token);
|
|
|
|
|
|
|
|
CronExpression cronExpression = new CronExpression("0 " + tokenMinutes.get(token) + " 0/1 * * ?"); // every hour at tokenMinutes.get(token) minutes
|
|
|
|
Scheduling scheduling = new Scheduling(cronExpression, true);
|
|
|
|
scheduling.setGlobal(true);
|
|
|
|
|
|
|
|
UUID uuid = scheduleTest(scheduling);
|
|
|
|
logger.debug("Launched with UUID : {}", uuid);
|
|
|
|
|
|
|
|
logger.info("\n\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-05-25 13:53:09 +02:00
|
|
|
@Test
|
|
|
|
public void getState() throws Exception {
|
|
|
|
SmartExecutorProxy proxy = ExecutorPlugin.getExecutorProxy(ISExporterPluginDeclaration.NAME).build();
|
|
|
|
Assert.assertNotNull(proxy);
|
|
|
|
|
|
|
|
PluginStateEvolution pluginStateEvolution = proxy.getStateEvolution("");
|
|
|
|
logger.debug("{}", pluginStateEvolution);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-11-21 16:32:32 +01:00
|
|
|
public void stop() throws Exception {
|
|
|
|
ExecutorPlugin runExecutorPlugin = new ExecutorPlugin();
|
|
|
|
SmartExecutorPluginQuery runQuery = new SmartExecutorPluginQuery(runExecutorPlugin);
|
|
|
|
runQuery.addConditions(ISExporterPluginDeclaration.NAME);
|
|
|
|
|
|
|
|
SpecificEndpointDiscoveryFilter sedf = new SpecificEndpointDiscoveryFilter("http://pc-frosini.isti.cnr.it:8080/smart-executor/gcube/vremanagement/smart-executor");
|
|
|
|
runQuery.setEndpointDiscoveryFilter(sedf);
|
|
|
|
SmartExecutorProxy proxy = new ProxyBuilderImpl<SmartExecutor, SmartExecutorProxy>(runExecutorPlugin, runQuery).build();
|
|
|
|
|
2017-05-17 18:05:49 +02:00
|
|
|
Assert.assertNotNull(proxy);
|
2017-11-21 16:32:32 +01:00
|
|
|
proxy.stop("321d8640-1b9f-4529-ba23-588ff2f17625");
|
2017-05-17 10:46:00 +02:00
|
|
|
}
|
2017-11-21 16:32:32 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void launchTest() throws Exception {
|
2017-05-17 10:46:00 +02:00
|
|
|
|
2017-11-21 16:32:32 +01:00
|
|
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
|
|
|
inputs.put(ISExporterPlugin.FILTERED_REPORT, true);
|
|
|
|
logger.debug("Inputs : {}", inputs);
|
|
|
|
|
|
|
|
LaunchParameter parameter = new LaunchParameter(ISExporterPluginDeclaration.NAME, inputs);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
ExecutorPlugin runExecutorPlugin = new ExecutorPlugin();
|
|
|
|
SmartExecutorPluginQuery runQuery = new SmartExecutorPluginQuery(runExecutorPlugin);
|
|
|
|
runQuery.addConditions(ISExporterPluginDeclaration.NAME);
|
|
|
|
|
|
|
|
SpecificEndpointDiscoveryFilter sedf = new SpecificEndpointDiscoveryFilter("http://pc-frosini.isti.cnr.it:8080/smart-executor/gcube/vremanagement/smart-executor");
|
|
|
|
runQuery.setEndpointDiscoveryFilter(sedf);
|
|
|
|
SmartExecutorProxy proxy = new ProxyBuilderImpl<SmartExecutor, SmartExecutorProxy>(runExecutorPlugin, runQuery).build();
|
|
|
|
|
|
|
|
String uuidString = proxy.launch(parameter);
|
|
|
|
UUID uuid = UUID.fromString(uuidString);
|
|
|
|
logger.debug("Launched with UUID : {}", uuid);
|
|
|
|
} catch(Exception e){
|
|
|
|
logger.error("Error launching sheduled task", e);
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-07-19 16:58:36 +02:00
|
|
|
*/
|
2017-05-17 10:46:00 +02:00
|
|
|
}
|