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

OAR: fixed a bug when deleting arrays. updateOar still needs some commenting!!


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

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@651 4c865b51-4357-4376-afb4-474e03ccb993
parent d971c939
No related branches found
No related tags found
No related merge requests found
...@@ -35,7 +35,7 @@ else ...@@ -35,7 +35,7 @@ else
end end
if ~isempty(fieldnames(oarparameters)) if ~isempty(fieldnames(oarparameters))
names = fieldnames(oarparameters); fnames = fieldnames(oarparameters);
error_ids.terminated = []; error_ids.terminated = [];
error_ids.error = []; error_ids.error = [];
...@@ -46,15 +46,18 @@ if ~isempty(fieldnames(oarparameters)) ...@@ -46,15 +46,18 @@ if ~isempty(fieldnames(oarparameters))
%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%
if (~isempty(funcname)) if (~isempty(funcname))
disp(['Looking for function named ' funcname ' ...']) disp(['Looking for function named ' funcname ' ...'])
match = strfind(names, funcname); match = strfind(fnames, funcname);
jj = 0; jj = 0;
while (~isempty(match) && (jj < length(names))) % XXX - Laura, what is this doing?? please comment!! looks like
% something very dirty. If you can avoid this kind of loops with
% while and jumping indexes, please do it! It gets very difficult to
% debug, in case of problems
while (~isempty(match) && (jj < length(fnames)))
jj = jj + 1; jj = jj + 1;
if isempty(match{jj}) if isempty(match{jj})
names(jj) = []; fnames(jj) = [];
k = jj; match(jj) = [];
match(k) = [];
jj = 0; jj = 0;
end end
end end
...@@ -62,17 +65,17 @@ if ~isempty(fieldnames(oarparameters)) ...@@ -62,17 +65,17 @@ if ~isempty(fieldnames(oarparameters))
if (strcmpi(action, 'delete')) if (strcmpi(action, 'delete'))
% loop over functions % loop over functions
for jj = 1:length(names) for jj = 1:length(fnames)
disp(['Deleting function ' names{jj} '...']); disp(['Deleting function ' fnames{jj} '...']);
arrayField = fieldnames(oarparameters.(names{jj})); arrayField = fieldnames(oarparameters.(fnames{jj}));
questionStr = ['Are you sure to remove the function ' names{jj} ' from OAR and oarparameters.mat? [y/n]']; questionStr = ['Are you sure to remove the function ' fnames{jj} ' from OAR and oarparameters.mat? [y/n]'];
check = inputwdefault(questionStr, 'y'); check = inputwdefault(questionStr, 'y');
if strcmpi(check, 'y') if strcmpi(check, 'y')
fprintf('Deleting jobs from OAR... ') fprintf('Deleting jobs from OAR... ')
cellfun(@(array) deleteOarArray(array(6:end)), arrayField); cellfun(@(array) deleteOarArray(array(6:end)), arrayField);
fprintf('Done.\nRemoving information about the jobs... ') fprintf('Done.\nRemoving information about the jobs... ')
oarparameters = rmfield(oarparameters, names{jj}); oarparameters = rmfield(oarparameters, fnames{jj});
save('oarparameters.mat', 'oarparameters', '-v7.3'); save('oarparameters.mat', 'oarparameters', '-v7.3');
fprintf('Done.\n') fprintf('Done.\n')
end end
...@@ -82,12 +85,12 @@ if ~isempty(fieldnames(oarparameters)) ...@@ -82,12 +85,12 @@ if ~isempty(fieldnames(oarparameters))
elseif (strcmpi(action, 'update')) elseif (strcmpi(action, 'update'))
% loop over functions % loop over functions
for jj = 1:length(names) for jj = 1:length(fnames)
arrays = fieldnames(oarparameters.(names{jj})); arrays = fieldnames(oarparameters.(fnames{jj}));
arrayName = names{jj}; arrayName = fnames{jj};
for k = 1:length(arrays) for kk = 1:length(arrays)
arrayField = arrays{k}; arrayField = arrays{kk};
[oarparameters, error_ids] = updateArray(oarparameters, arrayName, arrayField, error_ids); [oarparameters, error_ids] = updateArray(oarparameters, arrayName, arrayField, error_ids);
end % end for k end % end for k
end % end for j end % end for j
...@@ -99,54 +102,52 @@ if ~isempty(fieldnames(oarparameters)) ...@@ -99,54 +102,52 @@ if ~isempty(fieldnames(oarparameters))
print_structure(output,'output',false,true); print_structure(output,'output',false,true);
else else
disp(['Action ' action ' is not valid! Exiting...']) % Fail :)
return; error( 'OAR:wrong_argument', ...
'Action %s is not valid!', action)
end end
else else
%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%
% look for array number % % look for array number %
%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%
if any( cellfun(@(logarray) strcmpi(action, logarray), {'err','out','log','params','oar'}) ) if any( cellfun(@(logarray) strcmpi(action, logarray), {'err','out','log','params','oar'}) )
disp(['Looking for job number ' num2str(arrayid) '...']) fprintf('Looking for job number "%d"...\n', arrayid)
output = logviewOar(arrayid, action); output = logviewOar(arrayid, action);
print_structure(output,'output',false,true); print_structure(output, 'output', false, true);
else else
% loop over functions % loop over functions
disp(['Looking for array number ' num2str(arrayid) '...']) fprintf('Looking for array number "%d"...\n', arrayid)
for jj = 1:length(names) for jj = 1:length(fnames)
arrayName = names{jj}; arrayName = fnames{jj};
% search array id(s) for each function % search array id(s) for each function
arrays = logviewOar(arrayName, [], false); arrays = logviewOar(arrayName, [], false);
% check if arrayid exists % check if arrayid exists
if ~isempty(find(arrays.(arrayName).arrays == arrayid, 1)) if ~isempty(find(arrays.(arrayName).arrays == arrayid, 1))
% Do we want to delete?
arrayField = sprintf('array%d', arrayid);
if strcmpi(action, 'delete') if strcmpi(action, 'delete')
disp(['Deleting array n. ' num2str(arrayid) '...']);
disp(['Deleting array n. ' arrayField '...']);
questionStr = ['Are you sure to remove array ' num2str(arrayid) ' from oarparameters.mat? [y/n]']; questionStr = ['Are you sure to remove array ' num2str(arrayid) ' from oarparameters.mat? [y/n]'];
check = inputwdefault(questionStr, 'y'); check = inputwdefault(questionStr, 'y');
if strcmpi(check, 'y') if strcmpi(check, 'y')
fprintf('Deleting jobs from OAR... ') fprintf('Deleting jobs from OAR... ')
deleteOarArray(arrayField); deleteOarArray(arrayid);
fprintf('Done.\nRemoving information about the jobs... ') fprintf('Done.\nRemoving information about the jobs... ')
arrayField = sprintf('array%d', arrayid);
oarparameters.(arrayName) = rmfield(oarparameters.(arrayName), arrayField); oarparameters.(arrayName) = rmfield(oarparameters.(arrayName), arrayField);
save('oarparameters.mat', 'oarparameters', '-v7.3'); save('oarparameters.mat', 'oarparameters', '-v7.3');
fprintf('Done.\n') fprintf('Done.\n')
end end
% Do we want some update?
elseif strcmpi(action, 'update') elseif strcmpi(action, 'update')
[oarparameters, error_ids] = updateArray(oarparameters, arrayName, arrayField, error_ids); [oarparameters, error_ids] = updateArray(oarparameters, arrayName, arrayField, error_ids);
else else
disp(['Action ' action ' is not valid! Exiting...']) % Fail :)
return; error( 'OAR:wrong_argument', ...
'Action %s is not valid!', action)
end end
end % end if arrayid exists end % end if arrayid exists
...@@ -230,7 +231,6 @@ else ...@@ -230,7 +231,6 @@ else
elseif strcmpi(state, 'Error') elseif strcmpi(state, 'Error')
error_ids.error = [error_ids.error; jobid]; error_ids.error = [error_ids.error; jobid];
end end
end end
oarparameters.(arrayName).(arrayField).job = newJobs; oarparameters.(arrayName).(arrayField).job = newJobs;
......
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