Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
@@ -0,0 +1,133 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.hdds.scm.cli.datanode;

import java.util.List;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;

/**
* Represents filtered Datanode information for json use.
*/

public class DatanodeInfoJson {
Comment thread
errose28 marked this conversation as resolved.
Outdated
private final String id;
private final String hostName;
private final String ipAddress;
private final List<DatanodeDetails.Port> ports;
private final long setupTime;
private final int currentVersion;
private final String opState;
private final long persistedOpStateExpiryEpochSec;
private final String healthState;
private final boolean decommissioned;
private final boolean maintenance;
private final int level;
private final int cost;
private final int numOfLeaves;
private final String networkFullPath;
private final String networkLocation;
private final String networkName;

DatanodeInfoJson(ListInfoSubcommand.DatanodeWithAttributes dna) {
this.id = dna.getDatanodeDetails().getUuid().toString();
Comment thread
aryangupta1998 marked this conversation as resolved.
Outdated
this.ports = dna.getDatanodeDetails().getPorts();
this.opState = String.valueOf(dna.getOpState());
this.healthState = String.valueOf(dna.getHealthState());
this.hostName = dna.getDatanodeDetails().getHostName();
this.ipAddress = dna.getDatanodeDetails().getIpAddress();
this.persistedOpStateExpiryEpochSec = dna.getDatanodeDetails().getPersistedOpStateExpiryEpochSec();
this.decommissioned = dna.getDatanodeDetails().isDecommissioned();
this.maintenance = dna.getDatanodeDetails().isMaintenance();
this.level = dna.getDatanodeDetails().getLevel();
this.cost = dna.getDatanodeDetails().getCost();
this.numOfLeaves = dna.getDatanodeDetails().getNumOfLeaves();
this.networkFullPath = dna.getDatanodeDetails().getNetworkFullPath();
this.networkLocation = dna.getDatanodeDetails().getNetworkLocation();
this.networkName = dna.getDatanodeDetails().getNetworkName();
this.setupTime = dna.getDatanodeDetails().getSetupTime();
this.currentVersion = dna.getDatanodeDetails().getCurrentVersion();
}

public String getId() {
return id;
}

public List<DatanodeDetails.Port> getPorts() {
return ports;
}

public String getOpState() {
Comment thread
errose28 marked this conversation as resolved.
Outdated
return opState;
}

public String getHealthState() {
return healthState;
}

public String getHostName() {
return hostName;
}

public String getIpAddress() {
return ipAddress;
}

public long getPersistedOpStateExpiryEpochSec() {
return persistedOpStateExpiryEpochSec;
}

public boolean isDecommissioned() {
return decommissioned;
}

public boolean isMaintenance() {
return maintenance;
}

public int getLevel() {
return level;
}

public int getCost() {
return cost;
}

public int getNumOfLeaves() {
return numOfLeaves;
}

public String getNetworkFullPath() {
return networkFullPath;
}

public String getNetworkLocation() {
return networkLocation;
}

public String getNetworkName() {
return networkName;
}

public long getSetupTime() {
return setupTime;
}

public int getCurrentVersion() {
return currentVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public void execute(ScmClient scmClient) throws IOException {
node.getNodeStates(0));

if (json) {
List<DatanodeWithAttributes> singleList = Collections.singletonList(dwa);
System.out.println(JsonUtils.toJsonStringWithDefaultPrettyPrinter(singleList));
List<DatanodeInfoJson> dtoList = Collections.singletonList(new DatanodeInfoJson(dwa));
System.out.println(JsonUtils.toJsonStringWithDefaultPrettyPrinter(dtoList));
} else {
printDatanodeInfo(dwa);
}
Expand Down Expand Up @@ -127,10 +127,10 @@ public void execute(ScmClient scmClient) throws IOException {
}

if (json) {
List<DatanodeWithAttributes> datanodeList = allNodes.collect(
Collectors.toList());
System.out.println(
JsonUtils.toJsonStringWithDefaultPrettyPrinter(datanodeList));
List<DatanodeInfoJson> datanodeList = allNodes
.map(DatanodeInfoJson::new)
.collect(Collectors.toList());
System.out.println(JsonUtils.toJsonStringWithDefaultPrettyPrinter(datanodeList));
} else {
allNodes.forEach(this::printDatanodeInfo);
}
Expand Down Expand Up @@ -220,7 +220,7 @@ private void printDatanodeInfo(DatanodeWithAttributes dna) {
}
}

private static class DatanodeWithAttributes {
static class DatanodeWithAttributes {
Comment thread
errose28 marked this conversation as resolved.
Outdated
private DatanodeDetails datanodeDetails;
private HddsProtos.NodeOperationalState operationalState;
private HddsProtos.NodeState healthState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,8 @@ public void testDataNodeByUuidOutput()
assertEquals(1, root.size(), "Expected 1 node in JSON output");

JsonNode node = root.get(0);
assertTrue(node.has("datanodeDetails"), "Missing datanodeDetails");
String opState = node.get("opState").asText();
String uuid = node.get("datanodeDetails").get("uuid").asText();
String uuid = node.get("id").asText();

assertEquals("IN_SERVICE", opState, "Expected opState IN_SERVICE but got: " + opState);
assertEquals(nodes.get(0).getNodeID().getUuid(), uuid,
Expand Down Expand Up @@ -330,8 +329,6 @@ private List<HddsProtos.Node> getNodeDetails() {
dnd.setIpAddress("1.2.3." + i + 1);
dnd.setNetworkLocation("/default");
dnd.setNetworkName("host" + i);
dnd.addPorts(HddsProtos.Port.newBuilder()
.setName("ratis").setValue(5678).build());
dnd.setUuid(UUID.randomUUID().toString());

HddsProtos.Node.Builder builder = HddsProtos.Node.newBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Incomplete command

List datanodes as JSON
${output} = Execute ozone admin datanode list --json | jq -r '.'
Should contain ${output} datanodeDetails
Should contain ${output} id
Should contain ${output} healthState
Should contain ${output} opState

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ All container is closed

Get Datanode Ozone Used Bytes Info
[arguments] ${uuid}
${output} = Execute export DATANODES=$(ozone admin datanode list --json) && for datanode in $(echo "$\{DATANODES\}" | jq -r '.[].datanodeDetails.uuid'); do ozone admin datanode usageinfo --uuid=$\{datanode\} --json | jq '{(.[0].datanodeDetails.uuid) : .[0].ozoneUsed}'; done | jq -s add
${output} = Execute export DATANODES=$(ozone admin datanode list --json) && for datanode in $(echo "$\{DATANODES\}" | jq -r '.[].id'); do ozone admin datanode usageinfo --uuid=$\{datanode\} --json | jq '{(.[0].datanodeDetails.uuid) : .[0].ozoneUsed}'; done | jq -s add
${result} = Execute echo '${output}' | jq '. | to_entries | .[] | select(.key == "${uuid}") | .value'
[return] ${result}

Expand Down
Loading