org.kitesdk.morphline.base.Notifications类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(156)

本文整理了Java中org.kitesdk.morphline.base.Notifications类的一些代码示例,展示了Notifications类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Notifications类的具体详情如下:
包路径:org.kitesdk.morphline.base.Notifications
类名称:Notifications

Notifications介绍

[英]Tools for notifications on the control plane.
[中]控制平面上的通知工具。

代码示例

代码示例来源:origin: apache/flume

  1. @Override
  2. public void beginTransaction() {
  3. Notifications.notifyBeginTransaction(morphline);
  4. }

代码示例来源:origin: apache/flume

  1. @Override
  2. public void process(Event event) {
  3. numRecords.mark();
  4. Timer.Context timerContext = mappingTimer.time();
  5. try {
  6. Record record = new Record();
  7. for (Entry<String, String> entry : event.getHeaders().entrySet()) {
  8. record.put(entry.getKey(), entry.getValue());
  9. }
  10. byte[] bytes = event.getBody();
  11. if (bytes != null && bytes.length > 0) {
  12. record.put(Fields.ATTACHMENT_BODY, bytes);
  13. }
  14. try {
  15. Notifications.notifyStartSession(morphline);
  16. if (!morphline.process(record)) {
  17. numFailedRecords.mark();
  18. LOG.warn("Morphline {} failed to process record: {}", morphlineFileAndId, record);
  19. }
  20. } catch (RuntimeException t) {
  21. numExceptionRecords.mark();
  22. morphlineContext.getExceptionHandler().handleException(t, record);
  23. }
  24. } finally {
  25. timerContext.stop();
  26. }
  27. }

代码示例来源:origin: apache/flume

  1. @Override
  2. public void commitTransaction() {
  3. Notifications.notifyCommitTransaction(morphline);
  4. }

代码示例来源:origin: kite-sdk/kite

  1. @Test
  2. public void testNotifications() throws Exception {
  3. morphline = createMorphline("test-morphlines/pipeWithTwoBasicCommands");
  4. Notifications.notifyBeginTransaction(morphline);
  5. Notifications.notifyStartSession(morphline);
  6. Notifications.notifyCommitTransaction(morphline);
  7. Notifications.notifyRollbackTransaction(morphline);
  8. }

代码示例来源:origin: kite-sdk/kite

  1. /**
  2. * Determine whether or not the given notification contains the given lifecycle event.
  3. * @param notification A {@link Record} that represents a notification.
  4. * @param event A {@link LifecycleEvent} enumeration that is to be searched for in the given notification.
  5. */
  6. public static boolean containsLifecycleEvent(Record notification, LifecycleEvent event) {
  7. return getLifecycleEvents(notification).contains(event);
  8. }

代码示例来源:origin: cloudera-labs/envelope

  1. public static List<Record> executePipeline(Pipeline pipeline, Record inputRecord, boolean errorOnEmpty) {
  2. Command morphline = pipeline.getMorphline();
  3. try {
  4. LOG.trace("Input Record: {}", inputRecord);
  5. // Process the Record
  6. Notifications.notifyStartSession(morphline);
  7. boolean success = morphline.process(inputRecord);
  8. Notifications.notifyCommitTransaction(morphline);
  9. if (!success) {
  10. throw new MorphlineRuntimeException("Morphline failed to process incoming Record: " + inputRecord);
  11. }
  12. // Collect the output
  13. List<Record> outputRecords = pipeline.getCollector().getRecords();
  14. if (errorOnEmpty && !outputRecords.iterator().hasNext()) {
  15. throw new MorphlineRuntimeException("Morphline did not produce output Record(s)");
  16. }
  17. LOG.trace("Output Record(s): {}", outputRecords);
  18. return outputRecords;
  19. } catch (RuntimeException e) {
  20. Notifications.notifyRollbackTransaction(morphline);
  21. // TODO : Review exception handling
  22. LOG.warn("Morphline failed to execute properly on incoming Record: " + inputRecord, e);
  23. throw e;
  24. }
  25. }

代码示例来源:origin: cloudera/search

  1. public void cleanup() {
  2. Notifications.notifyCommitTransaction(morphline);
  3. Notifications.notifyShutdown(morphline);
  4. }

代码示例来源:origin: kite-sdk/kite

  1. record.put("user_friends_count", 123);
  2. record.put("text", "myText");
  3. Notifications.notifyBeginTransaction(morphline);
  4. assertTrue(morphline.process(record));
  5. assertEquals(1, collector.getRecords().size());
  6. assertEquals(Arrays.asList("hello sun", "goodbye mars"), docs.get(0).get("text"));
  7. Notifications.notifyCommitTransaction(morphline);
  8. Notifications.notifyShutdown(morphline);

代码示例来源:origin: kite-sdk/kite

  1. @Test
  2. public void testTokenizeText() throws Exception {
  3. morphline = createMorphline("test-morphlines" + File.separator + "tokenizeText");
  4. for (int i = 0; i < 3; i++) {
  5. Record record = new Record();
  6. record.put(Fields.MESSAGE, "Hello World!");
  7. record.put(Fields.MESSAGE, "\nFoo@Bar.com #%()123");
  8. Record expected = record.copy();
  9. expected.getFields().putAll("tokens", Arrays.asList("hello", "world", "foo", "bar.com", "123"));
  10. collector.reset();
  11. startSession();
  12. Notifications.notifyBeginTransaction(morphline);
  13. assertTrue(morphline.process(record));
  14. assertEquals(1, collector.getNumStartEvents());
  15. Notifications.notifyCommitTransaction(morphline);
  16. assertEquals(expected, collector.getFirstRecord());
  17. }
  18. }

代码示例来源:origin: kite-sdk/kite

  1. record.replaceValues(Fields.ID, "id0");
  2. record.replaceValues("first_name", "Nadja"); // will be sanitized
  3. Notifications.notifyBeginTransaction(morphline);
  4. assertTrue(morphline.process(record.copy()));
  5. assertEquals(1, query("*:*").getResults().size());
  6. assertNull(docs.get(1).getFirstValue(LoadSolrBuilder.LOAD_SOLR_DELETE_BY_QUERY));
  7. Notifications.notifyRollbackTransaction(morphline);
  8. Notifications.notifyShutdown(morphline);

代码示例来源:origin: apache/flume

  1. @Override
  2. public void stop() {
  3. Notifications.notifyShutdown(morphline);
  4. }

代码示例来源:origin: kite-sdk/kite

  1. @Override
  2. protected void doNotify(Record notification) {
  3. if (Notifications.containsLifecycleEvent(notification, Notifications.LifecycleEvent.START_SESSION)) {
  4. recordCounter = 0; // reset
  5. }
  6. super.doNotify(notification);
  7. }

代码示例来源:origin: apache/flume

  1. @Override
  2. public void rollbackTransaction() {
  3. Notifications.notifyRollbackTransaction(morphline);
  4. }

代码示例来源:origin: kite-sdk/kite

  1. /** Usage: java ... <morphline.conf> <dataFile1> ... <dataFileN> */
  2. public static void main(String[] args) throws IOException {
  3. // compile morphline.conf file on the fly
  4. File morphlineFile = new File(args[0]);
  5. String morphlineId = null;
  6. MorphlineContext morphlineContext = new MorphlineContext.Builder().build();
  7. Command morphline = new Compiler().compile(morphlineFile, morphlineId, morphlineContext, null);
  8. // process each input data file
  9. Notifications.notifyBeginTransaction(morphline);
  10. try {
  11. for (int i = 1; i < args.length; i++) {
  12. InputStream in = new BufferedInputStream(new FileInputStream(new File(args[i])));
  13. Record record = new Record();
  14. record.put(Fields.ATTACHMENT_BODY, in);
  15. Notifications.notifyStartSession(morphline);
  16. boolean success = morphline.process(record);
  17. if (!success) {
  18. System.out.println("Morphline failed to process record: " + record);
  19. }
  20. in.close();
  21. }
  22. Notifications.notifyCommitTransaction(morphline);
  23. } catch (RuntimeException e) {
  24. Notifications.notifyRollbackTransaction(morphline);
  25. morphlineContext.getExceptionHandler().handleException(e, null);
  26. }
  27. Notifications.notifyShutdown(morphline);
  28. }
  29. }

代码示例来源:origin: org.kitesdk/kite-morphlines-core

  1. /**
  2. * Determine whether or not the given notification contains the given lifecycle event.
  3. * @param notification A {@link Record} that represents a notification.
  4. * @param event A {@link LifecycleEvent} enumeration that is to be searched for in the given notification.
  5. */
  6. public static boolean containsLifecycleEvent(Record notification, LifecycleEvent event) {
  7. return getLifecycleEvents(notification).contains(event);
  8. }

代码示例来源:origin: com.cloudera.search/search-mr

  1. public void cleanup() {
  2. Notifications.notifyCommitTransaction(morphline);
  3. Notifications.notifyShutdown(morphline);
  4. }

代码示例来源:origin: kite-sdk/kite

  1. @Test
  2. public void testLoadSolrWithChildDocuments() throws Exception {
  3. morphline = createMorphline("test-morphlines" + File.separator + "loadSolrWithChildDocuments");
  4. Record record = new Record();
  5. record.put(Fields.ID, "id0");
  6. startSession();
  7. Notifications.notifyBeginTransaction(morphline);
  8. assertTrue(morphline.process(record));
  9. assertEquals(1, collector.getNumStartEvents());
  10. Notifications.notifyCommitTransaction(morphline);
  11. // This parent block join returns the parent records for records
  12. // where the child documents contain "bar" in the id field.
  13. SolrDocumentList docs = query("{!parent which='content_type:parent'}id:bar").getResults();
  14. assertEquals(1, docs.size());
  15. assertEquals("id0", docs.get(0).getFirstValue(Fields.ID));
  16. docs = query("*:*").getResults();
  17. assertEquals(3, docs.size());
  18. }

代码示例来源:origin: org.apache.flume.flume-ng-sinks/flume-ng-morphline-solr-sink

  1. @Override
  2. public void stop() {
  3. Notifications.notifyShutdown(morphline);
  4. }

代码示例来源:origin: kite-sdk/kite

  1. @Override
  2. public void notify(Record notification) {
  3. if (Notifications.containsLifecycleEvent(notification, Notifications.LifecycleEvent.START_SESSION)) {
  4. numStartEvents++;
  5. }
  6. }

代码示例来源:origin: org.apache.flume.flume-ng-sinks/flume-ng-morphline-solr-sink

  1. @Override
  2. public void rollbackTransaction() {
  3. Notifications.notifyRollbackTransaction(morphline);
  4. }

相关文章