Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
CLI options and commands renaming (#618)
Browse files Browse the repository at this point in the history
fixes Jira issues NC-2014, NC-2016, NC-2031, NC-2032, NC-2126 and NC-2127
  • Loading branch information
NicolasMassart authored Jan 22, 2019
1 parent cf9e307 commit 2a9fb15
Show file tree
Hide file tree
Showing 17 changed files with 1,007 additions and 560 deletions.
301 changes: 215 additions & 86 deletions docs/Reference/Pantheon-CLI-Syntax.md

Large diffs are not rendered by default.

140 changes: 140 additions & 0 deletions pantheon/src/main/java/tech/pegasys/pantheon/cli/BlocksSubCommand.java
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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
*/
package tech.pegasys.pantheon.cli;

import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode;
import tech.pegasys.pantheon.util.bytes.BytesValue;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;
Expand All @@ -23,13 +27,30 @@
import picocli.CommandLine;

interface DefaultCommandValues {
String CONFIG_FILE_OPTION_NAME = "--config";
String CONFIG_FILE_OPTION_NAME = "--config-file";

String MANDATORY_PATH_FORMAT_HELP = "<PATH>";
String MANDATORY_FILE_FORMAT_HELP = "<FILE>";
String PANTHEON_HOME_PROPERTY_NAME = "pantheon.home";
String DEFAULT_DATA_DIR_PATH = "./build/data";
String MANDATORY_INTEGER_FORMAT_HELP = "<INTEGER>";
String MANDATORY_MODE_FORMAT_HELP = "<MODE>";
String MANDATORY_NETWORK_FORMAT_HELP = "<CHAIN>";
String MANDATORY_NODE_ID_FORMAT_HELP = "<NODEID>";
Wei DEFAULT_MIN_TRANSACTION_GAS_PRICE = Wei.of(1000);
BytesValue DEFAULT_EXTRA_DATA = BytesValue.EMPTY;
long DEFAULT_MAX_REFRESH_DELAY = 3600000;
long DEFAULT_MIN_REFRESH_DELAY = 1;
String DOCKER_GENESIS_LOCATION = "/etc/pantheon/genesis.json";
String DOCKER_DATADIR_LOCATION = "/var/lib/pantheon";
String MANDATORY_HOST_FORMAT_HELP = "<HOST>";
String MANDATORY_PORT_FORMAT_HELP = "<PORT>";
// Default should be FAST for the next release
// but we use FULL for the moment as Fast is still in progress
SyncMode DEFAULT_SYNC_MODE = SyncMode.FULL;
int DEFAULT_MAX_PEERS = 25;

static Path getDefaultPantheonDataDir(final Object command) {
static Path getDefaultPantheonDataPath(final Object command) {
// this property is retrieved from Gradle tasks or Pantheon running shell script.
final String pantheonHomeProperty = System.getProperty(PANTHEON_HOME_PROPERTY_NAME);
final Path pantheonHome;
Expand Down

This file was deleted.

This file was deleted.

21 changes: 21 additions & 0 deletions pantheon/src/main/java/tech/pegasys/pantheon/cli/NetworkName.java
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
}
Loading

0 comments on commit 2a9fb15

Please sign in to comment.