@Test public void persistAndReadBack() throws Exception { String tmpDir = folder.getRoot().getPath(); Properties props = new Properties(); props.setProperty("clustermap.cluster.name", "test"); props.setProperty("clustermap.datacenter.name", "dc1"); props.setProperty("clustermap.host.name", "localhost"); String hardwareLayoutSer = tmpDir + "/hardwareLayoutSer.json"; String partitionLayoutSer = tmpDir + "/partitionLayoutSer.json"; String hardwareLayoutDe = tmpDir + "/hardwareLayoutDe.json"; String partitionLayoutDe = tmpDir + "/partitionLayoutDe.json"; ClusterMapConfig clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props)); StaticClusterManager clusterMapManagerSer = getTestClusterMap(clusterMapConfig); clusterMapManagerSer.persist(hardwareLayoutSer, partitionLayoutSer); StaticClusterManager clusterMapManagerDe = (new StaticClusterAgentsFactory(clusterMapConfig, hardwareLayoutSer, partitionLayoutSer)).getClusterMap(); assertEquals(clusterMapManagerSer, clusterMapManagerDe); clusterMapManagerDe.persist(hardwareLayoutDe, partitionLayoutDe); StaticClusterManager clusterMapManagerDeDe = (new StaticClusterAgentsFactory(clusterMapConfig, hardwareLayoutDe, partitionLayoutDe)).getClusterMap(); assertEquals(clusterMapManagerDe, clusterMapManagerDeDe); }
void persist(String hardwareLayoutPath, String partitionLayoutPath) throws IOException, JSONException { logger.trace("persist {}, {}", hardwareLayoutPath, partitionLayoutPath); writeJsonObjectToFile(hardwareLayout.toJSONObject(), hardwareLayoutPath); writeJsonObjectToFile(partitionLayout.toJSONObject(), partitionLayoutPath); }
StaticClusterManager implements ClusterMap { void persist(String hardwareLayoutPath, String partitionLayoutPath) throws IOException, JSONException { logger.trace("persist {}, {}", hardwareLayoutPath, partitionLayoutPath); writeJsonObjectToFile(hardwareLayout.toJSONObject(), hardwareLayoutPath); writeJsonObjectToFile(partitionLayout.toJSONObject(), partitionLayoutPath); } }
StaticClusterManager implements ClusterMap { void persist(String hardwareLayoutPath, String partitionLayoutPath) throws IOException, JSONException { logger.trace("persist {}, {}", hardwareLayoutPath, partitionLayoutPath); writeJsonObjectToFile(hardwareLayout.toJSONObject(), hardwareLayoutPath); writeJsonObjectToFile(partitionLayout.toJSONObject(), partitionLayoutPath); } StaticClusterManager(PartitionLayout partitionLayout, String localDatacenterName, MetricRegistry metricRegistry); }
StaticClusterManager implements ClusterMap { void persist(String hardwareLayoutPath, String partitionLayoutPath) throws IOException, JSONException { logger.trace("persist {}, {}", hardwareLayoutPath, partitionLayoutPath); writeJsonObjectToFile(hardwareLayout.toJSONObject(), hardwareLayoutPath); writeJsonObjectToFile(partitionLayout.toJSONObject(), partitionLayoutPath); } StaticClusterManager(PartitionLayout partitionLayout, String localDatacenterName, MetricRegistry metricRegistry); @Override List<PartitionId> getWritablePartitionIds(String partitionClass); @Override PartitionId getRandomWritablePartition(String partitionClass, List<PartitionId> partitionsToExclude); @Override List<PartitionId> getAllPartitionIds(String partitionClass); @Override PartitionId getPartitionIdFromStream(InputStream stream); @Override boolean hasDatacenter(String datacenterName); @Override byte getLocalDatacenterId(); @Override String getDatacenterName(byte id); @Override DataNodeId getDataNodeId(String hostname, int port); @Override List<ReplicaId> getReplicaIds(DataNodeId dataNodeId); @Override List<DataNodeId> getDataNodeIds(); @Override MetricRegistry getMetricRegistry(); @Override void registerClusterMapListener(ClusterMapChangeListener clusterMapChangeListener); @Override boolean equals(Object o); @Override void onReplicaEvent(ReplicaId replicaId, ReplicaEventType event); @Override JSONObject getSnapshot(); @Override ReplicaId getBootstrapReplica(String partitionIdStr, DataNodeId dataNodeId); @Override void close(); }
StaticClusterManager implements ClusterMap { void persist(String hardwareLayoutPath, String partitionLayoutPath) throws IOException, JSONException { logger.trace("persist {}, {}", hardwareLayoutPath, partitionLayoutPath); writeJsonObjectToFile(hardwareLayout.toJSONObject(), hardwareLayoutPath); writeJsonObjectToFile(partitionLayout.toJSONObject(), partitionLayoutPath); } StaticClusterManager(PartitionLayout partitionLayout, String localDatacenterName, MetricRegistry metricRegistry); @Override List<PartitionId> getWritablePartitionIds(String partitionClass); @Override PartitionId getRandomWritablePartition(String partitionClass, List<PartitionId> partitionsToExclude); @Override List<PartitionId> getAllPartitionIds(String partitionClass); @Override PartitionId getPartitionIdFromStream(InputStream stream); @Override boolean hasDatacenter(String datacenterName); @Override byte getLocalDatacenterId(); @Override String getDatacenterName(byte id); @Override DataNodeId getDataNodeId(String hostname, int port); @Override List<ReplicaId> getReplicaIds(DataNodeId dataNodeId); @Override List<DataNodeId> getDataNodeIds(); @Override MetricRegistry getMetricRegistry(); @Override void registerClusterMapListener(ClusterMapChangeListener clusterMapChangeListener); @Override boolean equals(Object o); @Override void onReplicaEvent(ReplicaId replicaId, ReplicaEventType event); @Override JSONObject getSnapshot(); @Override ReplicaId getBootstrapReplica(String partitionIdStr, DataNodeId dataNodeId); @Override void close();  }