getDiffList() {
- return diffList;
- }
+ private String volumeName;
+
+ private String bucketName;
@Override
public String toString() {
StringBuilder str = new StringBuilder();
- String from = "snapshot " + fromSnapshot;
- String to = "snapshot " + toSnapshot;
+ String from = "snapshot " + getFromSnapshot();
+ String to = "snapshot " + getToSnapshot();
str.append("Difference between ").append(from).append(" and ").append(to)
- .append(":")
- .append(LINE_SEPARATOR);
- for (DiffReportEntry entry : diffList) {
+ .append(":").append(LINE_SEPARATOR);
+ for (DiffReportEntry entry : getDiffList()) {
str.append(entry.toString()).append(LINE_SEPARATOR);
}
return str.toString();
}
- public SnapshotDiffReportProto toProtobuf() {
- final SnapshotDiffReportProto.Builder builder = SnapshotDiffReportProto
- .newBuilder();
- builder.setVolumeName(volumeName)
- .setBucketName(bucketName)
- .setFromSnapshot(fromSnapshot)
- .setToSnapshot(toSnapshot);
- builder.addAllDiffList(diffList.stream().map(DiffReportEntry::toProtobuf)
- .collect(Collectors.toList()));
+ public OzoneManagerProtocolProtos.SnapshotDiffReportProto toProtobuf() {
+ final OzoneManagerProtocolProtos.SnapshotDiffReportProto.Builder builder =
+ OzoneManagerProtocolProtos.SnapshotDiffReportProto.newBuilder();
+ builder.setVolumeName(volumeName).setBucketName(bucketName)
+ .setFromSnapshot(getFromSnapshot()).setToSnapshot(getToSnapshot());
+ builder.addAllDiffList(
+ getDiffList().stream().map(x -> toProtobufDiffReportEntry(x))
+ .collect(Collectors.toList()));
return builder.build();
}
+ public static OzoneManagerProtocolProtos
+ .DiffReportEntryProto toProtobufDiffReportEntry(DiffReportEntry entry) {
+ final OzoneManagerProtocolProtos.DiffReportEntryProto.Builder builder =
+ OzoneManagerProtocolProtos.DiffReportEntryProto.newBuilder();
+ builder.setDiffType(toProtobufDiffType(entry.getType()))
+ .setSourcePath(new String(entry.getSourcePath()));
+ if (entry.getTargetPath() != null) {
+ String targetPath = new String(entry.getTargetPath());
+ builder.setTargetPath(targetPath);
+ }
+ return builder.build();
+ }
+
+ public static OzoneManagerProtocolProtos.DiffReportEntryProto
+ .DiffTypeProto toProtobufDiffType(DiffType type) {
+ return OzoneManagerProtocolProtos.DiffReportEntryProto
+ .DiffTypeProto.valueOf(type.name());
+ }
+
public static SnapshotDiffReport fromProtobuf(
- final SnapshotDiffReportProto report) {
- return new SnapshotDiffReport(report.getVolumeName(),
- report.getBucketName(), report.getFromSnapshot(),
+ final OzoneManagerProtocolProtos.SnapshotDiffReportProto report) {
+ Path bucketPath = new Path(
+ OZONE_URI_DELIMITER + report.getVolumeName()
+ + OZONE_URI_DELIMITER + report.getBucketName());
+ OFSPath path = new OFSPath(bucketPath, new OzoneConfiguration());
+
+ // TODO handle conversion from PersistentList to java.util.List
+ return new SnapshotDiffReport(path.toString(), report.getFromSnapshot(),
report.getToSnapshot(), report.getDiffListList().stream()
- .map(DiffReportEntry::fromProtobuf).collect(Collectors.toList()));
+ .map(SnapshotDiffReport::fromProtobufDiffReportEntry)
+ .collect(Collectors.toList()), report.getVolumeName(),
+ report.getBucketName());
+ }
+
+ public static DiffType fromProtobufDiffType(
+ final OzoneManagerProtocolProtos.DiffReportEntryProto
+ .DiffTypeProto type) {
+ return DiffType.valueOf(type.name());
}
+ public static DiffReportEntry fromProtobufDiffReportEntry(
+ final OzoneManagerProtocolProtos.DiffReportEntryProto entry) {
+ if (entry == null) {
+ return null;
+ }
+ DiffType type = fromProtobufDiffType(entry.getDiffType());
+ return type == null ? null :
+ new DiffReportEntry(type, entry.getSourcePath().getBytes(),
+ entry.hasTargetPath() ? entry.getTargetPath().getBytes() : null);
+ }
}
diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestDistcpWithSnapshots.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestDistcpWithSnapshots.java
new file mode 100644
index 000000000000..a36ec1033f07
--- /dev/null
+++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestDistcpWithSnapshots.java
@@ -0,0 +1,328 @@
+/**
+ * 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.fs.ozone;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
+import org.apache.hadoop.fs.contract.ContractTestUtils;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.mapreduce.Job;
+import org.apache.hadoop.ozone.MiniOzoneCluster;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.TestDataUtil;
+import org.apache.hadoop.ozone.OFSPath;
+import org.apache.hadoop.ozone.client.OzoneBucket;
+import org.apache.hadoop.ozone.om.OMConfigKeys;
+import org.apache.hadoop.ozone.om.OMStorage;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
+import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
+import org.apache.hadoop.tools.DistCp;
+import org.apache.hadoop.tools.DistCpOptions;
+import org.apache.hadoop.tools.DistCpSync;
+import org.apache.hadoop.tools.mapred.CopyMapper;
+import org.apache.ozone.test.GenericTestUtils;
+import org.jetbrains.annotations.NotNull;
+import org.junit.Rule;
+import org.junit.AfterClass;
+import org.junit.Test;
+import org.junit.Assert;
+import org.junit.rules.Timeout;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.TimeoutException;
+
+import static org.apache.hadoop.ozone.OzoneConsts.OM_SNAPSHOT_DIR;
+import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER;
+import static org.apache.hadoop.ozone.OzoneConsts.OM_DB_NAME;
+import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
+import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ADDRESS_KEY;
+
+/**
+ * Testing Distcp with -diff option that uses snapdiff.
+ */
+@RunWith(Parameterized.class)
+public class TestDistcpWithSnapshots {
+
+ private static final Logger LOG =
+ LoggerFactory.getLogger(TestDistcpWithSnapshots.class);
+
+ @Rule
+ public Timeout globalTimeout = Timeout.seconds(300);
+ private static OzoneConfiguration conf;
+ private static MiniOzoneCluster cluster = null;
+ private static FileSystem fs;
+ private static BucketLayout bucketLayout;
+ private static String rootPath;
+ private static boolean enableRatis;
+
+ private static File metaDir;
+
+ @Parameterized.Parameters
+ public static Collection