in uReplicator-Controller/src/main/java/com/uber/stream/kafka/mirrormaker/controller/core/ClusterInfoBackupManager.java [88:137]
public synchronized void dumpState() throws Exception {
if (!_helixMirrorMakerManager.isLeader()) {
return;
}
LOGGER.info("Backing up the CurrentState and the IdealState!");
StringBuilder idealState = new StringBuilder();
StringBuilder partitionAssignment = new StringBuilder();
List<String> topicLists = _helixMirrorMakerManager.getTopicLists();
if (topicLists == null || topicLists.isEmpty()) {
LOGGER.info("No topics available to take backup");
return;
}
JSONArray resultList = new JSONArray();
for (String topicName : topicLists) {
IdealState idealStateForTopic = _helixMirrorMakerManager.getIdealStateForTopic(topicName);
JSONObject resultJson = new JSONObject();
resultJson.put("topic", topicName);
resultJson.put("idealStateMeta", idealStateForTopic);
resultList.add(resultJson);
}
idealState.append(new StringRepresentation(resultList.toJSONString()));
resultList = new JSONArray();
for (String topicName : topicLists) {
IdealState idealStateForTopic = _helixMirrorMakerManager.getIdealStateForTopic(topicName);
ExternalView externalViewForTopic = _helixMirrorMakerManager.getExternalViewForTopic(topicName);
JSONObject responseJson = TopicAssignmentViewBuilder.build(
topicName, idealStateForTopic, externalViewForTopic);
resultList.add(responseJson);
}
partitionAssignment.append(new StringRepresentation(resultList.toJSONString()));
String envInfo = "default";
if (_config.getEnvironment() != null && _config.getEnvironment().trim().length() > 0) {
envInfo = _config.getEnvironment().trim();
}
if (_config.getHelixClusterName() != null && !_config.getHelixClusterName().trim().isEmpty()) {
envInfo = envInfo + "-" + _config.getHelixClusterName().trim();
}
String idealStateFileName = "idealState-backup-" + envInfo;
String paritionAssignmentFileName = "partitionAssgn-backup-" + envInfo;
_handler.writeToFile(idealStateFileName, idealState.toString());
_handler.writeToFile(paritionAssignmentFileName, partitionAssignment.toString());
}