Support HDFS Tiering (#7484)

This is the 1st step to supporting HDFS Tiering
Changes:

Add new mounted folder icon. Will have separate commit for file icon
Disable delete/mkdir/upload for mounted files and folders
Disable delete for root HDFS folder (this was added in error)
This commit is contained in:
Kevin Cunnane
2019-10-03 14:48:19 -07:00
committed by GitHub
parent 18c12dac9a
commit e85f93abec
8 changed files with 146 additions and 20 deletions

View File

@@ -16,6 +16,7 @@ import * as nls from 'vscode-nls';
import * as constants from '../constants';
import { WebHDFS, HdfsError } from '../hdfs/webhdfs';
import { AclEntry, IAclStatus } from '../hdfs/aclEntry';
import { Mount, MountStatus } from '../hdfs/mount';
const localize = nls.loadMessageBundle();
@@ -29,9 +30,11 @@ export function joinHdfsPath(parent: string, child: string): string {
export interface IFile {
path: string;
isDirectory: boolean;
mountStatus?: MountStatus;
}
export class File implements IFile {
public mountStatus?: MountStatus;
constructor(public path: string, public isDirectory: boolean) {
}
@@ -58,7 +61,7 @@ export class File implements IFile {
}
export interface IFileSource {
enumerateFiles(path: string): Promise<IFile[]>;
enumerateFiles(path: string, refresh?: boolean): Promise<IFile[]>;
mkdir(dirName: string, remoteBasePath: string): Promise<void>;
createReadStream(path: string): fs.ReadStream;
readFile(path: string, maxBytes?: number): Promise<Buffer>;
@@ -159,18 +162,43 @@ export class FileSourceFactory {
}
export class HdfsFileSource implements IFileSource {
private mounts: Map<string, Mount>;
constructor(private client: WebHDFS) {
}
public enumerateFiles(path: string): Promise<IFile[]> {
public async enumerateFiles(path: string, refresh?: boolean): Promise<IFile[]> {
if (!this.mounts || refresh) {
await this.loadMounts();
}
return this.readdir(path);
}
private loadMounts(): Promise<void> {
return new Promise((resolve, reject) => {
this.client.getMounts((error, mounts) => {
this.mounts = new Map();
if (!error && mounts) {
mounts.forEach(m => this.mounts.set(m.mountPath, m));
}
resolve();
});
});
}
private readdir(path: string): Promise<IFile[]> {
return new Promise((resolve, reject) => {
this.client.readdir(path, (error, files) => {
if (error) {
reject(error);
} else {
let hdfsFiles: IFile[] = files.map(file => {
let hdfsFile = <IHdfsFileStatus>file;
return new File(File.createPath(path, hdfsFile.pathSuffix), hdfsFile.type === 'DIRECTORY');
}
else {
let hdfsFiles: IFile[] = files.map(fileStat => {
let hdfsFile = <IHdfsFileStatus>fileStat;
let file = new File(File.createPath(path, hdfsFile.pathSuffix), hdfsFile.type === 'DIRECTORY');
if (this.mounts && this.mounts.has(file.path)) {
file.mountStatus = MountStatus.Mount;
}
return file;
});
resolve(hdfsFiles);
}