コード例 #1
1
  @Override
  public <T> Collection<Resource> getAllocatedResources(Resource parent, Class<T> cls) {
    checkNotNull(parent);
    checkNotNull(cls);
    checkArgument(parent instanceof DiscreteResource);

    Versioned<Set<Resource>> children = childMap.get((DiscreteResource) parent);
    if (children == null) {
      return ImmutableList.of();
    }

    Stream<DiscreteResource> discrete =
        children
            .value()
            .stream()
            .filter(x -> x.last().getClass().equals(cls))
            .filter(x -> x instanceof DiscreteResource)
            .map(x -> (DiscreteResource) x)
            .filter(discreteConsumers::containsKey);

    Stream<ContinuousResource> continuous =
        children
            .value()
            .stream()
            .filter(x -> x.id().equals(parent.id().child(cls)))
            .filter(x -> x instanceof ContinuousResource)
            .map(x -> (ContinuousResource) x)
            .filter(x -> continuousConsumers.containsKey(x.id()))
            .filter(x -> continuousConsumers.get(x.id()) != null)
            .filter(x -> !continuousConsumers.get(x.id()).value().allocations().isEmpty());

    return Stream.concat(discrete, continuous).collect(Collectors.toList());
  }
コード例 #2
0
  @Override
  public Collection<Resource> getResources(ResourceConsumer consumer) {
    checkNotNull(consumer);

    // NOTE: getting all entries may become performance bottleneck
    // TODO: revisit for better backend data structure
    Stream<DiscreteResource> discreteStream =
        discreteConsumers
            .entrySet()
            .stream()
            .filter(x -> x.getValue().value().equals(consumer))
            .map(Map.Entry::getKey);

    Stream<ContinuousResource> continuousStream =
        continuousConsumers
            .values()
            .stream()
            .flatMap(
                x ->
                    x.value()
                        .allocations()
                        .stream()
                        .map(y -> Maps.immutableEntry(x.value().original(), y)))
            .filter(x -> x.getValue().consumer().equals(consumer))
            .map(x -> x.getKey());

    return Stream.concat(discreteStream, continuousStream).collect(Collectors.toList());
  }
コード例 #3
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");
  }
コード例 #4
0
 @Deactivate
 protected void deactivate() {
   regionsRepo.removeListener(listener);
   membershipRepo.removeListener(membershipListener);
   regionsByDevice.clear();
   log.info("Stopped");
 }
コード例 #5
0
  @Override
  public void addTunnelInfo(TunnelId tunnelId, ResourceConsumer tunnelConsumerId) {
    checkNotNull(tunnelId, TUNNEL_ID_NULL);
    checkNotNull(tunnelConsumerId, PCECC_TUNNEL_INFO_NULL);

    tunnelInfoMap.put(tunnelId, tunnelConsumerId);
  }
コード例 #6
0
 @Override
 public Map<TunnelId, ResourceConsumer> getTunnelInfos() {
   return tunnelInfoMap
       .entrySet()
       .stream()
       .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().value()));
 }
コード例 #7
0
  private List<ResourceConsumer> getConsumers(DiscreteResource resource) {
    Versioned<ResourceConsumer> consumer = discreteConsumers.get(resource);
    if (consumer == null) {
      return ImmutableList.of();
    }

    return ImmutableList.of(consumer.value());
  }
コード例 #8
0
  private boolean isAvailable(ContinuousResource resource) {
    Versioned<ContinuousResourceAllocation> allocation = continuousConsumers.get(resource.id());
    if (allocation == null) {
      // no allocation (=no consumer) full registered resources available
      return true;
    }

    return hasEnoughResource(allocation.value().original(), resource, allocation.value());
  }
コード例 #9
0
  @Override
  public boolean removeTunnelInfo(TunnelId tunnelId) {
    checkNotNull(tunnelId, TUNNEL_ID_NULL);

    if (tunnelInfoMap.remove(tunnelId) == null) {
      log.error("Tunnel info deletion for tunnel id {} has failed.", tunnelId.toString());
      return false;
    }
    return true;
  }
コード例 #10
0
 @Override
 public Region updateRegion(
     RegionId regionId, String name, Region.Type type, List<Set<NodeId>> masterNodeIds) {
   return regionsRepo
       .compute(
           regionId,
           (id, region) -> {
             nullIsNotFound(region, NO_REGION);
             return new DefaultRegion(regionId, name, type, masterNodeIds);
           })
       .value();
 }
コード例 #11
0
 @Override
 public Region createRegion(
     RegionId regionId, String name, Region.Type type, List<Set<NodeId>> masterNodeIds) {
   return regionsRepo
       .compute(
           regionId,
           (id, region) -> {
             checkArgument(region == null, DUPLICATE_REGION);
             return new DefaultRegion(regionId, name, type, masterNodeIds);
           })
       .value();
 }
コード例 #12
0
  private List<ResourceConsumer> getConsumers(ContinuousResource resource) {
    Versioned<ContinuousResourceAllocation> allocations = continuousConsumers.get(resource.id());
    if (allocations == null) {
      return ImmutableList.of();
    }

    return allocations
        .value()
        .allocations()
        .stream()
        .filter(x -> x.resource().equals(resource))
        .map(ResourceAllocation::consumer)
        .collect(GuavaCollectors.toImmutableList());
  }
コード例 #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 ResourceConsumer getTunnelInfo(TunnelId tunnelId) {
   checkNotNull(tunnelId, TUNNEL_ID_NULL);
   return tunnelInfoMap.get(tunnelId) == null ? null : tunnelInfoMap.get(tunnelId).value();
 }
コード例 #15
0
 @Override
 public int getTunnelInfoCount() {
   return tunnelInfoMap.size();
 }
コード例 #16
0
 @Override
 public boolean existsTunnelInfo(TunnelId tunnelId) {
   checkNotNull(tunnelId, TUNNEL_ID_NULL);
   return tunnelInfoMap.containsKey(tunnelId);
 }
コード例 #17
0
 @Override
 public void removeRegion(RegionId regionId) {
   membershipRepo.remove(regionId);
   regionsRepo.remove(regionId);
 }