refs #508: Support Config File to run task at service startup
https://support.d4science.org/issues/508 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@117750 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
195795f329
commit
4637d76de7
|
@ -46,12 +46,29 @@ public class JSONLaunchParameter extends LaunchParameter {
|
|||
this.inputs.put(key, inputsJsonObject.get(key));
|
||||
}
|
||||
|
||||
JSONObject schedulingJsonObject = jsonObject.getJSONObject(SCHEDULING);
|
||||
if(schedulingJsonObject!=null){
|
||||
if(jsonObject.has(SCHEDULING)){
|
||||
JSONObject schedulingJsonObject = jsonObject.getJSONObject(SCHEDULING);
|
||||
this.scheduling = new JSONScheduling(schedulingJsonObject);
|
||||
}
|
||||
|
||||
this.persist = jsonObject.getBoolean(PERSIST);
|
||||
this.persist = true;
|
||||
if(jsonObject.has(PERSIST)){
|
||||
this.persist = jsonObject.getBoolean(PERSIST);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the scheduling
|
||||
*/
|
||||
public JSONScheduling getScheduling() {
|
||||
return scheduling;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param scheduling the scheduling to set
|
||||
*/
|
||||
public void setScheduling(JSONScheduling scheduling) {
|
||||
this.scheduling = scheduling;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,11 @@ package org.gcube.vremanagement.executor.configuration;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.acme.HelloWorldPlugin;
|
||||
import org.acme.HelloWorldPluginDeclaration;
|
||||
import org.gcube.vremanagement.executor.api.types.Scheduling;
|
||||
import org.json.JSONException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -17,6 +21,7 @@ import org.junit.Test;
|
|||
*/
|
||||
public class ParserTest {
|
||||
|
||||
public static final String TEST = "test";
|
||||
|
||||
@Test
|
||||
public void testLaunchConfiguredTask() throws IOException, JSONException {
|
||||
|
@ -24,6 +29,36 @@ public class ParserTest {
|
|||
location = location + "/src/test/resources";
|
||||
Parser parser = new Parser(location);
|
||||
List<JSONLaunchParameter> configuredTasks = parser.getConfiguredTasks();
|
||||
Assert.assertEquals(2, configuredTasks.size());
|
||||
Assert.assertEquals(3, configuredTasks.size());
|
||||
|
||||
JSONLaunchParameter parameter = configuredTasks.get(0);
|
||||
Assert.assertEquals(HelloWorldPluginDeclaration.NAME, parameter.getPluginName());
|
||||
Map<String, Object> inputs = parameter.getInputs();
|
||||
Assert.assertEquals(1000, inputs.get(HelloWorldPlugin.SLEEP_TIME));
|
||||
Assert.assertEquals(1, inputs.get(TEST));
|
||||
Assert.assertEquals(null, parameter.getScheduling());
|
||||
Assert.assertEquals(true, parameter.isPersist());
|
||||
|
||||
parameter = configuredTasks.get(1);
|
||||
Assert.assertEquals(parameter.getPluginName(), HelloWorldPluginDeclaration.NAME);
|
||||
inputs = parameter.getInputs();
|
||||
Assert.assertEquals(1000, inputs.get(HelloWorldPlugin.SLEEP_TIME));
|
||||
Assert.assertEquals(2, inputs.get(TEST));
|
||||
Scheduling scheduling = parameter.getScheduling();
|
||||
Assert.assertEquals(null, scheduling.getCronExpression());
|
||||
Assert.assertEquals(new Integer(2000), scheduling.getDelay());
|
||||
Assert.assertEquals(2, scheduling.getSchedulingTimes());
|
||||
Assert.assertEquals(null, scheduling.getFirtStartTime());
|
||||
Assert.assertEquals(null, scheduling.getEndTime());
|
||||
Assert.assertEquals(false, scheduling.mustPreviousExecutionsCompleted());
|
||||
Assert.assertEquals(true, parameter.isPersist());
|
||||
|
||||
parameter = configuredTasks.get(2);
|
||||
Assert.assertEquals(parameter.getPluginName(), HelloWorldPluginDeclaration.NAME);
|
||||
inputs = parameter.getInputs();
|
||||
Assert.assertEquals(1000, inputs.get(HelloWorldPlugin.SLEEP_TIME));
|
||||
Assert.assertEquals(3, inputs.get(TEST));
|
||||
Assert.assertEquals(null, parameter.getScheduling());
|
||||
Assert.assertEquals(true, parameter.isPersist());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,33 @@
|
|||
[
|
||||
|
||||
{
|
||||
"pluginName" : "HelloWorld",
|
||||
"inputs" : {
|
||||
"sleepTime" : 1000
|
||||
"sleepTime" : 1000,
|
||||
"test" : 1
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"pluginName" : "HelloWorld",
|
||||
"inputs" : {
|
||||
"sleepTime" : 5000
|
||||
"sleepTime" : 1000,
|
||||
"test" : 2
|
||||
},
|
||||
"scheduling" : {
|
||||
"delay" : "2000",
|
||||
"schedulingTimes" : "2",
|
||||
"previuosExecutionsMustBeCompleted" : false
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
"pluginName" : "HelloWorld",
|
||||
"inputs" : {
|
||||
"sleepTime" : 1000,
|
||||
"test" : 3
|
||||
},
|
||||
"persist" : true
|
||||
}
|
||||
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue