-
Notifications
You must be signed in to change notification settings - Fork 3
Refactor client CLIs #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jnmt
wants to merge
2
commits into
master
Choose a base branch
from
refactor-cli
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactor client CLIs #324
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
44 changes: 44 additions & 0 deletions
44
client/src/main/java/com/scalar/dl/client/tool/AbstractClientCommand.java
This file contains hidden or 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,44 @@ | ||
| package com.scalar.dl.client.tool; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.scalar.dl.client.config.ClientConfig; | ||
| import com.scalar.dl.client.config.GatewayClientConfig; | ||
| import com.scalar.dl.client.exception.ClientException; | ||
| import com.scalar.dl.client.service.ClientService; | ||
| import com.scalar.dl.client.service.ClientServiceFactory; | ||
| import java.io.File; | ||
| import java.util.concurrent.Callable; | ||
|
|
||
| public abstract class AbstractClientCommand extends CommonOptions implements Callable<Integer> { | ||
|
|
||
| @Override | ||
| public Integer call() throws Exception { | ||
| return call(new ClientServiceFactory()); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public final Integer call(ClientServiceFactory factory) throws Exception { | ||
| try { | ||
| ClientService service = | ||
| useGateway | ||
| ? factory.create(new GatewayClientConfig(new File(properties))) | ||
| : factory.create(new ClientConfig(new File(properties))); | ||
| return execute(service); | ||
| } catch (ClientException e) { | ||
| Common.printError(e); | ||
| printStackTrace(e); | ||
| return 1; | ||
| } finally { | ||
| factory.close(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Executes the specific command logic. | ||
| * | ||
| * @param service the client service to use for execution. | ||
| * @return the exit code. | ||
| * @throws ClientException if the execution fails. | ||
| */ | ||
| protected abstract Integer execute(ClientService service) throws ClientException; | ||
| } | ||
38 changes: 5 additions & 33 deletions
38
client/src/main/java/com/scalar/dl/client/tool/Bootstrap.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,46 +1,18 @@ | ||
| package com.scalar.dl.client.tool; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.scalar.dl.client.config.ClientConfig; | ||
| import com.scalar.dl.client.config.GatewayClientConfig; | ||
| import com.scalar.dl.client.exception.ClientException; | ||
| import com.scalar.dl.client.service.ClientService; | ||
| import com.scalar.dl.client.service.ClientServiceFactory; | ||
| import java.io.File; | ||
| import java.util.concurrent.Callable; | ||
| import picocli.CommandLine.Command; | ||
|
|
||
| @Command( | ||
| name = "bootstrap", | ||
| description = "Bootstrap the ledger by registering identity and system contracts.") | ||
| public class Bootstrap extends CommonOptions implements Callable<Integer> { | ||
| public class Bootstrap extends AbstractClientCommand { | ||
|
|
||
| @Override | ||
| public Integer call() throws Exception { | ||
| return call(new ClientServiceFactory()); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| Integer call(ClientServiceFactory factory) throws Exception { | ||
| ClientService service = | ||
| useGateway | ||
| ? factory.create(new GatewayClientConfig(new File(properties))) | ||
| : factory.create(new ClientConfig(new File(properties))); | ||
| return call(factory, service); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| Integer call(ClientServiceFactory factory, ClientService service) { | ||
| try { | ||
| service.bootstrap(); | ||
| Common.printOutput(null); | ||
| return 0; | ||
| } catch (ClientException e) { | ||
| Common.printError(e); | ||
| printStackTrace(e); | ||
| return 1; | ||
| } finally { | ||
| factory.close(); | ||
| } | ||
| protected Integer execute(ClientService service) throws ClientException { | ||
| service.bootstrap(); | ||
| Common.printOutput(null); | ||
| return 0; | ||
| } | ||
| } |
38 changes: 5 additions & 33 deletions
38
client/src/main/java/com/scalar/dl/client/tool/CertificateRegistration.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,50 +1,22 @@ | ||
| package com.scalar.dl.client.tool; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.scalar.dl.client.config.ClientConfig; | ||
| import com.scalar.dl.client.config.GatewayClientConfig; | ||
| import com.scalar.dl.client.exception.ClientException; | ||
| import com.scalar.dl.client.service.ClientService; | ||
| import com.scalar.dl.client.service.ClientServiceFactory; | ||
| import java.io.File; | ||
| import java.util.concurrent.Callable; | ||
| import picocli.CommandLine; | ||
| import picocli.CommandLine.Command; | ||
|
|
||
| @Command(name = "register-cert", description = "Register a specified certificate.") | ||
| public class CertificateRegistration extends CommonOptions implements Callable<Integer> { | ||
| public class CertificateRegistration extends AbstractClientCommand { | ||
|
|
||
| public static void main(String[] args) { | ||
| int exitCode = new CommandLine(new CertificateRegistration()).execute(args); | ||
| System.exit(exitCode); | ||
| } | ||
|
|
||
| @Override | ||
| public Integer call() throws Exception { | ||
| return call(new ClientServiceFactory()); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| Integer call(ClientServiceFactory factory) throws Exception { | ||
| ClientService service = | ||
| useGateway | ||
| ? factory.create(new GatewayClientConfig(new File(properties))) | ||
| : factory.create(new ClientConfig(new File(properties))); | ||
| return call(factory, service); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| Integer call(ClientServiceFactory factory, ClientService service) { | ||
| try { | ||
| service.registerCertificate(); | ||
| Common.printOutput(null); | ||
| return 0; | ||
| } catch (ClientException e) { | ||
| Common.printError(e); | ||
| printStackTrace(e); | ||
| return 1; | ||
| } finally { | ||
| factory.close(); | ||
| } | ||
| protected Integer execute(ClientService service) throws ClientException { | ||
| service.registerCertificate(); | ||
| Common.printOutput(null); | ||
| return 0; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.