private long calculateDataNodeCount() { long count = 0; for (Datacenter datacenter : datacenters) { count += datacenter.getDataNodes().size(); } return count; }
private long calculateDiskCount() { long count = 0; for (Datacenter datacenter : datacenters) { for (DataNode dataNode : datacenter.getDataNodes()) { count += dataNode.getDisks().size(); } } return count; }
public long calculateUnavailableDataNodeCount() { long count = 0; for (Datacenter datacenter : datacenters) { for (DataNode dataNode : datacenter.getDataNodes()) { if (dataNode.isDown()) { count++; } } } return count; }
/** * 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; }
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; }
@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)); }
// 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."); }