Fixing service
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@111718 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3499e0018b
commit
85fa57370a
|
@ -83,6 +83,11 @@ public class ExecutorImpl implements Executor {
|
||||||
*/
|
*/
|
||||||
private static JDBCPersistenceConnector jdbcPersistenceConnector;
|
private static JDBCPersistenceConnector jdbcPersistenceConnector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application Context
|
||||||
|
*/
|
||||||
|
public static ApplicationContext ctx;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publish the provided resource on all Service Scopes retrieved from
|
* Publish the provided resource on all Service Scopes retrieved from
|
||||||
* Context
|
* Context
|
||||||
|
@ -94,15 +99,13 @@ public class ExecutorImpl implements Executor {
|
||||||
StringWriter stringWriter = new StringWriter();
|
StringWriter stringWriter = new StringWriter();
|
||||||
Resources.marshal(resource, stringWriter);
|
Resources.marshal(resource, stringWriter);
|
||||||
|
|
||||||
ApplicationContext ctx = ContextProvider.get();
|
if(ExecutorImpl.ctx == null){
|
||||||
|
|
||||||
if(ctx == null){
|
|
||||||
logger.error(String.format("%s null. Unable to Publish the Resource\n%s",
|
logger.error(String.format("%s null. Unable to Publish the Resource\n%s",
|
||||||
ApplicationContext.class.getSimpleName(), stringWriter.toString()));
|
ApplicationContext.class.getSimpleName(), stringWriter.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> scopeSet = ctx.configuration().startScopes();
|
Set<String> scopeSet = ExecutorImpl.ctx.configuration().startScopes();
|
||||||
List<String> scopes = new ArrayList<String>(scopeSet);
|
List<String> scopes = new ArrayList<String>(scopeSet);
|
||||||
|
|
||||||
ScopedPublisher scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
ScopedPublisher scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
||||||
|
@ -125,15 +128,7 @@ public class ExecutorImpl implements Executor {
|
||||||
StringWriter stringWriter = new StringWriter();
|
StringWriter stringWriter = new StringWriter();
|
||||||
Resources.marshal(resource, stringWriter);
|
Resources.marshal(resource, stringWriter);
|
||||||
|
|
||||||
ApplicationContext ctx = ContextProvider.get();
|
Set<String> scopeSet = ExecutorImpl.ctx.configuration().startScopes();
|
||||||
|
|
||||||
if(ctx == null){
|
|
||||||
logger.error(String.format("%s null. Unable to UnPublish the Resource\n%s",
|
|
||||||
ApplicationContext.class.getSimpleName(), stringWriter.toString()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> scopeSet = ctx.configuration().startScopes();
|
|
||||||
List<String> scopes = new ArrayList<String>(scopeSet);
|
List<String> scopes = new ArrayList<String>(scopeSet);
|
||||||
|
|
||||||
ScopedPublisher scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
ScopedPublisher scopedPublisher = RegistryPublisherFactory.scopedPublisher();
|
||||||
|
@ -198,7 +193,34 @@ public class ExecutorImpl implements Executor {
|
||||||
ExecutorImpl.serviceEndpoint = createServiceEndpoint();
|
ExecutorImpl.serviceEndpoint = createServiceEndpoint();
|
||||||
ExecutorImpl.pluginInstances = new HashMap<UUID, PluginThread<Plugin<? extends PluginDeclaration>>>();
|
ExecutorImpl.pluginInstances = new HashMap<UUID, PluginThread<Plugin<? extends PluginDeclaration>>>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
initContextDependendent();
|
||||||
|
} catch (ExecutorException e) {
|
||||||
|
// This is normal
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static void initContextDependendent() throws ExecutorException, Exception {
|
||||||
|
|
||||||
|
if(ExecutorImpl.ctx == null){
|
||||||
|
ExecutorImpl.ctx = ContextProvider.get();
|
||||||
|
if(ExecutorImpl.ctx == null){
|
||||||
|
String message = String.format("%s not ready",
|
||||||
|
ApplicationContext.class.getSimpleName());
|
||||||
|
throw new ExecutorException(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
initPersistence();
|
initPersistence();
|
||||||
|
} catch(Exception e){
|
||||||
|
String message = "Unable to init persistence";
|
||||||
|
throw new Exception(message);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO Before publishing the new Resource check if on IS there is
|
// TODO Before publishing the new Resource check if on IS there is
|
||||||
// an old published ServiceEndpoint resource that where not unpublished
|
// an old published ServiceEndpoint resource that where not unpublished
|
||||||
|
@ -223,7 +245,7 @@ public class ExecutorImpl implements Executor {
|
||||||
* discovered plugin and plugin state.
|
* discovered plugin and plugin state.
|
||||||
* @throws Exception if fails
|
* @throws Exception if fails
|
||||||
*/
|
*/
|
||||||
protected static void initPersistence() throws Exception {
|
private static void initPersistence() throws Exception {
|
||||||
try {
|
try {
|
||||||
jdbcPersistenceConnector = new JDBCPersistenceConnector();
|
jdbcPersistenceConnector = new JDBCPersistenceConnector();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -286,6 +308,16 @@ public class ExecutorImpl implements Executor {
|
||||||
@Override
|
@Override
|
||||||
public String launch(LaunchParameter parameter) throws InputsNullException,
|
public String launch(LaunchParameter parameter) throws InputsNullException,
|
||||||
PluginNotFoundException, LaunchException, ExecutorException {
|
PluginNotFoundException, LaunchException, ExecutorException {
|
||||||
|
if(ExecutorImpl.ctx == null){
|
||||||
|
try {
|
||||||
|
initContextDependendent();
|
||||||
|
} catch (ExecutorException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ExecutorException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, Object> inputs = parameter.getInputs();
|
Map<String, Object> inputs = parameter.getInputs();
|
||||||
if(inputs==null){
|
if(inputs==null){
|
||||||
throw new InputsNullException();
|
throw new InputsNullException();
|
||||||
|
@ -351,7 +383,17 @@ public class ExecutorImpl implements Executor {
|
||||||
|
|
||||||
/**{@inheritDoc}*/
|
/**{@inheritDoc}*/
|
||||||
@Override
|
@Override
|
||||||
public PluginState getState(String executionIdentifier) throws PluginInstanceNotFoundException, ExecutorException {
|
public PluginState getState(String executionIdentifier)
|
||||||
|
throws PluginInstanceNotFoundException, ExecutorException {
|
||||||
|
if(ExecutorImpl.ctx == null){
|
||||||
|
try {
|
||||||
|
initContextDependendent();
|
||||||
|
} catch (ExecutorException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ExecutorException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return jdbcPersistenceConnector.getPluginInstanceState(UUID.fromString(executionIdentifier));
|
return jdbcPersistenceConnector.getPluginInstanceState(UUID.fromString(executionIdentifier));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -11,8 +11,7 @@ import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.smartgears.ContextProvider;
|
import org.gcube.vremanagement.executor.ExecutorImpl;
|
||||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
|
||||||
import org.gcube.vremanagement.executor.plugin.PluginState;
|
import org.gcube.vremanagement.executor.plugin.PluginState;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -42,6 +41,8 @@ public class JDBCPersistenceConnector extends PersistenceConnector {
|
||||||
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE_TIMESTAMP_FIELD = "timestamp";
|
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE_TIMESTAMP_FIELD = "timestamp";
|
||||||
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE_STATE_FIELD = "state";
|
public final static String PLUGIN_INSTANCE_EVOLUTION_TABLE_STATE_FIELD = "state";
|
||||||
|
|
||||||
|
public final static String CATALINA_HOME = "CATALINA_HOME";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @throws Exception if fails
|
* @throws Exception if fails
|
||||||
|
@ -56,13 +57,13 @@ public class JDBCPersistenceConnector extends PersistenceConnector {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Get which actually result null ApplicationContext ctx = ContextProvider.get();
|
String dbFilePath;
|
||||||
ApplicationContext ctx = ContextProvider.get();
|
|
||||||
String dbFilePath = "/home/lucafrosini/workspace/runtime/tomcat/webapps/smart-executor-1.0.0-SNAPSHOT/WEB-INF/executor";
|
|
||||||
try {
|
try {
|
||||||
dbFilePath = ctx.application().getContextPath();
|
dbFilePath = String.format("%s%s", ExecutorImpl.ctx.application().getContextPath(), dbName);
|
||||||
} catch(Exception e){
|
} catch(Exception e){
|
||||||
|
dbFilePath = String.format("./%s", dbName);
|
||||||
}
|
}
|
||||||
|
|
||||||
String jdbcURL = String.format("%s%s", jdbcConnection, dbFilePath);
|
String jdbcURL = String.format("%s%s", jdbcConnection, dbFilePath);
|
||||||
logger.debug(String.format("DB URL : %s", jdbcURL));
|
logger.debug(String.format("DB URL : %s", jdbcURL));
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class JDBCPersistenceConnectorTest {
|
||||||
@Test
|
@Test
|
||||||
public void getPluginInstanceStateTest() throws Exception {
|
public void getPluginInstanceStateTest() throws Exception {
|
||||||
UUID uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
|
|
||||||
JDBCPersistenceConnector jdbcPersistenceConnector = new JDBCPersistenceConnector();
|
JDBCPersistenceConnector jdbcPersistenceConnector = new JDBCPersistenceConnector();
|
||||||
JDBCPersistence jdbcPersistence = new JDBCPersistence(jdbcPersistenceConnector, HelloWorldPluginDeclaration.name, uuid);
|
JDBCPersistence jdbcPersistence = new JDBCPersistence(jdbcPersistenceConnector, HelloWorldPluginDeclaration.name, uuid);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue