List of usage examples for org.apache.hadoop.hdfs.inotify Event getEventType
public EventType getEventType()
From source file:alluxio.underfs.hdfs.activesync.SupportedHdfsActiveSyncProvider.java
License:Apache License
private boolean processEvent(Event event, List<AlluxioURI> syncPointList, long txId) { boolean fileMatch = false; String filePath = ""; String renameFilePath = ""; switch (event.getEventType()) { case CREATE:/*from w w w .ja v a 2s.c om*/ Event.CreateEvent createEvent = (Event.CreateEvent) event; filePath = createEvent.getPath(); break; case UNLINK: Event.UnlinkEvent unlinkEvent = (Event.UnlinkEvent) event; filePath = unlinkEvent.getPath(); break; case APPEND: Event.AppendEvent appendEvent = (Event.AppendEvent) event; filePath = appendEvent.getPath(); break; case RENAME: Event.RenameEvent renameEvent = (Event.RenameEvent) event; filePath = renameEvent.getSrcPath(); renameFilePath = renameEvent.getDstPath(); break; case METADATA: Event.MetadataUpdateEvent metadataUpdateEvent = (Event.MetadataUpdateEvent) event; filePath = metadataUpdateEvent.getPath(); break; default: break; } if (filePath.isEmpty()) { return false; } for (AlluxioURI syncPoint : syncPointList) { try { // find out if the changed file falls under one of the sync points if (PathUtils.hasPrefix(filePath, syncPoint.getPath())) { fileMatch = true; recordFileChanged(syncPoint.toString(), filePath, txId); } } catch (InvalidPathException e) { LOG.info("Invalid path encountered {} ", filePath); } try { // find out if the changed file falls under one of the sync points if ((!renameFilePath.isEmpty()) && PathUtils.hasPrefix(renameFilePath, syncPoint.getPath())) { fileMatch = true; recordFileChanged(syncPoint.toString(), renameFilePath, txId); } } catch (InvalidPathException e) { LOG.info("Invalid path encountered {} ", renameFilePath); } } try (LockResource r = new LockResource(mWriteLock)) { mCurrentTxId = txId; } return fileMatch; }
From source file:hdfs.jsr203.HadoopWatchKey.java
License:Apache License
private void buildFromHadoop(Event raw_event, ArrayList<WatchEvent<?>> ls) { switch (raw_event.getEventType()) { case APPEND:/*from ww w . j ava 2s . co m*/ // Java 1.7 doesn't manage "APPEND" event // For append we translate to "MODIFY" AppendEvent appendEvent = (AppendEvent) raw_event; HadoopPath hadoopAppendPath = new HadoopPath(path.getFileSystem(), appendEvent.getPath().getBytes()); ls.add(new HadoopCreateWatchEvent(hadoopAppendPath, StandardWatchEventKinds.ENTRY_MODIFY)); break; case CREATE: // Create events are OK CreateEvent createEvent = (CreateEvent) raw_event; HadoopPath hadoopPath = new HadoopPath(path.getFileSystem(), createEvent.getPath().getBytes()); ls.add(new HadoopCreateWatchEvent(path.relativize(hadoopPath), StandardWatchEventKinds.ENTRY_CREATE)); break; case CLOSE: // Java 1.7 doesn't manage "CLOSE" event // For close we translate to "MODIFY" CloseEvent closeEvent = (CloseEvent) raw_event; HadoopPath hadoopClosePath = new HadoopPath(path.getFileSystem(), closeEvent.getPath().getBytes()); ls.add(new HadoopCreateWatchEvent(hadoopClosePath, StandardWatchEventKinds.ENTRY_MODIFY)); break; case METADATA: // Java 1.7 doesn't manage "METADATA" event // For meta data we translate to "MODIFY" MetadataUpdateEvent metadataEvent = (MetadataUpdateEvent) raw_event; HadoopPath hadoopMetadataPath = new HadoopPath(path.getFileSystem(), metadataEvent.getPath().getBytes()); ls.add(new HadoopCreateWatchEvent(hadoopMetadataPath, StandardWatchEventKinds.ENTRY_MODIFY)); break; case RENAME: // Java 1.7 doesn't manage "RENAME" event // For RENAME we translate to "DELETE" and "CREATE" RenameEvent renameEvent = (RenameEvent) raw_event; HadoopPath hadoopRenameSrcPath = new HadoopPath(path.getFileSystem(), renameEvent.getSrcPath().getBytes()); HadoopPath hadoopRenameDstPath = new HadoopPath(path.getFileSystem(), renameEvent.getDstPath().getBytes()); ls.add(new HadoopCreateWatchEvent(hadoopRenameSrcPath, StandardWatchEventKinds.ENTRY_DELETE)); ls.add(new HadoopCreateWatchEvent(hadoopRenameDstPath, StandardWatchEventKinds.ENTRY_CREATE)); break; case UNLINK: // Java 1.7 doesn't manage "UNLINK" event // For UNLINK we translate to "MODIFY" UnlinkEvent unlinkEvent = (UnlinkEvent) raw_event; HadoopPath hadoopUnlinkPath = new HadoopPath(path.getFileSystem(), unlinkEvent.getPath().getBytes()); ls.add(new HadoopCreateWatchEvent(hadoopUnlinkPath, StandardWatchEventKinds.ENTRY_MODIFY)); break; default: System.err.println("Eventype not know: " + raw_event.getEventType().name()); } }
From source file:org.apache.nifi.processors.hadoop.inotify.GetHDFSEvents.java
License:Apache License
private boolean toProcessEvent(ProcessContext context, Event event) { final String[] eventTypes = context.getProperty(EVENT_TYPES).getValue().split(","); for (String name : eventTypes) { if (name.trim().equalsIgnoreCase(event.getEventType().name())) { return notificationConfig.getPathFilter().accept(new Path(getPath(event))); }// ww w . jav a 2s . c o m } return false; }
From source file:org.apache.nifi.processors.hadoop.inotify.GetHDFSEvents.java
License:Apache License
private String getPath(Event event) { if (event == null || event.getEventType() == null) { throw new IllegalArgumentException("Event and event type must not be null."); }/*from w ww .java 2 s . c o m*/ switch (event.getEventType()) { case CREATE: return ((Event.CreateEvent) event).getPath(); case CLOSE: return ((Event.CloseEvent) event).getPath(); case APPEND: return ((Event.AppendEvent) event).getPath(); case RENAME: return ((Event.RenameEvent) event).getSrcPath(); case METADATA: return ((Event.MetadataUpdateEvent) event).getPath(); case UNLINK: return ((Event.UnlinkEvent) event).getPath(); default: throw new IllegalArgumentException("Unsupported event type."); } }