Implementing client proxy supporting queries
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor-client@111996 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
caa7994344
commit
fabf1d2910
7
pom.xml
7
pom.xml
|
@ -57,7 +57,12 @@
|
|||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.acme</groupId>
|
||||
<artifactId>HelloWorldPlugin</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -64,8 +64,8 @@ public class SmartExecutorPluginQuery implements Query<EndpointReference> {
|
|||
String propertyVariableName = String.format("$property%d", i);
|
||||
smartExecutorDiscoveryQuery
|
||||
.addVariable(propertyVariableName, "$accessPoint/Properties/Property")
|
||||
.addCondition(String.format("%s/Name/text()", propertyVariableName, tuple.getName()))
|
||||
.addCondition(String.format("%s/Value/text()", propertyVariableName, tuple.getValue()));
|
||||
.addCondition(String.format("%s/Name/text() eq '%s'", propertyVariableName, tuple.getName()))
|
||||
.addCondition(String.format("%s/Value/text() eq '%s'", propertyVariableName, tuple.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,6 +75,10 @@ public class SmartExecutorPluginQuery implements Query<EndpointReference> {
|
|||
|
||||
List<ServiceEndpoint> serviceEndpoints = smartExecutorDiscoveryClient.submit(smartExecutorDiscoveryQuery);
|
||||
|
||||
if(serviceEndpoints.size() == 0){
|
||||
throw new DiscoveryException("No running SmartExecutor wich match the requested conditions");
|
||||
}
|
||||
|
||||
/* Getting randomly one the host */
|
||||
Random random = new Random();
|
||||
int i = random.nextInt() % serviceEndpoints.size();
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.acme.HelloWorldPluginDeclaration;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||
import org.gcube.vremanagement.executor.client.plugins.ExecutorPlugin;
|
||||
|
@ -60,7 +61,7 @@ public class DefaultExecutorTest {
|
|||
public void testOk() {
|
||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||
inputs.put("Hello", "World");
|
||||
LaunchParameter launchParameter = new LaunchParameter("HelloWorld", inputs);
|
||||
LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs);
|
||||
try {
|
||||
String executionIdentifier = proxy.launch(launchParameter);
|
||||
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.client;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.acme.HelloWorldPluginDeclaration;
|
||||
import org.gcube.common.clients.exceptions.DiscoveryException;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||
import org.gcube.vremanagement.executor.client.plugins.ExecutorPlugin;
|
||||
import org.gcube.vremanagement.executor.client.proxies.SmartExecutorProxy;
|
||||
import org.gcube.vremanagement.executor.client.util.Tuple;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class QueriedClientTest {
|
||||
|
||||
private void lauchTest(SmartExecutorProxy proxy) throws Exception {
|
||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||
inputs.put("Hello", "World");
|
||||
LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs);
|
||||
try {
|
||||
String executionIdentifier = proxy.launch(launchParameter);
|
||||
proxy.getState(executionIdentifier);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoConditions() {
|
||||
ScopeProvider.instance.set("/gcube");
|
||||
SmartExecutorProxy proxy = ExecutorPlugin.getExecutorProxy(HelloWorldPluginDeclaration.NAME).build();
|
||||
Assert.assertNotNull(proxy);
|
||||
|
||||
try {
|
||||
lauchTest(proxy);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithSingleRighConditions() {
|
||||
ScopeProvider.instance.set("/gcube");
|
||||
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
|
||||
Map<String,String> map = helloWorldPluginDeclaration.getSupportedCapabilities();
|
||||
Tuple<String, String> tuple = new Tuple<String, String>();
|
||||
for(String key : map.keySet()){
|
||||
tuple = new Tuple<String, String>(key, map.get(key));
|
||||
break; // Get only the first
|
||||
}
|
||||
SmartExecutorProxy proxy = ExecutorPlugin.getExecutorProxy(HelloWorldPluginDeclaration.NAME, tuple).build();
|
||||
Assert.assertNotNull(proxy);
|
||||
|
||||
try {
|
||||
lauchTest(proxy);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithMultipleRighConditions() {
|
||||
ScopeProvider.instance.set("/gcube");
|
||||
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
|
||||
Map<String,String> map = helloWorldPluginDeclaration.getSupportedCapabilities();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Tuple<String, String>[] tuples = new Tuple[map.size()+1];
|
||||
|
||||
int i = 0;
|
||||
for(String key : map.keySet()){
|
||||
tuples[i] = new Tuple<String, String>(key, map.get(key));
|
||||
++i;
|
||||
}
|
||||
|
||||
tuples[i] = new Tuple<String, String>("Version", helloWorldPluginDeclaration.getVersion());
|
||||
|
||||
SmartExecutorProxy proxy = ExecutorPlugin.getExecutorProxy(HelloWorldPluginDeclaration.NAME, tuples).build();
|
||||
Assert.assertNotNull(proxy);
|
||||
|
||||
try {
|
||||
lauchTest(proxy);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithUnsatisfiedConditions() {
|
||||
ScopeProvider.instance.set("/gcube");
|
||||
Tuple<String, String> tuple = new Tuple<String, String>("Unsatisfied", "Condition");
|
||||
SmartExecutorProxy proxy = ExecutorPlugin.getExecutorProxy(HelloWorldPluginDeclaration.NAME, tuple).build();
|
||||
Assert.assertNotNull(proxy);
|
||||
try {
|
||||
lauchTest(proxy);
|
||||
} catch (Exception e) {
|
||||
Assert.assertEquals(DiscoveryException.class, e.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue