Java Code Examples for org.apache.hadoop.util.ToolRunner#confirmPrompt()

The following examples show how to use org.apache.hadoop.util.ToolRunner#confirmPrompt() . 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: Storage.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Iterate over each of the {@link FormatConfirmable} objects,
 * potentially checking with the user whether it should be formatted.
 * 
 * If running in interactive mode, will prompt the user for each
 * directory to allow them to format anyway. Otherwise, returns
 * false, unless 'force' is specified.
 * 
 * @param force format regardless of whether dirs exist
 * @param interactive prompt the user when a dir exists
 * @return true if formatting should proceed
 * @throws IOException if some storage cannot be accessed
 */
public static boolean confirmFormat(
    Iterable<? extends FormatConfirmable> items,
    boolean force, boolean interactive) throws IOException {
  for (FormatConfirmable item : items) {
    if (!item.hasSomeData())
      continue;
    if (force) { // Don't confirm, always format.
      System.err.println(
          "Data exists in " + item + ". Formatting anyway.");
      continue;
    }
    if (!interactive) { // Don't ask - always don't format
      System.err.println(
          "Running in non-interactive mode, and data appears to exist in " +
          item + ". Not formatting.");
      return false;
    }
    if (!ToolRunner.confirmPrompt("Re-format filesystem in " + item + " ?")) {
      System.err.println("Format aborted in " + item);
      return false;
    }
  }
  
  return true;
}
 
Example 2
Source File: ZKFailoverController.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private boolean confirmFormat() {
  String parentZnode = getParentZnode();
  System.err.println(
      "===============================================\n" +
      "The configured parent znode " + parentZnode + " already exists.\n" +
      "Are you sure you want to clear all failover information from\n" +
      "ZooKeeper?\n" +
      "WARNING: Before proceeding, ensure that all HDFS services and\n" +
      "failover controllers are stopped!\n" +
      "===============================================");
  try {
    return ToolRunner.confirmPrompt("Proceed formatting " + parentZnode + "?");
  } catch (IOException e) {
    LOG.debug("Failed to confirm", e);
    return false;
  }
}
 
Example 3
Source File: Storage.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Iterate over each of the {@link FormatConfirmable} objects,
 * potentially checking with the user whether it should be formatted.
 * 
 * If running in interactive mode, will prompt the user for each
 * directory to allow them to format anyway. Otherwise, returns
 * false, unless 'force' is specified.
 * 
 * @param force format regardless of whether dirs exist
 * @param interactive prompt the user when a dir exists
 * @return true if formatting should proceed
 * @throws IOException if some storage cannot be accessed
 */
public static boolean confirmFormat(
    Iterable<? extends FormatConfirmable> items,
    boolean force, boolean interactive) throws IOException {
  for (FormatConfirmable item : items) {
    if (!item.hasSomeData())
      continue;
    if (force) { // Don't confirm, always format.
      System.err.println(
          "Data exists in " + item + ". Formatting anyway.");
      continue;
    }
    if (!interactive) { // Don't ask - always don't format
      System.err.println(
          "Running in non-interactive mode, and data appears to exist in " +
          item + ". Not formatting.");
      return false;
    }
    if (!ToolRunner.confirmPrompt("Re-format filesystem in " + item + " ?")) {
      System.err.println("Format aborted in " + item);
      return false;
    }
  }
  
  return true;
}
 
Example 4
Source File: ZKFailoverController.java    From big-c with Apache License 2.0 6 votes vote down vote up
private boolean confirmFormat() {
  String parentZnode = getParentZnode();
  System.err.println(
      "===============================================\n" +
      "The configured parent znode " + parentZnode + " already exists.\n" +
      "Are you sure you want to clear all failover information from\n" +
      "ZooKeeper?\n" +
      "WARNING: Before proceeding, ensure that all HDFS services and\n" +
      "failover controllers are stopped!\n" +
      "===============================================");
  try {
    return ToolRunner.confirmPrompt("Proceed formatting " + parentZnode + "?");
  } catch (IOException e) {
    LOG.debug("Failed to confirm", e);
    return false;
  }
}
 
Example 5
Source File: CredentialShell.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public boolean validate() {
  provider = getCredentialProvider();
  if (provider == null) {
    out.println("There are no valid CredentialProviders configured.\n"
        + "Nothing will be deleted.\n"
        + "Consider using the -provider option to indicate the provider"
        + " to use.");
    return false;
  }
  if (alias == null) {
    out.println("There is no alias specified. Please provide the" +
        "mandatory <alias>. See the usage description with -help.");
    return false;
  }
  if (interactive) {
    try {
      cont = ToolRunner
          .confirmPrompt("You are about to DELETE the credential " +
              alias + " from CredentialProvider " + provider.toString() +
              ". Continue? ");
      if (!cont) {
        out.println("Nothing has been be deleted.");
      }
      return cont;
    } catch (IOException e) {
      out.println(alias + " will not be deleted.");
      e.printStackTrace(err);
    }
  }
  return true;
}
 
Example 6
Source File: HAAdmin.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private boolean confirmForceManual() throws IOException {
   return ToolRunner.confirmPrompt(
      "You have specified the --" + FORCEMANUAL + " flag. This flag is " +
      "dangerous, as it can induce a split-brain scenario that WILL " +
      "CORRUPT your HDFS namespace, possibly irrecoverably.\n" +
      "\n" +
      "It is recommended not to use this flag, but instead to shut down the " +
      "cluster and disable automatic failover if you prefer to manually " +
      "manage your HA state.\n" +
      "\n" +
      "You may abort safely by answering 'n' or hitting ^C now.\n" +
      "\n" +
      "Are you sure you want to continue?");
}
 
Example 7
Source File: KeyShell.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public boolean validate() {
  provider = getKeyProvider();
  if (provider == null) {
    out.println("There are no valid KeyProviders configured. Nothing\n"
      + "was deleted. Use the -provider option to specify a provider.");
    return false;
  }
  if (keyName == null) {
    out.println("There is no keyName specified. Please specify a " +
        "<keyname>. See the usage description with -help.");
    return false;
  }
  if (interactive) {
    try {
      cont = ToolRunner
          .confirmPrompt("You are about to DELETE all versions of "
              + " key " + keyName + " from KeyProvider "
              + provider + ". Continue? ");
      if (!cont) {
        out.println(keyName + " has not been deleted.");
      }
      return cont;
    } catch (IOException e) {
      out.println(keyName + " will not be deleted.");
      e.printStackTrace(err);
    }
  }
  return true;
}
 
Example 8
Source File: CredentialShell.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public boolean validate() {
  provider = getCredentialProvider();
  if (provider == null) {
    out.println("There are no valid CredentialProviders configured.\n"
        + "Nothing will be deleted.\n"
        + "Consider using the -provider option to indicate the provider"
        + " to use.");
    return false;
  }
  if (alias == null) {
    out.println("There is no alias specified. Please provide the" +
        "mandatory <alias>. See the usage description with -help.");
    return false;
  }
  if (interactive) {
    try {
      cont = ToolRunner
          .confirmPrompt("You are about to DELETE the credential " +
              alias + " from CredentialProvider " + provider.toString() +
              ". Continue? ");
      if (!cont) {
        out.println("Nothing has been be deleted.");
      }
      return cont;
    } catch (IOException e) {
      out.println(alias + " will not be deleted.");
      e.printStackTrace(err);
    }
  }
  return true;
}
 
Example 9
Source File: HAAdmin.java    From big-c with Apache License 2.0 5 votes vote down vote up
private boolean confirmForceManual() throws IOException {
   return ToolRunner.confirmPrompt(
      "You have specified the --" + FORCEMANUAL + " flag. This flag is " +
      "dangerous, as it can induce a split-brain scenario that WILL " +
      "CORRUPT your HDFS namespace, possibly irrecoverably.\n" +
      "\n" +
      "It is recommended not to use this flag, but instead to shut down the " +
      "cluster and disable automatic failover if you prefer to manually " +
      "manage your HA state.\n" +
      "\n" +
      "You may abort safely by answering 'n' or hitting ^C now.\n" +
      "\n" +
      "Are you sure you want to continue?");
}
 
Example 10
Source File: KeyShell.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public boolean validate() {
  provider = getKeyProvider();
  if (provider == null) {
    out.println("There are no valid KeyProviders configured. Nothing\n"
      + "was deleted. Use the -provider option to specify a provider.");
    return false;
  }
  if (keyName == null) {
    out.println("There is no keyName specified. Please specify a " +
        "<keyname>. See the usage description with -help.");
    return false;
  }
  if (interactive) {
    try {
      cont = ToolRunner
          .confirmPrompt("You are about to DELETE all versions of "
              + " key " + keyName + " from KeyProvider "
              + provider + ". Continue? ");
      if (!cont) {
        out.println(keyName + " has not been deleted.");
      }
      return cont;
    } catch (IOException e) {
      out.println(keyName + " will not be deleted.");
      e.printStackTrace(err);
    }
  }
  return true;
}