/** * */ package org.gcube.vremanagement.executor.configuration.jsonbased; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.text.ParseException; import java.util.ArrayList; import java.util.List; import java.util.UUID; import org.apache.commons.io.FileUtils; import org.gcube.smartgears.ContextProvider; import org.gcube.vremanagement.executor.api.types.LaunchParameter; import org.gcube.vremanagement.executor.api.types.Scheduling; import org.gcube.vremanagement.executor.configuration.ScheduledTaskConfiguration; import org.gcube.vremanagement.executor.exception.SchedulePersistenceException; import org.gcube.vremanagement.executor.exception.ScopeNotMatchException; 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 FileScheduledTaskConfiguration implements ScheduledTaskConfiguration { /** * Logger */ private static Logger logger = LoggerFactory.getLogger(FileScheduledTaskConfiguration.class); protected String configurationFileLocation; protected List configuredTasks; public static final String CONFIG_TASK_FILENAME = "definedTasks.json"; public FileScheduledTaskConfiguration() throws Exception { this(ContextProvider.get().persistence().location()); } public FileScheduledTaskConfiguration(String location) throws IOException, JSONException { this.configurationFileLocation = location; this.configuredTasks = new ArrayList(); this.configuredTasks = retriveConfiguredTask(); } protected Scheduling getScheduling(JSONObject jsonObject) throws JSONException, ParseException, ScopeNotMatchException { return new JSONScheduling(jsonObject); } protected static String configurationFileName(String configurationFileLocation){ return configurationFileLocation + "/" + CONFIG_TASK_FILENAME; } public List retriveConfiguredTask() throws IOException, JSONException { String configuredTasksDefinition = IOUtility.readFile(configurationFileName(configurationFileLocation)); List tasks = new ArrayList(); JSONArray jsonArray = new JSONArray(configuredTasksDefinition); for(int i=0; i getConfiguredTasks() { return configuredTasks; } /** * @param configuredTasks the configuredTasks to set */ public void setConfiguredTasks(List configuredTasks) { this.configuredTasks = configuredTasks; } /** {@inheritDoc} */ @Override public List getAvailableScheduledTasks() throws SchedulePersistenceException { // TODO Auto-generated method stub return null; } /** {@inheritDoc} */ @Override public void reserveScheduledTask(UUID uuid, String consumerID) throws SchedulePersistenceException { // TODO Auto-generated method stub } /** {@inheritDoc} */ @Override public void removeScheduledTask(UUID uuid) throws SchedulePersistenceException { // TODO Auto-generated method stub } /** {@inheritDoc} */ @Override public void releaseScheduledTask(UUID uuid) throws SchedulePersistenceException { // TODO Auto-generated method stub } /* (non-Javadoc) * @see org.gcube.vremanagement.executor.configuration.ScheduledTaskConfiguration#getScheduledTask(java.util.UUID) */ @Override public LaunchParameter getScheduledTask(UUID uuid) throws SchedulePersistenceException { // TODO Auto-generated method stub return null; } }