Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import java.util.Collections;
import java.util.concurrent.Callable;
import java.util.function.Supplier;
import org.apache.hadoop.crypto.OpensslCipher;
import org.apache.hadoop.hdds.cli.AbstractSubcommand;
import org.apache.hadoop.hdds.cli.DebugSubcommand;
import org.apache.hadoop.hdds.utils.NativeLibraryLoader;
Expand All @@ -37,27 +39,67 @@
@MetaInfServices(DebugSubcommand.class)
public class CheckNative extends AbstractSubcommand implements Callable<Void>, DebugSubcommand {

private static class LibraryCheckResult {
private final boolean loaded;
private final String detail;

LibraryCheckResult(boolean loaded, String detail) {
this.loaded = loaded;
this.detail = detail;
}

public boolean isLoaded() {
return loaded;
}

public String getDetail() {
return detail;
}
}

private LibraryCheckResult getLibraryStatus(
Supplier<String> failureReasonSupplier,
Supplier<String> libraryNameSupplier) {
String failureReason = failureReasonSupplier.get();
if (failureReason != null) {
return new LibraryCheckResult(false, failureReason);
} else {
return new LibraryCheckResult(true, libraryNameSupplier.get());
}
}

@Override
public Void call() throws Exception {
boolean nativeHadoopLoaded = org.apache.hadoop.util.NativeCodeLoader.isNativeCodeLoaded();
String hadoopLibraryName = "";
String isalDetail = "";
boolean isalLoaded = false;
String opensslDetail = "";
boolean opensslLoaded = false;

if (nativeHadoopLoaded) {
hadoopLibraryName = org.apache.hadoop.util.NativeCodeLoader.getLibraryName();

isalDetail = ErasureCodeNative.getLoadingFailureReason();
if (isalDetail != null) {
isalLoaded = false;
} else {
isalDetail = ErasureCodeNative.getLibraryName();
isalLoaded = true;
}
LibraryCheckResult isalStatus = getLibraryStatus(
ErasureCodeNative::getLoadingFailureReason,
ErasureCodeNative::getLibraryName
);
isalLoaded = isalStatus.isLoaded();
isalDetail = isalStatus.getDetail();

// Check OpenSSL status
LibraryCheckResult opensslStatus = getLibraryStatus(
OpensslCipher::getLoadingFailureReason,
OpensslCipher::getLibraryName
);
opensslLoaded = opensslStatus.isLoaded();
opensslDetail = opensslStatus.getDetail();
}
out().println("Native library checking:");
out().printf("hadoop: %b %s%n", nativeHadoopLoaded,
hadoopLibraryName);
out().printf("ISA-L: %b %s%n", isalLoaded, isalDetail);
out().printf("OpenSSL: %b %s%n", opensslLoaded, opensslDetail);

// Attempt to load the rocks-tools lib
boolean nativeRocksToolsLoaded = NativeLibraryLoader.getInstance().loadLibrary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ private void assertOutput(boolean expectedRocksNative) {
.contains("Native library checking:")
.contains("hadoop: false")
.contains("ISA-L: false")
.contains("OpenSSL: false")
.contains("rocks-tools: " + expectedRocksNative);
}

Expand Down
Loading