org.springframework.shell.core.annotation.CliOption Java Examples

The following examples show how to use org.springframework.shell.core.annotation.CliOption. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShellCommands.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@CliCommand(value = { CliStrings.ECHO }, help = CliStrings.ECHO__HELP)
@CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GFSH})
public Result echo(
    @CliOption(key = {CliStrings.ECHO__STR, ""},
               unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
               specifiedDefaultValue = "",
               mandatory = true,
               help = CliStrings.ECHO__STR__HELP) String stringToEcho) {
  Result result = null;

  if(stringToEcho.equals("$*")){
    Gfsh gfshInstance = getGfsh();
    Map<String, String> envMap = gfshInstance.getEnv();
    Set< Entry<String, String> > setEnvMap = envMap.entrySet();
    TabularResultData  resultData = buildResultForEcho(setEnvMap);

    result = ResultBuilder.buildResult(resultData);
  } else {
    result = ResultBuilder.createInfoResult(stringToEcho);
  }

  return result;
}
 
Example #2
Source File: TableCommand.java    From hudi with Apache License 2.0 6 votes vote down vote up
@CliCommand(value = "connect", help = "Connect to a hoodie table")
public String connect(
    @CliOption(key = {"path"}, mandatory = true, help = "Base Path of the table") final String path,
    @CliOption(key = {"layoutVersion"}, help = "Timeline Layout version") Integer layoutVersion,
    @CliOption(key = {"eventuallyConsistent"}, unspecifiedDefaultValue = "false",
        help = "Enable eventual consistency") final boolean eventuallyConsistent,
    @CliOption(key = {"initialCheckIntervalMs"}, unspecifiedDefaultValue = "2000",
        help = "Initial wait time for eventual consistency") final Integer initialConsistencyIntervalMs,
    @CliOption(key = {"maxWaitIntervalMs"}, unspecifiedDefaultValue = "300000",
        help = "Max wait time for eventual consistency") final Integer maxConsistencyIntervalMs,
    @CliOption(key = {"maxCheckIntervalMs"}, unspecifiedDefaultValue = "7",
        help = "Max checks for eventual consistency") final Integer maxConsistencyChecks)
    throws IOException {
  HoodieCLI
      .setConsistencyGuardConfig(ConsistencyGuardConfig.newBuilder().withConsistencyCheckEnabled(eventuallyConsistent)
          .withInitialConsistencyCheckIntervalMs(initialConsistencyIntervalMs)
          .withMaxConsistencyCheckIntervalMs(maxConsistencyIntervalMs).withMaxConsistencyChecks(maxConsistencyChecks)
          .build());
  HoodieCLI.initConf();
  HoodieCLI.connectTo(path, layoutVersion);
  HoodieCLI.initFS(true);
  HoodieCLI.state = HoodieCLI.CLIState.TABLE;
  return "Metadata for table " + HoodieCLI.getTableMetaClient().getTableConfig().getTableName() + " loaded";
}
 
Example #3
Source File: AppRegistryCommands.java    From spring-cloud-dashboard with Apache License 2.0 6 votes vote down vote up
@CliCommand(value = REGISTER_APPLICATION, help = "Register a new application")
public String register(
		@CliOption(mandatory = true,
				key = {"", "name"},
				help = "the name for the registered application")
		String name,
		@CliOption(mandatory = true,
				key = {"type"},
				help = "the type for the registered application")
				String type,
		@CliOption(mandatory = true,
				key = {"uri"},
				help = "URI for the application artifact")
		String uri,
		@CliOption(key = "force",
				help = "force update if application is already registered (only if not in use)",
				specifiedDefaultValue = "true",
				unspecifiedDefaultValue = "false")
		boolean force) {
	appRegistryOperations().register(name, type, uri, force);
	return String.format(("Successfully registered application '%s:%s'"), type, name);
}
 
Example #4
Source File: CommitsCommand.java    From hudi with Apache License 2.0 6 votes vote down vote up
@CliCommand(value = "commits show", help = "Show the commits")
public String showCommits(
    @CliOption(key = {"includeExtraMetadata"}, help = "Include extra metadata",
        unspecifiedDefaultValue = "false") final boolean includeExtraMetadata,
    @CliOption(key = {"createView"}, mandatory = false, help = "view name to store output table",
        unspecifiedDefaultValue = "") final String exportTableName,
    @CliOption(key = {"limit"}, help = "Limit commits",
        unspecifiedDefaultValue = "-1") final Integer limit,
    @CliOption(key = {"sortBy"}, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField,
    @CliOption(key = {"desc"}, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending,
    @CliOption(key = {"headeronly"}, help = "Print Header Only",
        unspecifiedDefaultValue = "false") final boolean headerOnly)
    throws IOException {

  HoodieActiveTimeline activeTimeline = HoodieCLI.getTableMetaClient().getActiveTimeline();
  if (includeExtraMetadata) {
    return printCommitsWithMetadata(activeTimeline, limit, sortByField, descending, headerOnly, exportTableName);
  } else  {
    return printCommits(activeTimeline, limit, sortByField, descending, headerOnly, exportTableName);
  }
}
 
Example #5
Source File: IndexCommands.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@CliCommand(value = CliStrings.LIST_INDEX, help = CliStrings.LIST_INDEX__HELP)
@CliMetaData(shellOnly = false, relatedTopic={CliStrings.TOPIC_GEMFIRE_REGION, CliStrings.TOPIC_GEMFIRE_DATA})
public Result listIndex(@CliOption(key = CliStrings.LIST_INDEX__STATS,
                                   mandatory = false,
                                   specifiedDefaultValue = "true",
                                   unspecifiedDefaultValue = "false",
                                   help = CliStrings.LIST_INDEX__STATS__HELP)
                          final boolean showStats) {
  try {
    return toTabularResult(getIndexListing(), showStats);
  }
  catch (FunctionInvocationTargetException ignore) {
    return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN,
      CliStrings.LIST_INDEX));
  }
  catch (VirtualMachineError e) {
    SystemFailure.initiateFailure(e);
    throw e;
  }
  catch (Throwable t) {
    SystemFailure.checkFailure();
    getCache().getLogger().error(t);
    return ResultBuilder.createGemFireErrorResult(String.format(CliStrings.LIST_INDEX__ERROR_MESSAGE,
      toString(t, isDebugging())));
  }
}
 
Example #6
Source File: CompactionCommand.java    From hudi with Apache License 2.0 6 votes vote down vote up
@CliCommand(value = "compactions show all", help = "Shows all compactions that are in active timeline")
public String compactionsAll(
    @CliOption(key = {"includeExtraMetadata"}, help = "Include extra metadata",
        unspecifiedDefaultValue = "false") final boolean includeExtraMetadata,
    @CliOption(key = {"limit"}, help = "Limit commits",
        unspecifiedDefaultValue = "-1") final Integer limit,
    @CliOption(key = {"sortBy"}, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField,
    @CliOption(key = {"desc"}, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending,
    @CliOption(key = {"headeronly"}, help = "Print Header Only",
        unspecifiedDefaultValue = "false") final boolean headerOnly)
    throws IOException {
  HoodieTableMetaClient client = checkAndGetMetaClient();
  HoodieActiveTimeline activeTimeline = client.getActiveTimeline();
  return printAllCompactions(activeTimeline,
          compactionPlanReader(this::readCompactionPlanForActiveTimeline, activeTimeline),
          includeExtraMetadata, sortByField, descending, limit, headerOnly);
}
 
Example #7
Source File: ContextCommands.java    From hdfs-shell with Apache License 2.0 6 votes vote down vote up
@CliCommand(value = "su", help = "Changes current active user [*experimental*]")
    public synchronized String su(@CliOption(key = {""}, help = "su [<username>]") String newUser) throws IOException {
        if (StringUtils.isEmpty(newUser)) {
            return "No username is defined! ";
        }
//        else {
//            newUser = BashUtils.parseArguments(newUser)[0];
//        }
        final FileSystem fs = getFileSystem();
        final Path usersDir = new Path("/user");
        if (fs.exists(usersDir)) {
            final String finalNewUser = newUser;
            final boolean foundUser = Arrays.stream(fs.listStatus(usersDir)).
                    filter(FileStatus::isDirectory).
                    anyMatch(fileStatus -> fileStatus.getPath().getName().equals(finalNewUser));
            if (!foundUser) {
                return "User " + newUser + " does not exist!";
            }
        }
        System.setProperty("HADOOP_USER_NAME", newUser);
        UserGroupInformation.loginUserFromSubject(null);
        currentDir = null;
        return "";
    }
 
Example #8
Source File: AppRegistryCommands.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = UNREGISTER_APPLICATION, help = "Unregister an application")
public String unregister(
		@CliOption(mandatory = true,
				key = {"", "name"},
				help = "name of the application to unregister")
				String name,
		@CliOption(mandatory = true,
				key = {"type"},
				help = "type of the application to unregister")
				String type) {

	appRegistryOperations().unregister(name, type);
	return String.format(("Successfully unregistered application '%s' with type %s"),
			name, type);
}
 
Example #9
Source File: SavepointsCommand.java    From hudi with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = "savepoint delete", help = "Delete the savepoint")
public String deleteSavepoint(@CliOption(key = {"commit"}, help = "Delete a savepoint") final String instantTime,
    @CliOption(key = {"sparkProperties"}, help = "Spark Properties File Path") final String sparkPropertiesPath,
    @CliOption(key = "sparkMaster", unspecifiedDefaultValue = "", help = "Spark Master") String master,
    @CliOption(key = "sparkMemory", unspecifiedDefaultValue = "4G",
        help = "Spark executor memory") final String sparkMemory)
    throws Exception {
  HoodieTableMetaClient metaClient = HoodieCLI.getTableMetaClient();
  HoodieTimeline completedInstants = metaClient.getActiveTimeline().getSavePointTimeline().filterCompletedInstants();
  if (completedInstants.empty()) {
    throw new HoodieException("There are no completed savepoint to run delete");
  }
  HoodieInstant savePoint = new HoodieInstant(false, HoodieTimeline.SAVEPOINT_ACTION, instantTime);

  if (!completedInstants.containsInstant(savePoint)) {
    return "Commit " + instantTime + " not found in Commits " + completedInstants;
  }

  SparkLauncher sparkLauncher = SparkUtil.initLauncher(sparkPropertiesPath);
  sparkLauncher.addAppArgs(SparkMain.SparkCommand.DELETE_SAVEPOINT.toString(), master, sparkMemory, instantTime,
      metaClient.getBasePath());
  Process process = sparkLauncher.launch();
  InputStreamConsumer.captureOutput(process);
  int exitCode = process.waitFor();
  // Refresh the current
  HoodieCLI.refreshTableMetadata();
  if (exitCode != 0) {
    return String.format("Failed: Could not delete savepoint \"%s\".", instantTime);
  }
  return String.format("Savepoint \"%s\" deleted.", instantTime);
}
 
Example #10
Source File: ShellCommands.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = CliStrings.ENCRYPT, help = CliStrings.ENCRYPT__HELP)
@CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GEMFIRE_DEBUG_UTIL})
public Result encryptPassword(
    @CliOption(key = CliStrings.ENCRYPT_STRING,
               help = CliStrings.ENCRYPT_STRING__HELP,
               mandatory = true)
               String stringToEncrypt) {
  return ResultBuilder.createInfoResult(PasswordUtil.encrypt(stringToEncrypt, false/*echo*/));
}
 
Example #11
Source File: HadoopDfsCommands.java    From hdfs-shell with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = {"lsr", "hdfs dfs -lsr"}, help = "(DEPRECATED) Same as 'ls -R'.")
public String lsr(
        @CliOption(key = {""}, help = "(DEPRECATED) Same as 'ls -R'.") String path
) {
    if (StringUtils.isEmpty(path)) {
        path = null;
    }
    return runCommand("lsr", path);
}
 
Example #12
Source File: CommitsCommand.java    From hudi with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = "commit rollback", help = "Rollback a commit")
public String rollbackCommit(@CliOption(key = {"commit"}, help = "Commit to rollback") final String instantTime,
    @CliOption(key = {"sparkProperties"}, help = "Spark Properties File Path") final String sparkPropertiesPath,
    @CliOption(key = "sparkMaster", unspecifiedDefaultValue = "", help = "Spark Master") String master,
    @CliOption(key = "sparkMemory", unspecifiedDefaultValue = "4G",
       help = "Spark executor memory") final String sparkMemory)
    throws Exception {
  HoodieActiveTimeline activeTimeline = HoodieCLI.getTableMetaClient().getActiveTimeline();
  HoodieTimeline completedTimeline = activeTimeline.getCommitsTimeline().filterCompletedInstants();
  HoodieTimeline filteredTimeline = completedTimeline.filter(instant -> instant.getTimestamp().equals(instantTime));
  if (filteredTimeline.empty()) {
    return "Commit " + instantTime + " not found in Commits " + completedTimeline;
  }

  SparkLauncher sparkLauncher = SparkUtil.initLauncher(sparkPropertiesPath);
  sparkLauncher.addAppArgs(SparkMain.SparkCommand.ROLLBACK.toString(), master, sparkMemory, instantTime,
      HoodieCLI.getTableMetaClient().getBasePath());
  Process process = sparkLauncher.launch();
  InputStreamConsumer.captureOutput(process);
  int exitCode = process.waitFor();
  // Refresh the current
  HoodieCLI.refreshTableMetadata();
  if (exitCode != 0) {
    return "Commit " + instantTime + " failed to roll back";
  }
  return "Commit " + instantTime + " rolled back";
}
 
Example #13
Source File: SavepointsCommand.java    From hudi with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = "savepoint rollback", help = "Savepoint a commit")
public String rollbackToSavepoint(
    @CliOption(key = {"savepoint"}, help = "Savepoint to rollback") final String instantTime,
    @CliOption(key = {"sparkProperties"}, help = "Spark Properties File Path") final String sparkPropertiesPath,
    @CliOption(key = "sparkMaster", unspecifiedDefaultValue = "", help = "Spark Master") String master,
    @CliOption(key = "sparkMemory", unspecifiedDefaultValue = "4G",
        help = "Spark executor memory") final String sparkMemory)
    throws Exception {
  HoodieTableMetaClient metaClient = HoodieCLI.getTableMetaClient();
  if (metaClient.getActiveTimeline().getSavePointTimeline().filterCompletedInstants().empty()) {
    throw new HoodieException("There are no completed instants to run rollback");
  }
  HoodieActiveTimeline activeTimeline = metaClient.getActiveTimeline();
  HoodieTimeline timeline = activeTimeline.getCommitTimeline().filterCompletedInstants();
  HoodieInstant commitInstant = new HoodieInstant(false, HoodieTimeline.COMMIT_ACTION, instantTime);

  if (!timeline.containsInstant(commitInstant)) {
    return "Commit " + instantTime + " not found in Commits " + timeline;
  }

  SparkLauncher sparkLauncher = SparkUtil.initLauncher(sparkPropertiesPath);
  sparkLauncher.addAppArgs(SparkMain.SparkCommand.ROLLBACK_TO_SAVEPOINT.toString(), master, sparkMemory,
      instantTime, metaClient.getBasePath());
  Process process = sparkLauncher.launch();
  InputStreamConsumer.captureOutput(process);
  int exitCode = process.waitFor();
  // Refresh the current
  HoodieCLI.refreshTableMetadata();
  if (exitCode != 0) {
    return String.format("Savepoint \"%s\" failed to roll back", instantTime);
  }
  return String.format("Savepoint \"%s\" rolled back", instantTime);
}
 
Example #14
Source File: CleansCommand.java    From hudi with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = "cleans show", help = "Show the cleans")
public String showCleans(
    @CliOption(key = {"limit"}, help = "Limit commits", unspecifiedDefaultValue = "-1") final Integer limit,
    @CliOption(key = {"sortBy"}, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField,
    @CliOption(key = {"desc"}, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending,
    @CliOption(key = {"headeronly"}, help = "Print Header Only",
        unspecifiedDefaultValue = "false") final boolean headerOnly)
    throws IOException {

  HoodieActiveTimeline activeTimeline = HoodieCLI.getTableMetaClient().getActiveTimeline();
  HoodieTimeline timeline = activeTimeline.getCleanerTimeline().filterCompletedInstants();
  List<HoodieInstant> cleans = timeline.getReverseOrderedInstants().collect(Collectors.toList());
  List<Comparable[]> rows = new ArrayList<>();
  for (HoodieInstant clean : cleans) {
    HoodieCleanMetadata cleanMetadata =
            TimelineMetadataUtils.deserializeHoodieCleanMetadata(timeline.getInstantDetails(clean).get());
    rows.add(new Comparable[]{clean.getTimestamp(), cleanMetadata.getEarliestCommitToRetain(),
            cleanMetadata.getTotalFilesDeleted(), cleanMetadata.getTimeTakenInMillis()});
  }

  TableHeader header =
      new TableHeader().addTableHeaderField(HoodieTableHeaderFields.HEADER_CLEAN_TIME)
          .addTableHeaderField(HoodieTableHeaderFields.HEADER_EARLIEST_COMMAND_RETAINED)
          .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_FILES_DELETED)
          .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_TIME_TAKEN);
  return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, rows);
}
 
Example #15
Source File: HadoopDfsCommands.java    From hdfs-shell with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = {"setfacl", "hdfs dfs -setfacl"}, help = "Sets Access Control Lists (ACLs) of files and directories.")
public String setfacl(
        @CliOption(key = {""}, help = "Sets Access Control Lists (ACLs) of files and directories.") String path
) {

    return runSetFaclCommand("setfacl", path);
}
 
Example #16
Source File: ContextCommands.java    From hdfs-shell with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = "set", help = "Set switch value")
public String set(@CliOption(key = {""}, help = "showResultCodeON/showResultCodeOFF") String commandSwitch) {
    if (commandSwitch == null) {
        return "possible parameters .... showResultCodeON/showResultCodeOFF";
    }
    if (commandSwitch.startsWith("showResultCode")) {
        showResultCode = "showResultCodeON".equalsIgnoreCase(commandSwitch);
        return commandSwitch + " has been set";
    }
    return "Unknown switch " + commandSwitch;
}
 
Example #17
Source File: GfshParserTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = { "testParamConcat" })
public static Result testParamConcat(
    @CliOption(key = { "string" }) String string,
    @CliOption(key = { "stringArray" }) @CliMetaData(valueSeparator = ",") String[] stringArray,
    @CliOption(key = { "stringList" }, optionContext = ConverterHint.STRING_LIST) @CliMetaData(valueSeparator = ",") List<String> stringList,
    @CliOption(key = { "integer" }) Integer integer,
    @CliOption(key = { "colonArray" }) @CliMetaData(valueSeparator = ":") String[] colonArray) {
  return null;
}
 
Example #18
Source File: CommitsCommand.java    From hudi with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = "commits showarchived", help = "Show the archived commits")
public String showArchivedCommits(
        @CliOption(key = {"includeExtraMetadata"}, help = "Include extra metadata",
                unspecifiedDefaultValue = "false") final boolean includeExtraMetadata,
        @CliOption(key = {"createView"}, mandatory = false, help = "view name to store output table",
                unspecifiedDefaultValue = "") final String exportTableName,
        @CliOption(key = {"startTs"},  mandatory = false, help = "start time for commits, default: now - 10 days")
        String startTs,
        @CliOption(key = {"endTs"},  mandatory = false, help = "end time for commits, default: now - 1 day")
        String endTs,
        @CliOption(key = {"limit"}, mandatory = false, help = "Limit commits", unspecifiedDefaultValue = "-1")
        final Integer limit,
        @CliOption(key = {"sortBy"}, help = "Sorting Field", unspecifiedDefaultValue = "")
        final String sortByField,
        @CliOption(key = {"desc"}, help = "Ordering", unspecifiedDefaultValue = "false")
        final boolean descending,
        @CliOption(key = {"headeronly"}, help = "Print Header Only", unspecifiedDefaultValue = "false")
        final boolean headerOnly)
        throws IOException {
  if (StringUtils.isNullOrEmpty(startTs)) {
    startTs = CommitUtil.getTimeDaysAgo(10);
  }
  if (StringUtils.isNullOrEmpty(endTs)) {
    endTs = CommitUtil.getTimeDaysAgo(1);
  }
  HoodieArchivedTimeline archivedTimeline = HoodieCLI.getTableMetaClient().getArchivedTimeline();
  try {
    archivedTimeline.loadInstantDetailsInMemory(startTs, endTs);
    HoodieDefaultTimeline timelineRange = archivedTimeline.findInstantsInRange(startTs, endTs);
    if (includeExtraMetadata) {
      return printCommitsWithMetadata(timelineRange, limit, sortByField, descending, headerOnly, exportTableName);
    } else  {
      return printCommits(timelineRange, limit, sortByField, descending, headerOnly, exportTableName);
    }
  } finally {
    // clear the instant details from memory after printing to reduce usage
    archivedTimeline.clearInstantDetailsFromMemory(startTs, endTs);
  }
}
 
Example #19
Source File: RollbacksCommand.java    From hudi with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = "show rollbacks", help = "List all rollback instants")
public String showRollbacks(
    @CliOption(key = {"limit"}, help = "Limit #rows to be displayed", unspecifiedDefaultValue = "10") Integer limit,
    @CliOption(key = {"sortBy"}, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField,
    @CliOption(key = {"desc"}, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending,
    @CliOption(key = {"headeronly"}, help = "Print Header Only",
        unspecifiedDefaultValue = "false") final boolean headerOnly) {
  HoodieActiveTimeline activeTimeline = new RollbackTimeline(HoodieCLI.getTableMetaClient());
  HoodieTimeline rollback = activeTimeline.getRollbackTimeline().filterCompletedInstants();

  final List<Comparable[]> rows = new ArrayList<>();
  rollback.getInstants().forEach(instant -> {
    try {
      HoodieRollbackMetadata metadata = TimelineMetadataUtils
          .deserializeAvroMetadata(activeTimeline.getInstantDetails(instant).get(), HoodieRollbackMetadata.class);
      metadata.getCommitsRollback().forEach(c -> {
        Comparable[] row = new Comparable[5];
        row[0] = metadata.getStartRollbackTime();
        row[1] = c;
        row[2] = metadata.getTotalFilesDeleted();
        row[3] = metadata.getTimeTakenInMillis();
        row[4] = metadata.getPartitionMetadata() != null ? metadata.getPartitionMetadata().size() : 0;
        rows.add(row);
      });
    } catch (IOException e) {
      e.printStackTrace();
    }
  });
  TableHeader header = new TableHeader().addTableHeaderField(HoodieTableHeaderFields.HEADER_INSTANT)
      .addTableHeaderField(HoodieTableHeaderFields.HEADER_ROLLBACK_INSTANT)
      .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_FILES_DELETED)
      .addTableHeaderField(HoodieTableHeaderFields.HEADER_TIME_TOKEN_MILLIS)
      .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_PARTITIONS);
  return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, rows);
}
 
Example #20
Source File: TempViewCommand.java    From hudi with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = "temp_query", help = "query against created temp view")
public String query(
        @CliOption(key = {"sql"}, mandatory = true, help = "select query to run against view") final String sql)
        throws IOException {

  HoodieCLI.getTempViewProvider().runQuery(sql);
  return EMPTY_STRING;
}
 
Example #21
Source File: UtilsCommand.java    From hudi with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = "utils loadClass", help = "Load a class")
public String loadClass(@CliOption(key = {"class"}, help = "Check mode") final String clazz) {
  if (StringUtils.isNullOrEmpty(clazz)) {
    return "Class to be loaded can not be null!";
  }
  try {
    Class klass = Class.forName(clazz);
    return klass.getProtectionDomain().getCodeSource().getLocation().toExternalForm();
  } catch (ClassNotFoundException e) {
    return String.format("Class %s not found!", clazz);
  }
}
 
Example #22
Source File: RepairsCommand.java    From hudi with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = "repair deduplicate",
    help = "De-duplicate a partition path contains duplicates & produce repaired files to replace with")
public String deduplicate(
    @CliOption(key = {"duplicatedPartitionPath"}, help = "Partition Path containing the duplicates",
        mandatory = true) final String duplicatedPartitionPath,
    @CliOption(key = {"repairedOutputPath"}, help = "Location to place the repaired files",
        mandatory = true) final String repairedOutputPath,
    @CliOption(key = {"sparkProperties"}, help = "Spark Properties File Path",
        unspecifiedDefaultValue = "") String sparkPropertiesPath,
    @CliOption(key = "sparkMaster", unspecifiedDefaultValue = "", help = "Spark Master") String master,
    @CliOption(key = "sparkMemory", unspecifiedDefaultValue = "4G",
        help = "Spark executor memory") final String sparkMemory,
    @CliOption(key = {"dryrun"},
        help = "Should we actually remove duplicates or just run and store result to repairedOutputPath",
        unspecifiedDefaultValue = "true") final boolean dryRun)
    throws Exception {
  if (StringUtils.isNullOrEmpty(sparkPropertiesPath)) {
    sparkPropertiesPath =
        Utils.getDefaultPropertiesFile(JavaConverters.mapAsScalaMapConverter(System.getenv()).asScala());
  }

  SparkLauncher sparkLauncher = SparkUtil.initLauncher(sparkPropertiesPath);
  sparkLauncher.addAppArgs(SparkMain.SparkCommand.DEDUPLICATE.toString(), master, sparkMemory,
      duplicatedPartitionPath, repairedOutputPath, HoodieCLI.getTableMetaClient().getBasePath(),
      String.valueOf(dryRun));
  Process process = sparkLauncher.launch();
  InputStreamConsumer.captureOutput(process);
  int exitCode = process.waitFor();

  if (exitCode != 0) {
    return "Deduplication failed!";
  }
  if (dryRun) {
    return DEDUPLICATE_RETURN_PREFIX + repairedOutputPath;
  } else {
    return DEDUPLICATE_RETURN_PREFIX + duplicatedPartitionPath;
  }
}
 
Example #23
Source File: ApplicationCommands.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = UNDEPLOY_APPLICATION_ALL, help = "Un-deploy all previously deployed applications")
public String undeployAllApplications(
		@CliOption(key = "force", help = "bypass confirmation prompt", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") boolean force
		) {
	if (force || "y".equalsIgnoreCase(userInput.promptWithOptions("Really undeploy all applications?", "n", "y", "n"))) {
		applicationOperations().undeployAll();
		return String.format("Un-deployed all the applications");
	}
	else {
		return "";
	}
}
 
Example #24
Source File: CommitsCommand.java    From hudi with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = "commits sync", help = "Compare commits with another Hoodie table")
public String syncCommits(@CliOption(key = {"path"}, help = "Path of the table to compare to") final String path) {
  HoodieCLI.syncTableMetadata = new HoodieTableMetaClient(HoodieCLI.conf, path);
  HoodieCLI.state = HoodieCLI.CLIState.SYNC;
  return "Load sync state between " + HoodieCLI.getTableMetaClient().getTableConfig().getTableName() + " and "
      + HoodieCLI.syncTableMetadata.getTableConfig().getTableName();
}
 
Example #25
Source File: ShellCommands.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = { CliStrings.RUN }, help = CliStrings.RUN__HELP)
@CliMetaData(shellOnly=true, relatedTopic = {CliStrings.TOPIC_GFSH})
public Result executeScript(
    @CliOption(key = CliStrings.RUN__FILE,
               optionContext = ConverterHint.FILE,
               mandatory = true,
               help = CliStrings.RUN__FILE__HELP)
               File file,
    @CliOption(key = { CliStrings.RUN__QUIET },
               specifiedDefaultValue = "true",
               unspecifiedDefaultValue = "false",
               help = CliStrings.RUN__QUIET__HELP)
                boolean quiet,
    @CliOption(key = { CliStrings.RUN__CONTINUEONERROR },
               specifiedDefaultValue = "true",
               unspecifiedDefaultValue = "false",
               help = CliStrings.RUN__CONTINUEONERROR__HELP)
                boolean continueOnError) {
  Result result = null;

  Gfsh gfsh = Gfsh.getCurrentInstance();
  try {
    result = gfsh.executeScript(file, quiet, continueOnError);
  } catch (IllegalArgumentException e) {
    result = ResultBuilder.createShellClientErrorResult(e.getMessage());
  } // let CommandProcessingException go to the caller

  return result;
}
 
Example #26
Source File: LauncherLifecycleCommands.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public Result startManager(@CliOption(key=CliStrings.START_MANAGER__MEMBERNAME,
                            unspecifiedDefaultValue=CliMetaData.ANNOTATION_NULL_VALUE,
                            help=CliStrings.START_MANAGER__MEMBERNAME__HELP)
                           String memberName,
                           @CliOption(key=CliStrings.START_MANAGER__DIR,
                            unspecifiedDefaultValue=CliMetaData.ANNOTATION_NULL_VALUE,
                            help=CliStrings.START_MANAGER__DIR__HELP)
                           String dir,
                           @CliOption(key=CliStrings.START_MANAGER__PORT,
                            unspecifiedDefaultValue="1099",
                            help=CliStrings.START_MANAGER__PORT__HELP)
                           int cacheServerPort,
                           @CliOption(key=CliStrings.START_MANAGER__BIND_ADDRESS,
                            unspecifiedDefaultValue="localhost",
                            help=CliStrings.START_MANAGER__BIND_ADDRESS__HELP)
                           String cacheServerHost,
                           @CliOption(key=CliStrings.START_MANAGER__CLASSPATH,
                            unspecifiedDefaultValue=CliMetaData.ANNOTATION_NULL_VALUE,
                            help=CliStrings.START_MANAGER__CLASSPATH__HELP)
                           String classpath,
                           @CliOption(key=CliStrings.START_MANAGER__MAXHEAP,
                            unspecifiedDefaultValue=CliMetaData.ANNOTATION_NULL_VALUE,
                            help=CliStrings.START_MANAGER__MAXHEAP__HELP)
                           String maxHeap,
                           @CliOption(key=CliStrings.START_MANAGER__INITIALHEAP,
                            unspecifiedDefaultValue=CliMetaData.ANNOTATION_NULL_VALUE,
                            help=CliStrings.START_MANAGER__INITIALHEAP__HELP)
                           String initialHeap,
                           @CliOption(key=CliStrings.START_MANAGER__J,
                            unspecifiedDefaultValue=CliMetaData.ANNOTATION_NULL_VALUE,
                            help=CliStrings.START_MANAGER__J__HELP)
                           Map<String, String> systepProps,
                           @CliOption(key=CliStrings.START_MANAGER__GEMFIREPROPS,
                            unspecifiedDefaultValue=CliMetaData.ANNOTATION_NULL_VALUE,
                            help=CliStrings.START_MANAGER__GEMFIREPROPS__HELP)
                           Map<String, String> gemfireProps)
{
  //TODO - Abhishek investigate passing gemfireProps
  return ResultBuilder.createInfoResult("Not-implemented");
}
 
Example #27
Source File: MiscellaneousCommands.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = CliStrings.SHUTDOWN, help = CliStrings.SHUTDOWN__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEMFIRE_LIFECYCLE },
    interceptor = "com.gemstone.gemfire.management.internal.cli.commands.MiscellaneousCommands$Interceptor")
public Result shutdown(
    @CliOption(key = CliStrings.SHUTDOWN__TIMEOUT, unspecifiedDefaultValue = "-1",
        help = CliStrings.SHUTDOWN__TIMEOUT__HELP) int timeOut) {
  try {
    GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.getAnyInstance();
    return executeFunction(cache, timeOut*1000);
  } catch (Exception ex) {
    return ResultBuilder.createUserErrorResult( ex.getMessage());
  }
}
 
Example #28
Source File: MiscellaneousCommands.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = CliStrings.GC, help = CliStrings.GC__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEMFIRE_DEBUG_UTIL })
public Result gc(
    @CliOption(key = CliStrings.GC__GROUP, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.GC__GROUP__HELP)
    String[] groups,
    @CliOption(key = CliStrings.GC__MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.GC__MEMBER__HELP)
    String memberId) {
  Cache cache = CacheFactory.getAnyInstance();
  Result result = null;
  CompositeResultData gcResultTable = ResultBuilder
      .createCompositeResultData();
  TabularResultData resultTable = gcResultTable.addSection().addTable(
      "Table1");
  String headerText = "GC Summary";
  resultTable.setHeader(headerText);
  Set<DistributedMember> dsMembers = new HashSet<DistributedMember>();
  if (memberId != null && memberId.length() > 0) {
    DistributedMember member = CliUtil
        .getDistributedMemberByNameOrId(memberId);
    if (member == null) {
      return ResultBuilder.createGemFireErrorResult(memberId
          + CliStrings.GC__MSG__MEMBER_NOT_FOUND);
    }
    dsMembers.add(member);
    result =  executeAndBuildResult(cache, resultTable, dsMembers);
  } else if (groups != null && groups.length > 0) {
    for (String group : groups) {
      dsMembers.addAll(cache.getDistributedSystem().getGroupMembers(group));
    }
    result = executeAndBuildResult(cache, resultTable, dsMembers);

  } else {
    // gc on entire cluster
    //exclude locators
    dsMembers = CliUtil.getAllNormalMembers(cache);
    result = executeAndBuildResult(cache, resultTable, dsMembers);

  }
  return result;
}
 
Example #29
Source File: MiscellaneousCommands.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = CliStrings.SHOW_DEADLOCK, help = CliStrings.SHOW_DEADLOCK__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEMFIRE_DEBUG_UTIL })
public Result showDeadlock(
    @CliOption(key = CliStrings.SHOW_DEADLOCK__DEPENDENCIES__FILE,
    help = CliStrings.SHOW_DEADLOCK__DEPENDENCIES__FILE__HELP,
    mandatory = true) String filename) {

  Result result = null;
  try {
    if (!filename.endsWith(".txt")) {
      return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.INVALID_FILE_EXTENTION, ".txt"));
    }
    Cache cache = CacheFactory.getAnyInstance();

    Set<DistributedMember> allMembers = CliUtil.getAllMembers(cache);
    GemFireDeadlockDetector gfeDeadLockDetector = new GemFireDeadlockDetector(allMembers);
    DependencyGraph dependencyGraph = gfeDeadLockDetector.find();
    LinkedList<Dependency> deadlock = dependencyGraph.findCycle();
    Set<Dependency> dependencies = (Set<Dependency>) dependencyGraph.getEdges();

    InfoResultData resultData = ResultBuilder.createInfoResultData();

    if (deadlock != null) {
      resultData.addLine(CliStrings.SHOW_DEADLOCK__DEADLOCK__DETECTED);
      resultData.addLine(DeadlockDetector.prettyFormat(deadlock));
    } else {
      resultData.addLine(CliStrings.SHOW_DEADLOCK__NO__DEADLOCK);
    }
    resultData.addAsFile(filename, DeadlockDetector.prettyFormat(dependencies),
        MessageFormat.format(CliStrings.SHOW_DEADLOCK__DEPENDENCIES__REVIEW,filename), false);
    result = ResultBuilder.buildResult(resultData);

  } catch (Exception e) {
    result = ResultBuilder.createGemFireErrorResult(CliStrings.SHOW_DEADLOCK__ERROR + " : " + e.getMessage());
  }
  return result;
}
 
Example #30
Source File: MiscellaneousCommands.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@CliCommand(value = CliStrings.EXPORT_LOGS, help = CliStrings.EXPORT_LOGS__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEMFIRE_SERVER, CliStrings.TOPIC_GEMFIRE_DEBUG_UTIL })
public Result exportLogs(
    @CliOption(key = CliStrings.EXPORT_LOGS__DIR,
        help = CliStrings.EXPORT_LOGS__DIR__HELP, mandatory=true) String dirName,
    @CliOption(key = CliStrings.EXPORT_LOGS__GROUP,
        unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
        optionContext = ConverterHint.MEMBERGROUP,
        help = CliStrings.EXPORT_LOGS__GROUP__HELP) String[] groups,
    @CliOption(key = CliStrings.EXPORT_LOGS__MEMBER,
        unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
        optionContext = ConverterHint.ALL_MEMBER_IDNAME,
        help = CliStrings.EXPORT_LOGS__MEMBER__HELP) String memberId,
    @CliOption(key = CliStrings.EXPORT_LOGS__LOGLEVEL,
        unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
        optionContext = ConverterHint.LOG_LEVEL,
        help = CliStrings.EXPORT_LOGS__LOGLEVEL__HELP) String logLevel,
    @CliOption(key = CliStrings.EXPORT_LOGS__UPTO_LOGLEVEL,
        unspecifiedDefaultValue = "false", help = CliStrings.EXPORT_LOGS__UPTO_LOGLEVEL__HELP) boolean onlyLogLevel,
    @CliOption(key = CliStrings.EXPORT_LOGS__MERGELOG,
        unspecifiedDefaultValue = "false", help = CliStrings.EXPORT_LOGS__MERGELOG__HELP) boolean mergeLog,
    @CliOption(key = CliStrings.EXPORT_LOGS__STARTTIME,
        unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.EXPORT_LOGS__STARTTIME__HELP) String start,
    @CliOption(key = CliStrings.EXPORT_LOGS__ENDTIME,
        unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.EXPORT_LOGS__ENDTIME__HELP) String end) {
  Result result = null;
  try {
    result =  exportLogsPreprocessing(  dirName,   groups,   memberId, logLevel,  onlyLogLevel, mergeLog, start,  end, 0 );
  } catch (Exception ex) {
    LogWrapper.getInstance().fine(ex.getMessage());
    result= ResultBuilder.createUserErrorResult(ex.getMessage()) ;
  }
  LogWrapper.getInstance().fine("Exporting logs returning =" + result );
  return result;
}