/** * */ package org.gcube.informationsystem.exporter; import java.io.File; 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.gcube.vremanagement.executor.plugin.PluginStateEvolution; import org.junit.Assert; import org.junit.Test; import org.quartz.CronExpression; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; /** * @author Luca Frosini (ISTI - CNR) */ public class ISExporterPluginSmartExecutorSchedulerTest extends ScopedTest { private static Logger logger = LoggerFactory.getLogger(ISExporterPluginSmartExecutorSchedulerTest.class); public UUID scheduleTest(Scheduling scheduling) throws Exception { Map inputs = new HashMap(); inputs.put(ISExporterPlugin.FILTERED_REPORT, true); logger.debug("Inputs : {}", inputs); LaunchParameter parameter = new LaunchParameter(ISExporterPluginDeclaration.NAME, inputs); if(scheduling!=null){ parameter.setScheduling(scheduling); } try { SmartExecutorProxy proxy = ExecutorPlugin.getExecutorProxy(ISExporterPluginDeclaration.NAME).build(); Assert.assertNotNull(proxy); String uuidString = proxy.launch(parameter); return UUID.fromString(uuidString); } catch(Exception e){ logger.error("Error launching sheduled task", e); throw e; } } @Test 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 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()); //UUID uuid = scheduleTest(scheduling); //logger.debug("Launched with UUID : {}", uuid); logger.info("\n\n\n"); } } @Test public void cronExpPreviousMustBeTerminated() throws Exception { Map tokenMinutes = new HashMap<>(); 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"); 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 getState() throws Exception { SmartExecutorProxy proxy = ExecutorPlugin.getExecutorProxy(ISExporterPluginDeclaration.NAME).build(); Assert.assertNotNull(proxy); PluginStateEvolution pluginStateEvolution = proxy.getStateEvolution(""); logger.debug("{}", pluginStateEvolution); } @Test public void unSchedule() throws Exception { SmartExecutorProxy proxy = ExecutorPlugin.getExecutorProxy(ISExporterPluginDeclaration.NAME).build(); Assert.assertNotNull(proxy); //proxy.unSchedule(null, true); } }