示例#1
0
  public static void main(final String[] args) {

    try {
      final Arguments arguments = new Arguments(args);

      // turn root log wide open, filters will be set to argument levels
      configureLogging(arguments.getConsoleLogLevel(), arguments.getFileLogLevel());

      LOG.info("Version: {}", arguments.getVersion());
      LOG.info("Command line args: {}", Joiner.on(", ").join(args));
      LOG.info("Console log level: {}", arguments.getConsoleLogLevel().toString());
      LOG.info("Log file log level: {}", arguments.getFileLogLevel().toString());
      LOG.info(CliCommand.getPlatformInformation());
      LOG.info(arguments.getArgumentLog());

      if (arguments.isHelp()) {
        // no need to connect to vend help
        final Ds3Cli runner = new Ds3Cli(null, arguments, null);
        final CommandResponse response = runner.getCommandHelp();
        System.out.println(response.getMessage());
        System.exit(response.getReturnCode());
      }

      final Ds3Client client = createClient(arguments);
      if (!Utils.isVersionSupported(client)) {
        System.out.println(
            String.format(
                "ERROR: Minimum Black Pearl supported is %s", Utils.MINIMUM_VERSION_SUPPORTED));
        System.exit(2);
      }

      final Ds3Provider provider = new Ds3ProviderImpl(client, Ds3ClientHelpers.wrap(client));
      final FileUtils fileUtils = new FileUtilsImpl();

      final Ds3Cli runner = new Ds3Cli(provider, arguments, fileUtils);
      final CommandResponse response = runner.call();
      System.out.println(response.getMessage());
      System.exit(response.getReturnCode());
    } catch (final FailedRequestException e) {
      System.out.println("ERROR: " + e.getMessage());
      LOG.info("Stack trace: ", e);
      LOG.info("Printing out the response from the server:");
      LOG.info(e.getResponseString());
      System.exit(2);
    } catch (final Exception e) {
      System.out.println("ERROR: " + e.getMessage());
      LOG.info("Stack trace: ", e);
      System.exit(2);
    }
  }
  private String deleteBucket()
      throws SignatureException, SSLSetupException, CommandException, IOException {
    try {
      getClient().deleteBucket(new DeleteBucketRequest(bucketName));
    } catch (final FailedRequestException e) {
      if (e.getStatusCode() == 409) { // BUCKET_NOT_EMPTY
        throw new CommandException(
            "Error: Tried to delete a non-empty bucket without the force delete objects flag.\nUse --force to delete all objects in the bucket");
      }
      throw new CommandException(
          "Error: Request failed with the following error: " + e.getMessage(), e);
    }

    return "Success: Deleted bucket '" + bucketName + "'.";
  }