Unverified Commit 638da0bd authored by J-shang's avatar J-shang Committed by GitHub
Browse files

cherry pick from PR3455 (#3528)

parent 4a0cc125
......@@ -146,6 +146,10 @@ class LinuxCommands extends OsCommands {
public fileExistCommand(filePath: string): string {
return `test -e ${filePath} && echo True || echo False`;
}
public getCurrentPath(): string {
return `pwd`;
}
}
export { LinuxCommands };
......@@ -134,6 +134,10 @@ class WindowsCommands extends OsCommands {
public fileExistCommand(filePath: string): string {
return `powershell Test-Path ${filePath} -PathType Leaf`;
}
public getCurrentPath(): string {
return `chdir`;
}
}
export { WindowsCommands };
......@@ -30,6 +30,7 @@ abstract class OsCommands {
public abstract executeScript(script: string, isFile: boolean): string;
public abstract setPythonPath(pythonPath: string | undefined, command: string | undefined): string | undefined;
public abstract fileExistCommand(filePath: string): string | undefined;
public abstract getCurrentPath(): string;
public joinPath(...paths: string[]): string {
let dir: string = paths.filter((path: any) => path !== '').join(this.pathSpliter);
......
......@@ -169,6 +169,16 @@ class ShellExecutor {
return this.tempPath;
}
public async getCurrentPath(): Promise<string> {
const commandText = this.osCommands && this.osCommands.getCurrentPath();
const commandResult = await this.execute(commandText);
if (commandResult.exitCode == 0) {
return commandResult.stdout;
} else {
throw Error(commandResult.stderr);
}
}
public getRemoteScriptsPath(experimentId: string): string {
return this.joinPath(this.getRemoteExperimentRootDir(experimentId), 'scripts');
}
......
......@@ -236,7 +236,10 @@ export class RemoteEnvironmentService extends EnvironmentService {
const executor = await this.getExecutor(environment.id);
if (environment.useSharedStorage) {
this.remoteExperimentRootDir = component.get<SharedStorageService>(SharedStorageService).remoteWorkingRoot;
const remoteMountCommand = component.get<SharedStorageService>(SharedStorageService).remoteMountCommand.replace(/echo -e /g, `echo `).replace(/echo /g, `echo -e `);
if (!this.remoteExperimentRootDir.startsWith('/')) {
this.remoteExperimentRootDir = executor.joinPath((await executor.getCurrentPath()).trim(), this.remoteExperimentRootDir);
}
const remoteMountCommand = component.get<SharedStorageService>(SharedStorageService).remoteMountCommand.replace(/echo -e /g, `echo `).replace(/echo /g, `echo -e `).replace(/\\\$/g, `\\\\\\$`);
const result = await executor.executeScript(remoteMountCommand, false, false);
if (result.exitCode !== 0) {
throw new Error(`Mount shared storage on remote machine failed.\n ERROR: ${result.stderr}`);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment