From 4cedf6c46b568926cf8ed06b8e0a817df07738ec Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 3 Feb 2017 15:29:25 +0000 Subject: [PATCH] Fixing bugs git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@142186 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 2 +- .../pluginmanager/RunnablePlugin.java | 15 ++----- .../executor/scheduledtask/ScheduledTask.java | 42 ++++++++++++------- .../ScheduledTaskPersistenceFactory.java | 2 +- .../scheduler/SmartExecutorScheduler.java | 4 +- ...SmartExecutorPersistenceConnectorTest.java | 2 +- 6 files changed, 37 insertions(+), 30 deletions(-) diff --git a/pom.xml b/pom.xml index 6d04a0e..6947491 100644 --- a/pom.xml +++ b/pom.xml @@ -118,7 +118,7 @@ com.orientechnologies - orientdb-graphdb + orientdb-client diff --git a/src/main/java/org/gcube/vremanagement/executor/pluginmanager/RunnablePlugin.java b/src/main/java/org/gcube/vremanagement/executor/pluginmanager/RunnablePlugin.java index cbd3bbb..70a7255 100644 --- a/src/main/java/org/gcube/vremanagement/executor/pluginmanager/RunnablePlugin.java +++ b/src/main/java/org/gcube/vremanagement/executor/pluginmanager/RunnablePlugin.java @@ -35,8 +35,6 @@ import org.slf4j.LoggerFactory; */ public class RunnablePlugin> implements Runnable { - private static final String LOCALHOST = "localhost"; - /** * Logger */ @@ -94,15 +92,10 @@ public class RunnablePlugin> imple taskUsageRecord.setConsumerId(SmartExecutorInitializator.getClientInfo().getId()); - try{ - RunOn runOn = ScheduledTask.generateRunOn(); - Ref hnRef = runOn.getHostingNode(); - taskUsageRecord.setRefHostingNodeId(hnRef.getId()); - taskUsageRecord.setHost(hnRef.getAddress()); - }catch(Exception e){ - taskUsageRecord.setRefHostingNodeId(LOCALHOST); - taskUsageRecord.setHost(LOCALHOST); - } + RunOn runOn = ScheduledTask.generateRunOn(); + Ref hnRef = runOn.getHostingNode(); + taskUsageRecord.setRefHostingNodeId(hnRef.getId()); + taskUsageRecord.setHost(hnRef.getAddress()); if(inputs!=null && inputs.size()>0){ HashMap map = diff --git a/src/main/java/org/gcube/vremanagement/executor/scheduledtask/ScheduledTask.java b/src/main/java/org/gcube/vremanagement/executor/scheduledtask/ScheduledTask.java index 51d5160..f8d7662 100644 --- a/src/main/java/org/gcube/vremanagement/executor/scheduledtask/ScheduledTask.java +++ b/src/main/java/org/gcube/vremanagement/executor/scheduledtask/ScheduledTask.java @@ -85,26 +85,40 @@ public class ScheduledTask { return runOn; } + + private static final String LOCALHOST = "localhost"; + /** * @param runOn the runOn to set */ public static RunOn generateRunOn() { - HostingNode hostingNode = ContextProvider.get().profile(HostingNode.class); - Ref hostingNodeRef = new Ref(hostingNode.id(), hostingNode.profile().description().name()); - - GCoreEndpoint gCoreEndpoint = ContextProvider.get().profile(GCoreEndpoint.class); - String address = ""; - Group endpoints = gCoreEndpoint.profile().endpoints(); - for(Endpoint endpoint : endpoints){ - if(endpoint.name().contains(Constants.remote_management)){ - continue; - }else{ - address = endpoint.uri().toString(); - break; - } + Ref hostingNodeRef = null; + try { + HostingNode hostingNode = ContextProvider.get().profile(HostingNode.class); + hostingNodeRef = new Ref(hostingNode.id(), hostingNode.profile().description().name()); + }catch (Exception e) { + // + hostingNodeRef = new Ref(LOCALHOST, LOCALHOST); } - Ref eServiceRef = new Ref(gCoreEndpoint.id(), address); + Ref eServiceRef = null; + try { + GCoreEndpoint gCoreEndpoint = ContextProvider.get().profile(GCoreEndpoint.class); + String address = ""; + Group endpoints = gCoreEndpoint.profile().endpoints(); + for(Endpoint endpoint : endpoints){ + if(endpoint.name().contains(Constants.remote_management)){ + continue; + }else{ + address = endpoint.uri().toString(); + break; + } + } + + eServiceRef = new Ref(gCoreEndpoint.id(), address); + }catch (Exception e) { + eServiceRef = new Ref(LOCALHOST, LOCALHOST); + } RunOn runOn = new RunOn(hostingNodeRef, eServiceRef); diff --git a/src/main/java/org/gcube/vremanagement/executor/scheduledtask/ScheduledTaskPersistenceFactory.java b/src/main/java/org/gcube/vremanagement/executor/scheduledtask/ScheduledTaskPersistenceFactory.java index e38b9f4..29562b6 100644 --- a/src/main/java/org/gcube/vremanagement/executor/scheduledtask/ScheduledTaskPersistenceFactory.java +++ b/src/main/java/org/gcube/vremanagement/executor/scheduledtask/ScheduledTaskPersistenceFactory.java @@ -11,7 +11,7 @@ import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFact */ public class ScheduledTaskPersistenceFactory { - public static ScheduledTaskPersistence getLaunchConfiguration() throws Exception { + public static ScheduledTaskPersistence getScheduledTaskPersistence() throws Exception { return (ScheduledTaskPersistence) SmartExecutorPersistenceFactory.getPersistenceConnector(); } diff --git a/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorScheduler.java b/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorScheduler.java index 45ecfd4..6f4c66c 100644 --- a/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorScheduler.java +++ b/src/main/java/org/gcube/vremanagement/executor/scheduler/SmartExecutorScheduler.java @@ -149,7 +149,7 @@ public class SmartExecutorScheduler { } try { - ScheduledTaskPersistence stc = ScheduledTaskPersistenceFactory.getLaunchConfiguration(); + ScheduledTaskPersistence stc = ScheduledTaskPersistenceFactory.getScheduledTaskPersistence(); ScheduledTask scheduledTask = new ScheduledTask(uuid, parameter); logger.debug("Going to persist Scheduled Task {} : {} ", scheduledTask); @@ -286,7 +286,7 @@ public class SmartExecutorScheduler { protected void removeFromPersistence(boolean global, UUID uuid, boolean remove) throws SchedulePersistenceException{ try { - ScheduledTaskPersistence stc = ScheduledTaskPersistenceFactory.getLaunchConfiguration(); + ScheduledTaskPersistence stc = ScheduledTaskPersistenceFactory.getScheduledTaskPersistence(); if(remove){ logger.debug("Going to remove the SmartExecutor Scheduled Task {} from global scheduling", uuid); stc.removeScheduledTask(uuid); diff --git a/src/test/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnectorTest.java b/src/test/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnectorTest.java index eaeaf92..e638b59 100644 --- a/src/test/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnectorTest.java +++ b/src/test/java/org/gcube/vremanagement/executor/persistence/SmartExecutorPersistenceConnectorTest.java @@ -69,7 +69,7 @@ public class SmartExecutorPersistenceConnectorTest extends ScopedTest { @Test public void getAvailableScheduledTasksTest() throws Exception { - ScheduledTaskPersistence stc = ScheduledTaskPersistenceFactory.getLaunchConfiguration(); + ScheduledTaskPersistence stc = ScheduledTaskPersistenceFactory.getScheduledTaskPersistence(); Assert.assertNotNull(stc); Assert.assertEquals(OrientDBPersistenceConnector.class, stc.getClass());