ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
Gson gson = injector.getInstance(Gson.class);
HostComponentDesiredStateDAO desiredStateDAO = injector.getInstance
(HostComponentDesiredStateDAO.class);
KeyValueEntity keyValueEntity = keyValueDAO.findByKey("decommissionDataNodesTag");
String value = null;
if (keyValueEntity != null) {
value = keyValueEntity.getValue();
if (value != null && !value.isEmpty()) {
List<ClusterEntity> clusterEntities = clusterDAO.findAll();
for (ClusterEntity clusterEntity : clusterEntities) {
Long clusterId = clusterEntity.getClusterId();
ClusterConfigEntityPK configEntityPK = new ClusterConfigEntityPK();
configEntityPK.setClusterId(clusterId);
configEntityPK.setType("hdfs-exclude-file");
configEntityPK.setTag(value.trim());
ClusterConfigEntity configEntity = clusterDAO.findConfig(configEntityPK);
if (configEntity != null) {
String configData = configEntity.getData();
if (configData != null) {
Map<String, String> properties = gson.<Map<String, String>>fromJson(configData, Map.class);
if (properties != null && !properties.isEmpty()) {
String decommissionedNodes = properties.get("datanodes");
if (decommissionedNodes != null) {
String[] nodes = decommissionedNodes.split(",");
if (nodes.length > 0) {
for (String node : nodes) {
HostComponentDesiredStateEntityPK entityPK =
new HostComponentDesiredStateEntityPK();
entityPK.setClusterId(clusterId);
entityPK.setServiceName("HDFS");
entityPK.setComponentName("DATANODE");
entityPK.setHostName(node.trim());
HostComponentDesiredStateEntity desiredStateEntity =
desiredStateDAO.findByPK(entityPK);
desiredStateEntity.setAdminState(HostComponentAdminState.DECOMMISSIONED);
desiredStateDAO.merge(desiredStateEntity);
}
}
}
}
}
}
}
}
// Rename saved key value entity so that the move is finalized
KeyValueEntity newEntity = new KeyValueEntity();
newEntity.setKey("decommissionDataNodesTag-Moved");
newEntity.setValue(value);
keyValueDAO.create(newEntity);
keyValueDAO.remove(keyValueEntity);
}
}