Пример #1
0
  @Activate
  public void activate() {
    discreteConsumers =
        service
            .<DiscreteResource, ResourceConsumer>consistentMapBuilder()
            .withName(DISCRETE_CONSUMER_MAP)
            .withSerializer(SERIALIZER)
            .build();
    continuousConsumers =
        service
            .<ResourceId, ContinuousResourceAllocation>consistentMapBuilder()
            .withName(CONTINUOUS_CONSUMER_MAP)
            .withSerializer(SERIALIZER)
            .build();
    childMap =
        service
            .<DiscreteResource, Set<Resource>>consistentMapBuilder()
            .withName(CHILD_MAP)
            .withSerializer(SERIALIZER)
            .build();

    Tools.retryable(
        () -> childMap.put(Resource.ROOT, new LinkedHashSet<>()),
        ConsistentMapException.class,
        MAX_RETRIES,
        RETRY_DELAY);
    log.info("Started");
  }
Пример #2
0
  @Activate
  protected void activate() {
    Serializer serializer =
        Serializer.using(
            Arrays.asList(KryoNamespaces.API),
            Identifier.class,
            RegionId.class,
            Region.class,
            DefaultRegion.class,
            Region.Type.class);

    regionsRepo =
        storageService
            .<RegionId, Region>consistentMapBuilder()
            .withSerializer(serializer)
            .withName("onos-regions")
            .withRelaxedReadConsistency()
            .build();
    regionsRepo.addListener(listener);
    regionsById = regionsRepo.asJavaMap();

    membershipRepo =
        storageService
            .<RegionId, Set<DeviceId>>consistentMapBuilder()
            .withSerializer(serializer)
            .withName("onos-region-devices")
            .withRelaxedReadConsistency()
            .build();
    membershipRepo.addListener(membershipListener);
    regionDevices = membershipRepo.asJavaMap();
    log.info("Started");
  }
Пример #3
0
  @Override
  public boolean allocate(List<? extends Resource<?, ?>> resources, ResourceConsumer consumer) {
    checkNotNull(resources);
    checkNotNull(consumer);

    TransactionContext tx = service.transactionContextBuilder().build();
    tx.begin();

    try {
      TransactionalMap<Resource<?, ?>, ResourceConsumer> txMap =
          tx.getTransactionalMap(MAP_NAME, SERIALIZER);
      for (Resource<?, ?> resource : resources) {
        ResourceConsumer existing = txMap.putIfAbsent(resource, consumer);
        // if the resource is already allocated to another consumer, the whole allocation fails
        if (existing != null) {
          tx.abort();
          return false;
        }
      }
      tx.commit();
      return true;
    } catch (Exception e) {
      log.error("Exception thrown, abort the transaction", e);
      tx.abort();
      return false;
    }
  }
Пример #4
0
  @Override
  public boolean release(
      List<? extends Resource<?, ?>> resources, List<ResourceConsumer> consumers) {
    checkNotNull(resources);
    checkNotNull(consumers);
    checkArgument(resources.size() == consumers.size());

    TransactionContext tx = service.transactionContextBuilder().build();
    tx.begin();

    try {
      TransactionalMap<Resource<?, ?>, ResourceConsumer> txMap =
          tx.getTransactionalMap(MAP_NAME, SERIALIZER);
      Iterator<? extends Resource<?, ?>> resourceIte = resources.iterator();
      Iterator<ResourceConsumer> consumerIte = consumers.iterator();

      while (resourceIte.hasNext() && consumerIte.hasNext()) {
        Resource<?, ?> resource = resourceIte.next();
        ResourceConsumer consumer = consumerIte.next();

        // if this single release fails (because the resource is allocated to another consumer,
        // the whole release fails
        if (!txMap.remove(resource, consumer)) {
          tx.abort();
          return false;
        }
      }

      return true;
    } catch (TransactionException e) {
      log.error("Exception thrown, abort the transaction", e);
      tx.abort();
      return false;
    }
  }
Пример #5
0
  @Activate
  public void activate(ComponentContext context) {
    configService.registerProperties(getClass());

    idGenerator = coreService.getIdGenerator(FlowRuleService.FLOW_OP_TOPIC);

    local = clusterService.getLocalNode().id();

    messageHandlingExecutor =
        Executors.newFixedThreadPool(
            msgHandlerPoolSize, groupedThreads("onos/store/flow", "message-handlers"));

    registerMessageHandlers(messageHandlingExecutor);

    if (backupEnabled) {
      replicaInfoManager.addListener(flowTable);
      backupTask =
          backupSenderExecutor.scheduleWithFixedDelay(
              flowTable::backup, 0, backupPeriod, TimeUnit.MILLISECONDS);
    }

    deviceTableStats =
        storageService
            .<DeviceId, List<TableStatisticsEntry>>eventuallyConsistentMapBuilder()
            .withName("onos-flow-table-stats")
            .withSerializer(SERIALIZER_BUILDER)
            .withAntiEntropyPeriod(5, TimeUnit.SECONDS)
            .withTimestampProvider((k, v) -> new WallClockTimestamp())
            .withTombstonesDisabled()
            .build();
    deviceTableStats.addListener(tableStatsListener);

    logConfig("Started");
  }
Пример #6
0
 @Activate
 public void activate() {
   consumers =
       service
           .<Resource<?, ?>, ResourceConsumer>consistentMapBuilder()
           .withName(MAP_NAME)
           .withSerializer(SERIALIZER)
           .build();
 }
Пример #7
0
 @Override
 public IdBlock getIdBlock(String topic) {
   AtomicCounter counter =
       topicCounters.computeIfAbsent(
           topic, name -> storageService.atomicCounterBuilder().withName(name).build());
   Long blockBase =
       Tools.retryable(counter::getAndAdd, StorageException.class, MAX_TRIES, RETRY_DELAY_MS)
           .apply(DEFAULT_BLOCK_SIZE);
   return new IdBlock(blockBase, DEFAULT_BLOCK_SIZE);
 }
Пример #8
0
  @Override
  public boolean allocate(List<Resource> resources, ResourceConsumer consumer) {
    checkNotNull(resources);
    checkNotNull(consumer);

    TransactionContext tx = service.transactionContextBuilder().build();
    tx.begin();

    TransactionalMap<DiscreteResource, Set<Resource>> childTxMap =
        tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
    TransactionalMap<DiscreteResource, ResourceConsumer> discreteConsumerTxMap =
        tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
    TransactionalMap<ResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
        tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);

    for (Resource resource : resources) {
      if (resource instanceof DiscreteResource) {
        if (!lookup(childTxMap, resource).isPresent()) {
          return abortTransaction(tx);
        }

        ResourceConsumer oldValue =
            discreteConsumerTxMap.put((DiscreteResource) resource, consumer);
        if (oldValue != null) {
          return abortTransaction(tx);
        }
      } else if (resource instanceof ContinuousResource) {
        Optional<ContinuousResource> continuous = lookup(childTxMap, (ContinuousResource) resource);
        if (!continuous.isPresent()) {
          return abortTransaction(tx);
        }

        ContinuousResourceAllocation allocations =
            continuousConsumerTxMap.get(continuous.get().id());
        if (!hasEnoughResource(continuous.get(), (ContinuousResource) resource, allocations)) {
          return abortTransaction(tx);
        }

        boolean success =
            appendValue(
                continuousConsumerTxMap,
                continuous.get(),
                new ResourceAllocation(continuous.get(), consumer));
        if (!success) {
          return abortTransaction(tx);
        }
      }
    }

    return tx.commit();
  }
Пример #9
0
  @Override
  public boolean release(List<Resource> resources, List<ResourceConsumer> consumers) {
    checkNotNull(resources);
    checkNotNull(consumers);
    checkArgument(resources.size() == consumers.size());

    TransactionContext tx = service.transactionContextBuilder().build();
    tx.begin();

    TransactionalMap<DiscreteResource, ResourceConsumer> discreteConsumerTxMap =
        tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
    TransactionalMap<ResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
        tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
    Iterator<Resource> resourceIte = resources.iterator();
    Iterator<ResourceConsumer> consumerIte = consumers.iterator();

    while (resourceIte.hasNext() && consumerIte.hasNext()) {
      Resource resource = resourceIte.next();
      ResourceConsumer consumer = consumerIte.next();

      if (resource instanceof DiscreteResource) {
        // if this single release fails (because the resource is allocated to another consumer,
        // the whole release fails
        if (!discreteConsumerTxMap.remove((DiscreteResource) resource, consumer)) {
          return abortTransaction(tx);
        }
      } else if (resource instanceof ContinuousResource) {
        ContinuousResource continuous = (ContinuousResource) resource;
        ContinuousResourceAllocation allocation = continuousConsumerTxMap.get(continuous.id());
        ImmutableList<ResourceAllocation> newAllocations =
            allocation
                .allocations()
                .stream()
                .filter(
                    x ->
                        !(x.consumer().equals(consumer)
                            && ((ContinuousResource) x.resource()).value() == continuous.value()))
                .collect(GuavaCollectors.toImmutableList());

        if (!continuousConsumerTxMap.replace(
            continuous.id(),
            allocation,
            new ContinuousResourceAllocation(allocation.original(), newAllocations))) {
          return abortTransaction(tx);
        }
      }
    }

    return tx.commit();
  }
Пример #10
0
  @Activate
  protected void activate() {
    tunnelInfoMap =
        storageService
            .<TunnelId, ResourceConsumer>consistentMapBuilder()
            .withName("onos-pce-tunnelinfomap")
            .withSerializer(
                Serializer.using(
                    new KryoNamespace.Builder()
                        .register(KryoNamespaces.API)
                        .register(TunnelId.class, TunnelConsumerId.class)
                        .build()))
            .build();

    failedPathSet =
        storageService
            .<PcePathInfo>setBuilder()
            .withName("failed-path-info")
            .withSerializer(SERIALIZER)
            .build()
            .asDistributedSet();

    log.info("Started");
  }
Пример #11
0
  @Activate
  public void activate() {

    KryoNamespace.Builder serializer =
        KryoNamespace.newBuilder()
            .register(KryoNamespaces.API)
            .register(MultiValuedTimestamp.class)
            .register(PortPair.class);

    portPairStore =
        storageService
            .<PortPairId, PortPair>eventuallyConsistentMapBuilder()
            .withName("portpairstore")
            .withSerializer(serializer)
            .withTimestampProvider((k, v) -> new WallClockTimestamp())
            .build();

    log.info("Started");
  }
Пример #12
0
  @Override
  public boolean register(List<Resource> resources) {
    checkNotNull(resources);
    if (log.isTraceEnabled()) {
      resources.forEach(r -> log.trace("registering {}", r));
    }

    TransactionContext tx = service.transactionContextBuilder().build();
    tx.begin();

    TransactionalMap<DiscreteResource, Set<Resource>> childTxMap =
        tx.getTransactionalMap(CHILD_MAP, SERIALIZER);

    Map<DiscreteResource, List<Resource>> resourceMap =
        resources
            .stream()
            .filter(x -> x.parent().isPresent())
            .collect(Collectors.groupingBy(x -> x.parent().get()));

    for (Map.Entry<DiscreteResource, List<Resource>> entry : resourceMap.entrySet()) {
      Optional<DiscreteResource> child = lookup(childTxMap, entry.getKey());
      if (!child.isPresent()) {
        return abortTransaction(tx);
      }

      if (!appendValues(childTxMap, entry.getKey(), entry.getValue())) {
        return abortTransaction(tx);
      }
    }

    boolean success = tx.commit();
    if (success) {
      List<ResourceEvent> events =
          resources
              .stream()
              .filter(x -> x.parent().isPresent())
              .map(x -> new ResourceEvent(RESOURCE_ADDED, x))
              .collect(Collectors.toList());
      notifyDelegate(events);
    }
    return success;
  }
Пример #13
0
  @Activate
  public void activate() {

    mcastRib =
        storageService
            .<McastRoute, MulticastData>consistentMapBuilder()
            .withName(MCASTRIB)
            .withSerializer(
                Serializer.using(
                    KryoNamespace.newBuilder()
                        .register(KryoNamespaces.API)
                        .register(
                            AtomicReference.class,
                            MulticastData.class,
                            McastRoute.class,
                            McastRoute.Type.class)
                        .build()))
            // .withRelaxedReadConsistency()
            .build();

    mcastRoutes = mcastRib.asJavaMap();

    log.info("Started");
  }
Пример #14
0
  @Override
  public boolean unregister(List<Resource> resources) {
    checkNotNull(resources);

    TransactionContext tx = service.transactionContextBuilder().build();
    tx.begin();

    TransactionalMap<DiscreteResource, Set<Resource>> childTxMap =
        tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
    TransactionalMap<DiscreteResource, ResourceConsumer> discreteConsumerTxMap =
        tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
    TransactionalMap<ResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
        tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);

    // Extract Discrete instances from resources
    Map<DiscreteResource, List<Resource>> resourceMap =
        resources
            .stream()
            .filter(x -> x.parent().isPresent())
            .collect(Collectors.groupingBy(x -> x.parent().get()));

    // even if one of the resources is allocated to a consumer,
    // all unregistrations are regarded as failure
    for (Map.Entry<DiscreteResource, List<Resource>> entry : resourceMap.entrySet()) {
      boolean allocated =
          entry
              .getValue()
              .stream()
              .anyMatch(
                  x -> {
                    if (x instanceof DiscreteResource) {
                      return discreteConsumerTxMap.get((DiscreteResource) x) != null;
                    } else if (x instanceof ContinuousResource) {
                      ContinuousResourceAllocation allocations =
                          continuousConsumerTxMap.get(x.id());
                      return allocations != null && !allocations.allocations().isEmpty();
                    } else {
                      return false;
                    }
                  });
      if (allocated) {
        return abortTransaction(tx);
      }

      if (!removeValues(childTxMap, entry.getKey(), entry.getValue())) {
        return abortTransaction(tx);
      }
    }

    boolean success = tx.commit();
    if (success) {
      List<ResourceEvent> events =
          resources
              .stream()
              .filter(x -> x.parent().isPresent())
              .map(x -> new ResourceEvent(RESOURCE_REMOVED, x))
              .collect(Collectors.toList());
      notifyDelegate(events);
    }
    return success;
  }