Skip to content
Snippets Groups Projects
Commit 01eedc86 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

OAR: fixed a bug in the oar stat reading


Signed-off-by: default avatarNicola Vigano <nicola.vigano@esrf.fr>

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@634 4c865b51-4357-4376-afb4-474e03ccb993
parent ee1da7c3
No related branches found
No related tags found
No related merge requests found
function finalStruct = gtMergeStructs(struct1, struct2, var)
% MERGESTRUCTS
% finalStruct = mergeStructs(struct1, struct2, var)
fn = [ fieldnames(struct1); fieldnames(struct2) ];
tempStruct1 = struct2cell(struct1);
tempStruct2 = struct2cell(struct2);
if (any(size(tempStruct2) == 0))
% In case the variable was not given by oarstat, we make it an empty
% string
struct2 = [];
struct2.(var) = '';
tempStruct2 = struct2cell(struct2);
fn = [ fieldnames(struct1); fieldnames(struct2) ];
end
finalStruct = {cell2struct([tempStruct1; tempStruct2], fn, 1)};
end % end of sub-function mergeStructs
...@@ -6,100 +6,74 @@ function statsTable = gtOarGetStats(IDs, vars) ...@@ -6,100 +6,74 @@ function statsTable = gtOarGetStats(IDs, vars)
% Sub-functions % Sub-functions
%[sub]- mergeStructs %[sub]- mergeStructs
jobsStrs = arrayfun(@(id){[' -j ' num2str(id)]}, IDs); % Creating the job query string
jobsStr = ['! oarstat' jobsStrs{:} ' -f']; jobsStrs = arrayfun(@(id){[' -j ' num2str(id)]}, IDs);
[~, output] = unix(jobsStr); jobsStr = ['! oarstat' jobsStrs{:} ' -f'];
% Getting the output
[~, output] = unix(jobsStr);
% Now we chop the input: % Now we chop the input:
jobsBlocks = regexp(output, '\n\n', 'split'); jobsBlocks = regexp(output, '\n\n', 'split');
statsTable = cell(1, length(jobsBlocks) - 1); statsTable = cell(1, length(jobsBlocks) - 1);
for ii = 1:length(IDs) for ii = 1:length(IDs)
statsTable{ii}.('Job_Id') = IDs(ii); statsTable{ii}.('Job_Id') = IDs(ii);
end end
%%%%%%%%%%%%%% %%%%%%%%%%%%%%
% check vars % check vars
%%%%%%%%%%%%%% %%%%%%%%%%%%%%
possible_vars = {... possible_vars = {...
'assigned_hostnames',... 'assigned_hostnames', ...
'assigned_resources',... 'assigned_resources', ...
'command',... 'command', ...
'cpuset_name',... 'cpuset_name', ...
'dependencies',... 'dependencies', ...
'events',... 'events', ...
'exit_code',... 'exit_code', ...
'initial_request',... 'initial_request', ...
'job_array_id',... 'job_array_id', ...
'job_array_index',... 'job_array_index', ...
'jobType',... 'jobType', ...
'launchingDirectory',... 'launchingDirectory', ...
'message',... 'message', ...
'name',... 'name', ...
'owner',... 'owner', ...
'project',... 'project', ...
'properties',... 'properties', ...
'queue',... 'queue', ...
'reservation',... 'reservation', ...
'resubmit_job_id',... 'resubmit_job_id', ...
'scheduledStart',... 'scheduledStart', ...
'startTime',... 'startTime', ...
'state',... 'state', ...
'stopTime',... 'stopTime', ...
'submissionTime',... 'submissionTime', ...
'types',... 'types', ...
'walltime',... 'walltime', ...
'wanted_resources'}; 'wanted_resources' };
% [~,possible_vars] = unix(['oarstat -j ' num2str(IDs(1)) ' -f | awk -F" = " ''{print $1}'' | sort -busi']); if ((~iscell(vars)) && (strcmpi(vars, 'all')))
% possible_vars = strtrim(possible_vars); vars = possible_vars;
% possible_vars = regexp(possible_vars,'\s+','split'); else
% delete = cell2mat( cellfun(@(name) ~isempty(regexp(name,'\d','match')),possible_vars,'UniformOutput',false) ); % Removing not allowed variables
% delete = delete | cell2mat( cellfun(@(name) ~isempty(regexp(name,':','match')),possible_vars,'UniformOutput',false) ); [newVars, acceptedIDs] = intersect(vars, possible_vars);
% ind = find(delete == false);
% possible_vars = arrayfun(@(name) possible_vars(name),ind);
if strcmpi(vars, 'all') if (length(newVars) ~= length(vars))
vars = possible_vars; fprintf('Removing not existing variables for OAR:\n ')
else rejectedIDs = setdiff(1:length(vars), acceptedIDs);
check = cell2mat( cellfun(@(name) any(strcmpi(possible_vars, name)), vars, 'UniformOutput', false) ); fprintf(' %s', vars{rejectedIDs});
ind2 = find(check == false); fprintf('\n');
if ~isempty(ind2) end
disp('Removing not existing variables for OAR...')
arrayfun(@(ind) disp(vars{ind}),ind2)
vars = vars(check==true);
disp('Possible variables are: ')
disp(possible_vars)
end
end
if (~isempty(statsTable)) vars = newVars;
jobsBlocks = jobsBlocks(1:end-1);
for ii = 1:length(vars)
stats = regexp(jobsBlocks, [vars{ii} ' = (?<' vars{ii} '>.*?)\n'], 'names', 'once');
statsTable = cellfun(@(x1, x2) mergeStructs(x1, x2, vars{ii}), statsTable, stats);
end end
end
%% % Now extract info from the output of 'oarstat'
% sub-functions if (~isempty(statsTable))
jobsBlocks = jobsBlocks(1:end-1);
function finalStruct = mergeStructs(struct1, struct2, var) for ii = 1:length(vars)
% MERGESTRUCTS stats = regexp(jobsBlocks, [vars{ii} ' = (?<' vars{ii} '>.*?)\n'], 'names', 'once');
% finalStruct = mergeStructs(struct1, struct2, var) statsTable = cellfun(@(x1, x2) gtMergeStructs(x1, x2, vars{ii}), statsTable, stats);
fn = [ fieldnames(struct1); fieldnames(struct2) ];
tempStruct1 = struct2cell(struct1);
tempStruct2 = struct2cell(struct2);
if (any(size(tempStruct2) == 0))
% In case the variable was not given by oarstat, we make it an empty
% string
struct2 = [];
struct2.(var) = '';
tempStruct2 = struct2cell(struct2);
fn = [ fieldnames(struct1); fieldnames(struct2) ];
end end
end
finalStruct = {cell2struct([tempStruct1; tempStruct2], fn, 1)};
end % end of sub-function mergeStructs
end % end of function end % end of function
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment