Removing OLD SOAP APIs which causes conflicts
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor-client@177261 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
77357fb01c
commit
bb4aa843cf
12
pom.xml
12
pom.xml
|
@ -9,7 +9,7 @@
|
|||
|
||||
<groupId>org.gcube.vremanagement</groupId>
|
||||
<artifactId>smart-executor-client</artifactId>
|
||||
<version>1.7.0-SNAPSHOT</version>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<description>Smart Executor Service Client Library</description>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
@ -57,7 +57,15 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.vremanagement</groupId>
|
||||
<artifactId>smart-executor-api</artifactId>
|
||||
<version>[1.7.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>gxHTTP</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.core</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
package org.gcube.vremanagement.executor.client;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.gcube.common.calls.jaxws.GcubeService;
|
||||
import org.gcube.vremanagement.executor.api.SmartExecutor;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
|
@ -15,27 +10,4 @@ public class Constants {
|
|||
public static final String SERVICE_NAME = "SmartExecutor";
|
||||
public static final String SERVICE_ENTRY_NAME = "org.gcube.vremanagement.executor.ResourceInitializer";
|
||||
|
||||
|
||||
/* Used for SOAP */
|
||||
|
||||
/* Must be the same of generated WEB-INF/gcube-app.xml */
|
||||
/**
|
||||
* Use SERVICE_CLASS instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String GCUBE_SERVICE_CLASS = SERVICE_CLASS;
|
||||
/**
|
||||
* Use SERVICE_NAME instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String GCUBE_SERVICE_NAME = SERVICE_NAME;
|
||||
|
||||
@Deprecated
|
||||
public static final QName SMART_EXECUTOR_QNAME = new QName(SmartExecutor.TARGET_NAMESPACE, SmartExecutor.WEB_SERVICE_SERVICE_NAME);
|
||||
@Deprecated
|
||||
public static final GcubeService<SmartExecutor> smartExecutor = GcubeService.service().withName(SMART_EXECUTOR_QNAME).andInterface(SmartExecutor.class);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package org.gcube.vremanagement.executor.client;
|
||||
|
||||
import org.gcube.vremanagement.executor.api.rest.SmartExecutor;
|
||||
|
||||
public interface SmartExecutorClient extends SmartExecutor {
|
||||
|
||||
}
|
|
@ -5,30 +5,20 @@ import java.util.Map;
|
|||
import java.util.Random;
|
||||
|
||||
import org.gcube.vremanagement.executor.api.rest.SmartExecutor;
|
||||
import org.gcube.vremanagement.executor.client.plugins.ExecutorPlugin;
|
||||
import org.gcube.vremanagement.executor.client.plugins.query.SmartExecutorPluginQuery;
|
||||
import org.gcube.vremanagement.executor.client.query.Discover;
|
||||
import org.gcube.vremanagement.executor.client.query.filter.GCoreEndpointQueryFilter;
|
||||
import org.gcube.vremanagement.executor.client.query.filter.ServiceEndpointQueryFilter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class SmartExecutorClientFactory {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SmartExecutorClientFactory.class);
|
||||
|
||||
private static String FORCED_URL = null;
|
||||
|
||||
protected static void forceToURL(String url) {
|
||||
FORCED_URL = url;
|
||||
}
|
||||
|
||||
public static SmartExecutor create(String pluginName, Map<String,String> capabilites,
|
||||
ServiceEndpointQueryFilter serviceEndpointQueryFilter, GCoreEndpointQueryFilter gCoreEndpointQueryFilter) {
|
||||
public static SmartExecutor create(String pluginName, Map<String,String> capabilites) {
|
||||
|
||||
if(FORCED_URL != null) {
|
||||
return new SmartExecutorClientImpl(pluginName, FORCED_URL);
|
||||
|
@ -37,36 +27,15 @@ public class SmartExecutorClientFactory {
|
|||
Discover discover = new Discover(Constants.SERVICE_ENTRY_NAME);
|
||||
discover.filterByPluginName(pluginName);
|
||||
discover.filterByCapabilities(capabilites);
|
||||
discover.setServiceEndpointQueryFilter(serviceEndpointQueryFilter);
|
||||
discover.setGCoreEndpointQueryFilter(gCoreEndpointQueryFilter);
|
||||
List<String> addresses = discover.getAddresses();
|
||||
|
||||
if(addresses == null || addresses.isEmpty()) {
|
||||
logger.debug("No REST smart-executor found. Looking for old SOAP Version");
|
||||
|
||||
ExecutorPlugin executorPlugin = new ExecutorPlugin();
|
||||
discover = new SmartExecutorPluginQuery(executorPlugin);
|
||||
discover.filterByPluginName(pluginName);
|
||||
discover.filterByCapabilities(capabilites);
|
||||
discover.setServiceEndpointQueryFilter(serviceEndpointQueryFilter);
|
||||
discover.setGCoreEndpointQueryFilter(gCoreEndpointQueryFilter);
|
||||
|
||||
addresses = discover.getAddresses();
|
||||
if(addresses == null || addresses.isEmpty()) {
|
||||
String error = String.format("No %s:%s found in the current context", Constants.SERVICE_CLASS,
|
||||
Constants.SERVICE_NAME);
|
||||
throw new RuntimeException(error);
|
||||
}
|
||||
return new SmartExecutorClientSOAPWrapper((SmartExecutorPluginQuery) discover, executorPlugin);
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
int index = random.nextInt(addresses.size());
|
||||
return new SmartExecutorClientImpl(pluginName, addresses.get(index));
|
||||
}
|
||||
|
||||
public static SmartExecutor create(String pluginName) {
|
||||
return create(pluginName, null, null, null);
|
||||
public static SmartExecutor create(String pluginName, String address) {
|
||||
return new SmartExecutorClientImpl(pluginName, address);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
package org.gcube.vremanagement.executor.client;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.net.MalformedURLException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.ws.rs.ForbiddenException;
|
||||
import javax.ws.rs.NotFoundException;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
|
||||
import org.gcube.common.gxhttp.reference.GXConnection;
|
||||
import org.gcube.common.gxhttp.reference.GXConnection.HTTPMETHOD;
|
||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||
import org.gcube.vremanagement.executor.api.rest.RestConstants;
|
||||
import org.gcube.vremanagement.executor.api.rest.SmartExecutor;
|
||||
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||
import org.gcube.vremanagement.executor.client.util.HTTPCall;
|
||||
import org.gcube.vremanagement.executor.client.util.HTTPCall.HTTPMETHOD;
|
||||
import org.gcube.vremanagement.executor.exception.ExecutorException;
|
||||
import org.gcube.vremanagement.executor.exception.InputsNullException;
|
||||
import org.gcube.vremanagement.executor.exception.LaunchException;
|
||||
|
@ -24,7 +31,7 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class SmartExecutorClientImpl implements SmartExecutor {
|
||||
public class SmartExecutorClientImpl implements SmartExecutorClient {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SmartExecutorClientImpl.class);
|
||||
|
||||
|
@ -32,7 +39,6 @@ public class SmartExecutorClientImpl implements SmartExecutor {
|
|||
|
||||
protected final String pluginName;
|
||||
protected final String address;
|
||||
protected HTTPCall httpCall;
|
||||
|
||||
public SmartExecutorClientImpl(String pluginName, String address) {
|
||||
this.pluginName = pluginName;
|
||||
|
@ -40,11 +46,51 @@ public class SmartExecutorClientImpl implements SmartExecutor {
|
|||
|
||||
}
|
||||
|
||||
private HTTPCall getHTTPCall() throws MalformedURLException {
|
||||
if(httpCall == null) {
|
||||
httpCall = new HTTPCall(address, SmartExecutorClientImpl.class.getSimpleName());
|
||||
protected static StringBuilder getStringBuilder(InputStream inputStream) throws IOException {
|
||||
StringBuilder result = new StringBuilder();
|
||||
try(BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
String line;
|
||||
while((line = reader.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected String parseHttpURLConnection(HttpURLConnection connection) throws WebApplicationException {
|
||||
try {
|
||||
int responseCode = connection.getResponseCode();
|
||||
// String responseMessage = connection.getResponseMessage();
|
||||
|
||||
if(connection.getRequestMethod().compareTo(HTTPMETHOD.HEAD.toString()) == 0) {
|
||||
if(responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
|
||||
return null;
|
||||
}
|
||||
if(responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
if(responseCode == HttpURLConnection.HTTP_FORBIDDEN) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
}
|
||||
|
||||
if(responseCode >= HttpURLConnection.HTTP_BAD_REQUEST) {
|
||||
InputStream inputStream = connection.getErrorStream();
|
||||
StringBuilder result = getStringBuilder(inputStream);
|
||||
String res = result.toString();
|
||||
throw new WebApplicationException(res, responseCode);
|
||||
}
|
||||
|
||||
StringBuilder result = getStringBuilder(connection.getInputStream());
|
||||
return result.toString();
|
||||
} catch (WebApplicationException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new WebApplicationException(e);
|
||||
} finally {
|
||||
connection.disconnect();
|
||||
}
|
||||
return httpCall;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,14 +99,16 @@ public class SmartExecutorClientImpl implements SmartExecutor {
|
|||
try {
|
||||
|
||||
logger.info("Going to launch {} ", launchParameter);
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(RestConstants.PLUGINS_PATH_PART);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(pluginName);
|
||||
|
||||
HTTPCall httpCall = getHTTPCall();
|
||||
String uuid = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.POST, launchParameter);
|
||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
||||
gxHTTPStringRequest.from(SmartExecutorClient.class.getSimpleName());
|
||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
gxHTTPStringRequest.header("Accept", "text/plain");
|
||||
gxHTTPStringRequest.path(RestConstants.PLUGINS_PATH_PART);
|
||||
gxHTTPStringRequest.path(pluginName);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post(launchParameter);
|
||||
String uuid = parseHttpURLConnection(httpURLConnection);
|
||||
|
||||
logger.debug("{} launched with UUID {} ", pluginName, uuid);
|
||||
return uuid;
|
||||
|
@ -88,21 +136,22 @@ public class SmartExecutorClientImpl implements SmartExecutor {
|
|||
public String getPluginStateEvolution(String executionIdentifier, Integer iterationNumber) throws PluginInstanceNotFoundException, ExecutorException {
|
||||
try {
|
||||
logger.info("Going to get {} of {} with UUID {} ", PluginStateEvolution.class.getSimpleName(), pluginName, executionIdentifier);
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(RestConstants.PLUGINS_PATH_PART);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(pluginName);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(executionIdentifier);
|
||||
|
||||
HTTPCall httpCall = getHTTPCall();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
||||
gxHTTPStringRequest.from(SmartExecutorClient.class.getSimpleName());
|
||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
gxHTTPStringRequest.path(RestConstants.PLUGINS_PATH_PART);
|
||||
gxHTTPStringRequest.path(pluginName);
|
||||
gxHTTPStringRequest.path(executionIdentifier);
|
||||
|
||||
if(iterationNumber!=null) {
|
||||
parameters.put(RestConstants.ITERATION_NUMBER_PARAM, iterationNumber.intValue());
|
||||
Map<String, String> parameters = new HashMap<>();
|
||||
parameters.put(RestConstants.ITERATION_NUMBER_PARAM, Integer.toString(iterationNumber));
|
||||
gxHTTPStringRequest.queryParams(parameters);
|
||||
}
|
||||
|
||||
String pluginStateEvolution = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.GET, parameters);
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||
String pluginStateEvolution = parseHttpURLConnection(httpURLConnection);
|
||||
return pluginStateEvolution;
|
||||
} catch(ExecutorException e) {
|
||||
throw e;
|
||||
|
@ -127,18 +176,21 @@ public class SmartExecutorClientImpl implements SmartExecutor {
|
|||
public boolean delete(String executionIdentifier, boolean globally) throws ExecutorException {
|
||||
try {
|
||||
logger.info("Going to stop plugin with UUID {} ", executionIdentifier);
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(RestConstants.PLUGINS_PATH_PART);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(pluginName);
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(executionIdentifier);
|
||||
|
||||
HTTPCall httpCall = getHTTPCall();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put(RestConstants.GLOBALLY_PARAM, globally);
|
||||
Boolean stopped = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.DELETE, parameters);
|
||||
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
|
||||
gxHTTPStringRequest.from(SmartExecutorClient.class.getSimpleName());
|
||||
gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
gxHTTPStringRequest.path(RestConstants.PLUGINS_PATH_PART);
|
||||
gxHTTPStringRequest.path(pluginName);
|
||||
gxHTTPStringRequest.path(executionIdentifier);
|
||||
|
||||
Map<String, String> parameters = new HashMap<>();
|
||||
parameters.put(RestConstants.GLOBALLY_PARAM, Boolean.toString(globally));
|
||||
gxHTTPStringRequest.queryParams(parameters);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.delete();
|
||||
String stoppedString = parseHttpURLConnection(httpURLConnection);
|
||||
Boolean stopped = Boolean.valueOf(stoppedString);
|
||||
|
||||
logger.debug("Plugin with UUID {} {} stopped", executionIdentifier, stopped ? "successfully" : "was not");
|
||||
return stopped;
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
package org.gcube.vremanagement.executor.client;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.vremanagement.executor.api.rest.SmartExecutor;
|
||||
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||
import org.gcube.vremanagement.executor.client.plugins.ExecutorPlugin;
|
||||
import org.gcube.vremanagement.executor.client.plugins.query.SmartExecutorPluginQuery;
|
||||
import org.gcube.vremanagement.executor.client.proxies.SmartExecutorProxy;
|
||||
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.PluginNotFoundException;
|
||||
import org.gcube.vremanagement.executor.json.SEMapper;
|
||||
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* Added to launch plugins running on SOAP only old smart-executor
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
class SmartExecutorClientSOAPWrapper implements SmartExecutor {
|
||||
|
||||
public static final String PATH_SEPARATOR = "/";
|
||||
|
||||
protected SmartExecutorProxy smartExecutorProxy;
|
||||
|
||||
public SmartExecutorClientSOAPWrapper(SmartExecutorProxy smartExecutorProxy) {
|
||||
this.smartExecutorProxy = smartExecutorProxy;
|
||||
}
|
||||
|
||||
public SmartExecutorClientSOAPWrapper(SmartExecutorPluginQuery query, ExecutorPlugin executorPlugin) {
|
||||
this.smartExecutorProxy = ExecutorPlugin.getExecutorProxy(query, executorPlugin).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String launch(String launchParameter)
|
||||
throws InputsNullException, PluginNotFoundException, LaunchException, ExecutorException {
|
||||
try {
|
||||
LaunchParameter lp = SEMapper.unmarshal(LaunchParameter.class, launchParameter);
|
||||
try {
|
||||
return smartExecutorProxy.launch(lp);
|
||||
}catch (Exception e) {
|
||||
throw (Exception) e.getCause();
|
||||
}
|
||||
} catch(ExecutorException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ExecutorException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID launch(LaunchParameter launchParameter)
|
||||
throws InputsNullException, PluginNotFoundException, LaunchException, ExecutorException {
|
||||
try {
|
||||
try {
|
||||
String uuid = smartExecutorProxy.launch(launchParameter);
|
||||
return UUID.fromString(uuid);
|
||||
}catch (Exception e) {
|
||||
throw (Exception) e.getCause();
|
||||
}
|
||||
} catch(ExecutorException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginStateEvolution(String executionIdentifier, Integer iterationNumber) throws ExecutorException {
|
||||
try {
|
||||
try {
|
||||
PluginStateEvolution pluginStateEvolution = null;
|
||||
if(iterationNumber!=null) {
|
||||
pluginStateEvolution = smartExecutorProxy.getIterationStateEvolution(executionIdentifier, iterationNumber);
|
||||
}else {
|
||||
pluginStateEvolution = smartExecutorProxy.getStateEvolution(executionIdentifier);
|
||||
}
|
||||
return SEMapper.marshal(pluginStateEvolution);
|
||||
}catch (Exception e) {
|
||||
throw (Exception) e.getCause();
|
||||
}
|
||||
} catch(ExecutorException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new ExecutorException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginStateEvolution getPluginStateEvolution(UUID executionIdentifier, Integer iterationNumber) throws ExecutorException {
|
||||
try {
|
||||
try {
|
||||
PluginStateEvolution pluginStateEvolution = null;
|
||||
if(iterationNumber!=null) {
|
||||
pluginStateEvolution = smartExecutorProxy.getIterationStateEvolution(executionIdentifier.toString(), iterationNumber);
|
||||
}else {
|
||||
pluginStateEvolution = smartExecutorProxy.getStateEvolution(executionIdentifier.toString());
|
||||
}
|
||||
return pluginStateEvolution;
|
||||
}catch (Exception e) {
|
||||
throw (Exception) e.getCause();
|
||||
}
|
||||
} catch(ExecutorException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(String executionIdentifier, boolean globally) throws ExecutorException {
|
||||
return smartExecutorProxy.unSchedule(executionIdentifier, globally);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(UUID executionIdentifier, boolean globally) throws ExecutorException {
|
||||
return delete(executionIdentifier.toString(), globally);
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package org.gcube.vremanagement.executor.client.plugins;
|
||||
|
||||
import org.gcube.common.clients.Plugin;
|
||||
import org.gcube.vremanagement.executor.api.SmartExecutor;
|
||||
import org.gcube.vremanagement.executor.client.Constants;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
* @param <S>
|
||||
* @param <P>
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractPlugin<S,P> implements Plugin<S,P> {
|
||||
|
||||
public final String name;
|
||||
|
||||
public AbstractPlugin(String name) {
|
||||
this.name=name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serviceClass() {
|
||||
return Constants.GCUBE_SERVICE_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serviceName() {
|
||||
return Constants.GCUBE_SERVICE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return SmartExecutor.TARGET_NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,120 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.client.plugins;
|
||||
|
||||
import javax.xml.ws.EndpointReference;
|
||||
|
||||
import org.gcube.common.calls.jaxws.StubFactory;
|
||||
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.SmartExecutor;
|
||||
import org.gcube.vremanagement.executor.client.Constants;
|
||||
import org.gcube.vremanagement.executor.client.SmartExecutorClientFactory;
|
||||
import org.gcube.vremanagement.executor.client.plugins.query.SmartExecutorPluginQuery;
|
||||
import org.gcube.vremanagement.executor.client.plugins.query.filter.EndpointDiscoveryFilter;
|
||||
import org.gcube.vremanagement.executor.client.plugins.query.filter.ServiceEndpointQueryFilter;
|
||||
import org.gcube.vremanagement.executor.client.proxies.DefaultSmartExecutorProxy;
|
||||
import org.gcube.vremanagement.executor.client.proxies.SmartExecutorProxy;
|
||||
import org.gcube.vremanagement.executor.client.util.Tuple;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* Use {@link SmartExecutorClientFactory} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class ExecutorPlugin extends AbstractPlugin<SmartExecutor,SmartExecutorProxy> {
|
||||
|
||||
/**
|
||||
* Use {@link SmartExecutorClientFactory#create(String, java.util.Map, org.gcube.vremanagement.executor.client.query.filter.ServiceEndpointQueryFilter, org.gcube.vremanagement.executor.client.query.filter.GCoreEndpointQueryFilter)}
|
||||
* instead
|
||||
* @param pluginName
|
||||
* @param tuples
|
||||
* @param serviceEndpointQueryFilter
|
||||
* @param endpointDiscoveryFilter
|
||||
* @return
|
||||
*/
|
||||
public static ProxyBuilder<SmartExecutorProxy> getExecutorProxy(String pluginName, Tuple<String,String>[] tuples,
|
||||
ServiceEndpointQueryFilter serviceEndpointQueryFilter, EndpointDiscoveryFilter endpointDiscoveryFilter) {
|
||||
ExecutorPlugin executorPlugin = new ExecutorPlugin();
|
||||
SmartExecutorPluginQuery query = new SmartExecutorPluginQuery(executorPlugin);
|
||||
query.addConditions(pluginName, tuples);
|
||||
query.setServiceEndpointQueryFilter(serviceEndpointQueryFilter);
|
||||
query.setEndpointDiscoveryFilter(endpointDiscoveryFilter);
|
||||
return new ProxyBuilderImpl<SmartExecutor,SmartExecutorProxy>(executorPlugin, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link SmartExecutorClientFactory#create(String, java.util.Map, org.gcube.vremanagement.executor.client.query.filter.ServiceEndpointQueryFilter, org.gcube.vremanagement.executor.client.query.filter.GCoreEndpointQueryFilter)}
|
||||
* instead
|
||||
* @param pluginName
|
||||
* @param tuples
|
||||
* @return
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static ProxyBuilder<SmartExecutorProxy> getExecutorProxy(String pluginName, Tuple<String,String>... tuples) {
|
||||
ExecutorPlugin executorPlugin = new ExecutorPlugin();
|
||||
SmartExecutorPluginQuery query = new SmartExecutorPluginQuery(executorPlugin);
|
||||
query.addConditions(pluginName, tuples);
|
||||
return new ProxyBuilderImpl<SmartExecutor,SmartExecutorProxy>(executorPlugin, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link SmartExecutorClientFactory#create()} instead
|
||||
* @return
|
||||
*/
|
||||
public static ProxyBuilder<SmartExecutorProxy> getExecutorProxy() {
|
||||
ExecutorPlugin executorPlugin = new ExecutorPlugin();
|
||||
return new ProxyBuilderImpl<SmartExecutor,SmartExecutorProxy>(executorPlugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal use only to support backward compatibility
|
||||
* @param query
|
||||
* @param executorPlugin
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public static ProxyBuilder<SmartExecutorProxy> getExecutorProxy(SmartExecutorPluginQuery query,
|
||||
ExecutorPlugin executorPlugin) {
|
||||
return new ProxyBuilderImpl<SmartExecutor,SmartExecutorProxy>(executorPlugin, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal use only to support backward compatibility
|
||||
*
|
||||
*/
|
||||
public ExecutorPlugin() {
|
||||
super(SmartExecutor.WEB_SERVICE_SERVICE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal use only to support backward compatibility
|
||||
* Use {@link SmartExecutorClientFactory} instead
|
||||
*/
|
||||
@Override
|
||||
public Exception convert(Exception fault, ProxyConfig<?,?> proxyConfig) {
|
||||
return fault;
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal use only to support backward compatibility
|
||||
* Use {@link SmartExecutorClientFactory#create(String)} instead
|
||||
*/
|
||||
@Override
|
||||
public SmartExecutorProxy newProxy(ProxyDelegate<SmartExecutor> proxyDelegate) {
|
||||
return new DefaultSmartExecutorProxy(proxyDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal use only to support backward compatibility
|
||||
* Use {@link SmartExecutorClientFactory} instead
|
||||
*/
|
||||
@Override
|
||||
public SmartExecutor resolve(EndpointReference endpoint, ProxyConfig<?,?> proxyConfig) throws Exception {
|
||||
return StubFactory.stubFor(Constants.smartExecutor).at(endpoint);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.client.plugins.query;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.ws.EndpointReference;
|
||||
import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
|
||||
|
||||
import org.gcube.common.clients.Plugin;
|
||||
import org.gcube.common.clients.exceptions.DiscoveryException;
|
||||
import org.gcube.common.clients.queries.Query;
|
||||
import org.gcube.vremanagement.executor.client.query.Discover;
|
||||
import org.gcube.vremanagement.executor.client.query.filter.impl.RandomGCoreEndpointQueryFilter;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* For internal use only to maintain backward compatibility
|
||||
*/
|
||||
public class SmartExecutorPluginQuery extends Discover implements Query<EndpointReference> {
|
||||
|
||||
public SmartExecutorPluginQuery(Plugin<?,?> plugin){
|
||||
super(plugin.name());
|
||||
this.endpointDiscoveryFilter = new RandomGCoreEndpointQueryFilter();
|
||||
this.containsFormat = "contains($entry/string(),'%1s')";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EndpointReference> fire() throws DiscoveryException {
|
||||
List<EndpointReference> refs = new ArrayList<EndpointReference>();
|
||||
try {
|
||||
List<String> addresses = getAddresses();
|
||||
for(String address : addresses)
|
||||
refs.add(new W3CEndpointReferenceBuilder().address(address).build());
|
||||
} catch(org.gcube.resources.discovery.client.api.DiscoveryException ex) {
|
||||
throw new DiscoveryException(ex);
|
||||
}
|
||||
|
||||
return refs;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.client.plugins.query.filter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.gcube.vremanagement.executor.client.query.filter.GCoreEndpointQueryFilter;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* Use {@link GCoreEndpointQueryFilter} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface EndpointDiscoveryFilter {
|
||||
|
||||
/**
|
||||
* @param simpleQuery
|
||||
* @param serviceEndpoints
|
||||
*/
|
||||
@Deprecated
|
||||
void filter(SimpleQuery simpleQuery, List<ServiceEndpoint> serviceEndpoints);
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.client.plugins.query.filter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Deprecated
|
||||
public class ListEndpointDiscoveryFilter implements EndpointDiscoveryFilter {
|
||||
|
||||
protected static final String containsFormat = "contains($entry/string(),'%1s')";
|
||||
|
||||
@Override
|
||||
public void filter(SimpleQuery simpleQuery, List<ServiceEndpoint> serviceEndpoints) {
|
||||
|
||||
String expression = "";
|
||||
int size = serviceEndpoints.size();
|
||||
for(int i=0; i<size; i++){
|
||||
String hostedOn = serviceEndpoints.get(i).profile().runtime().hostedOn();
|
||||
String condition = String.format(containsFormat, hostedOn);
|
||||
expression = String.format("%s %s", expression, condition);
|
||||
if(i<(size-1)){
|
||||
expression = String.format("%s or ", expression);
|
||||
}
|
||||
}
|
||||
|
||||
simpleQuery.addCondition(expression);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.client.plugins.query.filter;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.gcube.vremanagement.executor.client.query.filter.impl.RandomGCoreEndpointQueryFilter;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* Use {@link RandomGCoreEndpointQueryFilter} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class RandomEndpointDiscoveryFilter implements EndpointDiscoveryFilter {
|
||||
|
||||
protected static final String containsFormat = "contains($entry/string(),'%1s')";
|
||||
|
||||
@Override
|
||||
public void filter(SimpleQuery simpleQuery, List<ServiceEndpoint> serviceEndpoints) {
|
||||
/*
|
||||
* Generating a random number, assuring that is positive and
|
||||
* and limiting from 0 to the number of discovered ServiceEndpoints
|
||||
* Please note that there is only one ServiceEndpoints for each running
|
||||
* ghn
|
||||
*/
|
||||
Random random = new Random();
|
||||
int number = random.nextInt();
|
||||
while(number == Integer.MIN_VALUE){
|
||||
number = random.nextInt();
|
||||
}
|
||||
number = Math.abs(number);
|
||||
int i = number % serviceEndpoints.size();
|
||||
|
||||
/* Getting random hosts using the generated random number*/
|
||||
String hostedOn = serviceEndpoints.get(i).profile().runtime().hostedOn();
|
||||
simpleQuery.addCondition(format(containsFormat, hostedOn));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.client.plugins.query.filter;
|
||||
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* Use {@link org.gcube.vremanagement.executor.client.query.filter.ServiceEndpointQueryFilter} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ServiceEndpointQueryFilter {
|
||||
|
||||
public void filter(SimpleQuery simpleQuery);
|
||||
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.client.plugins.query.filter;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.gcube.vremanagement.executor.client.query.filter.impl.SpecificGCoreEndpointQueryFilter;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* Use {@link SpecificGCoreEndpointQueryFilter} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class SpecificEndpointDiscoveryFilter implements EndpointDiscoveryFilter {
|
||||
|
||||
protected static final String containsFormat = "contains($entry/string(),'%1s')";
|
||||
|
||||
private String endpointURI;
|
||||
|
||||
public SpecificEndpointDiscoveryFilter(String endpointURI){
|
||||
this.endpointURI = endpointURI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void filter(SimpleQuery simpleQuery, List<ServiceEndpoint> serviceEndpoints) {
|
||||
simpleQuery.addCondition(format(containsFormat, endpointURI));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,176 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.client.proxies;
|
||||
|
||||
import static org.gcube.common.clients.exceptions.FaultDSL.again;
|
||||
|
||||
import org.gcube.common.clients.Call;
|
||||
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||
import org.gcube.vremanagement.executor.api.SmartExecutor;
|
||||
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||
import org.gcube.vremanagement.executor.client.SmartExecutorClientFactory;
|
||||
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.gcube.vremanagement.executor.plugin.PluginState;
|
||||
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* Use {@link SmartExecutorClientFactory} instead to obtain {@link org.gcube.vremanagement.executor.api.rest.SmartExecutor}
|
||||
* instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class DefaultSmartExecutorProxy implements SmartExecutorProxy {
|
||||
|
||||
/**
|
||||
* Logger
|
||||
*/
|
||||
private static Logger logger = LoggerFactory.getLogger(DefaultSmartExecutorProxy.class);
|
||||
|
||||
private ProxyDelegate<SmartExecutor> proxyDelegate;
|
||||
|
||||
public DefaultSmartExecutorProxy(ProxyDelegate<SmartExecutor> proxyDelegate) {
|
||||
this.proxyDelegate = proxyDelegate;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String launch(final LaunchParameter launchParameter)
|
||||
throws InputsNullException, PluginNotFoundException,
|
||||
LaunchException, ExecutorException {
|
||||
|
||||
Call<SmartExecutor, String> call = new Call<SmartExecutor, String>() {
|
||||
@Override
|
||||
public String call(SmartExecutor endpoint) throws Exception {
|
||||
logger.debug("Calling launch() function");
|
||||
return endpoint.launch(launchParameter);
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
return proxyDelegate.make(call);
|
||||
} catch (Exception e) {
|
||||
logger.debug("Failed to call launch() function");
|
||||
throw again(e).asServiceException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* It is the same of calling
|
||||
* unSchedule(String executionIdentifier, boolean globally)
|
||||
* Passing false to globally
|
||||
*/
|
||||
@Override
|
||||
public boolean unSchedule(final String executionIdentifier) throws ExecutorException {
|
||||
return this.unSchedule(executionIdentifier, false);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean unSchedule(final String executionIdentifier, final boolean globally) throws ExecutorException {
|
||||
Call<SmartExecutor, Boolean> call = new Call<SmartExecutor, Boolean>() {
|
||||
@Override
|
||||
public Boolean call(SmartExecutor endpoint) throws Exception {
|
||||
logger.debug("Calling unSchedule(String,boolean) function");
|
||||
return endpoint.unSchedule(executionIdentifier, globally);
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
return proxyDelegate.make(call);
|
||||
} catch (Exception e) {
|
||||
logger.debug("Failed to call unSchedule(String,boolean) function");
|
||||
throw again(e).asServiceException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Deprecated
|
||||
@Override
|
||||
public PluginState getState(final String executionIdentifier)
|
||||
throws PluginInstanceNotFoundException, ExecutorException {
|
||||
return getStateEvolution(executionIdentifier).getPluginState();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public PluginStateEvolution getStateEvolution(final String executionIdentifier)
|
||||
throws PluginInstanceNotFoundException, ExecutorException {
|
||||
|
||||
Call<SmartExecutor, PluginStateEvolution> call = new Call<SmartExecutor, PluginStateEvolution>() {
|
||||
@Override
|
||||
public PluginStateEvolution call(SmartExecutor endpoint) throws Exception {
|
||||
logger.debug("Calling getState(String) function");
|
||||
return endpoint.getStateEvolution(executionIdentifier);
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
return proxyDelegate.make(call);
|
||||
} catch (Exception e) {
|
||||
logger.debug("Failed to call getState(String) function");
|
||||
throw again(e).asServiceException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Deprecated
|
||||
@Override
|
||||
public PluginState getIterationState(final String executionIdentifier, final int iterationNumber)
|
||||
throws PluginInstanceNotFoundException, ExecutorException {
|
||||
return getIterationStateEvolution(executionIdentifier, iterationNumber).getPluginState();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public PluginStateEvolution getIterationStateEvolution(final String executionIdentifier, final int iterationNumber)
|
||||
throws PluginInstanceNotFoundException, ExecutorException {
|
||||
|
||||
Call<SmartExecutor, PluginStateEvolution> call = new Call<SmartExecutor, PluginStateEvolution>() {
|
||||
@Override
|
||||
public PluginStateEvolution call(SmartExecutor endpoint) throws Exception {
|
||||
logger.debug("Calling getIterationState(String, int) function");
|
||||
return endpoint.getIterationStateEvolution(executionIdentifier, iterationNumber);
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
return proxyDelegate.make(call);
|
||||
} catch (Exception e) {
|
||||
logger.debug("Failed to call getIterationState(String, int) function");
|
||||
throw again(e).asServiceException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean stop(final String executionIdentifier) throws ExecutorException {
|
||||
|
||||
Call<SmartExecutor, Boolean> call = new Call<SmartExecutor, Boolean>() {
|
||||
@Override
|
||||
public Boolean call(SmartExecutor endpoint) throws Exception {
|
||||
logger.debug("Calling stop(String) function");
|
||||
return endpoint.stop(executionIdentifier);
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
return proxyDelegate.make(call);
|
||||
} catch (Exception e) {
|
||||
logger.debug("Failed to call stop(String) function");
|
||||
throw again(e).asServiceException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.client.proxies;
|
||||
|
||||
import org.gcube.vremanagement.executor.api.SmartExecutor;
|
||||
import org.gcube.vremanagement.executor.client.SmartExecutorClientFactory;
|
||||
import org.gcube.vremanagement.executor.exception.ExecutorException;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* Use {@link SmartExecutorClientFactory} instead to obtain {@link org.gcube.vremanagement.executor.api.rest.SmartExecutor}
|
||||
* instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface SmartExecutorProxy extends SmartExecutor {
|
||||
|
||||
/**
|
||||
* It is the same of calling
|
||||
* unSchedule(String executionIdentifier, boolean globally)
|
||||
* Passing false to globally
|
||||
*/
|
||||
public boolean unSchedule(final String executionIdentifier) throws ExecutorException;
|
||||
|
||||
}
|
|
@ -1,9 +1,7 @@
|
|||
package org.gcube.vremanagement.executor.client.query;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import org.gcube.common.clients.exceptions.DiscoveryException;
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
|
@ -11,16 +9,10 @@ import org.gcube.common.resources.gcore.ServiceEndpoint;
|
|||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.gcube.resources.discovery.icclient.ICFactory;
|
||||
import org.gcube.vremanagement.executor.client.Constants;
|
||||
import org.gcube.vremanagement.executor.client.plugins.query.filter.EndpointDiscoveryFilter;
|
||||
import org.gcube.vremanagement.executor.client.plugins.query.filter.SpecificEndpointDiscoveryFilter;
|
||||
import org.gcube.vremanagement.executor.client.query.filter.GCoreEndpointQueryFilter;
|
||||
import org.gcube.vremanagement.executor.client.query.filter.ServiceEndpointQueryFilter;
|
||||
import org.gcube.vremanagement.executor.client.util.Tuple;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Discover {
|
||||
|
||||
private static String classFormat = "$resource/Profile/ServiceClass/text() eq '%1s'";
|
||||
|
@ -33,9 +25,6 @@ public class Discover {
|
|||
|
||||
private final SimpleQuery serviceEndpointQuery;
|
||||
|
||||
protected org.gcube.vremanagement.executor.client.plugins.query.filter.ServiceEndpointQueryFilter serviceEndpointQueryFilter;
|
||||
protected EndpointDiscoveryFilter endpointDiscoveryFilter;
|
||||
|
||||
protected SimpleQuery getGCoreEndpointQuery() {
|
||||
return ICFactory.queryFor(GCoreEndpoint.class)
|
||||
.addCondition(String.format(classFormat, Constants.SERVICE_CLASS))
|
||||
|
@ -74,68 +63,8 @@ public class Discover {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Deprecated
|
||||
public void addConditions(String pluginName, Tuple<String,String>... tuples) {
|
||||
|
||||
filterByPluginName(pluginName);
|
||||
|
||||
if(tuples == null) {
|
||||
return;
|
||||
}
|
||||
Map<String, String> capabilities = new HashMap<>();
|
||||
for(int i = 0; i < tuples.length; i++) {
|
||||
capabilities.put(tuples[i].getName(), tuples[i].getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void setServiceEndpointQueryFilter(ServiceEndpointQueryFilter serviceEndpointQueryFilter) {
|
||||
this.serviceEndpointQueryFilter = serviceEndpointQueryFilter;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setServiceEndpointQueryFilter(org.gcube.vremanagement.executor.client.plugins.query.filter.ServiceEndpointQueryFilter serviceEndpointQueryFilter) {
|
||||
this.serviceEndpointQueryFilter = serviceEndpointQueryFilter;
|
||||
}
|
||||
|
||||
public void setGCoreEndpointQueryFilter(GCoreEndpointQueryFilter gCoreEndpointQueryFilter) {
|
||||
if(gCoreEndpointQueryFilter != null) {
|
||||
this.endpointDiscoveryFilter = gCoreEndpointQueryFilter;
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setEndpointDiscoveryFilter(EndpointDiscoveryFilter endpointDiscoveryFilter) {
|
||||
if(endpointDiscoveryFilter != null) {
|
||||
this.endpointDiscoveryFilter = endpointDiscoveryFilter;
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public List<String> discoverEndpoints(EndpointDiscoveryFilter endpointDiscoveryFilter) throws DiscoveryException {
|
||||
if(serviceEndpointQueryFilter != null) {
|
||||
serviceEndpointQueryFilter.filter(serviceEndpointQuery);
|
||||
}
|
||||
|
||||
List<ServiceEndpoint> serviceEndpoints = ICFactory.clientFor(ServiceEndpoint.class)
|
||||
.submit(serviceEndpointQuery);
|
||||
|
||||
if(serviceEndpoints.size() == 0) {
|
||||
throw new DiscoveryException("No running SmartExecutor wich match the requested conditions");
|
||||
}
|
||||
|
||||
SimpleQuery gCoreEndpointQuery = getGCoreEndpointQuery();
|
||||
endpointDiscoveryFilter.filter(gCoreEndpointQuery, serviceEndpoints);
|
||||
|
||||
return ICFactory.client().submit(gCoreEndpointQuery);
|
||||
|
||||
}
|
||||
|
||||
public List<String> getAddresses() throws DiscoveryException {
|
||||
if(serviceEndpointQueryFilter != null) {
|
||||
serviceEndpointQueryFilter.filter(serviceEndpointQuery);
|
||||
}
|
||||
|
||||
|
||||
List<ServiceEndpoint> serviceEndpoints = ICFactory.clientFor(ServiceEndpoint.class)
|
||||
.submit(serviceEndpointQuery);
|
||||
|
||||
|
@ -144,17 +73,8 @@ public class Discover {
|
|||
}
|
||||
|
||||
SimpleQuery gCoreEndpointDiscoveryQuery = getGCoreEndpointQuery();
|
||||
if(endpointDiscoveryFilter==null) {
|
||||
Random random = new Random();
|
||||
int index = random.nextInt(serviceEndpoints.size());
|
||||
ServiceEndpoint serviceEndpoint = serviceEndpoints.get(index);
|
||||
endpointDiscoveryFilter = new SpecificEndpointDiscoveryFilter(serviceEndpoint.profile().runtime().hostedOn());
|
||||
}
|
||||
endpointDiscoveryFilter.filter(gCoreEndpointDiscoveryQuery, serviceEndpoints);
|
||||
|
||||
List<String> addresses = ICFactory.client().submit(gCoreEndpointDiscoveryQuery);
|
||||
|
||||
return addresses;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
package org.gcube.vremanagement.executor.client.query.filter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.gcube.vremanagement.executor.client.plugins.query.filter.EndpointDiscoveryFilter;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public interface GCoreEndpointQueryFilter extends EndpointDiscoveryFilter {
|
||||
|
||||
@Override
|
||||
void filter(SimpleQuery simpleQuery, List<ServiceEndpoint> serviceEndpoints);
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.client.query.filter;
|
||||
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public interface ServiceEndpointQueryFilter
|
||||
extends org.gcube.vremanagement.executor.client.plugins.query.filter.ServiceEndpointQueryFilter {
|
||||
|
||||
@Override
|
||||
public void filter(SimpleQuery simpleQuery);
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package org.gcube.vremanagement.executor.client.query.filter.impl;
|
||||
|
||||
import org.gcube.vremanagement.executor.client.query.filter.GCoreEndpointQueryFilter;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class RandomGCoreEndpointQueryFilter
|
||||
extends org.gcube.vremanagement.executor.client.plugins.query.filter.RandomEndpointDiscoveryFilter
|
||||
implements GCoreEndpointQueryFilter {
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package org.gcube.vremanagement.executor.client.query.filter.impl;
|
||||
|
||||
import org.gcube.vremanagement.executor.client.query.filter.GCoreEndpointQueryFilter;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class SpecificGCoreEndpointQueryFilter
|
||||
extends org.gcube.vremanagement.executor.client.plugins.query.filter.SpecificEndpointDiscoveryFilter
|
||||
implements GCoreEndpointQueryFilter {
|
||||
|
||||
public SpecificGCoreEndpointQueryFilter(String endpointURI) {
|
||||
super(endpointURI);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,244 +0,0 @@
|
|||
package org.gcube.vremanagement.executor.client.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.vremanagement.executor.exception.ExecutorException;
|
||||
import org.gcube.vremanagement.executor.exception.SmartExecutorExceptionMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class HTTPCall {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(HTTPCall.class);
|
||||
|
||||
public static final String APPLICATION_JSON_CHARSET_UTF_8 = "application/json;charset=UTF-8";
|
||||
|
||||
public enum HTTPMETHOD {
|
||||
HEAD, GET, POST, PUT, DELETE;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name();
|
||||
}
|
||||
}
|
||||
|
||||
public static final String PATH_SEPARATOR = "/";
|
||||
public static final String PARAM_STARTER = "?";
|
||||
public static final String PARAM_EQUALS = "=";
|
||||
public static final String PARAM_SEPARATOR = "&";
|
||||
public static final String UTF8 = "UTF-8";
|
||||
|
||||
protected final String address;
|
||||
protected final String userAgent;
|
||||
|
||||
public HTTPCall(String address, String userAgent) {
|
||||
this.address = address;
|
||||
this.userAgent = userAgent;
|
||||
}
|
||||
|
||||
protected String getParametersDataString(Map<String, ? extends Object> parameters)
|
||||
throws UnsupportedEncodingException {
|
||||
|
||||
if (parameters == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (String key : parameters.keySet()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(PARAM_SEPARATOR);
|
||||
}
|
||||
result.append(URLEncoder.encode(key, UTF8));
|
||||
result.append(PARAM_EQUALS);
|
||||
result.append(URLEncoder.encode(String.valueOf(parameters.get(key)), UTF8));
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
protected URL getURL(String address, String path, String urlParameters) throws MalformedURLException {
|
||||
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
stringWriter.append(address);
|
||||
|
||||
if (address.endsWith(PATH_SEPARATOR)) {
|
||||
if (path.startsWith(PATH_SEPARATOR)) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
} else {
|
||||
if (!path.startsWith(PATH_SEPARATOR)) {
|
||||
stringWriter.append(PARAM_SEPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
stringWriter.append(path);
|
||||
|
||||
if (urlParameters != null) {
|
||||
stringWriter.append(PARAM_STARTER);
|
||||
stringWriter.append(urlParameters);
|
||||
}
|
||||
|
||||
return getURL(stringWriter.toString());
|
||||
}
|
||||
|
||||
protected URL getURL(String urlString) throws MalformedURLException {
|
||||
URL url = new URL(urlString);
|
||||
if (url.getProtocol().compareTo("https") == 0) {
|
||||
url = new URL(url.getProtocol(), url.getHost(), url.getDefaultPort(), url.getFile());
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
protected HttpURLConnection getConnection(String path, String urlParameters, HTTPMETHOD method, String body)
|
||||
throws Exception {
|
||||
URL url = getURL(address, path, urlParameters);
|
||||
return getConnection(url, method, body);
|
||||
}
|
||||
|
||||
protected HttpURLConnection getConnection(URL url, HTTPMETHOD method, String body) throws Exception {
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
if (SecurityTokenProvider.instance.get() == null) {
|
||||
if (ScopeProvider.instance.get() == null) {
|
||||
throw new RuntimeException("Null Token and Scope. Please set your token first.");
|
||||
}
|
||||
connection.setRequestProperty("gcube-scope", ScopeProvider.instance.get());
|
||||
} else {
|
||||
connection.setRequestProperty(org.gcube.common.authorization.client.Constants.TOKEN_HEADER_ENTRY,
|
||||
SecurityTokenProvider.instance.get());
|
||||
}
|
||||
|
||||
connection.setDoOutput(true);
|
||||
|
||||
connection.setRequestProperty("Content-type", APPLICATION_JSON_CHARSET_UTF_8);
|
||||
connection.setRequestProperty("User-Agent", userAgent);
|
||||
|
||||
connection.setRequestMethod(method.toString());
|
||||
|
||||
if (body != null && (method == HTTPMETHOD.POST || method == HTTPMETHOD.PUT)) {
|
||||
|
||||
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
|
||||
wr.write(body.getBytes("UTF-8"));
|
||||
wr.flush();
|
||||
wr.close();
|
||||
}
|
||||
|
||||
int responseCode = connection.getResponseCode();
|
||||
String responseMessage = connection.getResponseMessage();
|
||||
logger.trace("{} {} : {} - {}", method, connection.getURL(), responseCode, responseMessage);
|
||||
|
||||
if (responseCode == HttpURLConnection.HTTP_MOVED_TEMP || responseCode == HttpURLConnection.HTTP_MOVED_PERM
|
||||
|| responseCode == HttpURLConnection.HTTP_SEE_OTHER) {
|
||||
|
||||
URL redirectURL = getURL(connection.getHeaderField("Location"));
|
||||
|
||||
logger.trace("{} is going to be redirect to {}", url.toString(), redirectURL.toString());
|
||||
|
||||
connection = getConnection(redirectURL, method, body);
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
protected StringBuilder getStringBuilder(InputStream inputStream) throws IOException {
|
||||
StringBuilder result = new StringBuilder();
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public <C> C call(Class<C> clz, String path, HTTPMETHOD method) throws Exception {
|
||||
return call(clz, path, method, null, null);
|
||||
}
|
||||
|
||||
public <C> C call(Class<C> clz, String path, HTTPMETHOD method, Map<String, ? extends Object> parameters)
|
||||
throws Exception {
|
||||
return call(clz, path, method, parameters, null);
|
||||
}
|
||||
|
||||
public <C> C call(Class<C> clz, String path, HTTPMETHOD method, String body) throws Exception {
|
||||
return call(clz, path, method, null, body);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <C> C call(Class<C> clz, String path, HTTPMETHOD method, Map<String, ? extends Object> parameters,
|
||||
String body) throws Exception {
|
||||
|
||||
String urlParameters = getParametersDataString(parameters);
|
||||
|
||||
HttpURLConnection connection = getConnection(path, urlParameters, method, body);
|
||||
|
||||
try {
|
||||
|
||||
int responseCode = connection.getResponseCode();
|
||||
String responseMessage = connection.getResponseMessage();
|
||||
logger.info("{} {} : {} - {}", method, connection.getURL(), responseCode, responseMessage);
|
||||
|
||||
if (method == HTTPMETHOD.HEAD) {
|
||||
if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
|
||||
return null;
|
||||
}
|
||||
if (responseCode == HttpURLConnection.HTTP_NOT_FOUND || responseCode == HttpURLConnection.HTTP_FORBIDDEN) {
|
||||
throw new ExecutorException("Not Found");
|
||||
}
|
||||
if (responseCode == HttpURLConnection.HTTP_FORBIDDEN) {
|
||||
throw new ExecutorException("Forbidden");
|
||||
}
|
||||
}
|
||||
|
||||
if (responseCode >= HttpURLConnection.HTTP_BAD_REQUEST) {
|
||||
|
||||
InputStream inputStream = connection.getErrorStream();
|
||||
StringBuilder result = getStringBuilder(inputStream);
|
||||
|
||||
String res = result.toString();
|
||||
|
||||
ExecutorException rre = null;
|
||||
try {
|
||||
rre = SmartExecutorExceptionMapper.unmarshal(ExecutorException.class, res);
|
||||
} catch (Exception e) {
|
||||
rre = new ExecutorException(responseMessage);
|
||||
}
|
||||
|
||||
throw rre;
|
||||
|
||||
}
|
||||
|
||||
StringBuilder result = getStringBuilder(connection.getInputStream());
|
||||
|
||||
String res = result.toString();
|
||||
logger.trace("Server returned content : {}", res);
|
||||
|
||||
if (Boolean.class.isAssignableFrom(clz)) {
|
||||
return (C) ((Boolean) Boolean.valueOf(res));
|
||||
}
|
||||
|
||||
return (C) res;
|
||||
} finally {
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.client.util;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Deprecated
|
||||
public class Tuple<Name,Value> {
|
||||
|
||||
protected Name name;
|
||||
protected Value value;
|
||||
|
||||
public Tuple(){}
|
||||
|
||||
public Tuple(Name name, Value value){
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(Name name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
public Value getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value the value to set
|
||||
*/
|
||||
public void setValue(Value value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((value == null) ? 0 : value.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
@SuppressWarnings("rawtypes")
|
||||
Tuple other = (Tuple) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (value == null) {
|
||||
if (other.value != null)
|
||||
return false;
|
||||
} else if (!value.equals(other.value))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("<%s,%s>", name.toString(), value.toString());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue