Example #1
0
    @Override
    public void run() {
      // If there is no delegate, why bother? Just bail.
      if (delegate == null) {
        return;
      }

      if (event.reasons() == null || event.reasons().isEmpty()) {
        delegate.triggerCompile(Collections.emptySet(), true);

      } else {
        Set<Key> intentsToRecompile = new HashSet<>();
        boolean dontRecompileAllFailedIntents = true;

        // Scan through the list of reasons and keep accruing all
        // intents that need to be recompiled.
        for (Event reason : event.reasons()) {
          if (reason instanceof LinkEvent) {
            LinkEvent linkEvent = (LinkEvent) reason;
            final LinkKey linkKey = linkKey(linkEvent.subject());
            synchronized (intentsByLink) {
              Set<Key> intentKeys = intentsByLink.get(linkKey);
              log.debug(
                  "recompile triggered by LinkEvent {} ({}) for {}",
                  linkKey,
                  linkEvent.type(),
                  intentKeys);
              intentsToRecompile.addAll(intentKeys);
            }
            dontRecompileAllFailedIntents =
                dontRecompileAllFailedIntents
                    && (linkEvent.type() == LINK_REMOVED
                        || (linkEvent.type() == LINK_UPDATED && linkEvent.subject().isDurable()));
          }
        }
        delegate.triggerCompile(intentsToRecompile, !dontRecompileAllFailedIntents);
      }
    }
Example #2
0
  private void printEvent(Event<?, ?> event) {
    if (event instanceof DeviceEvent) {
      DeviceEvent deviceEvent = (DeviceEvent) event;
      if (event.type().toString().startsWith("PORT")) {
        // Port event
        print(
            "%s %s\t%s/%s [%s]",
            new LocalDateTime(event.time()),
            event.type(),
            deviceEvent.subject().id(),
            deviceEvent.port().number(),
            deviceEvent.port());
      } else {
        // Device event
        print(
            "%s %s\t%s [%s]",
            new LocalDateTime(event.time()),
            event.type(),
            deviceEvent.subject().id(),
            deviceEvent.subject());
      }

    } else if (event instanceof MastershipEvent) {
      print(
          "%s %s\t%s [%s]",
          new LocalDateTime(event.time()),
          event.type(),
          event.subject(),
          ((MastershipEvent) event).roleInfo());

    } else if (event instanceof LinkEvent) {
      LinkEvent linkEvent = (LinkEvent) event;
      Link link = linkEvent.subject();
      print(
          "%s %s\t%s/%s-%s/%s [%s]",
          new LocalDateTime(event.time()),
          event.type(),
          link.src().deviceId(),
          link.src().port(),
          link.dst().deviceId(),
          link.dst().port(),
          link);

    } else if (event instanceof HostEvent) {
      HostEvent hostEvent = (HostEvent) event;
      print(
          "%s %s\t%s [%s->%s]",
          new LocalDateTime(event.time()),
          event.type(),
          hostEvent.subject().id(),
          hostEvent.prevSubject(),
          hostEvent.subject());

    } else if (event instanceof TopologyEvent) {
      TopologyEvent topoEvent = (TopologyEvent) event;
      List<Event> reasons =
          MoreObjects.firstNonNull(topoEvent.reasons(), ImmutableList.<Event>of());
      Topology topo = topoEvent.subject();
      String summary =
          String.format(
              "(d=%d,l=%d,c=%d)", topo.deviceCount(), topo.linkCount(), topo.clusterCount());
      print(
          "%s %s%s [%s]",
          new LocalDateTime(event.time()),
          event.type(),
          summary,
          reasons.stream().map(e -> e.type()).collect(toList()));

    } else if (event instanceof ClusterEvent) {
      print(
          "%s %s\t%s [%s]",
          new LocalDateTime(event.time()),
          event.type(),
          ((ClusterEvent) event).subject().id(),
          event.subject());

    } else {
      // Unknown Event?
      print(
          "%s %s\t%s [%s]", new LocalDateTime(event.time()), event.type(), event.subject(), event);
    }
  }