feat(java-cli): inject GalaxyClientFactory seam (behavior-preserving default)
This commit is contained in:
+67
-6
@@ -131,6 +131,11 @@ public final class MxGatewayCli implements Callable<Integer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CommandLine commandLine(MxGatewayCliClientFactory clientFactory) {
|
static CommandLine commandLine(MxGatewayCliClientFactory clientFactory) {
|
||||||
|
return commandLine(clientFactory, new GrpcGalaxyClientFactory());
|
||||||
|
}
|
||||||
|
|
||||||
|
static CommandLine commandLine(
|
||||||
|
MxGatewayCliClientFactory clientFactory, GalaxyClientFactory galaxyClientFactory) {
|
||||||
CommandLine commandLine = new CommandLine(new MxGatewayCli(clientFactory));
|
CommandLine commandLine = new CommandLine(new MxGatewayCli(clientFactory));
|
||||||
commandLine.addSubcommand("version", new VersionCommand());
|
commandLine.addSubcommand("version", new VersionCommand());
|
||||||
commandLine.addSubcommand("open-session", new OpenSessionCommand(clientFactory));
|
commandLine.addSubcommand("open-session", new OpenSessionCommand(clientFactory));
|
||||||
@@ -152,11 +157,11 @@ public final class MxGatewayCli implements Callable<Integer> {
|
|||||||
commandLine.addSubcommand("stream-alarms", new StreamAlarmsCommand(clientFactory));
|
commandLine.addSubcommand("stream-alarms", new StreamAlarmsCommand(clientFactory));
|
||||||
commandLine.addSubcommand("acknowledge-alarm", new AcknowledgeAlarmCommand(clientFactory));
|
commandLine.addSubcommand("acknowledge-alarm", new AcknowledgeAlarmCommand(clientFactory));
|
||||||
commandLine.addSubcommand("smoke", new SmokeCommand(clientFactory));
|
commandLine.addSubcommand("smoke", new SmokeCommand(clientFactory));
|
||||||
commandLine.addSubcommand("galaxy-test-connection", new GalaxyTestConnectionCommand());
|
commandLine.addSubcommand("galaxy-test-connection", new GalaxyTestConnectionCommand(galaxyClientFactory));
|
||||||
commandLine.addSubcommand("galaxy-last-deploy", new GalaxyDeployTimeCommand());
|
commandLine.addSubcommand("galaxy-last-deploy", new GalaxyDeployTimeCommand(galaxyClientFactory));
|
||||||
commandLine.addSubcommand("galaxy-discover", new GalaxyDiscoverCommand());
|
commandLine.addSubcommand("galaxy-discover", new GalaxyDiscoverCommand(galaxyClientFactory));
|
||||||
commandLine.addSubcommand("galaxy-browse", new GalaxyBrowseCommand());
|
commandLine.addSubcommand("galaxy-browse", new GalaxyBrowseCommand(galaxyClientFactory));
|
||||||
commandLine.addSubcommand("galaxy-watch", new GalaxyWatchCommand());
|
commandLine.addSubcommand("galaxy-watch", new GalaxyWatchCommand(galaxyClientFactory));
|
||||||
commandLine.addSubcommand("batch", new BatchCommand(clientFactory));
|
commandLine.addSubcommand("batch", new BatchCommand(clientFactory));
|
||||||
return commandLine;
|
return commandLine;
|
||||||
}
|
}
|
||||||
@@ -359,14 +364,24 @@ public final class MxGatewayCli implements Callable<Integer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract static class GalaxyCommand implements Callable<Integer> {
|
abstract static class GalaxyCommand implements Callable<Integer> {
|
||||||
|
final GalaxyClientFactory galaxyClientFactory;
|
||||||
|
|
||||||
@Mixin
|
@Mixin
|
||||||
CommonOptions common = new CommonOptions();
|
CommonOptions common = new CommonOptions();
|
||||||
|
|
||||||
@Option(names = "--json", description = "Write JSON output.")
|
@Option(names = "--json", description = "Write JSON output.")
|
||||||
boolean json;
|
boolean json;
|
||||||
|
|
||||||
|
GalaxyCommand() {
|
||||||
|
this(new GrpcGalaxyClientFactory());
|
||||||
|
}
|
||||||
|
|
||||||
|
GalaxyCommand(GalaxyClientFactory galaxyClientFactory) {
|
||||||
|
this.galaxyClientFactory = galaxyClientFactory;
|
||||||
|
}
|
||||||
|
|
||||||
GalaxyRepositoryClient connect() {
|
GalaxyRepositoryClient connect() {
|
||||||
return GalaxyRepositoryClient.connect(common.resolved().toClientOptions());
|
return galaxyClientFactory.connect(common.resolved().toClientOptions());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,6 +390,13 @@ public final class MxGatewayCli implements Callable<Integer> {
|
|||||||
aliases = {"galaxy-test"},
|
aliases = {"galaxy-test"},
|
||||||
description = "Calls GalaxyRepository.TestConnection.")
|
description = "Calls GalaxyRepository.TestConnection.")
|
||||||
static final class GalaxyTestConnectionCommand extends GalaxyCommand {
|
static final class GalaxyTestConnectionCommand extends GalaxyCommand {
|
||||||
|
GalaxyTestConnectionCommand() {
|
||||||
|
}
|
||||||
|
|
||||||
|
GalaxyTestConnectionCommand(GalaxyClientFactory galaxyClientFactory) {
|
||||||
|
super(galaxyClientFactory);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer call() {
|
public Integer call() {
|
||||||
try (GalaxyRepositoryClient client = connect()) {
|
try (GalaxyRepositoryClient client = connect()) {
|
||||||
@@ -399,6 +421,13 @@ public final class MxGatewayCli implements Callable<Integer> {
|
|||||||
aliases = {"galaxy-deploy-time"},
|
aliases = {"galaxy-deploy-time"},
|
||||||
description = "Calls GalaxyRepository.GetLastDeployTime.")
|
description = "Calls GalaxyRepository.GetLastDeployTime.")
|
||||||
static final class GalaxyDeployTimeCommand extends GalaxyCommand {
|
static final class GalaxyDeployTimeCommand extends GalaxyCommand {
|
||||||
|
GalaxyDeployTimeCommand() {
|
||||||
|
}
|
||||||
|
|
||||||
|
GalaxyDeployTimeCommand(GalaxyClientFactory galaxyClientFactory) {
|
||||||
|
super(galaxyClientFactory);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer call() {
|
public Integer call() {
|
||||||
try (GalaxyRepositoryClient client = connect()) {
|
try (GalaxyRepositoryClient client = connect()) {
|
||||||
@@ -423,6 +452,13 @@ public final class MxGatewayCli implements Callable<Integer> {
|
|||||||
|
|
||||||
@Command(name = "galaxy-discover", description = "Calls GalaxyRepository.DiscoverHierarchy.")
|
@Command(name = "galaxy-discover", description = "Calls GalaxyRepository.DiscoverHierarchy.")
|
||||||
static final class GalaxyDiscoverCommand extends GalaxyCommand {
|
static final class GalaxyDiscoverCommand extends GalaxyCommand {
|
||||||
|
GalaxyDiscoverCommand() {
|
||||||
|
}
|
||||||
|
|
||||||
|
GalaxyDiscoverCommand(GalaxyClientFactory galaxyClientFactory) {
|
||||||
|
super(galaxyClientFactory);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer call() {
|
public Integer call() {
|
||||||
try (GalaxyRepositoryClient client = connect()) {
|
try (GalaxyRepositoryClient client = connect()) {
|
||||||
@@ -458,6 +494,13 @@ public final class MxGatewayCli implements Callable<Integer> {
|
|||||||
name = "galaxy-browse",
|
name = "galaxy-browse",
|
||||||
description = "Browses the Galaxy hierarchy via GalaxyRepository.BrowseChildren.")
|
description = "Browses the Galaxy hierarchy via GalaxyRepository.BrowseChildren.")
|
||||||
static final class GalaxyBrowseCommand extends GalaxyCommand {
|
static final class GalaxyBrowseCommand extends GalaxyCommand {
|
||||||
|
GalaxyBrowseCommand() {
|
||||||
|
}
|
||||||
|
|
||||||
|
GalaxyBrowseCommand(GalaxyClientFactory galaxyClientFactory) {
|
||||||
|
super(galaxyClientFactory);
|
||||||
|
}
|
||||||
|
|
||||||
@Spec
|
@Spec
|
||||||
private CommandSpec spec;
|
private CommandSpec spec;
|
||||||
|
|
||||||
@@ -718,6 +761,13 @@ public final class MxGatewayCli implements Callable<Integer> {
|
|||||||
name = "galaxy-watch",
|
name = "galaxy-watch",
|
||||||
description = "Streams GalaxyRepository.WatchDeployEvents until cancelled.")
|
description = "Streams GalaxyRepository.WatchDeployEvents until cancelled.")
|
||||||
static final class GalaxyWatchCommand extends GalaxyCommand {
|
static final class GalaxyWatchCommand extends GalaxyCommand {
|
||||||
|
GalaxyWatchCommand() {
|
||||||
|
}
|
||||||
|
|
||||||
|
GalaxyWatchCommand(GalaxyClientFactory galaxyClientFactory) {
|
||||||
|
super(galaxyClientFactory);
|
||||||
|
}
|
||||||
|
|
||||||
@Option(
|
@Option(
|
||||||
names = "--last-seen-deploy-time",
|
names = "--last-seen-deploy-time",
|
||||||
description =
|
description =
|
||||||
@@ -1725,6 +1775,10 @@ public final class MxGatewayCli implements Callable<Integer> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface GalaxyClientFactory {
|
||||||
|
GalaxyRepositoryClient connect(MxGatewayClientOptions options);
|
||||||
|
}
|
||||||
|
|
||||||
interface MxGatewayCliClientFactory {
|
interface MxGatewayCliClientFactory {
|
||||||
MxGatewayCliClient connect(CommonOptions options);
|
MxGatewayCliClient connect(CommonOptions options);
|
||||||
}
|
}
|
||||||
@@ -1781,6 +1835,13 @@ public final class MxGatewayCli implements Callable<Integer> {
|
|||||||
MxEventStream streamEventsAfter(long afterWorkerSequence);
|
MxEventStream streamEventsAfter(long afterWorkerSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static final class GrpcGalaxyClientFactory implements GalaxyClientFactory {
|
||||||
|
@Override
|
||||||
|
public GalaxyRepositoryClient connect(MxGatewayClientOptions options) {
|
||||||
|
return GalaxyRepositoryClient.connect(options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static final class GrpcMxGatewayCliClientFactory implements MxGatewayCliClientFactory {
|
static final class GrpcMxGatewayCliClientFactory implements MxGatewayCliClientFactory {
|
||||||
@Override
|
@Override
|
||||||
public MxGatewayCliClient connect(CommonOptions options) {
|
public MxGatewayCliClient connect(CommonOptions options) {
|
||||||
|
|||||||
Reference in New Issue
Block a user