/**
  * Deletes/Removes the {@code ActionInstance}. If it has a {@code CronTrigger} then it is also
  * un-scheduled from scheduler
  *
  * @throws com.netflix.scheduledactions.exceptions.ActionOperationException
  */
 @Override
 public void delete(ActionInstance actionInstance) {
   actionInstanceDao.deleteActionInstance(actionInstance.getGroup(), actionInstance);
   if (actionInstance.getFenzoTrigger() != null) {
     try {
       triggerOperator.deleteTrigger(actionInstance.getGroup(), actionInstance.getFenzoTrigger());
     } catch (SchedulerException e) {
       throw new ActionOperationException(
           String.format(
               "Exception occurred while deleting trigger %s for actionInstance %s",
               actionInstance.getTrigger(), actionInstance),
           e);
     }
   }
   logger.info("Successfully deleted the actionInstance {}", actionInstance);
 }
  /**
   * Registers a {@code ActionInstance} with actionInstance service
   *
   * @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();
  }