87 lines
2.4 KiB
Java
87 lines
2.4 KiB
Java
|
/**
|
||
|
*
|
||
|
*/
|
||
|
package org.gcube.vremanagement.executor.configuration;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.text.ParseException;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
|
||
|
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||
|
import org.gcube.vremanagement.executor.api.types.Scheduling;
|
||
|
import org.gcube.vremanagement.executor.utils.IOUtility;
|
||
|
import org.json.JSONArray;
|
||
|
import org.json.JSONException;
|
||
|
import org.json.JSONObject;
|
||
|
import org.slf4j.Logger;
|
||
|
import org.slf4j.LoggerFactory;
|
||
|
|
||
|
/**
|
||
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||
|
*
|
||
|
*/
|
||
|
public class Parser {
|
||
|
|
||
|
/**
|
||
|
* Logger
|
||
|
*/
|
||
|
private static Logger logger = LoggerFactory.getLogger(Parser.class);
|
||
|
|
||
|
protected String configurationFileLocation;
|
||
|
protected List<JSONLaunchParameter> configuredTasks;
|
||
|
|
||
|
public static final String CONFIG_TASK_FILENAME = "definedTasks.json";
|
||
|
|
||
|
|
||
|
public Parser(String location) throws IOException, JSONException {
|
||
|
this.configurationFileLocation = location;
|
||
|
this.configuredTasks = new ArrayList<JSONLaunchParameter>();
|
||
|
this.configuredTasks = retriveConfiguredTask();
|
||
|
}
|
||
|
|
||
|
protected Scheduling getScheduling(JSONObject jsonObject) throws JSONException, ParseException{
|
||
|
return new JSONScheduling(jsonObject);
|
||
|
}
|
||
|
|
||
|
protected List<JSONLaunchParameter> retriveConfiguredTask() throws IOException, JSONException {
|
||
|
|
||
|
String configuredTasksDefinition = IOUtility.readFile(configurationFileLocation + "/" + CONFIG_TASK_FILENAME);
|
||
|
List<JSONLaunchParameter> tasks = new ArrayList<JSONLaunchParameter>();
|
||
|
|
||
|
JSONArray jsonArray = new JSONArray(configuredTasksDefinition);
|
||
|
for(int i=0; i<jsonArray.length(); i++){
|
||
|
try {
|
||
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
||
|
JSONLaunchParameter parameter = new JSONLaunchParameter(jsonObject);
|
||
|
tasks.add(parameter);
|
||
|
} catch (Exception e) {
|
||
|
logger.error("Error launching configurad Task", e.getCause());
|
||
|
}
|
||
|
|
||
|
}
|
||
|
return tasks;
|
||
|
}
|
||
|
|
||
|
public void addLaunch(LaunchParameter parameter) throws ParseException {
|
||
|
configuredTasks.add(new JSONLaunchParameter(parameter));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return the configuredTasks
|
||
|
*/
|
||
|
public List<JSONLaunchParameter> getConfiguredTasks() {
|
||
|
return configuredTasks;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param configuredTasks the configuredTasks to set
|
||
|
*/
|
||
|
public void setConfiguredTasks(List<JSONLaunchParameter> configuredTasks) {
|
||
|
this.configuredTasks = configuredTasks;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|