Ejemplo n.º 1
0
  @Override
  public void propagateService(Task task, Date time) throws InternalErrorException {
    log.debug("   Is the execService ID:" + task.getExecServiceId() + " enabled globally?");
    if (!task.getExecService().isEnabled()) {
      schedulingPool.setTaskStatus(task, TaskStatus.DONE);
      log.info("Exec service for task {} is globally disabled, setting as done.", task.getId());
      return;
    } else {
      log.debug("   Yes, it is globally enabled.");
    }

    // Is the ExecService denied on this Facility?
    // If it is, we drop it and do nothing.
    log.debug(
        "   Is the execService ID:"
            + task.getExecServiceId()
            + " denied on facility ID:"
            + task.getFacilityId()
            + "?");
    if (denialsResolver.isExecServiceDeniedOnFacility(task.getExecService(), task.getFacility())) {
      schedulingPool.setTaskStatus(task, TaskStatus.DONE);
      log.info(
          "Exec service "
              + task.getExecServiceId()
              + " for task "
              + task.getId()
              + " is denied for facility "
              + task.getFacilityId()
              + ", setting as done.");
      return;
    } else {
      log.debug("   No, it is not.");
    }

    // check if we have destinations for this task
    List<Destination> destinations = task.getDestinations();
    if (destinations == null || destinations.isEmpty()) {
      // refetch the destination list from central database
      log.debug(
          "No destinations for task " + task.toString() + ", trying to query the database...");
      try {
        destinations =
            perun
                .getServicesManager()
                .getDestinations(
                    perunSession, task.getExecService().getService(), task.getFacility());
      } catch (ServiceNotExistsException e) {
        log.error("No destinations found for task " + task.toString());
        // TODO: remove the task?
        return;
      } catch (FacilityNotExistsException e) {
        log.error("Facility for task does not exist..." + task.toString());
        // TODO: remove the task?
        return;
      } catch (PrivilegeException e) {
        log.error("Privilege error accessing the database: " + e.getMessage());
        return;
      } catch (InternalErrorException e) {
        log.error("Internal error: " + e.getMessage());
        return;
      }
      task.setDestinations(destinations);
    }
    if (task.getExecService().getExecServiceType().equals(ExecServiceType.SEND)
        && (destinations == null || destinations.isEmpty())) {
      log.info("No destinations found for SEND task {}, marking as DONE", task.getId());
      schedulingPool.setTaskStatus(task, TaskStatus.DONE);
    } else {
      schedulingPool.setTaskStatus(task, TaskStatus.PLANNED);
      taskStatusManager.clearTaskStatus(task);
      task.setSchedule(time);
    }
  }