From 99312bdfdb6c6106b4b1972921779b748535c79d Mon Sep 17 00:00:00 2001 From: Wei-Chiu Chuang Date: Mon, 8 May 2023 15:20:56 -0700 Subject: [PATCH] HADOOP-18671. Add recoverLease(), setSafeMode(), isFileClosed() as interfaces to hadoop-common (#5553) (#5619) * HADOOP-18671. Add recoverLease(), setSafeMode(), isFileClosed() as interfaces to hadoop-common (#5553) The HDFS lease APIs have been replicated as interfaces in hadoop-common so other filesystems can also implement them. Applications which use the leasing APIs should migrate to the new interface where possible. Contributed by Stephen Wu (cherry picked from commit 0e46388474f52cd38578d946c26ba762be05ef1f) Conflicts: hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUpgrade.java hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestViewDistributedFileSystem.java hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithAcl.java hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRetryCacheMetrics.java hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestFSImageWithOrderedSnapshotDeletion.java hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestOrderedSnapshotDeletion.java hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForErasureCodingPolicy.java Co-authored-by: Tak Lon (Stephen) Wu --- .../hadoop/fs/CommonPathCapabilities.java | 6 ++ .../apache/hadoop/fs/LeaseRecoverable.java | 46 ++++++++++ .../java/org/apache/hadoop/fs/SafeMode.java | 50 +++++++++++ .../org/apache/hadoop/fs/SafeModeAction.java | 41 +++++++++ .../src/site/markdown/filesystem/index.md | 4 +- .../markdown/filesystem/leaserecoverable.md | 52 +++++++++++ .../src/site/markdown/filesystem/safemode.md | 45 ++++++++++ .../AbstractContractLeaseRecoveryTest.java | 90 +++++++++++++++++++ .../AbstractContractSafeModeTest.java | 54 +++++++++++ .../hadoop/hdfs/DistributedFileSystem.java | 86 ++++++++++++++++-- .../hdfs/ViewDistributedFileSystem.java | 2 + .../apache/hadoop/hdfs/client/HdfsUtils.java | 1 + .../federation/router/TestRouterRpc.java | 28 +++--- .../router/TestRouterRpcSingleNS.java | 4 +- .../apache/hadoop/hdfs/tools/DFSAdmin.java | 3 + .../hdfs/TestHDFSContractLeaseRecovery.java | 49 ++++++++++ .../hdfs/TestHDFSContractSafeMode.java | 49 ++++++++++ .../hadoop/hdfs/TestBlockStoragePolicy.java | 6 +- .../hadoop/hdfs/TestDFSClientRetries.java | 6 +- .../apache/hadoop/hdfs/TestDFSUpgrade.java | 6 +- .../hadoop/hdfs/TestEncryptionZones.java | 16 ++-- .../hdfs/TestErasureCodingPolicies.java | 6 +- .../TestErasureCodingPolicyWithSnapshot.java | 6 +- .../org/apache/hadoop/hdfs/TestGetBlocks.java | 6 +- .../hdfs/TestHDFSFileSystemContract.java | 18 ++++ .../hadoop/hdfs/TestMiniDFSCluster.java | 4 +- .../hadoop/hdfs/TestRollingUpgrade.java | 28 +++--- .../hdfs/TestRollingUpgradeDowngrade.java | 6 +- .../hdfs/TestRollingUpgradeRollback.java | 10 +-- .../org/apache/hadoop/hdfs/TestSafeMode.java | 28 +++--- .../hdfs/server/balancer/TestBalancer.java | 5 +- .../datanode/TestDataNodeRollingUpgrade.java | 4 +- .../fsdataset/impl/TestLazyPersistPolicy.java | 6 +- .../server/namenode/TestAddStripedBlocks.java | 6 +- .../server/namenode/TestCacheDirectives.java | 6 +- .../TestCheckPointForSecurityTokens.java | 4 +- .../hdfs/server/namenode/TestCheckpoint.java | 1 + .../hdfs/server/namenode/TestFSImage.java | 51 ++++++----- .../server/namenode/TestFSImageWithAcl.java | 13 ++- .../namenode/TestFSImageWithSnapshot.java | 30 +++---- .../server/namenode/TestFSImageWithXAttr.java | 7 +- .../server/namenode/TestFileTruncate.java | 12 +-- .../server/namenode/TestLeaseManager.java | 6 +- .../TestNameNodeRetryCacheMetrics.java | 6 +- .../namenode/TestNestedEncryptionZones.java | 6 +- .../namenode/TestQuotaByStorageType.java | 5 +- .../server/namenode/TestReencryption.java | 18 ++-- .../server/namenode/TestSaveNamespace.java | 35 ++++---- .../server/namenode/ha/TestHAMetrics.java | 4 +- .../server/namenode/ha/TestNNHealthCheck.java | 4 +- .../server/namenode/ha/TestObserverNode.java | 6 +- .../snapshot/TestRandomOpsWithSnapshots.java | 6 +- .../snapshot/TestRenameWithSnapshots.java | 14 +-- .../namenode/snapshot/TestSnapshot.java | 6 +- .../snapshot/TestSnapshotDeletion.java | 26 +++--- .../snapshot/TestXAttrWithSnapshot.java | 6 +- .../TestOfflineImageViewer.java | 10 +-- .../TestOfflineImageViewerForAcl.java | 4 +- ...stOfflineImageViewerForContentSummary.java | 4 +- ...estOfflineImageViewerForStoragePolicy.java | 3 +- .../TestOfflineImageViewerForXAttr.java | 4 +- ...stOfflineImageViewerWithStripedBlocks.java | 6 +- .../v2/hs/TestHistoryFileManager.java | 20 ++--- ...storyFileManagerInitWithNonRunningDFS.java | 4 +- 64 files changed, 842 insertions(+), 262 deletions(-) create mode 100644 hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LeaseRecoverable.java create mode 100644 hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/SafeMode.java create mode 100644 hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/SafeModeAction.java create mode 100644 hadoop-common-project/hadoop-common/src/site/markdown/filesystem/leaserecoverable.md create mode 100644 hadoop-common-project/hadoop-common/src/site/markdown/filesystem/safemode.md create mode 100644 hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractLeaseRecoveryTest.java create mode 100644 hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractSafeModeTest.java create mode 100644 hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/contract/hdfs/TestHDFSContractLeaseRecovery.java create mode 100644 hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/contract/hdfs/TestHDFSContractSafeMode.java diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonPathCapabilities.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonPathCapabilities.java index aa231554eb..b898fde43c 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonPathCapabilities.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonPathCapabilities.java @@ -163,5 +163,11 @@ private CommonPathCapabilities() { public static final String ETAGS_PRESERVED_IN_RENAME = "fs.capability.etags.preserved.in.rename"; + /** + * Does this Filesystem support lease recovery operations such as + * {@link LeaseRecoverable#recoverLease(Path)} and {@link LeaseRecoverable#isFileClosed(Path)}}? + * Value: {@value}. + */ + public static final String LEASE_RECOVERABLE = "fs.capability.lease.recoverable"; } diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LeaseRecoverable.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LeaseRecoverable.java new file mode 100644 index 0000000000..87b54663e6 --- /dev/null +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LeaseRecoverable.java @@ -0,0 +1,46 @@ +/* + * 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; + +import java.io.IOException; + +/** + * Whether the given Path of the FileSystem has the capability to perform lease recovery. + */ +public interface LeaseRecoverable { + + /** + * Start the lease recovery of a file. + * + * @param file path to a file. + * @return true if the file is already closed, and it does not require lease recovery. + * @throws IOException if an error occurs during lease recovery. + * @throws UnsupportedOperationException if lease recovery is not supported by this filesystem. + */ + boolean recoverLease(Path file) throws IOException; + + /** + * Get the close status of a file. + * @param file The string representation of the path to the file + * @return return true if file is closed + * @throws IOException If an I/O error occurred + * @throws UnsupportedOperationException if isFileClosed is not supported by this filesystem. + */ + boolean isFileClosed(Path file) throws IOException; +} diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/SafeMode.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/SafeMode.java new file mode 100644 index 0000000000..37713dfcf7 --- /dev/null +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/SafeMode.java @@ -0,0 +1,50 @@ +/* + * 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; + +import java.io.IOException; + +/** + * Whether the given filesystem is in any status of safe mode. + */ +public interface SafeMode { + + /** + * Enter, leave, or get safe mode. + * + * @param action One of {@link SafeModeAction} LEAVE, ENTER, GET, FORCE_EXIT. + * @throws IOException if set safe mode fails to proceed. + * @return true if the action is successfully accepted, otherwise false means rejected. + */ + default boolean setSafeMode(SafeModeAction action) throws IOException { + return setSafeMode(action, false); + } + + /** + * Enter, leave, or get safe mode. + * + * @param action One of {@link SafeModeAction} LEAVE, ENTER, GET, FORCE_EXIT. + * @param isChecked If true check only for Active metadata node / NameNode's status, + * else check first metadata node / NameNode's status. + * @throws IOException if set safe mode fails to proceed. + * @return true if the action is successfully accepted, otherwise false means rejected. + */ + boolean setSafeMode(SafeModeAction action, boolean isChecked) throws IOException; + +} diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/SafeModeAction.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/SafeModeAction.java new file mode 100644 index 0000000000..775f41637e --- /dev/null +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/SafeModeAction.java @@ -0,0 +1,41 @@ +/* + * 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; + +/** + * An identical copy from org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction, that helps + * the other file system implementation to define {@link SafeMode}. + */ +public enum SafeModeAction { + /** + * Starting entering into safe mode. + */ + ENTER, + /** + * Gracefully exit from safe mode. + */ + LEAVE, + /** + * Force Exit from safe mode. + */ + FORCE_EXIT, + /** + * Get the status of the safe mode. + */ + GET; +} diff --git a/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/index.md b/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/index.md index e18f4c3bf4..df39839e83 100644 --- a/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/index.md +++ b/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/index.md @@ -41,4 +41,6 @@ HDFS as these are commonly expected by Hadoop client applications. 2. [Extending the specification and its tests](extending.html) 1. [Uploading a file using Multiple Parts](multipartuploader.html) 1. [IOStatistics](iostatistics.html) -1. [openFile()](openfile.html). +1. [openFile()](openfile.html) +1. [SafeMode](safemode.html) +1. [LeaseRecoverable](leaserecoverable.html) \ No newline at end of file diff --git a/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/leaserecoverable.md b/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/leaserecoverable.md new file mode 100644 index 0000000000..5640e7c49c --- /dev/null +++ b/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/leaserecoverable.md @@ -0,0 +1,52 @@ + + +# interface `LeaseRecoverable` + +The `LeaseRecoverable` interface tells whether a given path of current filesystem can perform lease +recovery for open file that a lease is not explicitly renewed or the client holding it goes away. + +This interface should be implemented accordingly when necessary to any Filesystem that supports +lease recovery, e.g. `DistributedFileSystem` (HDFS) and `ViewDistributedFileSystem`. + +```java +public interface LeaseRecoverable { + boolean recoverLease(Path file) throws IOException; + boolean isFileClosed(Path file) throws IOException; +} +``` + +There are two main functions of this interface, one performs lease recovery and another one +verifies if a file has been closed. + +### boolean recoverLease(Path file) + +This function performs the lease recovery for the given file path, and it does not support +directory path recovery. +1. Return `true`, if the file has already closed, or does not require lease recovery. +1. Return `false`, if the lease recovery is yet completed. +1. Throw `IOException` if a directory path is given as input. + +### boolean isFileClosed(Path file) + +This function only checks if the give file path has been closed, and it does not support directory +verification. +1. Return `true`, if the file has been closed. +1. Return `false`, if the file is still open. +1. Throw `IOException` if a directory path is given as input. + +### Path Capabilities SHOULD BE declared + +If a filesystem supports `LeaseRecoverable`, it should return `true` to +`PathCapabilities.hasPathCapability(path, "fs.capability.lease.recoverable")` for a given path. \ No newline at end of file diff --git a/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/safemode.md b/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/safemode.md new file mode 100644 index 0000000000..22ab4aa75c --- /dev/null +++ b/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/safemode.md @@ -0,0 +1,45 @@ + + +# interface `SafeMode` + +The `SafeMode` interface provides a way to perform safe mode actions and obtain the +status after such actions performed to the `FileSystem`. + +This is admin only interface, should be implemented accordingly when necessary to +Filesystem that support safe mode, e.g. `DistributedFileSystem` (HDFS) and +`ViewDistributedFileSystem`. + +```java +public interface SafeMode { + default boolean setSafeMode(SafeModeAction action) throws IOException { + return setSafeMode(action, false); + } + boolean setSafeMode(SafeModeAction action, boolean isChecked) throws IOException; +} +``` + +The goals of this interface is allow any file system implementation to share the +same concept of safe mode with the following actions and states + +### Safe mode actions +1. `GET`, get the safe mode status of the file system. +1. `ENTER`, enter the safe mode for the file system. +1. `LEAVE`, exit safe mode for the file system gracefully. +1. `FORCE_EXIT`, exit safe mode for the file system even if there is any ongoing data process. + +### Safe mode states +1. return true, when safe mode is on. +1. return false, when safe mode is off, usually it's the result of safe mode actions +with `GET`, `LEAVE`, `FORCE_EXIT`. \ No newline at end of file diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractLeaseRecoveryTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractLeaseRecoveryTest.java new file mode 100644 index 0000000000..e99b62ae1e --- /dev/null +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractLeaseRecoveryTest.java @@ -0,0 +1,90 @@ +/* + * 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.contract; + +import java.io.FileNotFoundException; +import java.io.IOException; + +import org.assertj.core.api.Assertions; +import org.junit.Test; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.LeaseRecoverable; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.test.LambdaTestUtils; + +import static org.apache.hadoop.fs.CommonPathCapabilities.LEASE_RECOVERABLE; + +public abstract class AbstractContractLeaseRecoveryTest extends + AbstractFSContractTestBase { + + @Test + public void testLeaseRecovery() throws Throwable { + final Path path = methodPath(); + final FileSystem fs = getFileSystem(); + ContractTestUtils.touch(fs, path); + LeaseRecoverable leaseRecoverableFs = verifyAndGetLeaseRecoverableInstance(fs, path); + + Assertions.assertThat(leaseRecoverableFs.recoverLease(path)) + .describedAs("Issuing lease recovery on a closed file must be successful") + .isTrue(); + + Assertions.assertThat(leaseRecoverableFs.isFileClosed(path)) + .describedAs("Get the isFileClose status on a closed file must be successful") + .isTrue(); + } + + @Test + public void testLeaseRecoveryFileNotExist() throws Throwable { + final Path path = new Path("notExist"); + final FileSystem fs = getFileSystem(); + LeaseRecoverable leaseRecoverableFs = verifyAndGetLeaseRecoverableInstance(fs, path); + + LambdaTestUtils.intercept(FileNotFoundException.class, "File does not exist", + () -> leaseRecoverableFs.recoverLease(path)); + + LambdaTestUtils.intercept(FileNotFoundException.class, "File does not exist", + () -> leaseRecoverableFs.isFileClosed(path)); + } + + @Test + public void testLeaseRecoveryFileOnDirectory() throws Throwable { + final Path path = methodPath(); + final FileSystem fs = getFileSystem(); + LeaseRecoverable leaseRecoverableFs = verifyAndGetLeaseRecoverableInstance(fs, path); + final Path parentDirectory = path.getParent(); + + LambdaTestUtils.intercept(FileNotFoundException.class, "Path is not a file", + () -> leaseRecoverableFs.recoverLease(parentDirectory)); + + LambdaTestUtils.intercept(FileNotFoundException.class, "Path is not a file", + () -> leaseRecoverableFs.isFileClosed(parentDirectory)); + } + + private LeaseRecoverable verifyAndGetLeaseRecoverableInstance(FileSystem fs, Path path) + throws IOException { + Assertions.assertThat(fs.hasPathCapability(path, LEASE_RECOVERABLE)) + .describedAs("path capability %s of %s", LEASE_RECOVERABLE, path) + .isTrue(); + Assertions.assertThat(fs) + .describedAs("filesystem %s", fs) + .isInstanceOf(LeaseRecoverable.class); + return (LeaseRecoverable) fs; + } +} diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractSafeModeTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractSafeModeTest.java new file mode 100644 index 0000000000..72d0dce9ff --- /dev/null +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractSafeModeTest.java @@ -0,0 +1,54 @@ +/* + * 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.contract; + +import org.assertj.core.api.Assertions; +import org.junit.Test; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.SafeMode; +import org.apache.hadoop.fs.SafeModeAction; + +public abstract class AbstractContractSafeModeTest extends AbstractFSContractTestBase { + + @Test + public void testSafeMode() throws Throwable { + final FileSystem fs = getFileSystem(); + SafeMode fsWithSafeMode = verifyAndGetSafeModeInstance(fs); + Assertions.assertThat(fsWithSafeMode.setSafeMode(SafeModeAction.GET)) + .describedAs("Getting the status of safe mode before entering should be off.").isFalse(); + Assertions.assertThat(fsWithSafeMode.setSafeMode(SafeModeAction.ENTER)) + .describedAs("Entering Safe mode and safe mode turns on.").isTrue(); + Assertions.assertThat(fsWithSafeMode.setSafeMode(SafeModeAction.GET)) + .describedAs("Getting the status of safe mode after entering, safe mode should be on.") + .isTrue(); + Assertions.assertThat(fsWithSafeMode.setSafeMode(SafeModeAction.LEAVE)) + .describedAs("Leaving safe mode, and safe mode switches off.").isFalse(); + Assertions.assertThat(fsWithSafeMode.setSafeMode(SafeModeAction.FORCE_EXIT)) + .describedAs("Force exist safe mode at any time, safe mode should always switches off.") + .isFalse(); + } + + private SafeMode verifyAndGetSafeModeInstance(FileSystem fs) { + Assertions.assertThat(fs) + .describedAs("File system %s must be an instance of %s", fs, SafeMode.class.getClass()) + .isInstanceOf(SafeMode.class); + return (SafeMode) fs; + } +} diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java index 2b648ecf67..4b25925a4b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java @@ -18,12 +18,14 @@ package org.apache.hadoop.hdfs; - import org.apache.hadoop.ipc.RpcNoSuchMethodException; -import org.apache.hadoop.thirdparty.com.google.common.annotations.VisibleForTesting; import org.apache.hadoop.thirdparty.com.google.common.base.Preconditions; import org.apache.hadoop.thirdparty.com.google.common.collect.Lists; import org.apache.commons.collections.list.TreeList; +import org.apache.hadoop.fs.LeaseRecoverable; +import org.apache.hadoop.fs.SafeMode; + +import org.apache.hadoop.classification.VisibleForTesting; import org.apache.hadoop.HadoopIllegalArgumentException; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; @@ -63,6 +65,7 @@ import org.apache.hadoop.fs.PathFilter; import org.apache.hadoop.fs.QuotaUsage; import org.apache.hadoop.fs.RemoteIterator; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.StorageStatistics; import org.apache.hadoop.fs.StorageType; import org.apache.hadoop.fs.UnresolvedLinkException; @@ -97,7 +100,6 @@ import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType; import org.apache.hadoop.hdfs.protocol.HdfsConstants.ReencryptAction; import org.apache.hadoop.hdfs.protocol.HdfsConstants.RollingUpgradeAction; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.HdfsFileStatus; import org.apache.hadoop.hdfs.protocol.HdfsPathHandle; import org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus; @@ -145,7 +147,7 @@ @InterfaceAudience.LimitedPrivate({ "MapReduce", "HBase" }) @InterfaceStability.Unstable public class DistributedFileSystem extends FileSystem - implements KeyProviderTokenIssuer, BatchListingOperations { + implements KeyProviderTokenIssuer, BatchListingOperations, LeaseRecoverable, SafeMode { private Path workingDir; private URI uri; @@ -307,6 +309,7 @@ public void setVerifyChecksum(boolean verifyChecksum) { * @return true if the file is already closed * @throws IOException if an error occurs */ + @Override public boolean recoverLease(final Path f) throws IOException { Path absF = fixRelativePart(f); return new FileSystemLinkResolver() { @@ -1634,6 +1637,63 @@ public DatanodeInfo[] getDataNodeStats(final DatanodeReportType type) * @see org.apache.hadoop.hdfs.protocol.ClientProtocol#setSafeMode( * HdfsConstants.SafeModeAction,boolean) */ + @Override + public boolean setSafeMode(SafeModeAction action) + throws IOException { + return setSafeMode(action, false); + } + + /** + * Enter, leave or get safe mode. + * + * @param action + * One of SafeModeAction.ENTER, SafeModeAction.LEAVE and + * SafeModeAction.GET. + * @param isChecked + * If true check only for Active NNs status, else check first NN's + * status. + */ + @Override + @SuppressWarnings("deprecation") + public boolean setSafeMode(SafeModeAction action, boolean isChecked) + throws IOException { + return this.setSafeMode(convertToClientProtocolSafeModeAction(action), isChecked); + } + + /** + * Translating the {@link SafeModeAction} into {@link HdfsConstants.SafeModeAction} + * that is used by {@link DFSClient#setSafeMode(HdfsConstants.SafeModeAction, boolean)}. + * + * @param action any supported action listed in {@link SafeModeAction}. + * @return the converted {@link HdfsConstants.SafeModeAction}. + * @throws UnsupportedOperationException if the provided {@link SafeModeAction} cannot be + * translated. + */ + private static HdfsConstants.SafeModeAction convertToClientProtocolSafeModeAction( + SafeModeAction action) { + switch (action) { + case ENTER: + return HdfsConstants.SafeModeAction.SAFEMODE_ENTER; + case LEAVE: + return HdfsConstants.SafeModeAction.SAFEMODE_LEAVE; + case FORCE_EXIT: + return HdfsConstants.SafeModeAction.SAFEMODE_FORCE_EXIT; + case GET: + return HdfsConstants.SafeModeAction.SAFEMODE_GET; + default: + throw new UnsupportedOperationException("Unsupported safe mode action " + action); + } + } + + /** + * Enter, leave or get safe mode. + * + * @see org.apache.hadoop.hdfs.protocol.ClientProtocol#setSafeMode(HdfsConstants.SafeModeAction, + * boolean) + * + * @deprecated please instead use {@link #setSafeMode(SafeModeAction)}. + */ + @Deprecated public boolean setSafeMode(HdfsConstants.SafeModeAction action) throws IOException { return setSafeMode(action, false); @@ -1644,12 +1704,18 @@ public boolean setSafeMode(HdfsConstants.SafeModeAction action) * * @param action * One of SafeModeAction.ENTER, SafeModeAction.LEAVE and - * SafeModeAction.GET + * SafeModeAction.GET. * @param isChecked * If true check only for Active NNs status, else check first NN's - * status - * @see org.apache.hadoop.hdfs.protocol.ClientProtocol#setSafeMode(SafeModeAction, boolean) + * status. + * + * @see org.apache.hadoop.hdfs.protocol.ClientProtocol#setSafeMode(HdfsConstants.SafeModeAction, + * boolean) + * + * @deprecated please instead use + * {@link DistributedFileSystem#setSafeMode(SafeModeAction, boolean)}. */ + @Deprecated public boolean setSafeMode(HdfsConstants.SafeModeAction action, boolean isChecked) throws IOException { return dfs.setSafeMode(action, isChecked); @@ -1686,7 +1752,7 @@ public long rollEdits() throws IOException { } /** - * enable/disable/check restoreFaileStorage + * enable/disable/check restoreFaileStorage. * * @see org.apache.hadoop.hdfs.protocol.ClientProtocol#restoreFailedStorage(String arg) */ @@ -2049,7 +2115,7 @@ protected URI canonicalizeUri(URI uri) { * when there is an issue communicating with the NameNode */ public boolean isInSafeMode() throws IOException { - return setSafeMode(SafeModeAction.SAFEMODE_GET, true); + return setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_GET, true); } /** @see org.apache.hadoop.hdfs.client.HdfsAdmin#allowSnapshot(Path) */ @@ -2390,6 +2456,7 @@ public SnapshotDiffReport next(final FileSystem fs, final Path p) * @throws FileNotFoundException if the file does not exist. * @throws IOException If an I/O error occurred */ + @Override public boolean isFileClosed(final Path src) throws IOException { Path absF = fixRelativePart(src); return new FileSystemLinkResolver() { @@ -3648,6 +3715,7 @@ public boolean hasPathCapability(final Path path, final String capability) // (yet/ever) in the WebHDFS API. switch (validatePathCapabilityArgs(path, capability)) { case CommonPathCapabilities.FS_EXPERIMENTAL_BATCH_LISTING: + case CommonPathCapabilities.LEASE_RECOVERABLE: return true; default: // fall through diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ViewDistributedFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ViewDistributedFileSystem.java index 6f8ebae696..0502ea5b8c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ViewDistributedFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ViewDistributedFileSystem.java @@ -806,6 +806,7 @@ public DatanodeInfo[] getDataNodeStats( } @Override + @SuppressWarnings("deprecation") public boolean setSafeMode(HdfsConstants.SafeModeAction action) throws IOException { if (this.vfs == null) { @@ -816,6 +817,7 @@ public boolean setSafeMode(HdfsConstants.SafeModeAction action) } @Override + @SuppressWarnings("deprecation") public boolean setSafeMode(HdfsConstants.SafeModeAction action, boolean isChecked) throws IOException { if (this.vfs == null) { diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/HdfsUtils.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/HdfsUtils.java index 3b77a3f8ee..59e45e5451 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/HdfsUtils.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/HdfsUtils.java @@ -47,6 +47,7 @@ public class HdfsUtils { * @param uri the HDFS URI. Note that the URI path is ignored. * @return true if HDFS is healthy; false, otherwise. */ + @SuppressWarnings("deprecation") public static boolean isHealthy(URI uri) { //check scheme final String scheme = uri.getScheme(); diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java index 48420ed416..143972ca23 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java @@ -64,6 +64,7 @@ import org.apache.hadoop.fs.FsServerDefaults; import org.apache.hadoop.fs.Options; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.RemoteIterator; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.DFSClient; @@ -86,7 +87,6 @@ import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicyState; import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.HdfsFileStatus; import org.apache.hadoop.hdfs.protocol.LocatedBlock; import org.apache.hadoop.hdfs.protocol.LocatedBlocks; @@ -1401,27 +1401,27 @@ public void testProxyGetMostRecentCheckpointTxId() throws IOException { @Test public void testProxySetSafemode() throws Exception { boolean routerSafemode = - routerProtocol.setSafeMode(SafeModeAction.SAFEMODE_GET, false); + routerProtocol.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_GET, false); boolean nnSafemode = - nnProtocol.setSafeMode(SafeModeAction.SAFEMODE_GET, false); + nnProtocol.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_GET, false); assertEquals(nnSafemode, routerSafemode); routerSafemode = - routerProtocol.setSafeMode(SafeModeAction.SAFEMODE_GET, true); + routerProtocol.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_GET, true); nnSafemode = - nnProtocol.setSafeMode(SafeModeAction.SAFEMODE_GET, true); + nnProtocol.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_GET, true); assertEquals(nnSafemode, routerSafemode); assertFalse(routerProtocol.setSafeMode( - SafeModeAction.SAFEMODE_GET, false)); + HdfsConstants.SafeModeAction.SAFEMODE_GET, false)); assertTrue(routerProtocol.setSafeMode( - SafeModeAction.SAFEMODE_ENTER, false)); + HdfsConstants.SafeModeAction.SAFEMODE_ENTER, false)); assertTrue(routerProtocol.setSafeMode( - SafeModeAction.SAFEMODE_GET, false)); + HdfsConstants.SafeModeAction.SAFEMODE_GET, false)); assertFalse(routerProtocol.setSafeMode( - SafeModeAction.SAFEMODE_LEAVE, false)); + HdfsConstants.SafeModeAction.SAFEMODE_LEAVE, false)); assertFalse(routerProtocol.setSafeMode( - SafeModeAction.SAFEMODE_GET, false)); + HdfsConstants.SafeModeAction.SAFEMODE_GET, false)); } @Test @@ -1653,18 +1653,18 @@ public void testGetCurrentTXIDandRollEdits() throws IOException { @Test public void testSaveNamespace() throws IOException { cluster.getCluster().getFileSystem(0) - .setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + .setSafeMode(SafeModeAction.ENTER); cluster.getCluster().getFileSystem(1) - .setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + .setSafeMode(SafeModeAction.ENTER); Boolean saveNamespace = routerProtocol.saveNamespace(0, 0); assertTrue(saveNamespace); cluster.getCluster().getFileSystem(0) - .setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + .setSafeMode(SafeModeAction.LEAVE); cluster.getCluster().getFileSystem(1) - .setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + .setSafeMode(SafeModeAction.LEAVE); } /* diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpcSingleNS.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpcSingleNS.java index ae0afa42e4..503a417721 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpcSingleNS.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpcSingleNS.java @@ -19,9 +19,9 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.NameNodeProxies; import org.apache.hadoop.hdfs.protocol.ClientProtocol; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster; import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder; import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocol; @@ -203,7 +203,7 @@ public void testGetCurrentTXIDandRollEdits() throws IOException { @Test public void testSaveNamespace() throws IOException { cluster.getCluster().getFileSystem() - .setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + .setSafeMode(SafeModeAction.ENTER); Boolean saveNamespace = routerProtocol.saveNamespace(0, 0); assertTrue(saveNamespace); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java index bc384b8bd4..656431d91a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java @@ -489,6 +489,7 @@ protected DistributedFileSystem getDFS() throws IOException { * Gives a report on how the FileSystem is doing. * @exception IOException if the filesystem does not exist. */ + @SuppressWarnings("deprecation") public void report(String[] argv, int i) throws IOException { DistributedFileSystem dfs = getDFS(); FsStatus ds = dfs.getStatus(); @@ -655,6 +656,7 @@ private static void printSlowDataNodeReports(DistributedFileSystem dfs, boolean * @param idx The index of the command that is being processed. * @exception IOException if the filesystem does not exist. */ + @SuppressWarnings("deprecation") public void setSafeMode(String[] argv, int idx) throws IOException { if (idx != argv.length - 1) { printUsage("-safemode"); @@ -708,6 +710,7 @@ public void setSafeMode(String[] argv, int idx) throws IOException { } + @SuppressWarnings("deprecation") private boolean waitExitSafeMode(DistributedFileSystem dfs, boolean inSafeMode) throws IOException { while (inSafeMode) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/contract/hdfs/TestHDFSContractLeaseRecovery.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/contract/hdfs/TestHDFSContractLeaseRecovery.java new file mode 100644 index 0000000000..c3ad3c694a --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/contract/hdfs/TestHDFSContractLeaseRecovery.java @@ -0,0 +1,49 @@ +/* + * 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.contract.hdfs; + +import java.io.IOException; + +import org.junit.AfterClass; +import org.junit.BeforeClass; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.contract.AbstractContractLeaseRecoveryTest; +import org.apache.hadoop.fs.contract.AbstractFSContract; + +/** + * Test lease recovery on HDFS. + */ +public class TestHDFSContractLeaseRecovery extends AbstractContractLeaseRecoveryTest { + + @BeforeClass + public static void createCluster() throws IOException { + HDFSContract.createCluster(); + } + + @AfterClass + public static void teardownCluster() throws IOException { + HDFSContract.destroyCluster(); + } + + @Override + protected AbstractFSContract createContract(Configuration conf) { + return new HDFSContract(conf); + } +} diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/contract/hdfs/TestHDFSContractSafeMode.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/contract/hdfs/TestHDFSContractSafeMode.java new file mode 100644 index 0000000000..13621327fe --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/contract/hdfs/TestHDFSContractSafeMode.java @@ -0,0 +1,49 @@ +/* + * 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.contract.hdfs; + +import java.io.IOException; + +import org.junit.AfterClass; +import org.junit.BeforeClass; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.contract.AbstractContractSafeModeTest; +import org.apache.hadoop.fs.contract.AbstractFSContract; + +/** + * Test safe mode interface on HDFS. + */ +public class TestHDFSContractSafeMode extends AbstractContractSafeModeTest { + + @BeforeClass + public static void createCluster() throws IOException { + HDFSContract.createCluster(); + } + + @AfterClass + public static void teardownCluster() throws IOException { + HDFSContract.destroyCluster(); + } + + @Override + protected AbstractFSContract createContract(Configuration conf) { + return new HDFSContract(conf); + } +} diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestBlockStoragePolicy.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestBlockStoragePolicy.java index def5afa9ea..9310fb7da8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestBlockStoragePolicy.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestBlockStoragePolicy.java @@ -32,9 +32,9 @@ import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.StorageType; import org.apache.hadoop.hdfs.protocol.*; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.security.token.block.BlockTokenSecretManager; import org.apache.hadoop.hdfs.server.blockmanagement.*; import org.apache.hadoop.hdfs.server.datanode.DataNode; @@ -972,9 +972,9 @@ public void testSetStoragePolicy() throws Exception { checkDirectoryListing(barList, WARM, HOT); // restart namenode with checkpoint to make sure the fsimage is correct - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(true); dirList = fs.getClient().listPaths(dir.toString(), HdfsFileStatus.EMPTY_NAME).getPartialListing(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientRetries.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientRetries.java index ff32895260..236e89b490 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientRetries.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSClientRetries.java @@ -60,6 +60,7 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys; import org.apache.hadoop.hdfs.client.HdfsUtils; @@ -69,7 +70,6 @@ import org.apache.hadoop.hdfs.protocol.DatanodeID; import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.hdfs.protocol.ExtendedBlock; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.HdfsFileStatus; import org.apache.hadoop.hdfs.protocol.LocatedBlock; import org.apache.hadoop.hdfs.protocol.LocatedBlocks; @@ -1120,7 +1120,7 @@ public void run() { //enter safe mode assertTrue(HdfsUtils.isHealthy(uri)); - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); assertFalse(HdfsUtils.isHealthy(uri)); //leave safe mode in a new thread @@ -1131,7 +1131,7 @@ public void run() { //sleep and then leave safe mode TimeUnit.SECONDS.sleep(30); assertFalse(HdfsUtils.isHealthy(uri)); - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); assertTrue(HdfsUtils.isHealthy(uri)); } catch (Exception e) { exceptions.add(e); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUpgrade.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUpgrade.java index e8bd5cefc7..77cae4f0e6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUpgrade.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUpgrade.java @@ -34,8 +34,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.protocol.HdfsConstants.RollingUpgradeAction; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption; @@ -239,7 +239,7 @@ public void testUpgrade() throws Exception { // make sure that rolling upgrade cannot be started try { final DistributedFileSystem dfs = cluster.getFileSystem(); - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); dfs.rollingUpgrade(RollingUpgradeAction.PREPARE); fail(); } catch(RemoteException re) { @@ -383,7 +383,7 @@ public void testUpgrade() throws Exception { // make sure that rolling upgrade cannot be started try { final DistributedFileSystem dfs = cluster.getFileSystem(); - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); dfs.rollingUpgrade(RollingUpgradeAction.PREPARE); fail(); } catch(RemoteException re) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java index d4c27869cc..d46bc73def 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestEncryptionZones.java @@ -66,13 +66,13 @@ import org.apache.hadoop.fs.FsShell; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.RemoteIterator; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.permission.FsAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.client.CreateEncryptionZoneFlag; import org.apache.hadoop.hdfs.client.HdfsAdmin; import org.apache.hadoop.hdfs.protocol.ClientProtocol; import org.apache.hadoop.hdfs.protocol.EncryptionZone; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.HdfsFileStatus; import org.apache.hadoop.hdfs.protocol.LocatedBlocks; import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport; @@ -569,9 +569,9 @@ public Object run() throws Exception { assertZonePresent(null, zonePath.toString()); } - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(true); assertNumZones(numZones); assertEquals("Unexpected number of encryption zones!", numZones, cluster @@ -604,9 +604,9 @@ public void testBasicOperationsRootDir() throws Exception { // Verify rootDir ez is present after restarting the NameNode // and saving/loading from fsimage. - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(true); assertNumZones(numZones); assertZonePresent(null, rootDir.toString()); @@ -1199,9 +1199,9 @@ public void testEncryptionZonesWithSnapshots() throws Exception { fs.getSnapshotDiffReport(snapshottable, "snap1", ""); System.out.println(report); Assert.assertEquals(0, report.getDiffList().size()); - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(true); report = fs.getSnapshotDiffReport(snapshottable, "snap1", ""); @@ -1716,7 +1716,7 @@ public void testOfflineImageViewerOnEncryptionZones() throws Exception { fsWrapper.mkdir(zone1, FsPermission.getDirDefault(), true); dfsAdmin.createEncryptionZone(zone1, TEST_KEY, NO_TRASH); DFSTestUtil.createFile(fs, zone1File, len, (short) 1, 0xFEED); - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER, false); + fs.setSafeMode(SafeModeAction.ENTER, false); fs.saveNamespace(); File originalFsimage = FSImageTestUtil.findLatestImageFile(FSImageTestUtil diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicies.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicies.java index 1fd909c949..938bbebbf8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicies.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicies.java @@ -23,12 +23,12 @@ import org.apache.hadoop.fs.CreateFlag; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.protocol.AddErasureCodingPolicyResponse; import org.apache.hadoop.hdfs.protocol.DirectoryListing; import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicyInfo; import org.apache.hadoop.hdfs.protocol.SystemErasureCodingPolicies; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.HdfsFileStatus; import org.apache.hadoop.hdfs.server.namenode.ErasureCodingPolicyManager; import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; @@ -236,9 +236,9 @@ public void testBasicSetECPolicy() fs.getErasureCodingPolicy(disabledPolicy)); // Also check loading disabled EC policies from fsimage - fs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNodes(); Assert.assertEquals("Dir does not have policy set", diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicyWithSnapshot.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicyWithSnapshot.java index b7e7bba183..6ea2bbab81 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicyWithSnapshot.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestErasureCodingPolicyWithSnapshot.java @@ -25,10 +25,10 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FsShell; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.contract.ContractTestUtils; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.SystemErasureCodingPolicies; import org.apache.hadoop.util.ToolRunner; import org.junit.After; @@ -168,9 +168,9 @@ public void testSnapshotsOnErasureCodingDirAfterNNRestart() throws Exception { ecSnap); // save namespace, restart namenode, and check ec policy correctness. - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(true); ErasureCodingPolicy ecSnap1 = fs.getErasureCodingPolicy(snap1); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestGetBlocks.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestGetBlocks.java index 5f087557c6..85e50e93dc 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestGetBlocks.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestGetBlocks.java @@ -34,6 +34,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.LocatedFileStatus; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.RemoteIterator; import org.apache.hadoop.hdfs.client.HdfsDataInputStream; import org.apache.hadoop.hdfs.protocol.Block; @@ -41,7 +42,6 @@ import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.LocatedBlock; import org.apache.hadoop.hdfs.protocol.LocatedBlocks; import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo; @@ -287,13 +287,13 @@ public void testGetBlocks() throws Exception { assertEquals(blkLocsSize, locs.length); assertFalse(fs.isInSafeMode()); LOG.info("Entering safe mode"); - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); LOG.info("Entered safe mode"); assertTrue(fs.isInSafeMode()); getBlocksWithException(namenode, info, replicationFactor, 0, RemoteException.class, "Cannot execute getBlocks. Name node is in safe mode."); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); assertFalse(fs.isInSafeMode()); } finally { if (fs != null) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHDFSFileSystemContract.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHDFSFileSystemContract.java index 6da46dec37..20378d7d97 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHDFSFileSystemContract.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHDFSFileSystemContract.java @@ -24,13 +24,18 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.fs.FileSystemContractBaseTest; +import org.apache.hadoop.fs.LeaseRecoverable; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeMode; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.test.GenericTestUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; +import static org.apache.hadoop.fs.CommonPathCapabilities.LEASE_RECOVERABLE; +import static org.assertj.core.api.Assertions.assertThat; + public class TestHDFSFileSystemContract extends FileSystemContractBaseTest { private MiniDFSCluster cluster; @@ -67,4 +72,17 @@ protected String getDefaultWorkingDirectory() { public void testAppend() throws IOException { AppendTestUtil.testAppend(fs, new Path("/testAppend/f")); } + + @Test + public void testFileSystemCapabilities() throws Exception { + final Path p = new Path("testFileSystemCapabilities"); + // ViewFileSystem does not support LeaseRecoverable and SafeMode. + if (fs instanceof DistributedFileSystem) { + final boolean leaseRecovery = fs.hasPathCapability(p, LEASE_RECOVERABLE); + assertThat(leaseRecovery).describedAs("path capabilities %s=%s in %s", LEASE_RECOVERABLE, + leaseRecovery, fs).isTrue(); + assertThat(fs).describedAs("filesystem %s", fs).isInstanceOf(LeaseRecoverable.class); + assertThat(fs).describedAs("filesystem %s", fs).isInstanceOf(SafeMode.class); + } + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMiniDFSCluster.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMiniDFSCluster.java index c65437154c..84f62325fe 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMiniDFSCluster.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestMiniDFSCluster.java @@ -34,9 +34,9 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.StorageType; import org.apache.hadoop.hdfs.MiniDFSCluster.NameNodeInfo; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsDatasetSpi; import org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.FsVolumeImpl; @@ -219,7 +219,7 @@ public void testIsClusterUpAfterShutdown() throws Throwable { new MiniDFSCluster.Builder(conf, testDataCluster4).build(); try { DistributedFileSystem dfs = cluster4.getFileSystem(); - dfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); cluster4.shutdown(); } finally { while(cluster4.isClusterUp()){ diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java index bb5da24a68..495195a0c5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java @@ -45,9 +45,9 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.MiniDFSCluster.DataNodeProperties; import org.apache.hadoop.hdfs.protocol.HdfsConstants.RollingUpgradeAction; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo; import org.apache.hadoop.hdfs.qjournal.MiniJournalCluster; import org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster; @@ -136,9 +136,9 @@ public void testDFSAdminRollingUpgradeCommands() throws Exception { runCmd(dfsadmin, true, "-rollingUpgrade"); //start rolling upgrade - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); runCmd(dfsadmin, true, "-rollingUpgrade", "prepare"); - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); //query rolling upgrade runCmd(dfsadmin, true, "-rollingUpgrade", "query"); @@ -163,9 +163,9 @@ public void testDFSAdminRollingUpgradeCommands() throws Exception { Assert.assertTrue(dfs.exists(bar)); Assert.assertTrue(dfs.exists(baz)); - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); dfs.saveNamespace(); - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); } // Ensure directories exist after restart @@ -241,9 +241,9 @@ public void testRollingUpgradeWithQJM() throws Exception { dfs.mkdirs(foo); //start rolling upgrade - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); info1 = dfs.rollingUpgrade(RollingUpgradeAction.PREPARE); - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); LOG.info("START\n" + info1); //query rolling upgrade @@ -397,9 +397,9 @@ private static void startRollingUpgrade(Path foo, Path bar, final DistributedFileSystem dfs = cluster.getFileSystem(); //start rolling upgrade - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); dfs.rollingUpgrade(RollingUpgradeAction.PREPARE); - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); dfs.mkdirs(bar); Assert.assertTrue(dfs.exists(foo)); @@ -587,13 +587,13 @@ public void testQueryAfterRestart() throws IOException, InterruptedException { cluster.waitActive(); DistributedFileSystem dfs = cluster.getFileSystem(); - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); // start rolling upgrade dfs.rollingUpgrade(RollingUpgradeAction.PREPARE); queryForPreparation(dfs); - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); dfs.saveNamespace(); - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNodes(); dfs.rollingUpgrade(RollingUpgradeAction.QUERY); @@ -781,9 +781,9 @@ public void testCheckpointWithSNN() throws Exception { snn.doCheckpoint(); //start rolling upgrade - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); dfs.rollingUpgrade(RollingUpgradeAction.PREPARE); - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); dfs.mkdirs(new Path("/test/bar")); // do checkpoint in SNN again diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgradeDowngrade.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgradeDowngrade.java index ff17c2f617..1b8221a20b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgradeDowngrade.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgradeDowngrade.java @@ -24,8 +24,8 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.protocol.HdfsConstants.RollingUpgradeAction; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo; import org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster; import org.apache.hadoop.hdfs.server.namenode.NNStorage; @@ -99,9 +99,9 @@ public void testRejectNewFsImage() throws IOException { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); cluster.waitActive(); DistributedFileSystem fs = cluster.getFileSystem(); - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); NNStorage storage = spy(cluster.getNameNode().getFSImage().getStorage()); int futureVersion = NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION - 1; doReturn(futureVersion).when(storage).getServiceLayoutVersion(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgradeRollback.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgradeRollback.java index b5ef5eea19..aaa65f0a61 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgradeRollback.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgradeRollback.java @@ -22,8 +22,8 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.protocol.HdfsConstants.RollingUpgradeAction; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.RollingUpgradeInfo; import org.apache.hadoop.hdfs.qjournal.MiniJournalCluster; import org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster; @@ -102,10 +102,10 @@ public void testRollbackCommand() throws Exception { dfs.mkdirs(foo); // start rolling upgrade - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); Assert.assertEquals(0, dfsadmin.run(new String[] { "-rollingUpgrade", "prepare" })); - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); // create new directory dfs.mkdirs(bar); @@ -164,10 +164,10 @@ public void testRollbackWithQJM() throws Exception { dfs.mkdirs(foo); // start rolling upgrade - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); Assert.assertEquals(0, dfsadmin.run(new String[] { "-rollingUpgrade", "prepare" })); - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); // create new directory dfs.mkdirs(bar); dfs.close(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSafeMode.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSafeMode.java index b741ec695d..a73639681f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSafeMode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSafeMode.java @@ -36,12 +36,12 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.permission.AclEntry; import org.apache.hadoop.fs.permission.FsAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.MiniDFSCluster.DataNodeProperties; import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.server.blockmanagement.BlockManagerTestUtil; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption; import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; @@ -134,10 +134,10 @@ public void testManualSafeMode() throws IOException { dfs = cluster.getFileSystem(); assertTrue("No datanode is started. Should be in SafeMode", - dfs.setSafeMode(SafeModeAction.SAFEMODE_GET)); + dfs.setSafeMode(SafeModeAction.GET)); // manually set safemode. - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); // now bring up the datanode and wait for it to be active. cluster.startDataNodes(conf, 1, true, null, null); @@ -149,9 +149,9 @@ public void testManualSafeMode() throws IOException { } catch (InterruptedException ignored) {} assertTrue("should still be in SafeMode", - dfs.setSafeMode(SafeModeAction.SAFEMODE_GET)); + dfs.setSafeMode(SafeModeAction.GET)); assertFalse("should not be in SafeMode", - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE)); + dfs.setSafeMode(SafeModeAction.LEAVE)); } /** @@ -311,7 +311,7 @@ public void testSafeModeExceptionText() throws Exception { final Path file1 = new Path("/file1"); DFSTestUtil.createFile(fs, file1, 1024, (short)1, 0); assertTrue("Could not enter SM", - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER)); + dfs.setSafeMode(SafeModeAction.ENTER)); try { FSRun fsRun = new FSRun() { @Override @@ -339,10 +339,10 @@ public void testOperationsWhileInSafeMode() throws IOException, InterruptedException { final Path file1 = new Path("/file1"); - assertFalse(dfs.setSafeMode(SafeModeAction.SAFEMODE_GET)); + assertFalse(dfs.setSafeMode(SafeModeAction.GET)); DFSTestUtil.createFile(fs, file1, 1024, (short)1, 0); assertTrue("Could not enter SM", - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER)); + dfs.setSafeMode(SafeModeAction.ENTER)); runFsFun("Set quota while in SM", new FSRun() { @Override @@ -492,7 +492,7 @@ public FileSystem run() throws IOException { } assertFalse("Could not leave SM", - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE)); + dfs.setSafeMode(SafeModeAction.LEAVE)); } /** @@ -536,11 +536,11 @@ public void testSafeModeUtils() throws IOException { dfs = cluster.getFileSystem(); // Enter safemode. - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); assertTrue("State was expected to be in safemode.", dfs.isInSafeMode()); // Exit safemode. - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); assertFalse("State was expected to be out of safemode.", dfs.isInSafeMode()); } @@ -561,11 +561,11 @@ public void testSafeModeWhenZeroBlockLocations() throws IOException { NameNode namenode = cluster.getNameNode(); // manually set safemode. - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); assertTrue("should still be in SafeMode", namenode.isInSafeMode()); // getBlock locations should still work since block locations exists checkGetBlockLocationsWorks(fs, file1); - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); assertFalse("should not be in SafeMode", namenode.isInSafeMode()); @@ -595,7 +595,7 @@ public void testSafeModeWhenZeroBlockLocations() throws IOException { } - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); assertFalse("Should not be in safemode", namenode.isInSafeMode()); checkGetBlockLocationsWorks(fs, file1); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancer.java index 35a9c2c7f4..3dcb94aa3f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancer.java @@ -82,6 +82,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.StorageType; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSTestUtil; @@ -1478,9 +1479,9 @@ public void testBalancerDuringUpgrade() throws Exception { // Run balancer final BalancerParameters p = BalancerParameters.DEFAULT; - fs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.rollingUpgrade(HdfsConstants.RollingUpgradeAction.PREPARE); - fs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); // Rolling upgrade should abort the balancer assertEquals(ExitStatus.UNFINALIZED_UPGRADE.getExitCode(), diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeRollingUpgrade.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeRollingUpgrade.java index 04f6ce1f59..f285ce3cee 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeRollingUpgrade.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeRollingUpgrade.java @@ -31,6 +31,7 @@ import org.slf4j.LoggerFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.DFSClient; import org.apache.hadoop.hdfs.DFSOutputStream; import org.apache.hadoop.hdfs.DFSTestUtil; @@ -44,7 +45,6 @@ import org.apache.hadoop.hdfs.protocol.BlockLocalPathInfo; import org.apache.hadoop.hdfs.protocol.ExtendedBlock; import org.apache.hadoop.hdfs.protocol.LocatedBlocks; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.tools.DFSAdmin; import org.apache.hadoop.test.GenericTestUtils; @@ -169,7 +169,7 @@ private boolean isBlockFileInPrevious(File blockFile) { private void startRollingUpgrade() throws Exception { LOG.info("Starting rolling upgrade"); - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); final DFSAdmin dfsadmin = new DFSAdmin(conf); TestRollingUpgrade.runCmd(dfsadmin, true, "-rollingUpgrade", "prepare"); triggerHeartBeats(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestLazyPersistPolicy.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestLazyPersistPolicy.java index 6b198f1bae..6454f51abd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestLazyPersistPolicy.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestLazyPersistPolicy.java @@ -19,7 +19,7 @@ package org.apache.hadoop.hdfs.server.datanode.fsdataset.impl; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.protocol.HdfsFileStatus; import org.apache.hadoop.test.GenericTestUtils; import org.junit.Test; @@ -79,9 +79,9 @@ public void testPolicyPersistenceInFsImage() throws IOException { makeTestFile(path, 0, true); // checkpoint - fs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(true); // Stat the file and check that the lazyPersist flag is returned back. diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddStripedBlocks.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddStripedBlocks.java index aec681176b..a3c2ebbdd3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddStripedBlocks.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestAddStripedBlocks.java @@ -20,6 +20,7 @@ import org.apache.hadoop.fs.BlockLocation; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.DFSStripedOutputStream; import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.DistributedFileSystem; @@ -31,7 +32,6 @@ import org.apache.hadoop.hdfs.protocol.DatanodeID; import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.LocatedBlock; import org.apache.hadoop.hdfs.protocol.LocatedBlocks; import org.apache.hadoop.hdfs.protocol.LocatedStripedBlock; @@ -194,9 +194,9 @@ public void testAddStripedBlock() throws Exception { // save namespace, restart namenode, and check dfs = cluster.getFileSystem(); - dfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); dfs.saveNamespace(); - dfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(true); fsdir = cluster.getNamesystem().getFSDirectory(); fileNode = fsdir.getINode4Write(file.toString()).asFile(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java index 9a52548140..1331c50e80 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCacheDirectives.java @@ -55,6 +55,7 @@ import org.apache.hadoop.fs.FsTracer; import org.apache.hadoop.fs.InvalidRequestException; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.RemoteIterator; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.client.impl.BlockReaderTestUtil; @@ -75,7 +76,6 @@ import org.apache.hadoop.hdfs.protocol.CachePoolStats; import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.LocatedBlocks; import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor; import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor.CachedBlocksList.Type; @@ -693,9 +693,9 @@ public void testCacheManagerRestart() throws Exception { .setPath(new Path("/image")).setPool(imagePool).build()); // Save a new image to force a fresh fsimage download - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); dfs.saveNamespace(); - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); // Checkpoint again forcing a reload of FSN state boolean fetchImage = secondary.doCheckpoint(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckPointForSecurityTokens.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckPointForSecurityTokens.java index cff4e1f32f..b5c7fcc93d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckPointForSecurityTokens.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckPointForSecurityTokens.java @@ -24,11 +24,11 @@ import java.io.IOException; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.MiniDFSCluster; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier; import org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory; import org.apache.hadoop.hdfs.server.namenode.FileJournalManager.EditLogFile; @@ -95,7 +95,7 @@ public void testSaveNamespace() throws IOException { } // Saving image in safe mode should succeed - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); try { admin.run(args); } catch(Exception e) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java index 3e1198d3e2..309a902724 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java @@ -1140,6 +1140,7 @@ public void testCheckpoint() throws IOException { * Tests save namespace. */ @Test + @SuppressWarnings("deprecation") public void testSaveNamespace() throws IOException { MiniDFSCluster cluster = null; DistributedFileSystem fs = null; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImage.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImage.java index f4cd33bc9f..8110f98d33 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImage.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImage.java @@ -63,6 +63,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSOutputStream; import org.apache.hadoop.hdfs.DFSTestUtil; @@ -70,8 +71,6 @@ import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.client.HdfsDataOutputStream.SyncFlag; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.BlockUCState; import org.apache.hadoop.hdfs.server.namenode.LeaseManager.Lease; import org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeDirType; @@ -146,9 +145,9 @@ private void testPersistHelper(Configuration conf) throws IOException { .of(SyncFlag.UPDATE_LENGTH)); // checkpoint - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(); cluster.waitActive(); @@ -346,9 +345,9 @@ public void testDigest() throws IOException { try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); DistributedFileSystem fs = cluster.getFileSystem(); - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); File currentDir = FSImageTestUtil.getNameNodeCurrentDirs(cluster, 0).get( 0); File fsimage = FSImageTestUtil.findNewestImageFile(currentDir @@ -388,9 +387,9 @@ public void testLoadMtimeAtime() throws Exception { long atimeLink = hdfs.getFileLinkStatus(link).getAccessTime(); // save namespace and restart cluster - hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) .numDataNodes(1).build(); @@ -509,9 +508,9 @@ public void testSupportBlockGroup() throws Exception { DFSTestUtil.writeFile(fs, file_3_2, new String(bytes)); // Save namespace and restart NameNode - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNodes(); fs = cluster.getFileSystem(); @@ -788,9 +787,9 @@ public void testSaveAndLoadFileUnderReplicationPolicyDir() .of(SyncFlag.UPDATE_LENGTH)); // checkpoint - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(); cluster.waitActive(); @@ -847,9 +846,9 @@ public void testSaveAndLoadErasureCodingPolicies() throws IOException{ DFSTestUtil.enableAllECPolicies(fs); // Save namespace and restart NameNode - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNodes(); cluster.waitActive(); @@ -870,9 +869,9 @@ public void testSaveAndLoadErasureCodingPolicies() throws IOException{ newPolicy = ret[0].getPolicy(); // Save namespace and restart NameNode - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNodes(); cluster.waitActive(); @@ -918,9 +917,9 @@ private void testChangeErasureCodingPolicyState(MiniDFSCluster cluster, // Save namespace and restart NameNode - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNodes(); cluster.waitActive(); @@ -940,9 +939,9 @@ private void testChangeErasureCodingPolicyState(MiniDFSCluster cluster, // 2. Disable an erasure coding policy fs.disableErasureCodingPolicy(ecPolicy.getName()); // Save namespace and restart NameNode - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNodes(); cluster.waitActive(); @@ -978,9 +977,9 @@ private void testChangeErasureCodingPolicyState(MiniDFSCluster cluster, fs.removeErasureCodingPolicy(ecPolicy.getName()); // Save namespace and restart NameNode - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNodes(); cluster.waitActive(); @@ -1042,9 +1041,9 @@ private MiniDFSCluster createAndLoadParallelFSImage(Configuration conf) } // checkpoint - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(); cluster.waitActive(); @@ -1185,9 +1184,9 @@ public void testUpdateBlocksMapAndNameCacheAsync() throws IOException { SnapshotTestHelper.dumpTree2File(fsdir, preRestartTree); // checkpoint - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(); cluster.waitActive(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithAcl.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithAcl.java index 81251ee81c..a6957639e2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithAcl.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithAcl.java @@ -27,19 +27,18 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.permission.AclEntry; import org.apache.hadoop.fs.permission.AclStatus; -import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.MiniDFSCluster; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; +import org.apache.hadoop.util.Lists; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.apache.hadoop.thirdparty.com.google.common.collect.Lists; public class TestFSImageWithAcl { private static Configuration conf; @@ -82,9 +81,9 @@ private void testAcl(boolean persistNamespace) throws IOException { fs.removeAcl(p); if (persistNamespace) { - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); } cluster.restartNameNode(); @@ -249,9 +248,9 @@ public void testRootACLAfterLoadingFsImage() throws IOException { private void restart(DistributedFileSystem fs, boolean persistNamespace) throws IOException { if (persistNamespace) { - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); } cluster.restartNameNode(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java index f27c8f28bd..b3f64a95d6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java @@ -21,6 +21,7 @@ import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.DFSUtil; @@ -28,7 +29,6 @@ import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.client.HdfsDataOutputStream; import org.apache.hadoop.hdfs.client.HdfsDataOutputStream.SyncFlag; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus; import org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeFile; import org.apache.hadoop.hdfs.server.namenode.snapshot.DiffList; @@ -186,9 +186,9 @@ public void testSnapshotOnRoot() throws Exception { hdfs = cluster.getFileSystem(); // save namespace and restart cluster - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) .numDataNodes(NUM_DATANODES).build(); @@ -213,9 +213,9 @@ public void testSnapshotOnRoot() throws Exception { assertEquals(root, sdirs[0].getFullPath()); // save namespace and restart cluster - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) .numDataNodes(NUM_DATANODES).build(); @@ -407,9 +407,9 @@ public void testLoadImageWithAppending() throws Exception { out.hsync(EnumSet.of(SyncFlag.UPDATE_LENGTH)); // save namespace and restart cluster - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) @@ -431,9 +431,9 @@ public void testLoadImageWithEmptyFile() throws Exception { out.close(); // save namespace - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); // append to the empty file out = hdfs.append(file); @@ -501,9 +501,9 @@ public void testSaveLoadImageAfterSnapshotDeletion() hdfs = cluster.getFileSystem(); // save namespace to fsimage - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) @@ -583,9 +583,9 @@ public void testDoubleRename() throws Exception { void restartCluster() throws Exception { final File before = dumpTree2File("before.txt"); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) @@ -639,9 +639,9 @@ public void testFSImageWithDoubleRename() throws Exception { hdfs.delete(renamePath1, true); hdfs.deleteSnapshot(dir1, "s1"); // save namespace and restart cluster - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) .numDataNodes(NUM_DATANODES).build(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithXAttr.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithXAttr.java index 4cef3214e9..9d7b4706cf 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithXAttr.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithXAttr.java @@ -24,11 +24,12 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.XAttrSetFlag; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.MiniDFSCluster; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; + import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -123,9 +124,9 @@ public void testXAttrEditLog() throws IOException { private void restart(DistributedFileSystem fs, boolean persistNamespace) throws IOException { if (persistNamespace) { - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); } cluster.restartNameNode(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java index 9cff6f8d27..513efd5979 100755 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFileTruncate.java @@ -48,6 +48,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FsShell; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.AppendTestUtil; import org.apache.hadoop.hdfs.DFSConfigKeys; @@ -57,7 +58,6 @@ import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.protocol.Block; import org.apache.hadoop.hdfs.protocol.HdfsConstants; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.LocatedBlock; import org.apache.hadoop.hdfs.protocol.LocatedBlocks; import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoContiguous; @@ -949,9 +949,9 @@ public void testTruncateWithDataNodesShutdownImmediately() throws Exception { @Test public void testTruncateEditLogLoad() throws IOException { // purge previously accumulated edits - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); int startingFileSize = 2 * BLOCK_SIZE + BLOCK_SIZE / 2; int toTruncate = 1; @@ -1047,7 +1047,7 @@ public void testUpgradeAndRestart() throws IOException { assertFileLength(snapshotFile, startingFileSize); // empty edits and restart - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); cluster.restartNameNode(true); assertThat("Total block count should be unchanged from start-up", @@ -1242,10 +1242,10 @@ public void testTruncateWithRollingUpgrade() throws Exception { final DFSAdmin dfsadmin = new DFSAdmin(cluster.getConfiguration(0)); DistributedFileSystem dfs = cluster.getFileSystem(); //start rolling upgrade - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); int status = dfsadmin.run(new String[]{"-rollingUpgrade", "prepare"}); assertEquals("could not prepare for rolling upgrade", 0, status); - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); Path dir = new Path("/testTruncateWithRollingUpgrade"); fs.mkdirs(dir); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java index 61eeb362a1..1ea43f0b74 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestLeaseManager.java @@ -25,6 +25,7 @@ import org.apache.hadoop.thirdparty.com.google.common.collect.Lists; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.PermissionStatus; import org.apache.hadoop.hdfs.DFSUtil; @@ -32,7 +33,6 @@ import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.protocol.HdfsConstants; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.OpenFilesIterator; import org.apache.hadoop.hdfs.protocol.QuotaExceededException; import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo; @@ -164,9 +164,9 @@ public void testLeaseRestorationOnRestart() throws Exception { file.getFileUnderConstructionFeature().getClientName(), file); // Save a fsimage. - dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); cluster.getNameNodeRpc().saveNamespace(0,0); - dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); // Restart the namenode. cluster.restartNameNode(true); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRetryCacheMetrics.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRetryCacheMetrics.java index fb3a84083c..27f0f4a213 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRetryCacheMetrics.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRetryCacheMetrics.java @@ -20,8 +20,8 @@ import java.io.IOException; import org.apache.hadoop.hdfs.DFSClient; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.server.namenode.ha.HATestUtil; import org.apache.hadoop.ipc.metrics.RetryCacheMetrics; import org.apache.hadoop.conf.Configuration; @@ -106,9 +106,9 @@ private void checkMetrics(long hit, long cleared, long updated) { } private void trySaveNamespace() throws IOException { - filesystem.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + filesystem.setSafeMode(SafeModeAction.ENTER); filesystem.saveNamespace(); - filesystem.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + filesystem.setSafeMode(SafeModeAction.LEAVE); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNestedEncryptionZones.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNestedEncryptionZones.java index 92187d1128..573250af8a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNestedEncryptionZones.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNestedEncryptionZones.java @@ -24,13 +24,13 @@ import org.apache.hadoop.fs.FileSystemTestHelper; import org.apache.hadoop.fs.FsShell; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.MiniDFSCluster; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.util.ToolRunner; import org.apache.log4j.Level; @@ -133,9 +133,9 @@ public void testNestedEncryptionZones() throws Exception { // Checkpoint and restart NameNode, to test if nested EZs can be loaded // from fsimage - fs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNodes(); cluster.waitActive(); fs = cluster.getFileSystem(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestQuotaByStorageType.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestQuotaByStorageType.java index a53b319eab..d6fe3a7a49 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestQuotaByStorageType.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestQuotaByStorageType.java @@ -26,6 +26,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.ContentSummary; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.StorageType; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSTestUtil; @@ -723,9 +724,9 @@ public void testQuotaByStorageTypePersistenceInFsImage() throws IOException { assertEquals(file1Len, ssdConsumed); // Restart the namenode with checkpoint to make sure fsImage is correct - dfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + dfs.setSafeMode(SafeModeAction.ENTER); dfs.saveNamespace(); - dfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + dfs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(true); refreshClusterState(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReencryption.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReencryption.java index 7f4be8afc9..a17cce5542 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReencryption.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestReencryption.java @@ -41,6 +41,7 @@ import org.apache.hadoop.fs.FileSystemTestHelper; import org.apache.hadoop.fs.FileSystemTestWrapper; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.RemoteIterator; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.DFSConfigKeys; @@ -51,7 +52,6 @@ import org.apache.hadoop.hdfs.client.CreateEncryptionZoneFlag; import org.apache.hadoop.hdfs.client.HdfsAdmin; import org.apache.hadoop.hdfs.protocol.HdfsConstants.ReencryptAction; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.ReencryptionStatus; import org.apache.hadoop.hdfs.protocol.SnapshotAccessControlException; import org.apache.hadoop.hdfs.protocol.ZoneReencryptionStatus; @@ -538,9 +538,9 @@ public void testRestartAfterReencryptAndCheckpoint() throws Exception { final FileEncryptionInfo fei0new = getFileEncryptionInfo(encFile0); final FileEncryptionInfo fei9new = getFileEncryptionInfo(encFile9); - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); restartClusterDisableReencrypt(); assertKeyVersionEquals(encFile0, fei0new); @@ -651,9 +651,9 @@ public void testReencryptLoadedFromFsimage() throws Exception { dfsAdmin.reencryptEncryptionZone(zone, ReencryptAction.START); waitForQueuedZones(1); - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); // verify after loading from fsimage the command is loaded restartClusterDisableReencrypt(); @@ -716,9 +716,9 @@ public void testReencryptCommandsQueuedOrdering() throws Exception { } // Verify the same is true after loading from FSImage - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); fs.saveNamespace(); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); restartClusterDisableReencrypt(); waitForQueuedZones(numZones - cancelled.size()); @@ -1714,7 +1714,7 @@ public void testReencryptionNNSafeMode() throws Exception { dfsAdmin.reencryptEncryptionZone(zone, ReencryptAction.START); waitForReencryptedFiles(zone.toString(), 5); - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); getEzManager().resumeReencryptForTesting(); for (int i = 0; i < 3; ++i) { Thread.sleep(1000); @@ -1727,7 +1727,7 @@ public void testReencryptionNNSafeMode() throws Exception { assertEquals(5, zs.getFilesReencrypted()); } - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); // trigger the background thread to run, without having to // wait for DFS_NAMENODE_REENCRYPT_SLEEP_INTERVAL_KEY getHandler().notifyNewSubmission(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSaveNamespace.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSaveNamespace.java index ee919944bc..6ffc8c4110 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSaveNamespace.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestSaveNamespace.java @@ -47,6 +47,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.permission.FsAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.PermissionStatus; @@ -55,7 +56,7 @@ import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.MiniDFSCluster; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; +import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.server.blockmanagement.BlockIdManager; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NamenodeRole; import org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory; @@ -212,7 +213,7 @@ private void saveNamespaceWithInjectedFault(Fault fault) throws Exception { doAnEdit(fsn, 1); // Save namespace - this may fail, depending on fault injected - fsn.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fsn.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); try { fsn.saveNamespace(0, 0); if (shouldFail) { @@ -226,7 +227,7 @@ private void saveNamespaceWithInjectedFault(Fault fault) throws Exception { } } - fsn.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fsn.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); // Should still be able to perform edits doAnEdit(fsn, 2); @@ -281,7 +282,7 @@ public void testReinsertnamedirsInSavenamespace() throws Exception { try { doAnEdit(fsn, 1); - fsn.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fsn.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); // Save namespace - should mark the first storage dir as faulty // since it's not traversable. @@ -420,7 +421,7 @@ public void doTestFailedSaveNamespace(boolean restoreStorageAfterFailure) doAnEdit(fsn, 1); // Save namespace - fsn.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fsn.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); try { fsn.saveNamespace(0, 0); fail("saveNamespace did not fail even when all directories failed!"); @@ -469,7 +470,7 @@ public void testSaveWhileEditsRolled() throws Exception { doAnEdit(fsn, 2); // Save namespace - fsn.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fsn.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); fsn.saveNamespace(0, 0); // Now shut down and restart the NN @@ -503,7 +504,7 @@ public void testTxIdPersistence() throws Exception { doAnEdit(fsn, 1); assertEquals(2, fsn.getEditLog().getLastWrittenTxId()); - fsn.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fsn.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); fsn.saveNamespace(0, 0); // 2 more txns: END the first segment, BEGIN a new one @@ -560,7 +561,7 @@ public void testCancelSaveNamespace() throws Exception { final Canceler canceler = new Canceler(); // Save namespace - fsn.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fsn.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); try { Future saverFuture = pool.submit(new Callable() { @Override @@ -628,9 +629,9 @@ public void testSaveNamespaceWithRenamedLease() throws Exception { out = fs.create(new Path("/test-source/foo")); // don't close fs.rename(new Path("/test-source/"), new Path("/test-target/")); - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); cluster.getNameNodeRpc().saveNamespace(0, 0); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); } finally { IOUtils.cleanupWithLogger(LOG, out, fs); cluster.shutdown(); @@ -646,9 +647,9 @@ public void testSaveNamespaceWithDanglingLease() throws Exception { try { cluster.getNamesystem().leaseManager.addLease("me", INodeId.ROOT_INODE_ID + 1); - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); cluster.getNameNodeRpc().saveNamespace(0, 0); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); } finally { cluster.shutdown(); } @@ -678,9 +679,9 @@ public void testSkipSnapshotSection() throws Exception { file.getFileWithSnapshotFeature().getDiffs() != null); // saveNamespace - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); cluster.getNameNodeRpc().saveNamespace(0, 0); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); // restart namenode cluster.restartNameNode(true); @@ -708,7 +709,7 @@ public void testSaveNamespaceBeforeShutdown() throws Exception { final FSImage fsimage = cluster.getNameNode().getFSImage(); final long before = fsimage.getStorage().getMostRecentCheckpointTxId(); - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); // set the timewindow to 1 hour and tx gap to 1000, which means that if // there is a checkpoint during the past 1 hour or the tx number happening // after the latest checkpoint is <= 1000, this saveNamespace request @@ -723,14 +724,14 @@ public void testSaveNamespaceBeforeShutdown() throws Exception { // do another checkpoint. this time set the timewindow to 1s // we should see a new checkpoint cluster.getNameNodeRpc().saveNamespace(1, 1000); - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); after = fsimage.getStorage().getMostRecentCheckpointTxId(); Assert.assertTrue(after > before); fs.mkdirs(new Path("/foo/bar/baz")); // 3 new tx - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + fs.setSafeMode(SafeModeAction.ENTER); cluster.getNameNodeRpc().saveNamespace(3600, 5); // 3 + end/start segment long after2 = fsimage.getStorage().getMostRecentCheckpointTxId(); // no checkpoint should be made diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAMetrics.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAMetrics.java index 8beba74c6f..c1a78815dc 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAMetrics.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAMetrics.java @@ -22,12 +22,12 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSNNTopology; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; import org.apache.hadoop.io.IOUtils; import org.junit.Test; @@ -157,7 +157,7 @@ public void testHAInodeCount() throws Exception { // Save fsimage so that nn does not build up namesystem by replaying // edits, but load from the image. - ((DistributedFileSystem)fs).setSafeMode(SafeModeAction.SAFEMODE_ENTER); + ((DistributedFileSystem)fs).setSafeMode(SafeModeAction.ENTER); ((DistributedFileSystem)fs).saveNamespace(); // Flip the two namenodes and restart the standby, which will load diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestNNHealthCheck.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestNNHealthCheck.java index ab7e0afbca..fcc5e25a58 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestNNHealthCheck.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestNNHealthCheck.java @@ -27,12 +27,12 @@ import java.io.IOException; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.ha.HAServiceProtocol; import org.apache.hadoop.ha.HealthCheckFailedException; import org.apache.hadoop.hdfs.DFSUtil; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSNNTopology; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.server.namenode.MockNameNodeResourceChecker; import org.apache.hadoop.hdfs.tools.NNHAServiceTarget; import org.apache.hadoop.ipc.RemoteException; @@ -90,7 +90,7 @@ public void testNNHealthCheckWithSafemodeAsUnhealthy() throws Exception { // manually set safemode. cluster.getFileSystem(0) - .setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + .setSafeMode(SafeModeAction.ENTER); NNHAServiceTarget haTarget = new NNHAServiceTarget(conf, DFSUtil.getNamenodeNameServiceId(conf), "nn1"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestObserverNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestObserverNode.java index 178f2fcde9..bb901423bb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestObserverNode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestObserverNode.java @@ -44,6 +44,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState; import org.apache.hadoop.ha.ServiceFailedException; @@ -53,7 +54,6 @@ import org.apache.hadoop.hdfs.protocol.Block; import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.hdfs.protocol.ExtendedBlock; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.LocatedBlock; import org.apache.hadoop.hdfs.protocol.LocatedBlocks; import org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster; @@ -313,7 +313,7 @@ public void testObserverNodeSafeModeWithBlockLocations() throws Exception { assertSentTo(2); // Set observer to safe mode. - dfsCluster.getFileSystem(2).setSafeMode(SafeModeAction.SAFEMODE_ENTER); + dfsCluster.getFileSystem(2).setSafeMode(SafeModeAction.ENTER); // Mock block manager for observer to generate some fake blocks which // will trigger the (retriable) safe mode exception. @@ -336,7 +336,7 @@ public void testObserverNodeSafeModeWithBlockLocations() throws Exception { Mockito.reset(bmSpy); // Remove safe mode on observer, request should still go to it. - dfsCluster.getFileSystem(2).setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + dfsCluster.getFileSystem(2).setSafeMode(SafeModeAction.LEAVE); dfs.open(testPath).close(); assertSentTo(2); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRandomOpsWithSnapshots.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRandomOpsWithSnapshots.java index 662957fe7a..300a8aed81 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRandomOpsWithSnapshots.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRandomOpsWithSnapshots.java @@ -23,11 +23,11 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Options; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.MiniDFSCluster; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.SnapshotException; import org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus; import org.apache.hadoop.test.GenericTestUtils; @@ -582,9 +582,9 @@ private void checkClusterHealth() throws IOException, InterruptedException, // Randomly decide whether we want to do a check point if (generator.nextBoolean()) { LOG.info("checkClusterHealth, doing a checkpoint on NN."); - hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); } /** Restart name node making sure loading from image successfully */ diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java index 3bfe971aef..df30b34952 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java @@ -24,11 +24,11 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.Options.Rename; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.*; import org.apache.hadoop.hdfs.client.HdfsDataOutputStream.SyncFlag; import org.apache.hadoop.hdfs.protocol.HdfsConstants; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.NSQuotaExceededException; import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport; import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry; @@ -565,9 +565,9 @@ private void restartClusterAndCheckImage(boolean compareQuota) SnapshotTestHelper.dumpTree2File(fsdir, fsnMiddle); // save namespace and restart cluster - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) .numDataNodes(REPL).build(); @@ -1811,9 +1811,9 @@ public void testRenameUndo_7() throws Exception { // correct. Note that when loading fsimage, foo and bar will be converted // back to normal INodeDirectory and INodeFile since they do not store any // snapshot data - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) .numDataNodes(REPL).build(); @@ -2485,9 +2485,9 @@ public void testDoubleRenamesWithSnapshotDelete() throws Exception { deleteSnapshot(sub1, snap6); deleteSnapshot(sub1, snap3); // save namespace and restart Namenode - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(true); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshot.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshot.java index 0a262f899a..adfbbf1690 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshot.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshot.java @@ -40,6 +40,7 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.permission.FsAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.DFSConfigKeys; @@ -48,7 +49,6 @@ import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.client.HdfsDataOutputStream; import org.apache.hadoop.hdfs.protocol.HdfsConstants; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.server.namenode.FSDirectory; import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil; import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; @@ -208,9 +208,9 @@ private void checkFSImage() throws Exception { SnapshotTestHelper.dumpTree2File(fsdir, fsnMiddle); // save namespace and restart cluster - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) .numDataNodes(REPLICATION).build(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java index 82bfa88f44..e1b270a818 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java @@ -32,6 +32,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FsShell; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.DFSUtil; @@ -40,7 +41,6 @@ import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSNNTopology; import org.apache.hadoop.hdfs.protocol.HdfsConstants; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport; import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo; import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager; @@ -167,9 +167,9 @@ public void testApplyEditLogForDeletion() throws Exception { .getNumSnapshottableDirs()); assertEquals(0, cluster.getNamesystem().getSnapshotManager() .getSnapshottableDirs().length); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(0); } @@ -1143,10 +1143,10 @@ public void testCorrectNumberOfBlocksAfterRestart() hdfs.allowSnapshot(foo); hdfs.createSnapshot(foo, snapshotName); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); hdfs.deleteSnapshot(foo, snapshotName); hdfs.delete(bar, true); hdfs.delete(foo, true); @@ -1188,9 +1188,9 @@ public void testFsImageCorruption() throws Exception { hdfs.deleteSnapshot(st, "s1"); hdfs.deleteSnapshot(st, "s2"); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNodes(); } @@ -1273,9 +1273,9 @@ public void testSnapshotWithConcatException() throws Exception { exception.expectMessage(error); hdfs.concat(dest, files); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNodes(); } @@ -1310,9 +1310,9 @@ public void testSnapshotDeleteWithConcat() throws Exception { hdfs.deleteSnapshot(st, "s1"); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNodes(); } @@ -1354,9 +1354,9 @@ public void testSnapshotDiffReportWithConcat() throws Exception { hdfs.deleteSnapshot(st, "s1"); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNodes(); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestXAttrWithSnapshot.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestXAttrWithSnapshot.java index 03931d6c66..be0aec832b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestXAttrWithSnapshot.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestXAttrWithSnapshot.java @@ -28,12 +28,12 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FsShell; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.XAttrSetFlag; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.MiniDFSCluster; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.SnapshotAccessControlException; import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport; import org.apache.hadoop.hdfs.server.namenode.NameNode; @@ -155,9 +155,9 @@ public void testXattrWithSnapshotAndNNRestart() throws Exception { hdfs.getSnapshotDiffReport(path, snapshotName, ""); System.out.println(report); Assert.assertEquals(0, report.getDiffList().size()); - hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + hdfs.setSafeMode(SafeModeAction.ENTER); hdfs.saveNamespace(); - hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + hdfs.setSafeMode(SafeModeAction.LEAVE); cluster.restartNameNode(true); report = hdfs.getSnapshotDiffReport(path, snapshotName, ""); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java index ef588fa0ff..768b59b966 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java @@ -99,6 +99,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystemTestHelper; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.permission.FsAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.PermissionStatus; @@ -108,9 +109,8 @@ import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.protocol.BlockType; import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; -import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos; import org.apache.hadoop.hdfs.protocol.SystemErasureCodingPolicies; +import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos; import org.apache.hadoop.hdfs.server.namenode.FsImageProto; import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil; import org.apache.hadoop.hdfs.server.namenode.INodeFile; @@ -352,9 +352,9 @@ public static void createOriginalFSImage() throws IOException { filesECCount++; // Write results to the fsimage file - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER, false); + hdfs.setSafeMode(SafeModeAction.ENTER, false); hdfs.saveNamespace(); - hdfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE, false); + hdfs.setSafeMode(SafeModeAction.LEAVE, false); // Determine location of fsimage file originalFsimage = FSImageTestUtil.findLatestImageFile(FSImageTestUtil @@ -1239,7 +1239,7 @@ public void testFileDistributionCalculatorForException() throws Exception { } // Write results to the fsimage file - hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER, false); + hdfs.setSafeMode(SafeModeAction.ENTER, false); hdfs.saveNamespace(); // Determine location of fsimage file fsimageFile = diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForAcl.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForAcl.java index 4fb17a0031..caf33eb3c5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForAcl.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForAcl.java @@ -40,11 +40,11 @@ import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.permission.AclStatus; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.MiniDFSCluster; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil; import org.apache.hadoop.hdfs.web.WebHdfsFileSystem; import org.apache.hadoop.net.NetUtils; @@ -146,7 +146,7 @@ public static void createOriginalFSImage() throws IOException { writtenAcls.put(file.toString(), hdfs.getAclStatus(file)); // Write results to the fsimage file - hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER, false); + hdfs.setSafeMode(SafeModeAction.ENTER, false); hdfs.saveNamespace(); // Determine the location of the fsimage file diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForContentSummary.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForContentSummary.java index 360ed56e1a..a68729a985 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForContentSummary.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForContentSummary.java @@ -30,9 +30,9 @@ import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.MiniDFSCluster; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil; import org.apache.hadoop.hdfs.web.WebHdfsFileSystem; import org.apache.hadoop.net.NetUtils; @@ -102,7 +102,7 @@ public static void createOriginalFSImage() throws IOException { symLinkSummaryForDirContainsFromDFS = hdfs.getContentSummary(new Path( "/dirForLinks")); // Write results to the fsimage file - hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER, false); + hdfs.setSafeMode(SafeModeAction.ENTER, false); hdfs.saveNamespace(); // Determine the location of the fsimage file originalFsimage = FSImageTestUtil.findLatestImageFile(FSImageTestUtil diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForStoragePolicy.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForStoragePolicy.java index 782feb85cf..1790b3af22 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForStoragePolicy.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForStoragePolicy.java @@ -20,6 +20,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.DistributedFileSystem; @@ -116,7 +117,7 @@ public static void createOriginalFSImage() throws IOException { hdfs.setStoragePolicy(dir, HdfsConstants.HOT_STORAGE_POLICY_NAME); // Write results to the fsimage file - hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER, false); + hdfs.setSafeMode(SafeModeAction.ENTER, false); hdfs.saveNamespace(); // Determine the location of the fsimage file diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForXAttr.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForXAttr.java index 6c7d7b7896..e2b67268d6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForXAttr.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForXAttr.java @@ -36,11 +36,11 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.XAttr; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.XAttrHelper; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil; import org.apache.hadoop.hdfs.web.JsonUtil; import org.apache.hadoop.hdfs.web.WebHdfsFileSystem; @@ -81,7 +81,7 @@ public static void createOriginalFSImage() throws IOException { hdfs.setXAttr(dir, "user.attr1", "value1".getBytes()); hdfs.setXAttr(dir, "user.attr2", "value2".getBytes()); // Write results to the fsimage file - hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER, false); + hdfs.setSafeMode(SafeModeAction.ENTER, false); hdfs.saveNamespace(); List attributes = new ArrayList(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerWithStripedBlocks.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerWithStripedBlocks.java index 187b297b42..f8262c9751 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerWithStripedBlocks.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerWithStripedBlocks.java @@ -26,6 +26,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.UnresolvedLinkException; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSTestUtil; @@ -33,7 +34,6 @@ import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.StripedFileTestUtil; import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy; -import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.SnapshotAccessControlException; import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo; import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoStriped; @@ -121,7 +121,7 @@ public void testFileMoreThanOneStripe() throws Exception { private void testFileSize(int numBytes) throws IOException, UnresolvedLinkException, SnapshotAccessControlException { - fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + fs.setSafeMode(SafeModeAction.LEAVE); File orgFsimage = null; Path file = new Path("/eczone/striped"); FSDataOutputStream out = fs.create(file, true); @@ -130,7 +130,7 @@ private void testFileSize(int numBytes) throws IOException, out.close(); // Write results to the fsimage file - fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER, false); + fs.setSafeMode(SafeModeAction.ENTER, false); fs.saveNamespace(); // Determine location of fsimage file diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestHistoryFileManager.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestHistoryFileManager.java index f09329b668..0614cc4a3a 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestHistoryFileManager.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestHistoryFileManager.java @@ -32,11 +32,11 @@ import org.apache.hadoop.fs.CommonConfigurationKeysPublic; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileContext; import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.MiniDFSCluster; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.mapreduce.JobID; import org.apache.hadoop.mapreduce.TypeConverter; import org.apache.hadoop.mapreduce.v2.hs.HistoryFileManager.HistoryFileInfo; @@ -87,9 +87,9 @@ public static void cleanUpClass() throws Exception { public void cleanTest() throws Exception { new File(coreSitePath).delete(); dfsCluster.getFileSystem().setSafeMode( - HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + SafeModeAction.LEAVE); dfsCluster2.getFileSystem().setSafeMode( - HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + SafeModeAction.LEAVE); } private String getDoneDirNameForTest() { @@ -119,7 +119,7 @@ public void testCreateDirsWithoutFileSystem() throws Exception { @Test public void testCreateDirsWithFileSystem() throws Exception { dfsCluster.getFileSystem().setSafeMode( - HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + SafeModeAction.LEAVE); Assert.assertFalse(dfsCluster.getFileSystem().isInSafeMode()); testTryCreateHistoryDirs(dfsCluster.getConfiguration(0), true); } @@ -127,9 +127,9 @@ public void testCreateDirsWithFileSystem() throws Exception { @Test public void testCreateDirsWithAdditionalFileSystem() throws Exception { dfsCluster.getFileSystem().setSafeMode( - HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + SafeModeAction.LEAVE); dfsCluster2.getFileSystem().setSafeMode( - HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + SafeModeAction.LEAVE); Assert.assertFalse(dfsCluster.getFileSystem().isInSafeMode()); Assert.assertFalse(dfsCluster2.getFileSystem().isInSafeMode()); @@ -157,7 +157,7 @@ public void testCreateDirsWithAdditionalFileSystem() throws Exception { @Test public void testCreateDirsWithFileSystemInSafeMode() throws Exception { dfsCluster.getFileSystem().setSafeMode( - HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + SafeModeAction.ENTER); Assert.assertTrue(dfsCluster.getFileSystem().isInSafeMode()); testTryCreateHistoryDirs(dfsCluster.getConfiguration(0), false); } @@ -175,7 +175,7 @@ private void testCreateHistoryDirs(Configuration conf, Clock clock) public void testCreateDirsWithFileSystemBecomingAvailBeforeTimeout() throws Exception { dfsCluster.getFileSystem().setSafeMode( - HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + SafeModeAction.ENTER); Assert.assertTrue(dfsCluster.getFileSystem().isInSafeMode()); new Thread() { @Override @@ -183,7 +183,7 @@ public void run() { try { Thread.sleep(500); dfsCluster.getFileSystem().setSafeMode( - HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); + SafeModeAction.LEAVE); Assert.assertTrue(dfsCluster.getFileSystem().isInSafeMode()); } catch (Exception ex) { Assert.fail(ex.toString()); @@ -198,7 +198,7 @@ public void run() { public void testCreateDirsWithFileSystemNotBecomingAvailBeforeTimeout() throws Exception { dfsCluster.getFileSystem().setSafeMode( - HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + SafeModeAction.ENTER); Assert.assertTrue(dfsCluster.getFileSystem().isInSafeMode()); final ControlledClock clock = new ControlledClock(); clock.setTime(1); diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestHistoryFileManagerInitWithNonRunningDFS.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestHistoryFileManagerInitWithNonRunningDFS.java index d0fefef90a..fbadd61233 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestHistoryFileManagerInitWithNonRunningDFS.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestHistoryFileManagerInitWithNonRunningDFS.java @@ -19,10 +19,10 @@ package org.apache.hadoop.mapreduce.v2.hs; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.SafeModeAction; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.mapreduce.v2.jobhistory.JHAdminConfig; import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; -import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.junit.Assert; import org.junit.Test; @@ -57,7 +57,7 @@ public void testKeepRetryingWhileNameNodeInSafeMode() throws Exception { try { // set up a cluster with its name node in safe mode dfsCluster.getFileSystem().setSafeMode( - HdfsConstants.SafeModeAction.SAFEMODE_ENTER); + SafeModeAction.ENTER); Assert.assertTrue(dfsCluster.getFileSystem().isInSafeMode()); HistoryFileManager hfm = new HistoryFileManager();