Commit 4e099262 authored by Tristan Cavelier's avatar Tristan Cavelier

Redesigning job rules in order to add some rules at any time.

parent 979fca4a
......@@ -1115,20 +1115,89 @@ var jobRules = (function(spec, my) {
var that = {};
// Attributes //
var priv = {};
priv.compare = {};
priv.action = {};
that.eliminate = function() { return 'eliminate'; };
that.update = function() { return 'update'; };
that.dontAccept = function() { return 'dont accept'; };
that.wait = function() { return 'wait'; };
that.none = function() { return 'none'; };
priv.compare = {
};
priv.default_compare = function(job1,job2) {
that.default_action = that.none;
that.default_compare = function(job1,job2) {
return (job1.getCommand().getPath() === job2.getCommand().getPath() &&
JSON.stringify(job1.getStorage().serialized()) ===
JSON.stringify(job2.getStorage().serialized()));
};
priv.action = {
// Methods //
priv.getAction = function(job1,job2) {
var j1label, j2label, j1status;
j1label = job1.getCommand().getLabel();
j2label = job2.getCommand().getLabel();
j1status = (job1.getStatus().getLabel()==='on going'?
'on going':'not on going');
if (priv.action[j1label] &&
priv.action[j1label][j1status] &&
priv.action[j1label][j1status][j2label]) {
return priv.action[j1label][j1status][j2label](job1,job2);
} else {
return that.default_action(job1,job2);
}
};
priv.canCompare = function(job1,job2) {
var job1label = job1.getCommand().getLabel(),
job2label = job2.getCommand().getLabel();
if (priv.compare[job1label] &&
priv.compare[job2label]) {
return priv.compare[job1label][job2label](job1,job2);
} else {
return that.default_compare(job1,job2);
}
};
/**
* Returns an action string to show what to do if we want to add a job.
* @method validateJobAccordingToJob
* @param job1 {object} The current job.
* @param job2 {object} The new job.
* @return {string} The action string.
*/
that.validateJobAccordingToJob = function(job1,job2) {
if (priv.canCompare(job1,job2)) {
return {action:priv.getAction(job1,job2),job:job1};
}
return {action:that.default_action(job1,job2),job:job1};
};
/**
* Adds a rule the action rules.
* @method addActionRule
* @param method1 {string} The action label from the current job.
* @param ongoing {boolean} Is this action is on going or not?
* @param method2 {string} The action label from the new job.
* @param rule {function} The rule that return an action string.
*/
that.addActionRule = function(method1,ongoing,method2,rule) {
var ongoing_s = (ongoing?'on going':'not on going');
priv.action[method1] = priv.action[method1] || {};
priv.action[method1][ongoing_s] = priv.action[method1][ongoing_s] || {};
priv.action[method1][ongoing_s][method2] = rule;
};
/**
* Adds a rule the compare rules.
* @method addCompareRule
* @param method1 {string} The action label from the current job.
* @param method2 {string} The action label from the new job.
* @param rule {function} The rule that return a boolean
* - true if job1 and job2 can be compared, else false.
*/
that.addCompareRule = function(method1,method2,rule) {
priv.compare[method1] = priv.compare[method1] || {};
priv.compare[method1][method2] = rule;
};
/*
LEGEND:
- s: storage
......@@ -1179,103 +1248,36 @@ var jobRules = (function(spec, my) {
For more information, see documentation
*/
'saveDocument':{
'on going':{
'saveDocument' :function(job1,job2){
that.addActionRule ('saveDocument',true,'saveDocument',
function(job1,job2){
if (job1.getCommand().getContent() ===
job2.getCommand().getContent()) {
return that.dontAccept();
} else {
return that.wait();
}
},
'loadDocument' : that.wait,
'removeDocument' : that.wait,
'getDocumentList' : that.none
},
'not on going':{
'saveDocument' : that.update,
'loadDocument' : that.wait,
'removeDocument' : that.eliminate,
'getDocumentList' : that.none
}
},
'loadDocument':{
'on going':{
'saveDocument' : that.wait,
'loadDocument' : that.dontAccept,
'removeDocument' : that.wait,
'getDocumentList' : that.none
},
'not on going':{
'saveDocument' : that.wait,
'loadDocument' : that.update,
'removeDocument' : that.wait,
'getDocumentList' : that.none
}
},
'removeDocument':{
'on going':{
'saveDocument' : that.wait,
'loadDocument' : that.dontAccept,
'removeDocument' : that.dontAccept,
'getDocumentList' : that.none
},
'not on going':{
'saveDocument' : that.eliminate,
'loadDocument' : that.dontAccept,
'removeDocument' : that.update,
'getDocumentList' : that.none
}
},
'getDocumentList':{
'on going':{
'saveDocument' : that.none,
'loadDocument' : that.none,
'removeDocument' : that.none,
'getDocumentList' : that.dontAccept
},
'not on going':{
'saveDocument' : that.none,
'loadDocument' : that.none,
'removeDocument' : that.none,
'getDocumentList' : that.update
}
}
};
priv.default_action = that.none;
// Methods //
priv.getAction = function(job1,job2) {
var j1label, j2label, j1status;
j1label = job1.getCommand().getLabel();
j2label = job2.getCommand().getLabel();
j1status = (job1.getStatus().getLabel()==='on going'?
'on going':'not on going');
if (priv.action[j1label] &&
priv.action[j1label][j1status] &&
priv.action[j1label][j1status][j2label]) {
return priv.action[j1label][j1status][j2label](job1,job2);
} else {
return priv.default_action(job1,job2);
}
};
priv.canCompare = function(job1,job2) {
var job1label = job1.getCommand().getLabel(),
job2label = job2.getCommand().getLabel();
if (priv.compare[job1label] &&
priv.compare[job2label]) {
return priv.compare[job1label][job2label](job1,job2);
} else {
return priv.default_compare(job1,job2);
}
};
that.validateJobAccordingToJob = function(job1,job2) {
if (priv.canCompare(job1,job2)) {
return {action:priv.getAction(job1,job2),job:job1};
}
return {action:priv.default_action(job1,job2),job:job1};
};
});
that.addActionRule('saveDocument' ,true ,'loadDocument' ,that.wait);
that.addActionRule('saveDocument' ,true ,'removeDocument' ,that.wait);
that.addActionRule('saveDocument' ,false,'saveDocument' ,that.update);
that.addActionRule('saveDocument' ,false,'loadDocument' ,that.wait);
that.addActionRule('saveDocument' ,false,'removeDocument' ,that.eliminate);
that.addActionRule('loadDocument' ,true ,'saveDocument' ,that.wait);
that.addActionRule('loadDocument' ,true ,'loadDocument' ,that.dontAccept);
that.addActionRule('loadDocument' ,true ,'removeDocument' ,that.wait);
that.addActionRule('loadDocument' ,false,'saveDocument' ,that.wait);
that.addActionRule('loadDocument' ,false,'loadDocument' ,that.update);
that.addActionRule('loadDocument' ,false,'removeDocument' ,that.wait);
that.addActionRule('removeDocument' ,true ,'loadDocument' ,that.dontAccept);
that.addActionRule('removeDocument' ,true ,'removeDocument' ,that.dontAccept);
that.addActionRule('removeDocument' ,false,'saveDocument' ,that.eliminate);
that.addActionRule('removeDocument' ,false,'loadDocument' ,that.dontAccept);
that.addActionRule('removeDocument' ,false,'removeDocument' ,that.update);
that.addActionRule('getDocumentList',true ,'getDocumentList',that.dontAccept);
that.addActionRule('getDocumentList',false,'getDocumentList',that.update);
return that;
}());
......@@ -1333,6 +1335,15 @@ var jobRules = (function(spec, my) {
return priv.id;
};
/**
* Returns the jio job rules object used by the job manager.
* @method getJobRules
* @return {object} The job rules object
*/
that.getJobRules = function() {
return jobRules;
};
/**
* Checks if the storage description is valid or not.
* @method validateStorageDescription
......
This diff is collapsed.
......@@ -52,6 +52,15 @@
return priv.id;
};
/**
* Returns the jio job rules object used by the job manager.
* @method getJobRules
* @return {object} The job rules object
*/
that.getJobRules = function() {
return jobRules;
};
/**
* Checks if the storage description is valid or not.
* @method validateStorageDescription
......
......@@ -2,20 +2,89 @@ var jobRules = (function(spec, my) {
var that = {};
// Attributes //
var priv = {};
priv.compare = {};
priv.action = {};
that.eliminate = function() { return 'eliminate'; };
that.update = function() { return 'update'; };
that.dontAccept = function() { return 'dont accept'; };
that.wait = function() { return 'wait'; };
that.none = function() { return 'none'; };
priv.compare = {
};
priv.default_compare = function(job1,job2) {
that.default_action = that.none;
that.default_compare = function(job1,job2) {
return (job1.getCommand().getPath() === job2.getCommand().getPath() &&
JSON.stringify(job1.getStorage().serialized()) ===
JSON.stringify(job2.getStorage().serialized()));
};
priv.action = {
// Methods //
priv.getAction = function(job1,job2) {
var j1label, j2label, j1status;
j1label = job1.getCommand().getLabel();
j2label = job2.getCommand().getLabel();
j1status = (job1.getStatus().getLabel()==='on going'?
'on going':'not on going');
if (priv.action[j1label] &&
priv.action[j1label][j1status] &&
priv.action[j1label][j1status][j2label]) {
return priv.action[j1label][j1status][j2label](job1,job2);
} else {
return that.default_action(job1,job2);
}
};
priv.canCompare = function(job1,job2) {
var job1label = job1.getCommand().getLabel(),
job2label = job2.getCommand().getLabel();
if (priv.compare[job1label] &&
priv.compare[job2label]) {
return priv.compare[job1label][job2label](job1,job2);
} else {
return that.default_compare(job1,job2);
}
};
/**
* Returns an action string to show what to do if we want to add a job.
* @method validateJobAccordingToJob
* @param job1 {object} The current job.
* @param job2 {object} The new job.
* @return {string} The action string.
*/
that.validateJobAccordingToJob = function(job1,job2) {
if (priv.canCompare(job1,job2)) {
return {action:priv.getAction(job1,job2),job:job1};
}
return {action:that.default_action(job1,job2),job:job1};
};
/**
* Adds a rule the action rules.
* @method addActionRule
* @param method1 {string} The action label from the current job.
* @param ongoing {boolean} Is this action is on going or not?
* @param method2 {string} The action label from the new job.
* @param rule {function} The rule that return an action string.
*/
that.addActionRule = function(method1,ongoing,method2,rule) {
var ongoing_s = (ongoing?'on going':'not on going');
priv.action[method1] = priv.action[method1] || {};
priv.action[method1][ongoing_s] = priv.action[method1][ongoing_s] || {};
priv.action[method1][ongoing_s][method2] = rule;
};
/**
* Adds a rule the compare rules.
* @method addCompareRule
* @param method1 {string} The action label from the current job.
* @param method2 {string} The action label from the new job.
* @param rule {function} The rule that return a boolean
* - true if job1 and job2 can be compared, else false.
*/
that.addCompareRule = function(method1,method2,rule) {
priv.compare[method1] = priv.compare[method1] || {};
priv.compare[method1][method2] = rule;
};
/*
LEGEND:
- s: storage
......@@ -66,102 +135,35 @@ var jobRules = (function(spec, my) {
For more information, see documentation
*/
'saveDocument':{
'on going':{
'saveDocument' :function(job1,job2){
that.addActionRule ('saveDocument',true,'saveDocument',
function(job1,job2){
if (job1.getCommand().getContent() ===
job2.getCommand().getContent()) {
return that.dontAccept();
} else {
return that.wait();
}
},
'loadDocument' : that.wait,
'removeDocument' : that.wait,
'getDocumentList' : that.none
},
'not on going':{
'saveDocument' : that.update,
'loadDocument' : that.wait,
'removeDocument' : that.eliminate,
'getDocumentList' : that.none
}
},
'loadDocument':{
'on going':{
'saveDocument' : that.wait,
'loadDocument' : that.dontAccept,
'removeDocument' : that.wait,
'getDocumentList' : that.none
},
'not on going':{
'saveDocument' : that.wait,
'loadDocument' : that.update,
'removeDocument' : that.wait,
'getDocumentList' : that.none
}
},
'removeDocument':{
'on going':{
'saveDocument' : that.wait,
'loadDocument' : that.dontAccept,
'removeDocument' : that.dontAccept,
'getDocumentList' : that.none
},
'not on going':{
'saveDocument' : that.eliminate,
'loadDocument' : that.dontAccept,
'removeDocument' : that.update,
'getDocumentList' : that.none
}
},
'getDocumentList':{
'on going':{
'saveDocument' : that.none,
'loadDocument' : that.none,
'removeDocument' : that.none,
'getDocumentList' : that.dontAccept
},
'not on going':{
'saveDocument' : that.none,
'loadDocument' : that.none,
'removeDocument' : that.none,
'getDocumentList' : that.update
}
}
};
priv.default_action = that.none;
// Methods //
priv.getAction = function(job1,job2) {
var j1label, j2label, j1status;
j1label = job1.getCommand().getLabel();
j2label = job2.getCommand().getLabel();
j1status = (job1.getStatus().getLabel()==='on going'?
'on going':'not on going');
if (priv.action[j1label] &&
priv.action[j1label][j1status] &&
priv.action[j1label][j1status][j2label]) {
return priv.action[j1label][j1status][j2label](job1,job2);
} else {
return priv.default_action(job1,job2);
}
};
priv.canCompare = function(job1,job2) {
var job1label = job1.getCommand().getLabel(),
job2label = job2.getCommand().getLabel();
if (priv.compare[job1label] &&
priv.compare[job2label]) {
return priv.compare[job1label][job2label](job1,job2);
} else {
return priv.default_compare(job1,job2);
}
};
that.validateJobAccordingToJob = function(job1,job2) {
if (priv.canCompare(job1,job2)) {
return {action:priv.getAction(job1,job2),job:job1};
}
return {action:priv.default_action(job1,job2),job:job1};
};
});
that.addActionRule('saveDocument' ,true ,'loadDocument' ,that.wait);
that.addActionRule('saveDocument' ,true ,'removeDocument' ,that.wait);
that.addActionRule('saveDocument' ,false,'saveDocument' ,that.update);
that.addActionRule('saveDocument' ,false,'loadDocument' ,that.wait);
that.addActionRule('saveDocument' ,false,'removeDocument' ,that.eliminate);
that.addActionRule('loadDocument' ,true ,'saveDocument' ,that.wait);
that.addActionRule('loadDocument' ,true ,'loadDocument' ,that.dontAccept);
that.addActionRule('loadDocument' ,true ,'removeDocument' ,that.wait);
that.addActionRule('loadDocument' ,false,'saveDocument' ,that.wait);
that.addActionRule('loadDocument' ,false,'loadDocument' ,that.update);
that.addActionRule('loadDocument' ,false,'removeDocument' ,that.wait);
that.addActionRule('removeDocument' ,true ,'loadDocument' ,that.dontAccept);
that.addActionRule('removeDocument' ,true ,'removeDocument' ,that.dontAccept);
that.addActionRule('removeDocument' ,false,'saveDocument' ,that.eliminate);
that.addActionRule('removeDocument' ,false,'loadDocument' ,that.dontAccept);
that.addActionRule('removeDocument' ,false,'removeDocument' ,that.update);
that.addActionRule('getDocumentList',true ,'getDocumentList',that.dontAccept);
that.addActionRule('getDocumentList',false,'getDocumentList',that.update);
return that;
}());
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