Exemplo n.º 1
0
    @Override
    public Number calculate(Iterable<IScheduledTask> tasks, Range<Long> timeFrame) {
      Iterable<IScheduledTask> activeTasks =
          FluentIterable.from(tasks)
              .filter(Predicates.compose(Predicates.in(Tasks.ACTIVE_STATES), Tasks.GET_STATUS));

      List<Long> waitTimes = Lists.newLinkedList();
      for (IScheduledTask task : activeTasks) {
        long pendingTs = 0;
        for (ITaskEvent event : task.getTaskEvents()) {
          if (event.getStatus() == PENDING) {
            pendingTs = event.getTimestamp();
          } else if (event.getStatus() == status && timeFrame.contains(event.getTimestamp())) {

            if (pendingTs == 0) {
              throw new IllegalArgumentException(
                  "SLA: missing PENDING status for:" + task.getAssignedTask().getTaskId());
            }

            waitTimes.add(event.getTimestamp() - pendingTs);
            break;
          }
        }
      }

      return SlaUtil.percentile(waitTimes, 50.0);
    }
Exemplo n.º 2
0
          @Override
          public List<Interval> apply(List<ITaskEvent> events) {

            ImmutableList.Builder<Interval> intervals = ImmutableList.builder();
            Pair<SlaState, Long> current = Pair.of(SlaState.REMOVED, 0L);

            for (ITaskEvent event : events) {
              long timestamp = event.getTimestamp();

              // Event status in the instance timeline signifies either of the following:
              // - termination of the existing SlaState interval AND start of a new one;
              // - continuation of the existing matching SlaState interval.
              switch (event.getStatus()) {
                case LOST:
                case DRAINING:
                case PREEMPTING:
                  current = updateIntervals(timestamp, SlaState.DOWN, current, intervals);
                  break;

                case PENDING:
                case ASSIGNED:
                case STARTING:
                  if (current.getFirst() != SlaState.DOWN) {
                    current = updateIntervals(timestamp, SlaState.REMOVED, current, intervals);
                  }
                  break;

                case THROTTLED:
                case FINISHED:
                case RESTARTING:
                case FAILED:
                case KILLING:
                  current = updateIntervals(timestamp, SlaState.REMOVED, current, intervals);
                  break;

                case RUNNING:
                  current = updateIntervals(timestamp, SlaState.UP, current, intervals);
                  break;

                case KILLED:
                  if (current.getFirst() == SlaState.UP) {
                    current = updateIntervals(timestamp, SlaState.DOWN, current, intervals);
                  }
                  break;

                case INIT:
                  // Ignore.
                  break;

                default:
                  throw new IllegalArgumentException("Unsupported status:" + event.getStatus());
              }
            }
            // Add the last event interval.
            intervals.add(new Interval(current.getFirst(), current.getSecond(), Long.MAX_VALUE));
            return intervals.build();
          }
Exemplo n.º 3
0
 @Override
 public Long apply(ITaskEvent taskEvent) {
   return taskEvent.getTimestamp();
 }