diff --git a/pom.xml b/pom.xml index 6a0ea62..98efe71 100644 --- a/pom.xml +++ b/pom.xml @@ -154,6 +154,14 @@ [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) test + + + org.gcube.information-system + is-exporter-se-plugin + [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + test + + org.acme HelloWorldPlugin diff --git a/src/test/java/org/gcube/informationsystem/exporter/ISExporterPluginSmartExecutorSchedulerTest.java b/src/test/java/org/gcube/informationsystem/exporter/ISExporterPluginSmartExecutorSchedulerTest.java new file mode 100644 index 0000000..ef9788c --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/exporter/ISExporterPluginSmartExecutorSchedulerTest.java @@ -0,0 +1,90 @@ +/** + * + */ +package org.gcube.informationsystem.exporter; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +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; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +public class ISExporterPluginSmartExecutorSchedulerTest extends ScopedTest { + + private static Logger logger = LoggerFactory.getLogger(ISExporterPluginSmartExecutorSchedulerTest.class); + + private SmartExecutorProxy proxy; + + @Before + public void before() throws Exception{ + proxy = ExecutorPlugin.getExecutorProxy(ISExporterPluginDeclaration.NAME).build(); + Assert.assertNotNull(proxy); + } + + public UUID scheduleTest(Scheduling scheduling) throws Exception { + Map inputs = new HashMap(); + logger.debug("Inputs : {}", inputs); + + + LaunchParameter parameter = new LaunchParameter(ISExporterPluginDeclaration.NAME, inputs); + if(scheduling!=null){ + parameter.setScheduling(scheduling); + } + + try { + String uuidString = proxy.launch(parameter); + return UUID.fromString(uuidString); + } catch(Exception e){ + logger.error("Error launching sheduled task", e); + throw e; + } + + } + + @Test + public void cronExpPreviousMustBeTerminated() throws Exception { + + Map tokenMinutes = new HashMap<>(); + tokenMinutes.put(ScopedTest.GCUBE, "1"); + tokenMinutes.put(ScopedTest.GCUBE_DEVSEC, "20"); + tokenMinutes.put(ScopedTest.GCUBE_DEVSEC_DEVVRE, "30"); + tokenMinutes.put(ScopedTest.GCUBE_DEVNEXT, "40"); + tokenMinutes.put(ScopedTest.GCUBE_DEVNEXT_NEXTNEXT, "50"); + + + 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"); + } + + + } + + //@Test + public void unSchedule() throws Exception { + proxy.unSchedule(null, true); + } + +} diff --git a/src/test/java/org/gcube/informationsystem/resource_checker/utils/SendNotification.java b/src/test/java/org/gcube/informationsystem/resource_checker/utils/SendNotification.java new file mode 100644 index 0000000..625da04 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/resource_checker/utils/SendNotification.java @@ -0,0 +1,21 @@ +package org.gcube.informationsystem.resource_checker.utils; + +import java.util.Map; + +import org.gcube.vremanagement.executor.plugin.PluginStateEvolution; +import org.gcube.vremanagement.executor.plugin.PluginStateNotification; + +public class SendNotification extends PluginStateNotification{ + + public SendNotification(Map inputs) { + super(inputs); + // TODO Auto-generated constructor stub + } + + @Override + public void pluginStateEvolution(PluginStateEvolution pluginStateEvolution, Exception exception) throws Exception { + // TODO Auto-generated method stub + + } + +} diff --git a/src/test/java/org/gcube/informationsystem/socialdataindexer/ResourceCheckerPluginSmartExecutorSchedulerTest.java b/src/test/java/org/gcube/informationsystem/socialdataindexer/ResourceCheckerPluginSmartExecutorSchedulerTest.java new file mode 100644 index 0000000..bc7e652 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/socialdataindexer/ResourceCheckerPluginSmartExecutorSchedulerTest.java @@ -0,0 +1,71 @@ +package org.gcube.informationsystem.socialdataindexer; + +import java.util.HashMap; +import java.util.Map; + +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.informationsystem.resource_checker.utils.SendNotification; +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; + + +/** + * Launch the ResourceCheckerPlugin + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class ResourceCheckerPluginSmartExecutorSchedulerTest { + + private static Logger logger = LoggerFactory.getLogger(ResourceCheckerPluginSmartExecutorSchedulerTest.class); + private SmartExecutorProxy proxy; + + @Before + public void before() throws Exception{ + ScopeProvider.instance.set("/gcube"); + SecurityTokenProvider.instance.set("2c56a96d-5f17-41a0-94a8-b8efa44d9e7c-98187548"); // gcube scope, ResourceCheckerPlugin application + proxy = ExecutorPlugin.getExecutorProxy("resource-checker-se-plugin").build(); + Assert.assertNotNull(proxy); + } + + @Test + public void cronExpPreviousMustBeTerminated() throws Exception { + //CronExpression cronExpression = new CronExpression("0 0 0/4 * * ? *"); // every 30 minutes starting from now + CronExpression cronExpression = new CronExpression("0 0 0/1 * * ?"); // every 30 minutes starting from now + Scheduling scheduling = new Scheduling(cronExpression, true); + scheduling.setGlobal(true); + + Map inputs = new HashMap(); + inputs.put("role", "Administrator"); + logger.debug("Inputs : {}", inputs); + LaunchParameter parameter = new LaunchParameter("resource-checker-se-plugin", inputs); + Map inputsNotification = new HashMap(); + inputsNotification.put("recipient", "costantino.perciante"); + parameter.addPluginStateNotifications(SendNotification.class, inputsNotification); + parameter.setScheduling(scheduling); + + try { + String uuidString = proxy.launch(parameter); + logger.info("Launched with UUID : {}" + uuidString); + } catch(Exception e){ + logger.error("Error launching sheduled task" + e); + throw e; + } + + } + + //@Test + public void unSchedule() throws Exception { + String id = "c2918249-4644-47fb-b151-8f8448f67f05"; + //proxy.unSchedule(id, true); + proxy.stop(id); + } + +} diff --git a/src/test/java/org/gcube/testutility/ScopedTest.java b/src/test/java/org/gcube/testutility/ScopedTest.java index 7a07e83..314bdfe 100644 --- a/src/test/java/org/gcube/testutility/ScopedTest.java +++ b/src/test/java/org/gcube/testutility/ScopedTest.java @@ -39,6 +39,11 @@ public class ScopedTest { public static final String GCUBE_DEVSEC_DEVVRE_VARNAME = "GCUBE_DEVSEC_DEVVRE"; public static final String GCUBE_DEVSEC_DEVVRE; + + public static final String GCUBE_VARNAME = "GCUBE"; + public static final String GCUBE; + + public static final String DEFAULT_TEST_SCOPE; public static final String ALTERNATIVE_TEST_SCOPE; @@ -59,8 +64,10 @@ public class ScopedTest { GCUBE_DEVSEC = properties.getProperty(GCUBE_DEVSEC_VARNAME); GCUBE_DEVSEC_DEVVRE = properties.getProperty(GCUBE_DEVSEC_DEVVRE_VARNAME); + GCUBE = properties.getProperty(GCUBE_VARNAME); + DEFAULT_TEST_SCOPE = GCUBE_DEVNEXT; - ALTERNATIVE_TEST_SCOPE = GCUBE_DEVSEC; + ALTERNATIVE_TEST_SCOPE = GCUBE_DEVSEC_DEVVRE; } public static String getCurrentScope(String token) throws ObjectNotFound, Exception{ diff --git a/src/test/java/org/gcube/vremanagement/executor/client/DefaultExecutorTest.java b/src/test/java/org/gcube/vremanagement/executor/client/DefaultExecutorTest.java index 5a79989..87ea0e7 100644 --- a/src/test/java/org/gcube/vremanagement/executor/client/DefaultExecutorTest.java +++ b/src/test/java/org/gcube/vremanagement/executor/client/DefaultExecutorTest.java @@ -36,7 +36,7 @@ public class DefaultExecutorTest extends ScopedTest { @Before public void before() throws Exception{ - proxy = ExecutorPlugin.getExecutorProxy().build(); + proxy = ExecutorPlugin.getExecutorProxy("HelloWorld").build(); Assert.assertNotNull(proxy); }