Esempio n. 1
0
  @Override
  protected void populateAvroHeaders(Map<String, String> hdrs, Schema schema, Object message) {
    if (!initialized) {
      // initialize here rather than in activateOptions to avoid initialization
      // cycle in Configuration and log4j
      try {
        Class<?> c = Class.forName(datasetRepositoryClass);
        Constructor<?> cons = c.getConstructor(URI.class);
        DatasetRepository repo =
            (DatasetRepository) cons.newInstance(new URI(datasetRepositoryUri));

        Dataset dataset = repo.get(datasetName);
        if (dataset.getDescriptor().isPartitioned()) {
          partitionStrategy = dataset.getDescriptor().getPartitionStrategy();
        }
        URL schemaUrl = dataset.getDescriptor().getSchemaUrl();
        if (schemaUrl != null) {
          setAvroSchemaUrl(schemaUrl.toExternalForm());
        }
      } catch (Exception e) {
        throw new FlumeException(e);
      } finally {
        initialized = true;
      }
    }
    super.populateAvroHeaders(hdrs, schema, message);
    if (partitionStrategy != null) {
      key = partitionStrategy.partitionKeyForEntity(message, key);
      int i = 0;
      for (FieldPartitioner fp : partitionStrategy.getFieldPartitioners()) {
        hdrs.put(PARTITION_PREFIX + fp.getName(), key.get(i++).toString());
      }
    }
  }
Esempio n. 2
0
 @Override
 @SuppressWarnings({"unchecked", "deprecation"})
 protected void populateAvroHeaders(Map<String, String> hdrs, Schema schema, Object message) {
   if (!initialized) {
     // initialize here rather than in activateOptions to avoid initialization
     // cycle in Configuration and log4j
     try {
       URI datasetUri = new URIBuilder(datasetRepositoryUri, datasetName).build();
       Dataset dataset = Datasets.load(datasetUri);
       if (dataset.getDescriptor().isPartitioned()) {
         partitionStrategy = dataset.getDescriptor().getPartitionStrategy();
       }
       URL schemaUrl = dataset.getDescriptor().getSchemaUrl();
       if (schemaUrl != null) {
         setAvroSchemaUrl(schemaUrl.toExternalForm());
       }
     } catch (Exception e) {
       throw new FlumeException(e);
     } finally {
       initialized = true;
     }
   }
   super.populateAvroHeaders(hdrs, schema, message);
   if (partitionStrategy != null) {
     key = PartitionKey.partitionKeyForEntity(partitionStrategy, message, key);
     int i = 0;
     for (FieldPartitioner fp : partitionStrategy.getFieldPartitioners()) {
       hdrs.put(PARTITION_PREFIX + fp.getName(), fp.valueToString(key.get(i++)));
     }
   }
 }