示例#1
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;
 }
示例#2
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;
 }
示例#3
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));
  }