// 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;
     * @param actionInstance
     */
    @Override
    public String register(ActionInstance actionInstance) {
        validate(actionInstance);

        actionInstanceDao.createActionInstance(actionInstance.getGroup(), actionInstance);
        if (actionInstance.getTrigger() != null) {
            actionInstance.setFenzoTrigger(actionInstance.getTrigger().createFenzoTrigger(actionInstance.getContext(),
                InternalAction.class));
            try {
                triggerOperator.registerTrigger(actionInstance.getGroup(), actionInstance.getFenzoTrigger());
            } catch (SchedulerException e) {
                throw new ActionOperationException(String.format(
                    "Exception occurred while registering actionInstance %s", actionInstance), e);
            }
        }
        actionInstanceDao.updateActionInstance(actionInstance);

        logger.info("Successfully registered the actionInstance {}", actionInstance);
        return actionInstance.getId();
    }

    public static class InternalAction implements Action1<Context> {
        @Override
        public void call(Context context) {
            String actionInstanceId = context.getActionInstanceId();
            try {
                logger.info("[{}] InternalAction: Calling execute() on delegate with context: {}", actionInstanceId, context);
                actionOperationsDelegate.execute(actionInstanceId, "ScheduledTrigger"); // TODO: Pass trigger info from context
// 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;

     * @param actionInstance
     */
    @Override
    public String register(ActionInstance actionInstance) {
        validate(actionInstance);

        actionInstanceDao.createActionInstance(actionInstance.getGroup(), actionInstance);
        if (actionInstance.getTrigger() != null) {
            actionInstance.setFenzoTrigger(actionInstance.getTrigger().createFenzoTrigger(actionInstance.getContext(),
                InternalAction.class));
            try {
                triggerOperator.registerTrigger(actionInstance.getGroup(), actionInstance.getFenzoTrigger());
            } catch (SchedulerException e) {
                throw new ActionOperationException(String.format(
                    "Exception occurred while registering actionInstance %s", actionInstance), e);
            }
        }
        actionInstanceDao.updateActionInstance(actionInstance);

        logger.info("Successfully registered the actionInstance {}", actionInstance);
        return actionInstance.getId();
    }

    public static class InternalAction implements Action1<Context> {
        @Override
        public void call(Context context) {
            String actionInstanceId = context.getActionInstanceId();
            try {
                logger.info("[{}] InternalAction: Calling execute() on delegate with context: {}", actionInstanceId, context);
                actionOperationsDelegate.execute(actionInstanceId, "ScheduledTrigger"); // TODO: Pass trigger info from context
            } catch (ActionInstanceNotFoundException e) {}