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); } }