Skip to content

Commit

Permalink
HDDS-12003. Reduce code duplication related to tracing init (#7658)
Browse files Browse the repository at this point in the history
  • Loading branch information
adoroszlai authored Jan 9, 2025
1 parent 400e94d commit e21e724
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

import org.apache.hadoop.hdds.cli.AdminSubcommand;
import org.apache.hadoop.hdds.cli.ExtensibleParentCommand;
import org.apache.hadoop.hdds.cli.GenericCli;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.tracing.TracingUtil;
import org.apache.hadoop.ozone.shell.Shell;

import picocli.CommandLine;

Expand All @@ -33,20 +32,12 @@
description = "Developer tools for Ozone Admin operations",
versionProvider = HddsVersionProvider.class,
mixinStandardHelpOptions = true)
public class OzoneAdmin extends GenericCli implements ExtensibleParentCommand {
public class OzoneAdmin extends Shell implements ExtensibleParentCommand {

public static void main(String[] argv) {
new OzoneAdmin().run(argv);
}

@Override
public int execute(String[] argv) {
TracingUtil.initTracing("shell", getOzoneConf());
String spanName = "ozone admin " + String.join(" ", argv);
return TracingUtil.executeInNewSpan(spanName,
() -> super.execute(argv));
}

@Override
public Class<? extends AdminSubcommand> subcommandType() {
return AdminSubcommand.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@

import org.apache.hadoop.hdds.cli.DebugSubcommand;
import org.apache.hadoop.hdds.cli.ExtensibleParentCommand;
import org.apache.hadoop.hdds.cli.GenericCli;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;

import org.apache.hadoop.ozone.shell.Shell;
import picocli.CommandLine;

/**
Expand All @@ -32,7 +31,7 @@
description = "Developer tools for Ozone Debug operations",
versionProvider = HddsVersionProvider.class,
mixinStandardHelpOptions = true)
public class OzoneDebug extends GenericCli implements ExtensibleParentCommand {
public class OzoneDebug extends Shell implements ExtensibleParentCommand {

public static void main(String[] argv) {
new OzoneDebug().run(argv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.hadoop.ozone.shell;

import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.tracing.TracingUtil;
import org.apache.hadoop.ozone.shell.bucket.BucketCommands;
import org.apache.hadoop.ozone.shell.keys.KeyCommands;
import org.apache.hadoop.ozone.shell.prefix.PrefixCommands;
Expand Down Expand Up @@ -47,21 +46,7 @@
mixinStandardHelpOptions = true)
public class OzoneShell extends Shell {

/**
* Main for the ozShell Command handling.
*
* @param argv - System Args Strings[]
*/
public static void main(String[] argv) throws Exception {
new OzoneShell().run(argv);
}

@Override
public int execute(String[] argv) {
TracingUtil.initTracing("shell", getOzoneConf());
String spanName = "ozone sh " + String.join(" ", argv);
return TracingUtil.executeInNewSpan(spanName,
() -> super.execute(argv));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
package org.apache.hadoop.ozone.shell;

import org.apache.hadoop.hdds.cli.GenericCli;
import org.apache.hadoop.hdds.tracing.TracingUtil;
import org.apache.hadoop.ozone.om.exceptions.OMException;

import picocli.CommandLine;
import picocli.shell.jline3.PicocliCommands.PicocliCommandsFactory;

Expand Down Expand Up @@ -85,7 +87,9 @@ public void run(String[] argv) {
spec.name(""); // use short name (e.g. "token get" instead of "ozone sh token get")
new REPL(this, getCmd(), (PicocliCommandsFactory) getCmd().getFactory());
} else {
super.run(argv);
TracingUtil.initTracing("shell", getOzoneConf());
String spanName = spec.name() + " " + String.join(" ", argv);
TracingUtil.executeInNewSpan(spanName, () -> super.run(argv));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.apache.hadoop.ozone.shell.s3;

import org.apache.hadoop.hdds.tracing.TracingUtil;
import org.apache.hadoop.ozone.shell.Shell;

import picocli.CommandLine.Command;
Expand All @@ -34,19 +33,6 @@
})
public class S3Shell extends Shell {

@Override
public int execute(String[] argv) {
TracingUtil.initTracing("s3shell", getOzoneConf());
String spanName = "ozone s3 " + String.join(" ", argv);
return TracingUtil.executeInNewSpan(spanName,
() -> super.execute(argv));
}

/**
* Main for the S3Shell Command handling.
*
* @param argv - System Args Strings[]
*/
public static void main(String[] argv) {
new S3Shell().run(argv);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package org.apache.hadoop.ozone.shell.tenant;

import org.apache.hadoop.hdds.tracing.TracingUtil;
import org.apache.hadoop.ozone.shell.Shell;

import picocli.CommandLine.Command;

/**
Expand All @@ -35,19 +35,6 @@
})
public class TenantShell extends Shell {

@Override
public int execute(String[] argv) {
TracingUtil.initTracing("tenant-shell", getOzoneConf());
String spanName = "ozone tenant " + String.join(" ", argv);
return TracingUtil.executeInNewSpan(spanName,
() -> super.execute(argv));
}

/**
* Main for the TenantShell Command handling.
*
* @param argv - System Args Strings[]
*/
public static void main(String[] argv) {
new TenantShell().run(argv);
}
Expand Down

0 comments on commit e21e724

Please sign in to comment.