2019-09-20 15:20:40 +02:00
|
|
|
package org.gcube.vremanagement.executor.client;
|
|
|
|
|
2019-09-24 14:59:43 +02:00
|
|
|
import java.io.IOException;
|
2019-09-24 16:55:13 +02:00
|
|
|
import java.util.HashMap;
|
2019-09-24 14:59:43 +02:00
|
|
|
import java.util.List;
|
2019-09-24 16:55:13 +02:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
2019-09-24 14:59:43 +02:00
|
|
|
|
2019-09-24 16:55:13 +02:00
|
|
|
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
|
|
|
import org.gcube.vremanagement.executor.api.types.Scheduling;
|
2019-09-26 12:53:25 +02:00
|
|
|
import org.gcube.vremanagement.executor.client.query.Discover;
|
2019-09-24 14:59:43 +02:00
|
|
|
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
|
2019-09-24 16:55:13 +02:00
|
|
|
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
|
|
|
|
import org.gcube.vremanagement.executor.plugin.ScheduledTask;
|
|
|
|
import org.gcube.vremanagement.helloworld.HelloWorldPlugin;
|
|
|
|
import org.gcube.vremanagement.helloworld.HelloWorldPluginDeclaration;
|
2019-09-20 15:20:40 +02:00
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
2019-09-24 14:59:43 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2019-09-20 15:20:40 +02:00
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
2019-09-24 16:55:13 +02:00
|
|
|
public class SmartExecutorClientTest extends ContextTest {
|
2019-09-20 15:20:40 +02:00
|
|
|
|
2019-09-24 14:59:43 +02:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(SmartExecutorClientTest.class);
|
|
|
|
|
2019-09-20 15:20:40 +02:00
|
|
|
public static final String HTTP_ADDRESS = "http://smartexecutor.d4science.org:8090/smart-executor/rest";
|
|
|
|
public static final String HTTPS_ADDRESS = "https://smartexecutor.d4science.org:8090/smart-executor/rest";
|
|
|
|
public static final String HOST = "smartexecutor.d4science.org";
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSetAddress() {
|
|
|
|
SmartExecutorClientImpl smartExecutorClient = new SmartExecutorClientImpl();
|
|
|
|
smartExecutorClient.setAddress(HTTP_ADDRESS);
|
|
|
|
|
|
|
|
Assert.assertTrue(smartExecutorClient.getAddress().compareTo(HTTP_ADDRESS) == 0);
|
|
|
|
Assert.assertTrue(smartExecutorClient.getHost().compareTo(HOST) == 0);
|
|
|
|
|
|
|
|
smartExecutorClient.setAddress(HTTPS_ADDRESS);
|
|
|
|
Assert.assertTrue(smartExecutorClient.getAddress().compareTo(HTTPS_ADDRESS) == 0);
|
|
|
|
Assert.assertTrue(smartExecutorClient.getHost().compareTo(HOST) == 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-24 16:55:13 +02:00
|
|
|
private LaunchParameter getLaunchParameter() {
|
|
|
|
Scheduling scheduling = new Scheduling(20);
|
2019-09-26 12:53:25 +02:00
|
|
|
Map<String,Object> inputs = new HashMap<String,Object>();
|
2019-09-24 16:55:13 +02:00
|
|
|
inputs.put(HelloWorldPlugin.SLEEP_TIME, TimeUnit.SECONDS.toMillis(10));
|
|
|
|
inputs.put("TestUUID", UUID.randomUUID());
|
2019-09-26 12:53:25 +02:00
|
|
|
|
2019-09-24 16:55:13 +02:00
|
|
|
LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs);
|
|
|
|
launchParameter.setScheduling(scheduling);
|
|
|
|
|
|
|
|
return launchParameter;
|
|
|
|
}
|
|
|
|
|
2019-12-04 09:57:49 +01:00
|
|
|
@Test
|
|
|
|
public void testServiceInteraction() throws Exception {
|
|
|
|
SmartExecutorClientFactory.forceURL("http://pc-frosini.isti.cnr.it:8080/smart-executor");
|
|
|
|
|
2019-09-24 16:55:13 +02:00
|
|
|
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
|
|
|
|
logger.debug("Going to test smart executor using {} plugin", helloWorldPluginDeclaration.getName());
|
2019-09-26 12:53:25 +02:00
|
|
|
SmartExecutorClient smartExecutorClient = SmartExecutorClientFactory
|
|
|
|
.getClient(helloWorldPluginDeclaration.getName());
|
2019-09-24 16:55:13 +02:00
|
|
|
String host = smartExecutorClient.getHost();
|
|
|
|
Assert.assertTrue(host.contains("pc-frosini.isti.cnr.it"));
|
|
|
|
|
|
|
|
List<PluginDeclaration> plugins = smartExecutorClient.getPlugins();
|
2019-09-26 12:53:25 +02:00
|
|
|
Assert.assertTrue(plugins.size() == 1);
|
2019-09-24 16:55:13 +02:00
|
|
|
PluginDeclaration pluginDeclaration = plugins.get(0);
|
|
|
|
|
2019-09-26 12:53:25 +02:00
|
|
|
Assert.assertTrue(pluginDeclaration.getName().compareTo(helloWorldPluginDeclaration.getName()) == 0);
|
|
|
|
Assert.assertTrue(
|
|
|
|
pluginDeclaration.getDescription().compareTo(helloWorldPluginDeclaration.getDescription()) == 0);
|
|
|
|
Assert.assertTrue(pluginDeclaration.getVersion().compareTo(helloWorldPluginDeclaration.getVersion()) == 0);
|
|
|
|
Assert.assertTrue(pluginDeclaration.getSupportedCapabilities()
|
|
|
|
.equals(helloWorldPluginDeclaration.getSupportedCapabilities()));
|
2019-09-24 16:55:13 +02:00
|
|
|
|
|
|
|
List<ScheduledTask> orphans = smartExecutorClient.getOrphanScheduledLaunches();
|
|
|
|
for(ScheduledTask orphan : orphans) {
|
|
|
|
boolean removed = smartExecutorClient.delete(orphan.getUUID(), true);
|
|
|
|
Assert.assertTrue(removed);
|
|
|
|
}
|
|
|
|
orphans = smartExecutorClient.getOrphanScheduledLaunches();
|
2019-09-26 12:53:25 +02:00
|
|
|
Assert.assertTrue(orphans.size() == 0);
|
2019-09-24 16:55:13 +02:00
|
|
|
|
|
|
|
LaunchParameter launchParameter = getLaunchParameter();
|
|
|
|
|
|
|
|
UUID executionIdentifier = smartExecutorClient.launch(launchParameter);
|
|
|
|
|
|
|
|
List<ScheduledTask> launches = smartExecutorClient.getScheduledLaunches();
|
2019-09-26 12:53:25 +02:00
|
|
|
Assert.assertTrue(launches.size() == 1);
|
2019-09-24 16:55:13 +02:00
|
|
|
ScheduledTask scheduledTask = launches.get(0);
|
2019-09-26 12:53:25 +02:00
|
|
|
Assert.assertTrue(scheduledTask.getUUID().compareTo(executionIdentifier) == 0);
|
2019-09-24 16:55:13 +02:00
|
|
|
|
|
|
|
PluginStateEvolution pluginStateEvolution = smartExecutorClient.getPluginStateEvolution(executionIdentifier);
|
2019-09-26 12:53:25 +02:00
|
|
|
Assert.assertTrue(pluginStateEvolution.getUUID().compareTo(executionIdentifier) == 0);
|
2019-09-24 16:55:13 +02:00
|
|
|
|
|
|
|
pluginStateEvolution = smartExecutorClient.getPluginStateEvolution(executionIdentifier, 1);
|
2019-09-26 12:53:25 +02:00
|
|
|
Assert.assertTrue(pluginStateEvolution.getUUID().compareTo(executionIdentifier) == 0);
|
2019-09-24 16:55:13 +02:00
|
|
|
|
|
|
|
boolean removed = smartExecutorClient.delete(executionIdentifier, true);
|
|
|
|
Assert.assertTrue(removed);
|
|
|
|
|
|
|
|
orphans = smartExecutorClient.getOrphanScheduledLaunches();
|
2019-09-26 12:53:25 +02:00
|
|
|
Assert.assertTrue(orphans.size() == 0);
|
2019-09-24 16:55:13 +02:00
|
|
|
|
2019-09-24 14:59:43 +02:00
|
|
|
}
|
2019-09-24 16:55:13 +02:00
|
|
|
|
2019-09-26 12:53:25 +02:00
|
|
|
@Test
|
|
|
|
public void uiTest() throws IOException {
|
|
|
|
List<String> hosts2Contect = Discover.getInstancesAddress();
|
|
|
|
boolean first = true;
|
|
|
|
for(String host : hosts2Contect) {
|
|
|
|
logger.debug("Host {}", SmartExecutorClientImpl.getHostFromCompleteURL(host));
|
|
|
|
SmartExecutorClientImpl client = new SmartExecutorClientImpl();
|
|
|
|
client.setAddress(host);
|
|
|
|
List<PluginDeclaration> plugins = client.getPlugins();
|
|
|
|
for(PluginDeclaration p : plugins) {
|
|
|
|
logger.debug("\tPlugin {}", p);
|
|
|
|
client.setPluginName(p.getName());
|
|
|
|
List<ScheduledTask> tasks = client.getScheduledLaunches();
|
|
|
|
for(ScheduledTask t : tasks) {
|
|
|
|
logger.debug("\t\tTask {}", t);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if(first) {
|
|
|
|
first = false;
|
|
|
|
List<ScheduledTask> orphansTasks = client.getOrphanScheduledLaunches();
|
|
|
|
for(ScheduledTask t : orphansTasks) {
|
|
|
|
logger.debug("Orphan Tasks {}" + t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-20 15:20:40 +02:00
|
|
|
}
|