Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

package org.apache.hadoop.hdds;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.protobuf.ServiceException;

import jakarta.annotation.Nonnull;
Expand All @@ -30,8 +35,11 @@
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.file.Path;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand All @@ -40,6 +48,8 @@
import java.util.OptionalInt;
import java.util.TreeMap;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.hadoop.conf.ConfigRedactor;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
Expand All @@ -49,6 +59,7 @@
import org.apache.hadoop.hdds.conf.ConfigurationException;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProtoOrBuilder;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto.State;
Expand Down Expand Up @@ -870,4 +881,68 @@ public static HddsProtos.UUID toProtobuf(UUID uuid) {
? Thread.currentThread().getStackTrace()
: null;
}



public static List<HddsProtos.Node> getDecommissioningNodesList(Stream<HddsProtos.Node> allNodes,
Comment thread
sumitagrawl marked this conversation as resolved.
Outdated
String uuid,
String ipAddress) {
List<HddsProtos.Node> decommissioningNodes;
if (!Strings.isNullOrEmpty(uuid)) {
decommissioningNodes = allNodes.filter(p -> p.getNodeID().getUuid()
.equals(uuid)).collect(Collectors.toList());
} else if (!Strings.isNullOrEmpty(ipAddress)) {
decommissioningNodes = allNodes.filter(p -> p.getNodeID().getIpAddress()
.compareToIgnoreCase(ipAddress) == 0).collect(Collectors.toList());
} else {
decommissioningNodes = allNodes.collect(Collectors.toList());
}
return decommissioningNodes;
}

public static JsonNode getBeansJsonNode(String metricsJson) throws IOException {
JsonNode jsonNode;
ObjectMapper objectMapper = new ObjectMapper();
JsonFactory factory = objectMapper.getFactory();
JsonParser parser = factory.createParser(metricsJson);
jsonNode = (JsonNode) objectMapper.readTree(parser).get("beans").get(0);
return jsonNode;
}

public static int getNumDecomNodes(JsonNode jsonNode) {
int numDecomNodes;
JsonNode totalDecom = jsonNode.get("DecommissioningMaintenanceNodesTotal");
numDecomNodes = (totalDecom == null ? -1 : Integer.parseInt(totalDecom.toString()));
return numDecomNodes;
}

@Nullable
public static Map<String, Object> getCountsMap(DatanodeDetails datanode, JsonNode counts, int numDecomNodes,
Map<String, Object> countsMap, String errMsg)
throws IOException {
for (int i = 1; i <= numDecomNodes; i++) {
if (datanode.getHostName().equals(counts.get("tag.datanode." + i).asText())) {
JsonNode pipelinesDN = counts.get("PipelinesWaitingToCloseDN." + i);
JsonNode underReplicatedDN = counts.get("UnderReplicatedDN." + i);
JsonNode unclosedDN = counts.get("UnclosedContainersDN." + i);
JsonNode startTimeDN = counts.get("StartTimeDN." + i);
if (pipelinesDN == null || underReplicatedDN == null || unclosedDN == null || startTimeDN == null) {
throw new IOException(errMsg);
}

int pipelines = Integer.parseInt(pipelinesDN.toString());
double underReplicated = Double.parseDouble(underReplicatedDN.toString());
double unclosed = Double.parseDouble(unclosedDN.toString());
long startTime = Long.parseLong(startTimeDN.toString());
Date date = new Date(startTime);
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss z");
countsMap.put("decommissionStartTime", formatter.format(date));
countsMap.put("numOfUnclosedPipelines", pipelines);
countsMap.put("numOfUnderReplicatedContainers", underReplicated);
countsMap.put("numOfUnclosedContainers", unclosed);
return countsMap;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
*/
package org.apache.hadoop.hdds.scm.cli.datanode;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import org.apache.hadoop.hdds.HddsUtils;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
Expand All @@ -32,11 +30,8 @@
import picocli.CommandLine;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.LinkedHashMap;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -72,26 +67,21 @@ public class DecommissionStatusSubCommand extends ScmSubcommand {

@Override
public void execute(ScmClient scmClient) throws IOException {
List<HddsProtos.Node> decommissioningNodes;
Stream<HddsProtos.Node> allNodes = scmClient.queryNode(DECOMMISSIONING,
null, HddsProtos.QueryScope.CLUSTER, "").stream();
List<HddsProtos.Node> decommissioningNodes = HddsUtils.getDecommissioningNodesList(allNodes, uuid, ipAddress);
if (!Strings.isNullOrEmpty(uuid)) {
decommissioningNodes = allNodes.filter(p -> p.getNodeID().getUuid()
.equals(uuid)).collect(Collectors.toList());
if (decommissioningNodes.isEmpty()) {
System.err.println("Datanode: " + uuid + " is not in DECOMMISSIONING");
return;
}
} else if (!Strings.isNullOrEmpty(ipAddress)) {
decommissioningNodes = allNodes.filter(p -> p.getNodeID().getIpAddress()
.compareToIgnoreCase(ipAddress) == 0).collect(Collectors.toList());
if (decommissioningNodes.isEmpty()) {
System.err.println("Datanode: " + ipAddress + " is not in " +
"DECOMMISSIONING");
return;
}
} else {
decommissioningNodes = allNodes.collect(Collectors.toList());
if (!json) {
System.out.println("\nDecommission Status: DECOMMISSIONING - " +
decommissioningNodes.size() + " node(s)");
Expand All @@ -102,12 +92,8 @@ public void execute(ScmClient scmClient) throws IOException {
int numDecomNodes = -1;
JsonNode jsonNode = null;
if (metricsJson != null) {
ObjectMapper objectMapper = new ObjectMapper();
JsonFactory factory = objectMapper.getFactory();
JsonParser parser = factory.createParser(metricsJson);
jsonNode = (JsonNode) objectMapper.readTree(parser).get("beans").get(0);
JsonNode totalDecom = jsonNode.get("DecommissioningMaintenanceNodesTotal");
numDecomNodes = (totalDecom == null ? -1 : Integer.parseInt(totalDecom.toString()));
jsonNode = HddsUtils.getBeansJsonNode(metricsJson);
numDecomNodes = HddsUtils.getNumDecomNodes(jsonNode);
}

if (json) {
Expand Down Expand Up @@ -164,28 +150,9 @@ private Map<String, Object> getCounts(DatanodeDetails datanode, JsonNode counts,
Map<String, Object> countsMap = new LinkedHashMap<>();
String errMsg = getErrorMessage() + datanode.getHostName();
try {
for (int i = 1; i <= numDecomNodes; i++) {
if (datanode.getHostName().equals(counts.get("tag.datanode." + i).asText())) {
JsonNode pipelinesDN = counts.get("PipelinesWaitingToCloseDN." + i);
JsonNode underReplicatedDN = counts.get("UnderReplicatedDN." + i);
JsonNode unclosedDN = counts.get("UnclosedContainersDN." + i);
JsonNode startTimeDN = counts.get("StartTimeDN." + i);
if (pipelinesDN == null || underReplicatedDN == null || unclosedDN == null || startTimeDN == null) {
throw new IOException(errMsg);
}

int pipelines = Integer.parseInt(pipelinesDN.toString());
double underReplicated = Double.parseDouble(underReplicatedDN.toString());
double unclosed = Double.parseDouble(unclosedDN.toString());
long startTime = Long.parseLong(startTimeDN.toString());
Date date = new Date(startTime);
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss z");
countsMap.put("decommissionStartTime", formatter.format(date));
countsMap.put("numOfUnclosedPipelines", pipelines);
countsMap.put("numOfUnderReplicatedContainers", underReplicated);
countsMap.put("numOfUnclosedContainers", unclosed);
return countsMap;
}
countsMap = HddsUtils.getCountsMap(datanode, counts, numDecomNodes, countsMap, errMsg);
if (countsMap != null) {
return countsMap;
}
System.err.println(errMsg);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ public final class ReconServerConfigKeys {

public static final int
OZONE_RECON_SCM_CLIENT_FAILOVER_MAX_RETRY_DEFAULT = 3;

public static final long
OZONE_RECON_COMMAND_PROCESS_TIME_OUT_DEFAULT = 60L;
Comment thread
sumitagrawl marked this conversation as resolved.
Outdated

/**
* Private constructor for utility class.
*/
Expand Down
Loading