refs #2112: Port SmartExecutor to be compliant with new Authorization

https://support.d4science.org/issues/2112

Changed the way to retrieve ApplicationContext

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@122910 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-02-08 14:22:06 +00:00
parent c371db1f4b
commit ca24d6bea1
5 changed files with 17 additions and 56 deletions

View File

@ -5,7 +5,6 @@ import java.util.UUID;
import javax.jws.WebService; import javax.jws.WebService;
import org.gcube.smartgears.annotations.ManagedBy; import org.gcube.smartgears.annotations.ManagedBy;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.vremanagement.executor.api.SmartExecutor; import org.gcube.vremanagement.executor.api.SmartExecutor;
import org.gcube.vremanagement.executor.api.types.LaunchParameter; import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.exception.ExecutorException; import org.gcube.vremanagement.executor.exception.ExecutorException;
@ -40,15 +39,6 @@ public class SmartExecutorImpl implements SmartExecutor {
*/ */
private static Logger logger = LoggerFactory.getLogger(SmartExecutorImpl.class); private static Logger logger = LoggerFactory.getLogger(SmartExecutorImpl.class);
protected static ApplicationContext ctx;
/**
* @return the ctx
*/
public static ApplicationContext getCtx() {
return ctx;
}
/**{@inheritDoc}*/ /**{@inheritDoc}*/
@Override @Override
public String launch(LaunchParameter parameter) throws InputsNullException, public String launch(LaunchParameter parameter) throws InputsNullException,

View File

@ -24,6 +24,7 @@ import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery; import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.resources.discovery.icclient.ICFactory; import org.gcube.resources.discovery.icclient.ICFactory;
import org.gcube.smartgears.ApplicationManager; import org.gcube.smartgears.ApplicationManager;
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.configuration.container.ContainerConfiguration; import org.gcube.smartgears.configuration.container.ContainerConfiguration;
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector; import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector;
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory; import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory;
@ -46,36 +47,6 @@ public class SmartExecutorInitializator implements ApplicationManager {
public static final long JOIN_TIMEOUT = 1000; public static final long JOIN_TIMEOUT = 1000;
/* *
* Contains the ServiceEnpoint Resource to be published/unpublished on IS
* /
private static ServiceEndpoint serviceEndpoint;
*/
/* *
* The application context
* /
protected static ApplicationContext ctx;
/**
* @return the ctx
* /
public static ApplicationContext getCtx() {
return ctx;
}
*/
/*
protected static ScheduledTaskConfiguration launchConfiguration;
/**
* @return the configuredTasks
* /
public static ScheduledTaskConfiguration getConfiguredTasks() {
return launchConfiguration;
}
*/
/** /**
* Publish the provided resource on all Service Scopes retrieved from * Publish the provided resource on all Service Scopes retrieved from
* Context * Context
@ -176,13 +147,13 @@ public class SmartExecutorInitializator implements ApplicationManager {
logger.debug("Creating ServiceEndpoint to publish on IS available plugins and their own supported capabilities"); logger.debug("Creating ServiceEndpoint to publish on IS available plugins and their own supported capabilities");
ServiceEndpoint serviceEndpoint = new ServiceEndpoint(); ServiceEndpoint serviceEndpoint = new ServiceEndpoint();
Profile profile = serviceEndpoint.newProfile(); Profile profile = serviceEndpoint.newProfile();
profile.category(SmartExecutorImpl.ctx.configuration().serviceClass()); profile.category(ContextProvider.get().configuration().serviceClass());
profile.name(SmartExecutorImpl.ctx.configuration().name()); profile.name(ContextProvider.get().configuration().name());
String version = SmartExecutorImpl.ctx.configuration().version(); String version = ContextProvider.get().configuration().version();
profile.version(version); profile.version(version);
profile.description(SmartExecutorImpl.ctx.configuration().description()); profile.description(ContextProvider.get().configuration().description());
String runningOn = getRunningOn(SmartExecutorImpl.ctx.container().configuration()); String runningOn = getRunningOn(ContextProvider.get().container().configuration());
Platform platform = profile.newPlatform(); Platform platform = profile.newPlatform();
platform.name(runningOn); platform.name(runningOn);
@ -194,7 +165,7 @@ public class SmartExecutorInitializator implements ApplicationManager {
Runtime runtime = profile.newRuntime(); Runtime runtime = profile.newRuntime();
runtime.hostedOn(runningOn); runtime.hostedOn(runningOn);
runtime.status(SmartExecutorImpl.ctx.configuration().mode().toString()); runtime.status(ContextProvider.get().configuration().mode().toString());
Group<AccessPoint> accessPoints = profile.accessPoints(); Group<AccessPoint> accessPoints = profile.accessPoints();
Map<String, PluginDeclaration> availablePlugins = pluginManager.getAvailablePlugins(); Map<String, PluginDeclaration> availablePlugins = pluginManager.getAvailablePlugins();
@ -256,9 +227,9 @@ public class SmartExecutorInitializator implements ApplicationManager {
private void cleanServiceEndpoints(){ private void cleanServiceEndpoints(){
try { try {
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class) SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class)
.addCondition(String.format("$resource/Profile/Category/text() eq '%s'", SmartExecutorImpl.ctx.configuration().serviceClass())) .addCondition(String.format("$resource/Profile/Category/text() eq '%s'", ContextProvider.get().configuration().serviceClass()))
.addCondition(String.format("$resource/Profile/Name/text() eq '%s'", SmartExecutorImpl.ctx.configuration().name())) .addCondition(String.format("$resource/Profile/Name/text() eq '%s'", ContextProvider.get().configuration().name()))
.addCondition(String.format("$resource/Profile/RunTime/HostedOn/text() eq '%s'", getRunningOn(SmartExecutorImpl.ctx.container().configuration()))) .addCondition(String.format("$resource/Profile/RunTime/HostedOn/text() eq '%s'", getRunningOn(ContextProvider.get().container().configuration())))
.setResult("$resource"); .setResult("$resource");
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class); DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);

View File

@ -13,7 +13,7 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.gcube.vremanagement.executor.SmartExecutorImpl; import org.gcube.smartgears.ContextProvider;
import org.gcube.vremanagement.executor.api.types.LaunchParameter; import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.api.types.Scheduling; import org.gcube.vremanagement.executor.api.types.Scheduling;
import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfiguration; import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfiguration;
@ -44,7 +44,7 @@ public class FileScheduledTaskConfiguration implements ScheduledTaskConfiguratio
public static final String CONFIG_TASK_FILENAME = "definedTasks.json"; public static final String CONFIG_TASK_FILENAME = "definedTasks.json";
public FileScheduledTaskConfiguration() throws Exception { public FileScheduledTaskConfiguration() throws Exception {
this(SmartExecutorImpl.getCtx().persistence().location()); this(ContextProvider.get().persistence().location());
} }
public FileScheduledTaskConfiguration(String location) throws IOException, JSONException { public FileScheduledTaskConfiguration(String location) throws IOException, JSONException {

View File

@ -10,7 +10,7 @@ import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.node.ObjectNode; import org.codehaus.jackson.node.ObjectNode;
import org.gcube.common.resources.gcore.GCoreEndpoint; import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.vremanagement.executor.SmartExecutorImpl; import org.gcube.smartgears.ContextProvider;
import org.gcube.vremanagement.executor.plugin.PluginDeclaration; import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution; import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
@ -46,9 +46,9 @@ public class PluginStateEvolutionObjectNode {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
ObjectNode objectNode = objectMapper.createObjectNode(); ObjectNode objectNode = objectMapper.createObjectNode();
try { try {
GCoreEndpoint gCoreEndpoint = SmartExecutorImpl.getCtx().profile(GCoreEndpoint.class); GCoreEndpoint gCoreEndpoint = ContextProvider.get().profile(GCoreEndpoint.class);
objectNode.put(GHN_ID_FIELD, gCoreEndpoint.profile().ghnId()); objectNode.put(GHN_ID_FIELD, gCoreEndpoint.profile().ghnId());
objectNode.put(GHN_HOSTNAME_FIELD, SmartExecutorImpl.getCtx().container().configuration().hostname()); objectNode.put(GHN_HOSTNAME_FIELD, ContextProvider.get().container().configuration().hostname());
}catch(Exception e){ }catch(Exception e){
objectNode.put(GHN_ID_FIELD, LOCALHOST + "_" + UUID.randomUUID()); objectNode.put(GHN_ID_FIELD, LOCALHOST + "_" + UUID.randomUUID());
objectNode.put(GHN_HOSTNAME_FIELD, LOCALHOST); objectNode.put(GHN_HOSTNAME_FIELD, LOCALHOST);

View File

@ -12,7 +12,7 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.gcube.common.resources.gcore.GCoreEndpoint; import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.vremanagement.executor.SmartExecutorImpl; import org.gcube.smartgears.ContextProvider;
import org.gcube.vremanagement.executor.api.types.LaunchParameter; import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.api.types.Scheduling; import org.gcube.vremanagement.executor.api.types.Scheduling;
import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfiguration; import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfiguration;
@ -150,7 +150,7 @@ public class SmartExecutorScheduler {
} }
try { try {
String runningInstanceID = SmartExecutorImpl.getCtx().profile(GCoreEndpoint.class).id(); String runningInstanceID = ContextProvider.get().profile(GCoreEndpoint.class).id();
logger.debug("Going to persist Scheduled Task {} which will be assigned to Running Instance {}. LaunchParameters : {} ", logger.debug("Going to persist Scheduled Task {} which will be assigned to Running Instance {}. LaunchParameters : {} ",
uuid.toString(), runningInstanceID, parameter); uuid.toString(), runningInstanceID, parameter);
ScheduledTaskConfiguration stc = ScheduledTaskConfigurationFactory.getLaunchConfiguration(); ScheduledTaskConfiguration stc = ScheduledTaskConfigurationFactory.getLaunchConfiguration();