protected int getNumReducers(Job job, Collection<Tier> allTiers) throws IOException {
   long totRecords = 0;
   for (Tier t : allTiers) {
     totRecords += t.getNumRecords();
   }
   return getNumTypeReducers(job.getConfiguration(), totRecords);
 }
Beispiel #2
0
 /**
  * Link the given next leaf after the given leaf.
  *
  * @param <T> The value type of the b+tree objects.
  * @param <A> The address type used to identify an inner or leaf tier.
  * @param mutation The mutation state container.
  * @param leaf The leaf.
  * @param nextLeaf The next leaf.
  */
 public static <T, A> void link(Mutation<T, A> mutation, Tier<T, A> leaf, Tier<T, A> nextLeaf) {
   Structure<T, A> structure = mutation.getStructure();
   Stage<T, A> writer = structure.getStage();
   writer.dirty(mutation.getStash(), leaf);
   writer.dirty(mutation.getStash(), nextLeaf);
   nextLeaf.setNext(leaf.getNext());
   leaf.setNext(nextLeaf.getAddress());
 }
Beispiel #3
0
 public static Tier fromNumerical(int numerical) {
   for (Tier tier : Tier.values()) {
     if (tier.toNumerical() == numerical) {
       return tier;
     }
   }
   return null;
 }
Beispiel #4
0
 /**
  * Get the next leaf in the b-tree from the next property of the given leaf, lock it and add it to
  * the list of locked leaves in the given leaf level.
  *
  * @param <T> The value type of the b+tree objects.
  * @param <A> The address type used to identify an inner or leaf tier.
  * @param mutation The mutation state container.
  * @param leaf The leaf.
  * @param leafLevel The mutation state for the leaf level.
  * @return The next leaf or null if the given leaf is the last leaf in the b-tree.
  */
 public static <T, A> Tier<T, A> getNextAndLock(
     Mutation<T, A> mutation, Tier<T, A> leaf, Level<T, A> leafLevel) {
   Structure<T, A> structure = mutation.getStructure();
   if (!structure.getStorage().isNull(leaf.getNext())) {
     Tier<T, A> next = structure.getStorage().load(mutation.getStash(), leaf.getNext());
     leafLevel.lockAndAdd(next);
     return next;
   }
   return null;
 }
 public Tier getTier() {
   final String tier = get(XMLProperty.tier);
   if (!tier.isEmpty()) {
     return Tier.valueOf(tier);
   }
   return Tier.UNRANKED;
 }
 protected void splitUp(Tier tier, Job j) throws IOException {
   while (true) {
     Path[] files = tier.getCreationOutputFiles(Solver.underscoreFilter);
     if (files.length == 0) break;
     Path file = files[0];
     String name = file.getName();
     String ext = name.substring(name.lastIndexOf("."));
     Tier nextTier = getTier(ext);
     if (!nextTier.filter.accept(file)) {
       throw new Error(nextTier.filter + " does not accept " + file);
     }
     updateEdges(tier, nextTier);
     tier.createTempFolder();
     Path[] sameTier = tier.getCreationOutputFiles(nextTier.filter);
     assert Util.contains(sameTier, file);
     for (Path n : sameTier) tier.moveToTemp(n);
     long numPositions = recordsWritten(j, nextTier.num);
     putBack(tier, nextTier, numPositions);
   }
 }
Beispiel #7
0
  @Test
  public void testIsDifferentRegions() {
    Tier tier = new Tier("name1", new Integer(1), new Integer(5), new Integer(1), null);
    tier.setRegion("region1");

    Tier tier2 = new Tier("name2", new Integer(1), new Integer(5), new Integer(1), null);
    tier.setRegion("region2");

    Set<Tier> tiers = new HashSet<Tier>();
    tiers.add(tier);
    tiers.add(tier2);

    Environment env = new Environment();

    env.setName("environmentName");
    env.addTier(tier);
    env.addTier(tier2);

    boolean result = env.isDifferentRegions();
    assertEquals(result, true);
  }
Beispiel #8
0
  @Test
  public void testIsNetworkFederated() {

    ProductRelease productRelease = new ProductRelease("product", "2.0");
    List<ProductRelease> productReleases = new ArrayList<ProductRelease>();
    productReleases.add(productRelease);

    Tier tier = new Tier("name1", new Integer(1), new Integer(5), new Integer(1), productReleases);
    tier.setRegion("region1");
    tier.addNetwork(new Network("uno", VDC, REGION));

    Tier tier2 = new Tier("name2", new Integer(1), new Integer(5), new Integer(1), productReleases);
    tier2.setRegion("region2");
    tier2.addNetwork(new Network("uno", VDC, REGION));

    Set<Tier> tiers = new HashSet<Tier>();
    tiers.add(tier);
    tiers.add(tier2);

    Environment envResult = new Environment("environemntName", tiers, "description", "ORG", VDC);
    envResult.setName("environemntName");
    envResult.setTiers(tiers);

    boolean result = envResult.isNetworkFederated();
    assertEquals(result, true);
    assertEquals(envResult.getDescription(), "description");
    assertEquals(envResult.getVdc(), VDC);
    assertEquals(envResult.getOrg(), "ORG");
  }
Beispiel #9
0
  @Test
  public void testCreateEnvironment() throws Exception {

    ProductRelease productRelease = new ProductRelease("product", "2.0");
    List<ProductRelease> productReleases = new ArrayList<ProductRelease>();
    productReleases.add(productRelease);

    Tier tier = new Tier();
    tier.setInitialNumberInstances(new Integer(1));
    tier.setMaximumNumberInstances(new Integer(5));
    tier.setMinimumNumberInstances(new Integer(1));
    tier.setName("tierName");
    tier.setProductReleases(productReleases);
    tier.setFlavour("3");
    tier.setFloatingip("true");
    tier.setImage("image");

    Tier tier2 =
        new Tier(
            "name",
            new Integer(1),
            new Integer(1),
            new Integer(1),
            productReleases,
            "4",
            "image2",
            "icone2");

    Set<Tier> tiers = new HashSet<Tier>();
    tiers.add(tier);
    tiers.add(tier2);

    Environment envResult = new Environment();
    envResult.setName("environemntName");
    envResult.addTier(tier2);
    envResult.addTier(tier);
    // envResult.setTiers(tiers);

    EnvironmentDto envDto = envResult.toDto();
    Environment env2 = envDto.fromDto();
    assertEquals(env2, envResult);

    assertEquals(envResult.getTiers().size(), 2);
  }
Beispiel #10
0
  private byte[] getInternal(Tier tier, long hashCode) {
    byte[] existingData;

    /**
     * Need SPIN to retrieve data from the underlying array because the index might have changed
     * with the _split.
     */

    // Map key to an array index
    int index = tier.getMainIndex(hashCode, _level, _split);

    do {
      // Read existing data at the index
      existingData = _dataArray.get(index);

      // Check that key is still mapped to the known index
      int indexNew = tier.getMainIndex(hashCode, _level, _split);
      if (indexNew == index) break;
      index = indexNew;
    } while (true);

    return existingData;
  }
Beispiel #11
0
  public void testGetNetworkWithRegionAndName() {
    Tier tier = new Tier("name1", new Integer(1), new Integer(5), new Integer(1), null);
    tier.setRegion(REGION);
    tier.addNetwork(new Network("uno2", VDC, REGION));

    Tier tier3 = new Tier("name3", new Integer(1), new Integer(5), new Integer(1), null);
    tier3.setRegion("region3");
    tier3.addNetwork(new Network("uno3", VDC, REGION + 3));

    Set<Tier> tiers = new HashSet<Tier>();
    tiers.add(tier);
    tiers.add(tier3);

    Environment envResult = new Environment("environemntName", tiers);

    Network net = envResult.getNetworkWithRegionAndName(REGION, "uno2");
    Network net2 = envResult.getNetworkWithRegionAndName(REGION + 3, "uno3");
    assertEquals(net.getNetworkName(), "uno2");
    assertEquals(net2.getNetworkName(), "uno3");
    assertNull(envResult.getNetworkWithRegionAndName(REGION + 3, "noexists"));
  }
Beispiel #12
0
  @Test
  public void testEnvironmentII() {

    Tier tier = new Tier("name1", new Integer(1), new Integer(5), new Integer(1), null);
    tier.setRegion("region1");
    tier.addNetwork(new Network("uno2", VDC, REGION));

    Tier tier3 = new Tier("name3", new Integer(1), new Integer(5), new Integer(1), null);
    tier3.setRegion("region3");
    tier3.addNetwork(new Network("uno2", VDC, REGION));

    Tier tier2 = new Tier("name2", new Integer(1), new Integer(5), new Integer(1), null);
    tier2.setRegion("region2");
    tier2.addNetwork(new Network("uno", VDC, REGION));

    Set<Tier> tiers = new HashSet<Tier>();
    tiers.add(tier);

    Environment envResult = new Environment("environemntName", tiers);
    assertEquals(envResult.getTiers().size(), 1);

    envResult.addTier(tier2);
    assertEquals(envResult.getTiers().size(), 2);

    envResult.deleteTier(tier);
    assertEquals(envResult.getTiers().size(), 1);

    envResult.updateTier(tier2, tier3);

    for (Tier t : envResult.getTiers()) {
      assertEquals(t.getName(), "name3");
    }
  }
Beispiel #13
0
  /**
   * Define the tier in which the pool will be added.
   *
   * @see API: <a href=
   *     "http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-Createastoragepoolwithatierlink"
   *     > http://community.abiquo.com/display/ABI20/StoragePoolResource# StoragePoolResource-
   *     Createastoragepoolwithatierlink</a>
   */
  public void setTier(final Tier tier) {
    checkNotNull(tier, ValidationErrors.NULL_RESOURCE + Privilege.class);
    checkNotNull(tier.getId(), ValidationErrors.MISSING_REQUIRED_FIELD + " id in " + Tier.class);

    this.updateLink(target, ParentLinkName.TIER, tier.unwrap(), "edit");
  }
 public LolStatus setTier(Tier t) {
   setElement(XMLProperty.tier, t.name());
   return this;
 }
 public LolStatus setRankedLeagueTier(Tier t) {
   setElement(XMLProperty.rankedLeagueTier, t.name());
   return this;
 }
Beispiel #16
0
 protected Tier getTier(int index) {
   return _tier1.hasIndex(index) ? _tier1 : (_tier2.hasIndex(index) ? _tier2 : _tier3);
 }
Beispiel #17
0
 /**
  * If the root inner tier is currently at the root inner tier capacity then the decision returns
  * true.
  *
  * @param mutation The mutation state container.
  * @param rootLevel The per level mutation state for the root level.
  * @param root The root inner tier.
  * @return True if root inner tier is at capacity.
  */
 public boolean test(Mutation<T, A> mutation, Level<T, A> rootLevel, Tier<T, A> root) {
   return mutation.getStructure().getInnerSize() == root.getSize();
 }
Beispiel #18
0
  @Test
  public void testgetRegionNetworks() {

    ProductRelease productRelease = new ProductRelease("product", "2.0");
    List<ProductRelease> productReleases = new ArrayList<ProductRelease>();
    productReleases.add(productRelease);

    Tier tier = new Tier("name1", new Integer(1), new Integer(5), new Integer(1), productReleases);
    tier.setRegion("region1");
    tier.addNetwork(new Network("uno2", VDC, REGION));

    Tier tier3 = new Tier("name3", new Integer(1), new Integer(5), new Integer(1), productReleases);
    tier3.setRegion("region3");
    tier3.addNetwork(new Network("uno2", VDC, REGION));

    Tier tier2 = new Tier("name2", new Integer(1), new Integer(5), new Integer(1), productReleases);
    tier2.setRegion("region2");
    tier2.addNetwork(new Network("uno", VDC, REGION));

    Tier tier4 = new Tier("name5", new Integer(1), new Integer(5), new Integer(1), productReleases);
    tier4.setRegion("region2");
    tier4.addNetwork(new Network("uno2", VDC, REGION));

    Set<Tier> tiers = new HashSet<Tier>();
    tiers.add(tier);
    tiers.add(tier2);
    tiers.add(tier3);
    tiers.add(tier4);

    Environment envResult = new Environment("environemntName", tiers);
    Set<String> nets = envResult.getFederatedNetworks();
    assertEquals(nets.size(), 1);
  }
Beispiel #19
0
  protected synchronized void split() throws Exception {
    // Ensure address capacity
    _addrArray.expandCapacity(_split + _levelCapacity);

    // Read data from the _split index
    byte[] data = _dataArray.get(_split);

    // Process read data
    if (data != null && data.length > 0) {
      // Get split tier
      Tier tier = getTier(_split);

      // Wrap data in byte buffer
      ByteBuffer bb = ByteBuffer.wrap(data);

      int cnt = bb.getInt();

      if (tier.isColliding()) {
        while (cnt > 0) {
          // Read key
          int len = bb.getInt();
          byte[] key = new byte[len];
          bb.get(key);

          int newIndex = tier.getSplitIndex(hash(key), _level, _split);
          if (newIndex == _split) /* No need to split */ {
            // Pass value
            len = bb.getInt();
            bb.position(bb.position() + len);
          } else {
            // Read value
            len = bb.getInt();
            byte[] value = new byte[len];
            bb.get(value);

            // Remove at the old index
            deleteInternal(_split, key);

            // Update at the new index
            putInternal(newIndex, key, value);
          }

          cnt--;
        }
      } else {
        // Read key
        int len = bb.getInt();
        byte[] key = new byte[len];
        bb.get(key);

        int newIndex = tier.getSplitIndex(hash(key), _level, _split);
        if (newIndex != _split) {
          long scn = nextScn();
          _addrArray.set(newIndex, _addrArray.get(_split), scn);
          _addrArray.set(_split, 0, scn);
        }
      }
    }

    _split++;

    if (_split % _unitCapacity == 0) {
      _log.info("split " + getStatus());
    }

    if (_split == _levelCapacity) {
      _split = 0;
      _level++;
      _levelCapacity = getUnitCapacity() * (1 << _level);
      _levelThreshold = (int) (_levelCapacity * _loadThreshold);

      _log.info(getStatus());
    }
  }