public URI getBpURI(String bpid, String currentStorageDir) { try { File localFile = new File(getUri()); return new File(new File(localFile, currentStorageDir), bpid).toURI(); } catch (IllegalArgumentException e) { return null; } }
private StorageDirectory(File dir, StorageDirType dirType, boolean isShared, StorageLocation location) { this.root = dir; this.lock = null; // default dirType is UNDEFINED this.dirType = (dirType == null ? NameNodeDirType.UNDEFINED : dirType); this.isShared = isShared; this.location = location; assert location == null || dir == null || dir.getAbsolutePath().startsWith( new File(location.getUri()).getAbsolutePath()): "The storage location and directory should be equal"; }
private static File getStorageLocationFile(StorageLocation location) { if (location == null || location.getStorageType() == StorageType.PROVIDED) { return null; } try { return new File(location.getUri()); } catch (IllegalArgumentException e) { //if location does not refer to a File return null; } }
@Override public void updateWithReplica(StorageLocation replicaLocation) { // for local replicas, the replica location is assumed to be a file. File diskFile = null; try { diskFile = new File(replicaLocation.getUri()); } catch (IllegalArgumentException e) { diskFile = null; } if (null == diskFile) { setDirInternal(null); } else { setDirInternal(diskFile.getParentFile()); } }
ProvidedVolumeImpl(FsDatasetImpl dataset, String storageID, StorageDirectory sd, FileIoProvider fileIoProvider, Configuration conf) throws IOException { super(dataset, storageID, sd, fileIoProvider, conf, null); assert getStorageLocation().getStorageType() == StorageType.PROVIDED: "Only provided storages must use ProvidedVolume"; baseURI = getStorageLocation().getUri(); df = new ProvidedVolumeDF(); remoteFS = FileSystem.get(baseURI, conf); }
static List<StorageLocation> checkStorageLocations( Collection<StorageLocation> dataDirs, LocalFileSystem localFS, DataNodeDiskChecker dataNodeDiskChecker) throws IOException { ArrayList<StorageLocation> locations = new ArrayList<StorageLocation>(); StringBuilder invalidDirs = new StringBuilder(); for (StorageLocation location : dataDirs) { final URI uri = location.getUri(); try { dataNodeDiskChecker.checkDir(localFS, new Path(uri)); locations.add(location); } catch (IOException ioe) { LOG.warn("Invalid " + DFS_DATANODE_DATA_DIR_KEY + " " + location.getFile() + " : ", ioe); invalidDirs.append("\"").append(uri.getPath()).append("\" "); } } if (locations.size() == 0) { throw new IOException("All directories in " + DFS_DATANODE_DATA_DIR_KEY + " are invalid: " + invalidDirs); } return locations; }
static List<StorageLocation> checkStorageLocations( Collection<StorageLocation> dataDirs, LocalFileSystem localFS, DataNodeDiskChecker dataNodeDiskChecker) throws IOException { ArrayList<StorageLocation> locations = new ArrayList<StorageLocation>(); StringBuilder invalidDirs = new StringBuilder(); for (StorageLocation location : dataDirs) { final URI uri = location.getUri(); try { dataNodeDiskChecker.checkDir(localFS, new Path(uri)); locations.add(location); } catch (IOException ioe) { LOG.warn("Invalid " + DFS_DATANODE_DATA_DIR_KEY + " " + location.getFile() + " : ", ioe); invalidDirs.append("\"").append(uri.getPath()).append("\" "); } } if (locations.size() == 0) { throw new IOException("All directories in " + DFS_DATANODE_DATA_DIR_KEY + " are invalid: " + invalidDirs); } return locations; }
assertThat(locations.size(), is(5)); assertThat(locations.get(0).getStorageType(), is(StorageType.DISK)); assertThat(locations.get(0).getUri(), is(dir0.toURI())); assertThat(locations.get(1).getStorageType(), is(StorageType.DISK)); assertThat(locations.get(1).getUri(), is(dir1.toURI())); assertThat(locations.get(2).getStorageType(), is(StorageType.SSD)); assertThat(locations.get(2).getUri(), is(dir2.toURI())); assertThat(locations.get(3).getStorageType(), is(StorageType.DISK)); assertThat(locations.get(3).getUri(), is(dir3.toURI())); assertThat(locations.get(4).getStorageType(), is(StorageType.RAM_DISK)); assertThat(locations.get(4).getUri(), is(dir4.toURI())); assertThat(locations.size(), is(2)); assertThat(locations.get(0).getStorageType(), is(StorageType.DISK)); assertThat(locations.get(0).getUri(), is(dir0.toURI())); assertThat(locations.get(1).getStorageType(), is(StorageType.DISK)); assertThat(locations.get(1).getUri(), is(dir1.toURI()));