List of usage examples for org.apache.hadoop.fs FileSystem getScheme
public String getScheme()
From source file:org.apache.gobblin.data.management.copy.CopyableFile.java
License:Apache License
/** * Set file system based source and destination dataset for this {@link CopyableFile} * * @param originFs {@link FileSystem} where this {@link CopyableFile} origins * @param targetFs {@link FileSystem} where this {@link CopyableFile} is copied to *///from w w w. ja va2 s. co m public void setFsDatasets(FileSystem originFs, FileSystem targetFs) { /* * By default, the raw Gobblin dataset for CopyableFile lineage is its parent folder * if itself is not a folder */ boolean isDir = origin.isDirectory(); Path fullSourcePath = Path.getPathWithoutSchemeAndAuthority(origin.getPath()); String sourceDatasetName = isDir ? fullSourcePath.toString() : fullSourcePath.getParent().toString(); DatasetDescriptor sourceDataset = new DatasetDescriptor(originFs.getScheme(), sourceDatasetName); sourceDataset.addMetadata(DatasetConstants.FS_URI, originFs.getUri().toString()); sourceData = sourceDataset; Path fullDestinationPath = Path.getPathWithoutSchemeAndAuthority(destination); String destinationDatasetName = isDir ? fullDestinationPath.toString() : fullDestinationPath.getParent().toString(); DatasetDescriptor destinationDataset = new DatasetDescriptor(targetFs.getScheme(), destinationDatasetName); destinationDataset.addMetadata(DatasetConstants.FS_URI, targetFs.getUri().toString()); destinationData = destinationDataset; }
From source file:org.apache.gobblin.data.management.copy.CopyableFileTest.java
License:Apache License
@Test public void testSetFsDatasets() throws URISyntaxException { FileSystem originFs = mock(FileSystem.class); String originFsUri = "hdfs://source.company.biz:2000"; String originPath = "/data/databases/source/profile"; when(originFs.getUri()).thenReturn(new URI(originFsUri)); when(originFs.getScheme()).thenReturn("hdfs"); FileSystem targetFs = mock(FileSystem.class); String targetFsUri = "file:///"; String destinationPath = "/data/databases/destination/profile"; when(targetFs.getUri()).thenReturn(new URI(targetFsUri)); when(targetFs.getScheme()).thenReturn("file"); // Test when source file is not a directory FileStatus origin = new FileStatus(0l, false, 0, 0l, 0l, new Path(originPath)); CopyableFile copyableFile = new CopyableFile(origin, new Path(destinationPath), null, null, null, PreserveAttributes.fromMnemonicString(""), "", 0, 0, Maps.<String, String>newHashMap(), "", null); copyableFile.setFsDatasets(originFs, targetFs); DatasetDescriptor source = (DatasetDescriptor) copyableFile.getSourceData(); Assert.assertEquals(source.getName(), "/data/databases/source"); Assert.assertEquals(source.getPlatform(), "hdfs"); Assert.assertEquals(source.getMetadata().get("fsUri"), originFsUri); DatasetDescriptor destination = (DatasetDescriptor) copyableFile.getDestinationData(); Assert.assertEquals(destination.getName(), "/data/databases/destination"); Assert.assertEquals(destination.getPlatform(), "file"); Assert.assertEquals(destination.getMetadata().get("fsUri"), targetFsUri); // Test when source file is a directory originPath = originFsUri + originPath; destinationPath = targetFsUri + destinationPath; origin = new FileStatus(0l, true, 0, 0l, 0l, new Path(originPath)); copyableFile = new CopyableFile(origin, new Path(destinationPath), null, null, null, PreserveAttributes.fromMnemonicString(""), "", 0, 0, Maps.<String, String>newHashMap(), "", null); copyableFile.setFsDatasets(originFs, targetFs); source = (DatasetDescriptor) copyableFile.getSourceData(); Assert.assertEquals(source.getName(), "/data/databases/source/profile"); Assert.assertEquals(source.getPlatform(), "hdfs"); Assert.assertEquals(source.getMetadata().get("fsUri"), originFsUri); destination = (DatasetDescriptor) copyableFile.getDestinationData(); Assert.assertEquals(destination.getName(), "/data/databases/destination/profile"); Assert.assertEquals(destination.getPlatform(), "file"); Assert.assertEquals(destination.getMetadata().get("fsUri"), targetFsUri); }
From source file:org.apache.gobblin.publisher.BaseDataPublisher.java
License:Apache License
/** * Create destination dataset descriptor *///from w ww. ja va 2 s. c o m protected DatasetDescriptor createDestinationDescriptor(WorkUnitState state, int branchId) { Path publisherOutputDir = getPublisherOutputDir(state, branchId); FileSystem fs = this.publisherFileSystemByBranches.get(branchId); DatasetDescriptor destination = new DatasetDescriptor(fs.getScheme(), publisherOutputDir.toString()); destination.addMetadata(DatasetConstants.FS_URI, fs.getUri().toString()); destination.addMetadata(DatasetConstants.BRANCH, String.valueOf(branchId)); return destination; }
From source file:org.apache.gobblin.util.filesystem.FileSystemInstrumentation.java
License:Apache License
public FileSystemInstrumentation(FileSystem underlying) { super(underlying.getScheme(), underlying.getScheme()); this.underlyingFs = underlying; Runtime.getRuntime().addShutdownHook(new Thread() { @Override/*w ww. j ava 2 s. c o m*/ public void run() { if (!FileSystemInstrumentation.this.closed) { onClose(); } } }); }