-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iRODS Rest strategy for data management implemented
- Loading branch information
massi
committed
Dec 17, 2014
1 parent
582e9cf
commit 635380c
Showing
4 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* @author Massimiliano Izzo | ||
*/ | ||
var IrodsRestStrategy = require('./lib/IrodsRestStrategy.js'); | ||
var FileSystemManager = require('./lib/FileSystemManager.js'); | ||
module.exports.IrodsRestStrategy = IrodsRestStrategy; | ||
module.exports.FileSystemManager = FileSystemManager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* @author Massimiliano Izzo | ||
* @description this builder works as a context for the query/search strategy | ||
*/ | ||
var IrodsRestStrategy = require('./IrodsRestStrategy.js'); | ||
|
||
function FileSystemManager(strategy, options) { | ||
if (!fileSystem) { | ||
strategy = new IrodsRestStrategy(options); | ||
} | ||
this.setStrategy(strategy); | ||
} | ||
|
||
FileSystemManager.prototype = { | ||
|
||
setStrategy: function(strategy) { | ||
this.strategy = strategy; | ||
}, | ||
|
||
storeFile: function() { | ||
this.strategy.storeFile.apply(this.fileSystem, arguments); | ||
} | ||
|
||
}; | ||
|
||
module.exports = FileSystemManager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/** | ||
* @author Massimiliano Izzo | ||
*/ | ||
var storeFileRule = [ | ||
'xtensFileMove {', | ||
'*destColl = str(*irodsHome)++"/"++str(*repoColl)++"/"++str(*dataTypeName);', | ||
'writeLine("serverLog", "idData is *idData");', | ||
'if (int(*idData) > 0) then {', | ||
'*destColl = *destColl ++ "/" ++ str(*idData);', | ||
'}', | ||
'writeLine("serverLog", "destColl is *destColl");', | ||
'msiCollCreate(str(*destColl), "1", *status) ::: msiRollback;', | ||
'*source = str(*irodsHome)++"/"++str(*landingColl)++"/"++str(*fileName);', | ||
'writeLine("serverLog", "source is *source");', | ||
'*destination = str(*destColl)++"/"++str(*fileName);', | ||
'writeLine("serverLog", "destination is *destination");', | ||
'msiDataObjRename(*source, *destination, "0", *status);', | ||
'}', | ||
'INPUT *irodsHome = "/biolabZone/home/superbiorods", *landingColl="land", *fileName = "void.txt", *dataTypeName = "none", *repoColl="test-repo", *idData =0', | ||
'OUTPUT *ruleExecOut' | ||
].join('\r\n'); | ||
|
||
/** | ||
* @description API to manage data through iRODS Rest API | ||
*/ | ||
function IrodsRestStrategy(irodsConf) { | ||
if (!irodsConf) { | ||
// throw some error | ||
return; | ||
} | ||
this.irodsHome = irodsConf.irodsHome; | ||
this.landingCollection = irodsConf.landingCollection; | ||
this.repoCollection = irodsConf.repoCollection; | ||
this.irodsRest = irodsConf.irodsRest; | ||
this.username = irodsConf.username; | ||
this.password = irodsConf.password; | ||
} | ||
|
||
IrodsRestStrategy.prototype = { | ||
|
||
storeFile: function(xtensDataFile, idData, dataTypeName, callback) { | ||
|
||
var file = xtensDataFile; | ||
var irodsRuleInputParameters = [ | ||
{name: "*irodsHome", value: this.irodsHome}, | ||
{name: "*dataTypeName", value: dataTypeName}, | ||
{name: "*fileName", value: file.name}, | ||
{name: "*landingColl", value: this.landingCollection}, | ||
{name: "*repoColl", value: this.repoCollection} | ||
]; | ||
|
||
if (idData) { | ||
console.log("adding idData..."); | ||
irodsRuleInputParameters.push({name: "*idData", value: idData}); | ||
} | ||
|
||
var postOptions = { | ||
hostname: this.irodsRest.hostname, | ||
port: this.irodsRest.port, | ||
path: this.irodsRest.path + '/rule', | ||
method: 'POST', | ||
auth: this.username + ':' + this.password, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Accept': 'application/json' | ||
} | ||
}; | ||
|
||
var postRequest = http.request(postOptions,function(res) { | ||
res.setEncoding('utf8'); | ||
|
||
var resBody = ''; | ||
|
||
res.on('data', function(chunk) { | ||
resBody += chunk; | ||
}); | ||
|
||
res.on('end', function() { | ||
console.log('res.end'); | ||
console.log(resBody); | ||
file.uri = this.irodsHome + "/" + this.repoColl + "/" + dataTypeName + "/" + | ||
(idData ? idData + "/" : "") + file.name; | ||
delete file.name; | ||
console.log("irods.moveFile: uri = " + file.uri); | ||
console.log("irods.moveFile: success...calling callback"); | ||
callback(); | ||
}); | ||
}); | ||
|
||
postRequest.on('error',function(err) { | ||
console.log('irods.moveFile: problem with request: ' + err.message); | ||
callback(err); | ||
}); | ||
|
||
var body = { | ||
ruleProcessingType: "INTERNAL", | ||
ruleAsOriginalText: storeFileRule, | ||
irodsRuleInputParameters: irodsRuleInputParameters | ||
}; | ||
|
||
postRequest.write(JSON.stringify(body)); | ||
postRequest.end(); | ||
|
||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "xtens-fs", | ||
"version": "1.0.0", | ||
"description": "A module for managing interaction with the file system in XTENS", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/biolab-unige/xtens-fs.git" | ||
}, | ||
"keywords": [ | ||
"file", | ||
"storage", | ||
"xtens", | ||
"irods" | ||
], | ||
"author": "Massimiliano Izzo", | ||
"license": "BSD", | ||
"bugs": { | ||
"url": "https://github.com/biolab-unige/xtens-fs/issues" | ||
}, | ||
"homepage": "https://github.com/biolab-unige/xtens-fs" | ||
} |