// Path: scheduled-actions-core/src/main/java/com/netflix/scheduledactions/exceptions/ActionInstanceNotFoundException.java
// public class ActionInstanceNotFoundException extends Exception {
// 
//     public ActionInstanceNotFoundException(String message) {
//         super(message);
//     }
// 
//     public ActionInstanceNotFoundException(String message, Throwable throwable) {
//         super(message, throwable);
//     }
// }
// 
// Path: scheduled-actions-core/src/main/java/com/netflix/scheduledactions/executors/Executor.java
// public interface Executor {
//     public void execute(Action action, ActionInstance actionInstance, Execution execution) throws ExecutionException;
//     public void cancel(Action action, ActionInstance actionInstance, Execution execution) throws ExecutionException;
// }
// 
// Path: scheduled-actions-core/src/main/java/com/netflix/scheduledactions/persistence/ExecutionDao.java
// public interface ExecutionDao {
// 
//     public String createExecution(String actionInstanceId, Execution execution);
//     public void updateExecution(Execution execution);
//     public Execution getExecution(String executionId);
//     public void deleteExecution(String actionInstanceId, Execution execution);
//     public List<Execution> getExecutions(String actionInstanceId, int count);
//     public List<Execution> getExecutions(String actionInstanceId);
// 
// }


import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.netflix.fenzo.triggers.TriggerOperator;
import com.netflix.fenzo.triggers.exceptions.SchedulerException;
import com.netflix.scheduledactions.exceptions.ActionInstanceNotFoundException;
import com.netflix.scheduledactions.exceptions.ActionOperationException;
import com.netflix.scheduledactions.exceptions.ExecutionException;
import com.netflix.scheduledactions.exceptions.ExecutionNotFoundException;
import com.netflix.scheduledactions.executors.Executor;
import com.netflix.scheduledactions.persistence.ActionInstanceDao;
import com.netflix.scheduledactions.persistence.ExecutionDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rx.functions.Action1;
import java.util.ArrayList;
     * Enables the {@code ActionInstance}
     * @throws com.netflix.scheduledactions.exceptions.ActionOperationException
     */
    @Override
    public void enable(ActionInstance actionInstance) {
        actionInstance.setDisabled(false);
        actionInstanceDao.updateActionInstance(actionInstance);
        if (actionInstance.getFenzoTrigger() != null) {
            try {
                triggerOperator.enableTrigger(actionInstance.getFenzoTrigger());
            } catch (SchedulerException e) {
                throw new ActionOperationException(String.format(
                    "Exception occurred while enabling trigger %s for actionInstance %s", actionInstance.getTrigger(), actionInstance), e);
            }
        }
        logger.info("Successfully enabled the actionInstance {}", actionInstance);
    }

    /**
     * Deletes/Removes the {@code ActionInstance} associated with this actionInstanceId.
     * If it has a {@code CronTrigger} then it is also un-scheduled from scheduler
     * @throws ActionInstanceNotFoundException
     * @throws com.netflix.scheduledactions.exceptions.ActionOperationException
     */
    @Override
    public ActionInstance delete(String actionInstanceId) throws ActionInstanceNotFoundException {
        ActionInstance actionInstance = actionInstanceDao.getActionInstance(actionInstanceId);
        if (actionInstance != null) {
            delete(actionInstance);
        } else {
// Path: scheduled-actions-core/src/main/java/com/netflix/scheduledactions/exceptions/ActionInstanceNotFoundException.java
// public class ActionInstanceNotFoundException extends Exception {
// 
//     public ActionInstanceNotFoundException(String message) {
//         super(message);
//     }
// 
//     public ActionInstanceNotFoundException(String message, Throwable throwable) {
//         super(message, throwable);
//     }
// }
// 
// Path: scheduled-actions-core/src/main/java/com/netflix/scheduledactions/executors/Executor.java
// public interface Executor {
//     public void execute(Action action, ActionInstance actionInstance, Execution execution) throws ExecutionException;
//     public void cancel(Action action, ActionInstance actionInstance, Execution execution) throws ExecutionException;
// }
// 
// Path: scheduled-actions-core/src/main/java/com/netflix/scheduledactions/persistence/ExecutionDao.java
// public interface ExecutionDao {
// 
//     public String createExecution(String actionInstanceId, Execution execution);
//     public void updateExecution(Execution execution);
//     public Execution getExecution(String executionId);
//     public void deleteExecution(String actionInstanceId, Execution execution);
//     public List<Execution> getExecutions(String actionInstanceId, int count);
//     public List<Execution> getExecutions(String actionInstanceId);
// 
// }


// Path: scheduled-actions-core/src/main/java/com/netflix/scheduledactions/AbstractActionOperationsDelegate.java
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.netflix.fenzo.triggers.TriggerOperator;
import com.netflix.fenzo.triggers.exceptions.SchedulerException;
import com.netflix.scheduledactions.exceptions.ActionInstanceNotFoundException;
import com.netflix.scheduledactions.exceptions.ActionOperationException;
import com.netflix.scheduledactions.exceptions.ExecutionException;
import com.netflix.scheduledactions.exceptions.ExecutionNotFoundException;
import com.netflix.scheduledactions.executors.Executor;
import com.netflix.scheduledactions.persistence.ActionInstanceDao;
import com.netflix.scheduledactions.persistence.ExecutionDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rx.functions.Action1;
import java.util.ArrayList;

     * Enables the {@code ActionInstance}
     * @throws com.netflix.scheduledactions.exceptions.ActionOperationException
     */
    @Override
    public void enable(ActionInstance actionInstance) {
        actionInstance.setDisabled(false);
        actionInstanceDao.updateActionInstance(actionInstance);
        if (actionInstance.getFenzoTrigger() != null) {
            try {
                triggerOperator.enableTrigger(actionInstance.getFenzoTrigger());
            } catch (SchedulerException e) {
                throw new ActionOperationException(String.format(
                    "Exception occurred while enabling trigger %s for actionInstance %s", actionInstance.getTrigger(), actionInstance), e);
            }
        }
        logger.info("Successfully enabled the actionInstance {}", actionInstance);
    }

    /**
     * Deletes/Removes the {@code ActionInstance} associated with this actionInstanceId.
     * If it has a {@code CronTrigger} then it is also un-scheduled from scheduler
     * @throws ActionInstanceNotFoundException
     * @throws com.netflix.scheduledactions.exceptions.ActionOperationException
     */
    @Override
    public ActionInstance delete(String actionInstanceId) throws ActionInstanceNotFoundException {
        ActionInstance actionInstance = actionInstanceDao.getActionInstance(actionInstanceId);
        if (actionInstance != null) {
            delete(actionInstance);
        } else {
            throw new ActionInstanceNotFoundException("No actionInstance found with actionInstance id: " + actionInstanceId);