-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBASE-27567 Introduce ChaosMonkey Action to print HDFS Cluster status
Signed-off-by: Reid Chan <reidchan@apache.org> Signed-off-by: Duo Zhang <zhangduo@apache.org>
- Loading branch information
Showing
5 changed files
with
202 additions
and
39 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...e-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/DumpHdfsClusterStatusAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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.hbase.chaos.actions; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.net.URI; | ||
import java.util.List; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.hdfs.DistributedFileSystem; | ||
import org.apache.hadoop.hdfs.HAUtil; | ||
import org.apache.hadoop.hdfs.HAUtilClient; | ||
import org.apache.hadoop.hdfs.protocol.ClientProtocol; | ||
import org.apache.hadoop.hdfs.protocol.DatanodeInfo; | ||
import org.apache.hadoop.hdfs.protocol.HdfsConstants; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class DumpHdfsClusterStatusAction extends Action { | ||
private static final Logger LOG = LoggerFactory.getLogger(DumpHdfsClusterStatusAction.class); | ||
private static final String PREFIX = "\n "; | ||
|
||
@Override | ||
protected Logger getLogger() { | ||
return LOG; | ||
} | ||
|
||
@Override | ||
public void perform() throws Exception { | ||
StringBuilder sb = new StringBuilder(); | ||
try (final DistributedFileSystem dfs = HdfsActionUtils.createDfs(getConf())) { | ||
final Configuration dfsConf = dfs.getConf(); | ||
final URI dfsUri = dfs.getUri(); | ||
final boolean isHaAndLogicalUri = HAUtilClient.isLogicalUri(dfsConf, dfsUri); | ||
sb.append("Cluster status").append('\n'); | ||
if (isHaAndLogicalUri) { | ||
final String nsId = dfsUri.getHost(); | ||
final List<ClientProtocol> namenodes = | ||
HAUtil.getProxiesForAllNameNodesInNameservice(dfsConf, nsId); | ||
final boolean atLeastOneActive = HAUtil.isAtLeastOneActive(namenodes); | ||
final InetSocketAddress activeAddress = HAUtil.getAddressOfActive(dfs); | ||
sb.append("Active NameNode=").append(activeAddress).append(", isAtLeastOneActive=") | ||
.append(atLeastOneActive).append('\n'); | ||
} | ||
DatanodeInfo[] dns = dfs.getClient().datanodeReport(HdfsConstants.DatanodeReportType.LIVE); | ||
sb.append("Number of live DataNodes: ").append(dns.length); | ||
for (DatanodeInfo dni : dns) { | ||
sb.append(PREFIX).append("name=").append(dni.getName()).append(", used%=") | ||
.append(dni.getDfsUsedPercent()).append(", capacity=") | ||
.append(FileUtils.byteCountToDisplaySize(dni.getCapacity())); | ||
} | ||
sb.append('\n'); | ||
dns = dfs.getClient().datanodeReport(HdfsConstants.DatanodeReportType.DEAD); | ||
sb.append("Number of dead DataNodes: ").append(dns.length); | ||
for (DatanodeInfo dni : dns) { | ||
sb.append(PREFIX).append(dni.getName()).append("/").append(dni.getNetworkLocation()); | ||
} | ||
} | ||
// TODO: add more on NN, JNs, and ZK. | ||
// TODO: Print how long process has been up. | ||
getLogger().info(sb.toString()); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/actions/HdfsActionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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.hbase.chaos.actions; | ||
|
||
import java.io.IOException; | ||
import java.io.InterruptedIOException; | ||
import java.security.PrivilegedExceptionAction; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.hbase.util.CommonFSUtils; | ||
import org.apache.hadoop.hdfs.DistributedFileSystem; | ||
import org.apache.hadoop.security.UserGroupInformation; | ||
|
||
/** | ||
* Configuration common across the HDFS Actions. | ||
*/ | ||
public final class HdfsActionUtils { | ||
|
||
private HdfsActionUtils() { | ||
} | ||
|
||
/** | ||
* Specify a user as whom HDFS actions should be run. The chaos process must have permissions | ||
* sufficient to assume the role of the specified user. | ||
* @see <a href= | ||
* "https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/Superusers.html">Proxy | ||
* user - Superusers Acting On Behalf Of Other Users</a> | ||
*/ | ||
public static final String HDFS_USER_CONF_KEY = "org.apache.hadoop.hbase.chaos.actions.hdfs_user"; | ||
|
||
private static DistributedFileSystem createUnproxiedDfs(final Configuration conf) | ||
throws IOException { | ||
final Path rootDir = CommonFSUtils.getRootDir(conf); | ||
final FileSystem fs = rootDir.getFileSystem(conf); | ||
return (DistributedFileSystem) fs; | ||
} | ||
|
||
/** | ||
* Create an instance of {@link DistributedFileSystem} that honors {@value HDFS_USER_CONF_KEY}. | ||
*/ | ||
static DistributedFileSystem createDfs(final Configuration conf) throws IOException { | ||
final String proxyUser = conf.get(HDFS_USER_CONF_KEY); | ||
if (proxyUser == null) { | ||
return createUnproxiedDfs(conf); | ||
} | ||
final UserGroupInformation proxyUgi = | ||
UserGroupInformation.createProxyUser(proxyUser, UserGroupInformation.getLoginUser()); | ||
try { | ||
return proxyUgi | ||
.doAs((PrivilegedExceptionAction<DistributedFileSystem>) () -> createUnproxiedDfs(conf)); | ||
} catch (InterruptedException e) { | ||
final InterruptedIOException iioe = new InterruptedIOException(e.getMessage()); | ||
iioe.setStackTrace(e.getStackTrace()); | ||
throw iioe; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters