Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor client to use sciserver storage client. (Closes #1790) #1791

Merged
merged 6 commits into from
Jul 22, 2020
32 changes: 17 additions & 15 deletions src/common/compute/backends/sciserver-compute/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,30 +220,32 @@ define([
async _getFile (jobInfo, filename) {
const state = await this.getJobState(jobInfo);
if (state) {
const baseUrl = 'https://apps.sciserver.org/fileservice/api/file/';
const filepath = state.resultsFolderURI.replace(/\/?$/, '/') + filename;
const fileUrl = baseUrl + this._getEncodedFilePath(filepath);

const response = await this.fetch(fileUrl);
return await response.text();
const {config, dataInfo} = this._getStorageConfigAndDataInfo(filepath);
const storage = await Storage.getClient('sciserver-files', this.logger, config);
return (await storage.getFile(dataInfo)).toString('utf-8');
}
}

async _deleteFileDir (state) {
const baseUrl = 'https://apps.sciserver.org/fileservice/api/data/';
const filepath = state.command.split(' ').pop();
const fileUrl = baseUrl + this._getEncodedFilePath(filepath);
const response = await this.fetch(fileUrl, {method: 'DELETE'});
return await response.text();
const {dataInfo, config} = this._getStorageConfigAndDataInfo(filepath);
const storage = await Storage.getClient('sciserver-files', this.logger, config);
await storage.deleteDir(dataInfo.data.filename);
}

_getEncodedFilePath (filepath) {
_getStorageConfigAndDataInfo (filepath) {
const dirs = filepath.split('/').slice(4);
const filename = dirs.pop();
const drive = dirs.slice(0, 3).join('/') + '/';
const dirname = '/' + dirs.slice(3).join('/');

return drive + encodeURIComponent(dirname) + '/' + filename;
let [volumePool, username, volume] = dirs.slice(0, 3);
brollb marked this conversation as resolved.
Show resolved Hide resolved
const password = this.password;
volume = username + '/' + volume;
const filename = dirs.slice(3).join('/');
return {
config: {username, volumePool, password, volume},
dataInfo: {
data: {filename, volume, volumePool}
}
};
}

async _getComputeDomain () {
Expand Down