Package org.apache.mesos.Protos

Examples of org.apache.mesos.Protos.Resource


  private static double getScalarValue(Offer offer, String key) {
    return getScalarValue(offer.getResourcesList(), key);
  }

  private static double getScalarValue(List<Resource> resources, String key) {
    Resource resource = getResource(resources, key);
    if (resource == null) {
      return 0;
    }

    return resource.getScalar().getValue();
  }
View Full Code Here


      }
    };
  }

  private static Iterable<Range> getPortRanges(List<Resource> resources) {
    Resource resource = getResource(resources, Resources.PORTS);
    if (resource == null) {
      return ImmutableList.of();
    }

    return resource.getRanges().getRangeList();
  }
View Full Code Here

  private static final String NAME = "resource_name";

  @Test
  public void testPortRangeExact() {
    Resource portsResource = createPortRange(Pair.of(1, 5));
    Set<Integer> ports = Resources.getPorts(createOffer(portsResource), 5);
    assertEquals(5, ports.size());
  }
View Full Code Here

    assertEquals(5, ports.size());
  }

  @Test
  public void testOnePortAvailable() {
    Resource portsResource = createPortRange(Pair.of(3, 3));
    Set<Integer> ports = Resources.getPorts(createOffer(portsResource), 1);
    assertEquals(1, ports.size());
  }
View Full Code Here

    assertEquals(1, ports.size());
  }

  @Test
  public void testPortRangeAbundance() {
    Resource portsResource = createPortRange(Pair.of(1, 10));
    Set<Integer> ports = Resources.getPorts(createOffer(portsResource), 5);
    assertEquals(5, ports.size());
  }
View Full Code Here

    assertEquals(5, ports.size());
  }

  @Test
  public void testPortRangeExhaust() {
    Resource portsResource = createPortRanges(Pair.of(1, 2), Pair.of(10, 15));

    Set<Integer> ports = Resources.getPorts(createOffer(portsResource), 7);
    assertEquals(7, ports.size());

    ports = Resources.getPorts(createOffer(portsResource), 8);
View Full Code Here

    }
  }

  @Test
  public void testGetNoPorts() {
    Resource portsResource = createPortRange(Pair.of(1, 5));
    assertEquals(ImmutableSet.<Integer>of(), Resources.getPorts(createOffer(portsResource), 0));
  }
View Full Code Here

    assertEquals(NEGATIVE_ONE, Resources.subtract(TWO, THREE));
  }

  @Test(expected = Resources.InsufficientResourcesException.class)
  public void testPortRangeScarcity() {
    Resource portsResource = createPortRange(Pair.of(1, 2));
    Resources.getPorts(createOffer(portsResource), 5);
  }
View Full Code Here

            Resources.makeMesosResource(Resources.DISK_MB, TASK.getDiskMb())),
        ImmutableSet.copyOf(resources.toResourceList(ImmutableSet.<Integer>of())));
  }

  private void expectRanges(Set<Pair<Long, Long>> expected, Set<Integer> values) {
    Resource resource = Resources.makeMesosRangeResource(NAME, values);
    assertEquals(Type.RANGES, resource.getType());
    assertEquals(NAME, resource.getName());

    Set<Pair<Long, Long>> actual = ImmutableSet.copyOf(Iterables.transform(
        resource.getRanges().getRangeList(),
        new Function<Range, Pair<Long, Long>>() {
          @Override
          public Pair<Long, Long> apply(Range range) {
            return Pair.of(range.getBegin(), range.getEnd());
          }
View Full Code Here

    }
    Assert.assertEquals(numPorts, portsFound);
  }

  private void test(int numPorts, String... ranges) {
    Resource resource = MesosUtils.getPortsResource(numPorts, buildOffer(ranges));

    assertFound(numPorts, resource);
  }
View Full Code Here

TOP

Related Classes of org.apache.mesos.Protos.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.