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:
Luca Frosini 2015-02-05 11:38:46 +00:00
parent 3499e0018b
commit 85fa57370a
3 changed files with 66 additions and 22 deletions

View File

@ -83,6 +83,11 @@ public class ExecutorImpl implements Executor {
*/
private static JDBCPersistenceConnector jdbcPersistenceConnector;
/**
* Application Context
*/
public static ApplicationContext ctx;
/**
* Publish the provided resource on all Service Scopes retrieved from
* Context
@ -94,15 +99,13 @@ public class ExecutorImpl implements Executor {
StringWriter stringWriter = new StringWriter();
Resources.marshal(resource, stringWriter);
ApplicationContext ctx = ContextProvider.get();
if(ctx == null){
if(ExecutorImpl.ctx == null){
logger.error(String.format("%s null. Unable to Publish the Resource\n%s",
ApplicationContext.class.getSimpleName(), stringWriter.toString()));
return;
}
Set<String> scopeSet = ctx.configuration().startScopes();
Set<String> scopeSet = ExecutorImpl.ctx.configuration().startScopes();
List<String> scopes = new ArrayList<String>(scopeSet);
ScopedPublisher scopedPublisher = RegistryPublisherFactory.scopedPublisher();
@ -125,15 +128,7 @@ public class ExecutorImpl implements Executor {
StringWriter stringWriter = new StringWriter();
Resources.marshal(resource, stringWriter);
ApplicationContext ctx = ContextProvider.get();
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();
Set<String> scopeSet = ExecutorImpl.ctx.configuration().startScopes();
List<String> scopes = new ArrayList<String>(scopeSet);
ScopedPublisher scopedPublisher = RegistryPublisherFactory.scopedPublisher();
@ -198,7 +193,34 @@ public class ExecutorImpl implements Executor {
ExecutorImpl.serviceEndpoint = createServiceEndpoint();
ExecutorImpl.pluginInstances = new HashMap<UUID, PluginThread<Plugin<? extends PluginDeclaration>>>();
initPersistence();
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();
} 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
// an old published ServiceEndpoint resource that where not unpublished
@ -223,7 +245,7 @@ public class ExecutorImpl implements Executor {
* discovered plugin and plugin state.
* @throws Exception if fails
*/
protected static void initPersistence() throws Exception {
private static void initPersistence() throws Exception {
try {
jdbcPersistenceConnector = new JDBCPersistenceConnector();
} catch (Exception e) {
@ -286,6 +308,16 @@ public class ExecutorImpl implements Executor {
@Override
public String launch(LaunchParameter parameter) throws InputsNullException,
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();
if(inputs==null){
throw new InputsNullException();
@ -351,7 +383,17 @@ public class ExecutorImpl implements Executor {
/**{@inheritDoc}*/
@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 {
return jdbcPersistenceConnector.getPluginInstanceState(UUID.fromString(executionIdentifier));
} catch (Exception e) {

View File

@ -11,8 +11,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.UUID;
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.vremanagement.executor.ExecutorImpl;
import org.gcube.vremanagement.executor.plugin.PluginState;
import org.slf4j.Logger;
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_STATE_FIELD = "state";
public final static String CATALINA_HOME = "CATALINA_HOME";
/**
* Default Constructor
* @throws Exception if fails
@ -56,13 +57,13 @@ public class JDBCPersistenceConnector extends PersistenceConnector {
throw e;
}
// TODO Get which actually result null ApplicationContext ctx = ContextProvider.get();
ApplicationContext ctx = ContextProvider.get();
String dbFilePath = "/home/lucafrosini/workspace/runtime/tomcat/webapps/smart-executor-1.0.0-SNAPSHOT/WEB-INF/executor";
String dbFilePath;
try {
dbFilePath = ctx.application().getContextPath();
dbFilePath = String.format("%s%s", ExecutorImpl.ctx.application().getContextPath(), dbName);
} catch(Exception e){
dbFilePath = String.format("./%s", dbName);
}
String jdbcURL = String.format("%s%s", jdbcConnection, dbFilePath);
logger.debug(String.format("DB URL : %s", jdbcURL));

View File

@ -29,6 +29,7 @@ public class JDBCPersistenceConnectorTest {
@Test
public void getPluginInstanceStateTest() throws Exception {
UUID uuid = UUID.randomUUID();
JDBCPersistenceConnector jdbcPersistenceConnector = new JDBCPersistenceConnector();
JDBCPersistence jdbcPersistence = new JDBCPersistence(jdbcPersistenceConnector, HelloWorldPluginDeclaration.name, uuid);