Esempio n. 1
0
 private static void checkNotChanged(
     String what, @Nullable Object existing, @Nullable Object test) {
   ValidationException.check(
       (existing == test) || (existing != null && existing.equals(test)),
       "Dataset %s is not compatible with existing: %s != %s",
       what,
       String.valueOf(existing),
       String.valueOf(test));
 }
Esempio n. 2
0
  @Override
  public final void initialize() {
    Preconditions.checkState(
        state.equals(ReaderWriterState.NEW), "Unable to open a writer from state:%s", state);

    ValidationException.check(
        isSupportedFormat(descriptor), "Not a supported format: %s", descriptor.getFormat());

    // ensure the directory exists
    try {
      fs.mkdirs(directory);
    } catch (RuntimeException e) {
      this.state = ReaderWriterState.ERROR;
      throw new DatasetOperationException(e, "Failed to create path %s", directory);
    } catch (IOException ex) {
      this.state = ReaderWriterState.ERROR;
      throw new DatasetIOException("Failed to create path " + directory, ex);
    }

    // initialize paths
    try {
      this.finalPath = new Path(directory, uniqueFilename(descriptor.getFormat()));
      this.tempPath = tempFilename(finalPath);
    } catch (RuntimeException e) {
      this.state = ReaderWriterState.ERROR;
      throw new DatasetOperationException(e, "Failed to initialize file paths under %s", directory);
    }

    try {
      this.appender = newAppender(tempPath);
      appender.open();
    } catch (RuntimeException e) {
      this.state = ReaderWriterState.ERROR;
      throw new DatasetOperationException(e, "Failed to open appender %s", appender);
    } catch (IOException e) {
      this.state = ReaderWriterState.ERROR;
      throw new DatasetIOException("Failed to open appender " + appender, e);
    }

    this.count = 0;

    LOG.info("Opened output appender {} for {}", appender, finalPath);

    this.state = ReaderWriterState.OPEN;
  }
Esempio n. 3
0
  @Override
  public void initialize() {
    Preconditions.checkState(
        state.equals(ReaderWriterState.NEW), "Unable to open a writer from state:%s", state);

    DatasetDescriptor descriptor = view.getDataset().getDescriptor();
    ValidationException.check(
        FileSystemWriter.isSupportedFormat(descriptor),
        "Not a supported format: %s",
        descriptor.getFormat());

    LOG.debug("Opening partitioned dataset writer w/strategy:{}", partitionStrategy);

    cachedWriters =
        CacheBuilder.newBuilder()
            .maximumSize(maxWriters)
            .removalListener(new DatasetWriterCloser<E>())
            .build(createCacheLoader());

    state = ReaderWriterState.OPEN;
  }
Esempio n. 4
0
  @Override
  public int run(String[] args) throws Exception {

    if (getConf() != null) {
      DefaultConfiguration.set(getConf());
    }

    try {
      jc.parse(args);
    } catch (MissingCommandException e) {
      console.error(e.getMessage());
      return 1;
    } catch (ParameterException e) {
      console.error(e.getMessage());
      return 1;
    }

    // configure log4j
    if (debug) {
      org.apache.log4j.Logger console = org.apache.log4j.Logger.getLogger(Main.class);
      console.setLevel(Level.DEBUG);
    }

    String parsed = jc.getParsedCommand();
    if (parsed == null) {

      console.error("Unable to parse command.");
      return 1;
    }

    Command command = (Command) jc.getCommands().get(parsed).getObjects().get(0);
    if (command == null) {

      console.error("Unable to find command.");
      return 1;
    }

    try {
      if (command instanceof Configurable) {
        ((Configurable) command).setConf(getConf());
      }
      return command.run();
    } catch (IllegalArgumentException e) {
      if (debug) {
        console.error("Argument error", e);
      } else {
        console.error("Argument error: {}", e.getMessage());
      }
      return 1;
    } catch (IllegalStateException e) {
      if (debug) {
        console.error("State error", e);
      } else {
        console.error("State error: {}", e.getMessage());
      }
      return 1;
    } catch (ValidationException e) {
      if (debug) {
        console.error("Validation error", e);
      } else {
        console.error("Validation error: {}", e.getMessage());
      }
      return 1;
    } catch (DatasetNotFoundException e) {
      if (debug) {
        console.error("Cannot find dataset", e);
      } else {
        // the error message already contains "No such dataset: <name>"
        console.error(e.getMessage());
      }
      return 1;
    } catch (DatasetIOException e) {
      if (debug) {
        console.error("IO error", e);
      } else {
        console.error("IO error: {}", e.getMessage());
      }
      return 1;
    } catch (Exception e) {
      if (debug) {
        console.error("Unknown error", e);
      } else {
        console.error("Unknown error: {}", e.getMessage());
      }
      return 1;
    }
  }