Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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,156 @@
/*
* 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 com.fasterxml.jackson.annotation.JsonInclude;
import java.util.List;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;

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

public class DatanodeInfoJson {
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;
@JsonInclude(JsonInclude.Include.NON_NULL)
private Long used = null;
@JsonInclude(JsonInclude.Include.NON_NULL)
private Long capacity = null;
@JsonInclude(JsonInclude.Include.NON_NULL)
private Double percentUsed = null;

DatanodeInfoJson(ListInfoSubcommand.DatanodeWithAttributes dna) {
DatanodeDetails dn = dna.getDatanodeDetails();
this.id = dn.getUuid().toString();
this.ports = dn.getPorts();
this.opState = String.valueOf(dna.getOpState());
this.healthState = String.valueOf(dna.getHealthState());
this.hostName = dn.getHostName();
this.ipAddress = dn.getIpAddress();
this.persistedOpStateExpiryEpochSec = dn.getPersistedOpStateExpiryEpochSec();
this.decommissioned = dn.isDecommissioned();
this.maintenance = dn.isMaintenance();
this.level = dn.getLevel();
this.cost = dn.getCost();
this.numOfLeaves = dn.getNumOfLeaves();
this.networkFullPath = dn.getNetworkFullPath();
this.networkLocation = dn.getNetworkLocation();
this.networkName = dn.getNetworkName();
this.setupTime = dn.getSetupTime();
this.currentVersion = dn.getCurrentVersion();
this.used = dna.getUsed();
this.capacity = dna.getCapacity();
this.percentUsed = dna.getPercentUsed();
}

public String getId() {
return id;
}

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

public String getOpState() {
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;
}

public Long getUsed() {
return used;
}

public Long getCapacity() {
return capacity;
}

public Double getPercentUsed() {
return percentUsed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

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

import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.common.base.Strings;
import java.io.IOException;
import java.util.Collections;
Expand Down Expand Up @@ -97,8 +96,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 +126,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,15 +219,12 @@ private void printDatanodeInfo(DatanodeWithAttributes dna) {
}
}

private static class DatanodeWithAttributes {
static class DatanodeWithAttributes {
private DatanodeDetails datanodeDetails;
private HddsProtos.NodeOperationalState operationalState;
private HddsProtos.NodeState healthState;
@JsonInclude(JsonInclude.Include.NON_NULL)
private Long used = null;
@JsonInclude(JsonInclude.Include.NON_NULL)
private Long capacity = null;
@JsonInclude(JsonInclude.Include.NON_NULL)
private Double percentUsed = null;

DatanodeWithAttributes(DatanodeDetails dn,
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