Implementing client

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor-client@111734 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-02-05 15:29:38 +00:00
parent a4ea63516d
commit 24f6c6db3e
2 changed files with 136 additions and 0 deletions

View File

@ -0,0 +1,70 @@
/**
*
*/
package org.gcube.vremanagement.executor.client;
import javax.xml.ws.EndpointReference;
import org.gcube.common.calls.jaxws.StubFactory;
import org.gcube.common.clients.Plugin;
import org.gcube.common.clients.ProxyBuilder;
import org.gcube.common.clients.ProxyBuilderImpl;
import org.gcube.common.clients.config.ProxyConfig;
import org.gcube.common.clients.delegates.ProxyDelegate;
import org.gcube.vremanagement.executor.api.Executor;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class ExecutorPlugin implements Plugin<Executor, ExecutorProxy> {
private static final ExecutorPlugin executorPlugin = new ExecutorPlugin();
public static ProxyBuilder<ExecutorProxy> getExecutorProxy() {
return new ProxyBuilderImpl<Executor, ExecutorProxy>(executorPlugin);
}
/** {@inheritDoc} */
@Override
public Exception convert(Exception e, ProxyConfig<?, ?> proxy) {
return e;
}
/** {@inheritDoc} */
@Override
public String name() {
return ExecutorProxy.SERVICE_NAME + "/" + Executor.SERVICE_NAME;
}
/** {@inheritDoc} */
@Override
public String namespace() {
return ExecutorProxy.NAMESPACE;
}
/** {@inheritDoc} */
@Override
public ExecutorProxy newProxy(ProxyDelegate<Executor> proxyDelegate) {
return new DefaultExecutorProxy(proxyDelegate);
}
/** {@inheritDoc} */
@Override
public Executor resolve(EndpointReference endpoint, ProxyConfig<?, ?> proxyConfig) throws Exception {
return StubFactory.stubFor(ExecutorProxy.executor).at(endpoint);
}
/** {@inheritDoc} */
@Override
public String serviceClass() {
return ExecutorProxy.SERVICE_CLASS;
}
/** {@inheritDoc} */
@Override
public String serviceName() {
return ExecutorProxy.SERVICE_NAME;
}
}

View File

@ -0,0 +1,66 @@
/**
*
*/
package org.gcube.vremanagement.executor.client;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.exception.ExecutorException;
import org.gcube.vremanagement.executor.exception.InputsNullException;
import org.gcube.vremanagement.executor.exception.LaunchException;
import org.gcube.vremanagement.executor.exception.PluginInstanceNotFoundException;
import org.gcube.vremanagement.executor.exception.PluginNotFoundException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class DefaultExecutorTest {
/**
* Logger
*/
private static Logger logger = LoggerFactory.getLogger(DefaultExecutorTest.class);
private ExecutorProxy proxy;
@Before
public void init(){
ScopeProvider.instance.set("/gcube");
proxy = ExecutorPlugin.getExecutorProxy().build();
Assert.assertNotNull(proxy);
}
@Test
public void launch() {
Map<String, Object> inputs = new HashMap<String, Object>();
LaunchParameter launchParameter = new LaunchParameter("Test", inputs);
try {
proxy.launch(launchParameter);
} catch (Exception e) {
Assert.assertEquals(PluginNotFoundException.class, e.getClass());
}
}
@Test
public void getState() {
String executionIdentifier = UUID.randomUUID().toString();
try {
proxy.getState(executionIdentifier);
} catch (Exception e) {
Assert.assertEquals(PluginInstanceNotFoundException.class, e.getClass());
}
}
}