This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI options and commands renaming (#618)
fixes Jira issues NC-2014, NC-2016, NC-2031, NC-2032, NC-2126 and NC-2127
- Loading branch information
1 parent
cf9e307
commit 2a9fb15
Showing
17 changed files
with
1,007 additions
and
560 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
140 changes: 140 additions & 0 deletions
140
pantheon/src/main/java/tech/pegasys/pantheon/cli/BlocksSubCommand.java
This file contains 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,140 @@ | ||
/* | ||
* Copyright 2018 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.cli; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
import static tech.pegasys.pantheon.cli.BlocksSubCommand.COMMAND_NAME; | ||
import static tech.pegasys.pantheon.cli.DefaultCommandValues.MANDATORY_FILE_FORMAT_HELP; | ||
|
||
import tech.pegasys.pantheon.cli.BlocksSubCommand.ImportSubCommand; | ||
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; | ||
import tech.pegasys.pantheon.metrics.prometheus.MetricsHttpService; | ||
import tech.pegasys.pantheon.util.BlockImporter; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
|
||
import io.vertx.core.Vertx; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.ExecutionException; | ||
import picocli.CommandLine.Model.CommandSpec; | ||
import picocli.CommandLine.Option; | ||
import picocli.CommandLine.ParentCommand; | ||
import picocli.CommandLine.Spec; | ||
|
||
/** Blocks related sub-command */ | ||
@Command( | ||
name = COMMAND_NAME, | ||
description = "This command provides blocks related actions.", | ||
mixinStandardHelpOptions = true, | ||
subcommands = {ImportSubCommand.class} | ||
) | ||
class BlocksSubCommand implements Runnable { | ||
private static final Logger LOG = LogManager.getLogger(); | ||
|
||
static final String COMMAND_NAME = "blocks"; | ||
|
||
@SuppressWarnings("unused") | ||
@ParentCommand | ||
private PantheonCommand parentCommand; // Picocli injects reference to parent command | ||
|
||
@SuppressWarnings("unused") | ||
@Spec | ||
private CommandSpec spec; // Picocli injects reference to command spec | ||
|
||
private final BlockImporter blockImporter; | ||
private final PrintStream out; | ||
|
||
BlocksSubCommand(final BlockImporter blockImporter, final PrintStream out) { | ||
this.blockImporter = blockImporter; | ||
this.out = out; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
spec.commandLine().usage(out); | ||
} | ||
|
||
/** | ||
* blocks import sub-command | ||
* | ||
* <p>Imports blocks from a file into the database | ||
*/ | ||
@Command( | ||
name = "import", | ||
description = "This command imports blocks from a file into the database.", | ||
mixinStandardHelpOptions = true | ||
) | ||
static class ImportSubCommand implements Runnable { | ||
@SuppressWarnings("unused") | ||
@ParentCommand | ||
private BlocksSubCommand parentCommand; // Picocli injects reference to parent command | ||
|
||
@Option( | ||
names = "--from", | ||
required = true, | ||
paramLabel = MANDATORY_FILE_FORMAT_HELP, | ||
description = "File containing blocks to import", | ||
arity = "1..1" | ||
) | ||
private final File blocksImportFile = null; | ||
|
||
@Override | ||
public void run() { | ||
LOG.info("Runs import sub command with blocksImportFile : {}", blocksImportFile); | ||
|
||
checkNotNull(parentCommand); | ||
checkNotNull(parentCommand.parentCommand); | ||
checkNotNull(parentCommand.blockImporter); | ||
|
||
Optional<MetricsHttpService> metricsHttpService = Optional.empty(); | ||
try { | ||
final MetricsConfiguration metricsConfiguration = | ||
parentCommand.parentCommand.metricsConfiguration(); | ||
if (metricsConfiguration.isEnabled()) { | ||
metricsHttpService = | ||
Optional.of( | ||
new MetricsHttpService( | ||
Vertx.vertx(), | ||
metricsConfiguration, | ||
parentCommand.parentCommand.getMetricsSystem())); | ||
metricsHttpService.ifPresent(MetricsHttpService::start); | ||
} | ||
|
||
// As blocksImportFile even if initialized as null is injected by PicoCLI and param is | ||
// mandatory | ||
// So we are sure it's always not null, we can remove the warning | ||
//noinspection ConstantConditions | ||
Path path = blocksImportFile.toPath(); | ||
|
||
parentCommand.blockImporter.importBlockchain( | ||
path, parentCommand.parentCommand.buildController()); | ||
} catch (final FileNotFoundException e) { | ||
throw new ExecutionException( | ||
new CommandLine(this), "Could not find file to import: " + blocksImportFile); | ||
} catch (final IOException e) { | ||
throw new ExecutionException( | ||
new CommandLine(this), "Unable to import blocks from " + blocksImportFile, e); | ||
} finally { | ||
metricsHttpService.ifPresent(MetricsHttpService::stop); | ||
} | ||
} | ||
} | ||
} |
This file contains 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
67 changes: 0 additions & 67 deletions
67
pantheon/src/main/java/tech/pegasys/pantheon/cli/ExportPublicKeySubCommand.java
This file was deleted.
Oops, something went wrong.
83 changes: 0 additions & 83 deletions
83
pantheon/src/main/java/tech/pegasys/pantheon/cli/ImportSubCommand.java
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
pantheon/src/main/java/tech/pegasys/pantheon/cli/NetworkName.java
This file contains 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,21 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.cli; | ||
|
||
public enum NetworkName { | ||
MAINNET, | ||
OTTOMAN, | ||
RINKEBY, | ||
ROPSTEN, | ||
GOERLI | ||
} |
Oops, something went wrong.