summaryrefslogtreecommitdiff
path: root/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerReport.java
diff options
context:
space:
mode:
Diffstat (limited to 'hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerReport.java')
-rw-r--r--hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerReport.java218
1 files changed, 218 insertions, 0 deletions
diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerReport.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerReport.java
new file mode 100644
index 0000000000..50d2da3975
--- /dev/null
+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerReport.java
@@ -0,0 +1,218 @@
+/*
+ * 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.ozone.container.common.helpers;
+
+import com.google.common.base.Preconditions;
+import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerInfo;
+
+/**
+ * Container Report iterates the closed containers and sends a container report
+ * to SCM.
+ */
+public class ContainerReport {
+ private static final int UNKNOWN = -1;
+ private final String containerName;
+ private final String finalhash;
+ private long size;
+ private long keyCount;
+ private long bytesUsed;
+ private long readCount;
+ private long writeCount;
+ private long readBytes;
+ private long writeBytes;
+ private long containerID;
+
+ public long getContainerID() {
+ return containerID;
+ }
+
+ public void setContainerID(long containerID) {
+ this.containerID = containerID;
+ }
+
+
+
+
+ /**
+ * Constructs the ContainerReport.
+ *
+ * @param containerName - Container Name.
+ * @param finalhash - Final Hash.
+ */
+ public ContainerReport(String containerName, String finalhash) {
+ this.containerName = containerName;
+ this.finalhash = finalhash;
+ this.size = UNKNOWN;
+ this.keyCount = UNKNOWN;
+ this.bytesUsed = 0L;
+ this.readCount = 0L;
+ this.readBytes = 0L;
+ this.writeCount = 0L;
+ this.writeBytes = 0L;
+ }
+
+ /**
+ * Gets a containerReport from protobuf class.
+ *
+ * @param info - ContainerInfo.
+ * @return - ContainerReport.
+ */
+ public static ContainerReport getFromProtoBuf(ContainerInfo info) {
+ Preconditions.checkNotNull(info);
+ ContainerReport report = new ContainerReport(info.getContainerName(),
+ info.getFinalhash());
+ if (info.hasSize()) {
+ report.setSize(info.getSize());
+ }
+ if (info.hasKeyCount()) {
+ report.setKeyCount(info.getKeyCount());
+ }
+ if (info.hasUsed()) {
+ report.setBytesUsed(info.getUsed());
+ }
+ if (info.hasReadCount()) {
+ report.setReadCount(info.getReadCount());
+ }
+ if (info.hasReadBytes()) {
+ report.setReadBytes(info.getReadBytes());
+ }
+ if (info.hasWriteCount()) {
+ report.setWriteCount(info.getWriteCount());
+ }
+ if (info.hasWriteBytes()) {
+ report.setWriteBytes(info.getWriteBytes());
+ }
+
+ report.setContainerID(info.getContainerID());
+ return report;
+ }
+
+ /**
+ * Gets the container name.
+ *
+ * @return - Name
+ */
+ public String getContainerName() {
+ return containerName;
+ }
+
+ /**
+ * Returns the final signature for this container.
+ *
+ * @return - hash
+ */
+ public String getFinalhash() {
+ return finalhash;
+ }
+
+ /**
+ * Returns a positive number it is a valid number, -1 if not known.
+ *
+ * @return size or -1
+ */
+ public long getSize() {
+ return size;
+ }
+
+ /**
+ * Sets the size of the container on disk.
+ *
+ * @param size - int
+ */
+ public void setSize(long size) {
+ this.size = size;
+ }
+
+ /**
+ * Gets number of keys in the container if known.
+ *
+ * @return - Number of keys or -1 for not known.
+ */
+ public long getKeyCount() {
+ return keyCount;
+ }
+
+ /**
+ * Sets the key count.
+ *
+ * @param keyCount - Key Count
+ */
+ public void setKeyCount(long keyCount) {
+ this.keyCount = keyCount;
+ }
+
+ public long getReadCount() {
+ return readCount;
+ }
+
+ public void setReadCount(long readCount) {
+ this.readCount = readCount;
+ }
+
+ public long getWriteCount() {
+ return writeCount;
+ }
+
+ public void setWriteCount(long writeCount) {
+ this.writeCount = writeCount;
+ }
+
+ public long getReadBytes() {
+ return readBytes;
+ }
+
+ public void setReadBytes(long readBytes) {
+ this.readBytes = readBytes;
+ }
+
+ public long getWriteBytes() {
+ return writeBytes;
+ }
+
+ public void setWriteBytes(long writeBytes) {
+ this.writeBytes = writeBytes;
+ }
+
+ public long getBytesUsed() {
+ return bytesUsed;
+ }
+
+ public void setBytesUsed(long bytesUsed) {
+ this.bytesUsed = bytesUsed;
+ }
+
+ /**
+ * Gets a containerInfo protobuf message from ContainerReports.
+ *
+ * @return ContainerInfo
+ */
+ public ContainerInfo getProtoBufMessage() {
+ return ContainerInfo.newBuilder()
+ .setContainerName(this.getContainerName())
+ .setKeyCount(this.getKeyCount())
+ .setSize(this.getSize())
+ .setUsed(this.getBytesUsed())
+ .setReadCount(this.getReadCount())
+ .setReadBytes(this.getReadBytes())
+ .setWriteCount(this.getWriteCount())
+ .setWriteBytes(this.getWriteBytes())
+ .setFinalhash(this.getFinalhash())
+ .setContainerID(this.getContainerID())
+ .build();
+ }
+}