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 @@ -22,13 +22,7 @@
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.tracing.TracingUtil;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.util.NativeCodeLoader;

import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import picocli.CommandLine;

/**
Expand Down Expand Up @@ -75,12 +69,6 @@ public UserGroupInformation getUser() throws IOException {
* @param argv - System Args Strings[]
*/
public static void main(String[] argv) {
LogManager.resetConfiguration();
Logger.getRootLogger().setLevel(Level.INFO);
Logger.getRootLogger()
.addAppender(new ConsoleAppender(new PatternLayout("%m%n")));
Logger.getLogger(NativeCodeLoader.class).setLevel(Level.ERROR);

new OzoneAdmin().run(argv);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.scm.client.ScmClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;

import java.io.IOException;
Expand All @@ -35,12 +33,9 @@
versionProvider = HddsVersionProvider.class)
public class ReplicationManagerStartSubcommand extends ScmSubcommand {

private static final Logger LOG =
LoggerFactory.getLogger(ReplicationManagerStartSubcommand.class);

@Override
public void execute(ScmClient scmClient) throws IOException {
scmClient.startReplicationManager();
LOG.info("Starting ReplicationManager...");
System.out.println("Starting ReplicationManager...");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.scm.client.ScmClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;

import java.io.IOException;
Expand All @@ -35,18 +33,15 @@
versionProvider = HddsVersionProvider.class)
public class ReplicationManagerStatusSubcommand extends ScmSubcommand {

private static final Logger LOG =
LoggerFactory.getLogger(ReplicationManagerStatusSubcommand.class);

@Override
public void execute(ScmClient scmClient) throws IOException {
boolean execReturn = scmClient.getReplicationManagerStatus();

// Output data list
if (execReturn) {
LOG.info("ReplicationManager is Running.");
System.out.println("ReplicationManager is Running.");
} else {
LOG.info("ReplicationManager is Not Running.");
System.out.println("ReplicationManager is Not Running.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.scm.client.ScmClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;

import java.io.IOException;
Expand All @@ -35,14 +33,11 @@
versionProvider = HddsVersionProvider.class)
public class ReplicationManagerStopSubcommand extends ScmSubcommand {

private static final Logger LOG =
LoggerFactory.getLogger(ReplicationManagerStopSubcommand.class);

@Override
public void execute(ScmClient scmClient) throws IOException {
scmClient.stopReplicationManager();
LOG.info("Stopping ReplicationManager...");
LOG.info("Requested SCM to stop ReplicationManager, " +
System.out.println("Stopping ReplicationManager...");
System.out.println("Requested SCM to stop ReplicationManager, " +
"it might take sometime for the ReplicationManager to stop.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.scm.client.ScmClient;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;
import picocli.CommandLine.Command;

Expand All @@ -39,9 +37,6 @@
versionProvider = HddsVersionProvider.class)
public class SafeModeCheckSubcommand extends ScmSubcommand {

private static final Logger LOG =
LoggerFactory.getLogger(SafeModeCheckSubcommand.class);

@CommandLine.Option(names = {"--verbose"},
description = "Show detailed status of rules.")
private boolean verbose;
Expand All @@ -52,17 +47,17 @@ public void execute(ScmClient scmClient) throws IOException {

// Output data list
if (execReturn) {
LOG.info("SCM is in safe mode.");
System.out.println("SCM is in safe mode.");
if (verbose) {
for (Map.Entry<String, Pair<Boolean, String>> entry :
scmClient.getSafeModeRuleStatuses().entrySet()) {
Pair<Boolean, String> value = entry.getValue();
LOG.info("validated:{}, {}, {}",
System.out.printf("validated:%s, %s, %s%n",
value.getLeft(), entry.getKey(), value.getRight());
}
}
} else {
LOG.info("SCM is out of safe mode.");
System.out.println("SCM is out of safe mode.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.scm.client.ScmClient;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;

/**
Expand All @@ -36,14 +34,11 @@
versionProvider = HddsVersionProvider.class)
public class SafeModeExitSubcommand extends ScmSubcommand {

private static final Logger LOG =
LoggerFactory.getLogger(SafeModeExitSubcommand.class);

@Override
public void execute(ScmClient scmClient) throws IOException {
boolean execReturn = scmClient.forceExitSafeMode();
if (execReturn) {
LOG.info("SCM exit safe mode successfully.");
System.out.println("SCM exit safe mode successfully.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.scm.client.ScmClient;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Mixin;
Expand All @@ -39,9 +37,6 @@
versionProvider = HddsVersionProvider.class)
public class SafeModeWaitSubcommand implements Callable<Void> {

private static final Logger LOG =
LoggerFactory.getLogger(SafeModeWaitSubcommand.class);

@Option(description =
"Define timeout (in second) to wait until (exit code 1) "
+ "or until safemode is ended (exit code 0).", defaultValue = "30",
Expand All @@ -62,26 +57,26 @@ public Void call() throws Exception {
long remainingTime;
do {
if (!scmClient.inSafeMode()) {
LOG.info("SCM is out of safe mode.");
System.out.println("SCM is out of safe mode.");
return null;
}

remainingTime = getRemainingTimeInSec();

if (remainingTime > 0) {
LOG.info(
System.out.printf(
"SCM is in safe mode. Will retry in 1 sec. Remaining time "
+ "(sec): {}",
+ "(sec): %s%n",
remainingTime);
Thread.sleep(1000);
} else {
LOG.info("SCM is in safe mode. No more retries.");
System.out.println("SCM is in safe mode. No more retries.");
}
} while (remainingTime > 0);
} catch (InterruptedException ex) {
LOG.info(
"SCM is not available (yet?). Error is {}. Will retry in 1 sec. "
+ "Remaining time (sec): {}",
System.out.printf(
"SCM is not available (yet?). Error is %s. Will retry in 1 sec. "
+ "Remaining time (sec): %s%n",
ex.getMessage(), getRemainingTimeInSec());
Thread.sleep(1000);
Thread.currentThread().interrupt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.protocol.SCMSecurityProtocol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;

import java.io.IOException;
Expand All @@ -36,13 +34,10 @@
versionProvider = HddsVersionProvider.class)
public class CleanExpiredCertsSubcommand extends ScmCertSubcommand {

private static final Logger LOG =
LoggerFactory.getLogger(CleanExpiredCertsSubcommand.class);

@Override
protected void execute(SCMSecurityProtocol client) throws IOException {
List<String> pemEncodedCerts = client.removeExpiredCertificates();
LOG.info("List of removed expired certificates:");
printCertList(LOG, pemEncodedCerts);
System.out.println("List of removed expired certificates:");
printCertList(pemEncodedCerts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@
import org.apache.hadoop.hdds.protocol.SCMSecurityProtocol;

import org.apache.hadoop.hdds.security.x509.certificate.utils.CertificateCodec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Parameters;
import picocli.CommandLine.Spec;

/**
* This is the handler that process certificate info command.
Expand All @@ -44,12 +40,6 @@

class InfoSubcommand extends ScmCertSubcommand {

private static final Logger LOG =
LoggerFactory.getLogger(InfoSubcommand.class);

@Spec
private CommandSpec spec;

@Parameters(description = "Serial id of the certificate in decimal.")
private String serialId;

Expand All @@ -61,12 +51,12 @@ public void execute(SCMSecurityProtocol client) throws IOException {
"Certificate can't be found");

// Print container report info.
LOG.info("Certificate id: {}", serialId);
System.out.printf("Certificate id: %s%n", serialId);
try {
X509Certificate cert = CertificateCodec.getX509Certificate(certPemStr);
LOG.info(cert.toString());
System.out.println(cert);
} catch (CertificateException ex) {
LOG.error("Failed to get certificate id " + serialId);
System.err.println("Failed to get certificate id " + serialId);
throw new IOException("Fail to get certificate id " + serialId, ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.security.x509.certificate.utils.CertificateCodec;
import org.apache.hadoop.hdds.server.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;
import picocli.CommandLine.Help.Visibility;
import picocli.CommandLine.Option;
Expand All @@ -54,9 +52,6 @@
versionProvider = HddsVersionProvider.class)
public class ListSubcommand extends ScmCertSubcommand {

private static final Logger LOG =
LoggerFactory.getLogger(ListSubcommand.class);

@Option(names = {"-s", "--start"},
description = "Certificate serial id to start the iteration",
defaultValue = "0", showDefaultValue = Visibility.ALWAYS)
Expand Down Expand Up @@ -114,17 +109,17 @@ protected void execute(SCMSecurityProtocol client) throws IOException {
CertificateCodec.getX509Certificate(certPemStr);
certList.add(new Certificate(cert));
} catch (CertificateException ex) {
LOG.error("Failed to parse certificate.");
err.println("Failed to parse certificate.");
}
}
System.out.println(
JsonUtils.toJsonStringWithDefaultPrettyPrinter(certList));
return;
}

LOG.info("Certificate list:(Type={}, BatchSize={}, CertCount={})",
System.out.printf("Certificate list:(Type=%s, BatchSize=%s, CertCount=%s)%n",
type.toUpperCase(), count, certPemList.size());
printCertList(LOG, certPemList);
printCertList(certPemList);
}

private static class BigIntJsonSerializer extends JsonSerializer<BigInteger> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.hadoop.hdds.protocol.SCMSecurityProtocol;
import org.apache.hadoop.hdds.scm.cli.ScmOption;
import org.apache.hadoop.hdds.security.x509.certificate.utils.CertificateCodec;
import org.slf4j.Logger;
import picocli.CommandLine;

import java.io.IOException;
Expand All @@ -37,29 +36,29 @@ public abstract class ScmCertSubcommand implements Callable<Void> {
@CommandLine.Mixin
private ScmOption scmOption;

private static final String OUTPUT_FORMAT = "%-17s %-30s %-30s %-110s %-110s";
private static final String OUTPUT_FORMAT = "%-17s %-30s %-30s %-110s %-110s%n";

protected void printCertList(Logger log, List<String> pemEncodedCerts) {
protected void printCertList(List<String> pemEncodedCerts) {
if (pemEncodedCerts.isEmpty()) {
log.info("No certificates to list");
System.out.println("No certificates to list");
return;
}
log.info(String.format(OUTPUT_FORMAT, "SerialNumber", "Valid From",
"Expiry", "Subject", "Issuer"));
System.out.printf(OUTPUT_FORMAT, "SerialNumber", "Valid From",
"Expiry", "Subject", "Issuer");
for (String certPemStr : pemEncodedCerts) {
try {
X509Certificate cert = CertificateCodec.getX509Certificate(certPemStr);
printCert(cert, log);
printCert(cert);
} catch (CertificateException e) {
log.error("Failed to parse certificate.", e);
System.err.println("Failed to parse certificate: " + e.getMessage());
}
}
}

protected void printCert(X509Certificate cert, Logger log) {
log.info(String.format(OUTPUT_FORMAT, cert.getSerialNumber(),
protected void printCert(X509Certificate cert) {
System.out.printf(OUTPUT_FORMAT, cert.getSerialNumber(),
cert.getNotBefore(), cert.getNotAfter(), cert.getSubjectDN(),
cert.getIssuerDN()));
cert.getIssuerDN());
}

protected abstract void execute(SCMSecurityProtocol client)
Expand Down
Loading