Exemplo n.º 1
0
 private long calculateRawCapacityInBytes() {
   long capacityInBytes = 0;
   for (Datacenter datacenter : datacenters) {
     capacityInBytes += datacenter.getRawCapacityInBytes();
   }
   return capacityInBytes;
 }
Exemplo n.º 2
0
 private long calculateDataNodeCount() {
   long count = 0;
   for (Datacenter datacenter : datacenters) {
     count += datacenter.getDataNodes().size();
   }
   return count;
 }
Exemplo n.º 3
0
 /**
  * Finds Datacenter by name
  *
  * @param datacenterName name of datacenter to be found
  * @return Datacenter or null if not found.
  */
 public Datacenter findDatacenter(String datacenterName) {
   for (Datacenter datacenter : datacenters) {
     if (datacenter.getName().compareToIgnoreCase(datacenterName) == 0) {
       return datacenter;
     }
   }
   return null;
 }
Exemplo n.º 4
0
 private long calculateDiskCount() {
   long count = 0;
   for (Datacenter datacenter : datacenters) {
     for (DataNode dataNode : datacenter.getDataNodes()) {
       count += dataNode.getDisks().size();
     }
   }
   return count;
 }
Exemplo n.º 5
0
 public JSONObject toJSONObject() throws JSONException {
   JSONObject jsonObject =
       new JSONObject()
           .put("clusterName", clusterName)
           .put("version", version)
           .put("datacenters", new JSONArray());
   for (Datacenter datacenter : datacenters) {
     jsonObject.accumulate("datacenters", datacenter.toJSONObject());
   }
   return jsonObject;
 }
Exemplo n.º 6
0
 public long calculateUnavailableDataNodeCount() {
   long count = 0;
   for (Datacenter datacenter : datacenters) {
     for (DataNode dataNode : datacenter.getDataNodes()) {
       if (dataNode.isDown()) {
         count++;
       }
     }
   }
   return count;
 }
Exemplo n.º 7
0
 /**
  * Finds DataNode by hostname and port. Note that hostname is converted to canonical hostname for
  * comparison.
  *
  * @param hostname of datanode
  * @param port of datanode
  * @return DataNode or null if not found.
  */
 public DataNode findDataNode(String hostname, int port) {
   String canonicalHostname = DataNode.getFullyQualifiedDomainName(hostname);
   logger.trace("host to find host {} port {}", canonicalHostname, port);
   for (Datacenter datacenter : datacenters) {
     logger.trace("datacenter {}", datacenter.getName());
     for (DataNode dataNode : datacenter.getDataNodes()) {
       if (dataNode.getHostname().equals(canonicalHostname) && (dataNode.getPort() == port)) {
         return dataNode;
       }
     }
   }
   return null;
 }
Exemplo n.º 8
0
 private Map<HardwareState, Long> calculateDataNodeInHardStateCount() {
   Map<HardwareState, Long> dataNodeInStateCount = new HashMap<HardwareState, Long>();
   for (HardwareState hardwareState : HardwareState.values()) {
     dataNodeInStateCount.put(hardwareState, new Long(0));
   }
   for (Datacenter datacenter : datacenters) {
     for (DataNode dataNode : datacenter.getDataNodes()) {
       dataNodeInStateCount.put(
           dataNode.getState(), dataNodeInStateCount.get(dataNode.getState()) + 1);
     }
   }
   return dataNodeInStateCount;
 }
Exemplo n.º 9
0
  @Test
  public void basics() throws JSONException {
    JSONObject jsonObject = TestUtils.getJsonDatacenter("XYZ1", getDataNodes());
    ClusterMapConfig clusterMapConfig =
        new ClusterMapConfig(new VerifiableProperties(new Properties()));

    Datacenter datacenter = new TestDatacenter(jsonObject, clusterMapConfig);

    assertEquals(datacenter.getName(), "XYZ1");
    assertEquals(datacenter.getDataNodes().size(), dataNodeCount);
    assertEquals(
        datacenter.getRawCapacityInBytes(), dataNodeCount * diskCount * diskCapacityInBytes);
    assertFalse(datacenter.isRackAware());
    assertEquals(datacenter.toJSONObject().toString(), jsonObject.toString());
    assertEquals(datacenter, new TestDatacenter(datacenter.toJSONObject(), clusterMapConfig));

    jsonObject = TestUtils.getJsonDatacenter("XYZ1", getDataNodesRackAware());
    datacenter = new TestDatacenter(jsonObject, clusterMapConfig);
    assertTrue(datacenter.isRackAware());
    assertEquals(datacenter.toJSONObject().toString(), jsonObject.toString());
    assertEquals(datacenter, new TestDatacenter(datacenter.toJSONObject(), clusterMapConfig));
  }
Exemplo n.º 10
0
  // Validate each hardware component (Datacenter, DataNode, and Disk) are unique
  protected void validateUniqueness() throws IllegalStateException {
    logger.trace("begin validateUniqueness.");
    HashSet<Datacenter> datacenterSet = new HashSet<Datacenter>();
    HashSet<DataNode> dataNodeSet = new HashSet<DataNode>();
    HashSet<Disk> diskSet = new HashSet<Disk>();

    for (Datacenter datacenter : datacenters) {
      if (!datacenterSet.add(datacenter)) {
        throw new IllegalStateException("Duplicate Datacenter detected: " + datacenter.toString());
      }
      for (DataNode dataNode : datacenter.getDataNodes()) {
        if (!dataNodeSet.add(dataNode)) {
          throw new IllegalStateException("Duplicate DataNode detected: " + dataNode.toString());
        }
        for (Disk disk : dataNode.getDisks()) {
          if (!diskSet.add(disk)) {
            throw new IllegalStateException("Duplicate Disk detected: " + disk.toString());
          }
        }
      }
    }
    logger.trace("complete validateUniqueness.");
  }