Loading src/uws/job/JobList.java +84 −84 Original line number Original line Diff line number Diff line Loading @@ -16,7 +16,7 @@ package uws.job; * You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * * * Copyright 2012-2018 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Copyright 2012-2020 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Astronomisches Rechen Institut (ARI) * Astronomisches Rechen Institut (ARI) */ */ Loading Loading @@ -175,7 +175,7 @@ import uws.service.log.UWSLog.LogLevel; * </i></p> * </i></p> * * * @author Grégory Mantelet (CDS;ARI) * @author Grégory Mantelet (CDS;ARI) * @version 4.3 (10/2017) * @version 4.5 (07/2020) * * * @see UWSJob * @see UWSJob */ */ Loading @@ -190,10 +190,10 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { private final String name; private final String name; /** <b>[Required]</b> List of jobs. */ /** <b>[Required]</b> List of jobs. */ protected final Map<String,UWSJob> jobsList; protected final Map<String, UWSJob> jobsList; /** <b>[Required]</b> List of jobs per owner. */ /** <b>[Required]</b> List of jobs per owner. */ protected final Map<JobOwner,Map<String,UWSJob>> ownerJobs; protected final Map<JobOwner, Map<String, UWSJob>> ownerJobs; /** The destruction manager to use to take into account the destructionTime /** The destruction manager to use to take into account the destructionTime * field of contained jobs. */ * field of contained jobs. */ Loading Loading @@ -226,7 +226,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @see #JobList(String, ExecutionManager) * @see #JobList(String, ExecutionManager) */ */ public JobList(String jobListName) throws NullPointerException{ public JobList(String jobListName) throws NullPointerException { this(jobListName, null, new DefaultDestructionManager()); this(jobListName, null, new DefaultDestructionManager()); } } Loading @@ -241,7 +241,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * or empty * or empty * or if no execution manager is provided. * or if no execution manager is provided. */ */ public JobList(String jobListName, ExecutionManager executionManager) throws NullPointerException{ public JobList(String jobListName, ExecutionManager executionManager) throws NullPointerException { this(jobListName, executionManager, new DefaultDestructionManager()); this(jobListName, executionManager, new DefaultDestructionManager()); } } Loading @@ -257,7 +257,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * or empty * or empty * or if no destruction manager is provided. * or if no destruction manager is provided. */ */ public JobList(String jobListName, DestructionManager destructionManager) throws NullPointerException{ public JobList(String jobListName, DestructionManager destructionManager) throws NullPointerException { this(jobListName, new DefaultExecutionManager(), destructionManager); this(jobListName, new DefaultExecutionManager(), destructionManager); } } Loading @@ -276,18 +276,18 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * or if no execution manager and destruction * or if no execution manager and destruction * manager are provided. * manager are provided. */ */ public JobList(String jobListName, ExecutionManager executionManager, DestructionManager destructionManager) throws NullPointerException{ public JobList(String jobListName, ExecutionManager executionManager, DestructionManager destructionManager) throws NullPointerException { if (jobListName == null) if (jobListName == null) throw new NullPointerException("Missing job list name ! => Impossible to build the job list."); throw new NullPointerException("Missing job list name ! => Impossible to build the job list."); else{ else { jobListName = jobListName.trim(); jobListName = jobListName.trim(); if (jobListName.length() == 0) if (jobListName.length() == 0) throw new NullPointerException("Missing job list name ! => Impossible to build the job list."); throw new NullPointerException("Missing job list name ! => Impossible to build the job list."); } } name = jobListName; name = jobListName; jobsList = new ConcurrentHashMap<String,UWSJob>(); jobsList = new ConcurrentHashMap<String, UWSJob>(); ownerJobs = new ConcurrentHashMap<JobOwner,Map<String,UWSJob>>(); ownerJobs = new ConcurrentHashMap<JobOwner, Map<String, UWSJob>>(); this.executionManager = executionManager; this.executionManager = executionManager; Loading @@ -306,7 +306,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @return Its UWS or <i>null</i> if this jobs list is not yet part of a * @return Its UWS or <i>null</i> if this jobs list is not yet part of a * specific UWS). * specific UWS). */ */ public final UWS getUWS(){ public final UWS getUWS() { return uws; return uws; } } Loading @@ -325,7 +325,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * with a UWS (different from the given * with a UWS (different from the given * one) and contains some jobs. * one) and contains some jobs. */ */ public final void setUWS(UWS newUws) throws IllegalStateException{ public final void setUWS(UWS newUws) throws IllegalStateException { if (newUws == null) if (newUws == null) return; return; else if (newUws.equals(uws)) else if (newUws.equals(uws)) Loading @@ -345,7 +345,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see UWS#getLogger() * @see UWS#getLogger() * @see UWSToolBox#getDefaultLogger() * @see UWSToolBox#getDefaultLogger() */ */ public UWSLog getLogger(){ public UWSLog getLogger() { if (getUWS() != null && getUWS().getLogger() != null) if (getUWS() != null && getUWS().getLogger() != null) return getUWS().getLogger(); return getUWS().getLogger(); else else Loading @@ -362,7 +362,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @return Its destruction manager. * @return Its destruction manager. */ */ public final DestructionManager getDestructionManager(){ public final DestructionManager getDestructionManager() { return destructionManager; return destructionManager; } } Loading @@ -385,14 +385,14 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see DestructionManager#remove(UWSJob) * @see DestructionManager#remove(UWSJob) * @see DestructionManager#update(UWSJob) * @see DestructionManager#update(UWSJob) */ */ public final void setDestructionManager(DestructionManager newManager){ public final void setDestructionManager(DestructionManager newManager) { if (newManager == null) if (newManager == null) return; return; DestructionManager oldManager = destructionManager; DestructionManager oldManager = destructionManager; destructionManager = newManager; destructionManager = newManager; for(UWSJob job : this){ for(UWSJob job : this) { oldManager.remove(job); oldManager.remove(job); destructionManager.update(job); destructionManager.update(job); } } Loading @@ -403,8 +403,8 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @return The used execution manager. * @return The used execution manager. */ */ public final ExecutionManager getExecutionManager(){ public final ExecutionManager getExecutionManager() { if (executionManager == null){ if (executionManager == null) { if (uws == null) if (uws == null) executionManager = new DefaultExecutionManager(); executionManager = new DefaultExecutionManager(); else else Loading @@ -427,16 +427,16 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see ExecutionManager#remove(UWSJob) * @see ExecutionManager#remove(UWSJob) * @see ExecutionManager#execute(UWSJob) * @see ExecutionManager#execute(UWSJob) */ */ public synchronized final void setExecutionManager(final ExecutionManager manager){ public synchronized final void setExecutionManager(final ExecutionManager manager) { if (manager == null) if (manager == null) return; return; ExecutionManager oldManager = executionManager; ExecutionManager oldManager = executionManager; executionManager = manager; executionManager = manager; if (oldManager != null){ if (oldManager != null) { for(UWSJob job : this){ for(UWSJob job : this) { if (job.getPhase() != ExecutionPhase.PENDING && !job.isFinished()){ if (job.getPhase() != ExecutionPhase.PENDING && !job.isFinished()) { oldManager.remove(job); oldManager.remove(job); executionManager.execute(job); executionManager.execute(job); } } Loading @@ -451,7 +451,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @since 4.3 * @since 4.3 */ */ public final JobDestructionPolicy getDestroyPolicy(){ public final JobDestructionPolicy getDestroyPolicy() { return destructionPolicy; return destructionPolicy; } } Loading @@ -465,7 +465,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @since 4.3 * @since 4.3 */ */ public final void setDestructionPolicy(JobDestructionPolicy destroyPolicy){ public final void setDestructionPolicy(JobDestructionPolicy destroyPolicy) { this.destructionPolicy = (destroyPolicy == null) ? DEFAULT_JOB_DESTRUCTION_POLICY : destroyPolicy; this.destructionPolicy = (destroyPolicy == null) ? DEFAULT_JOB_DESTRUCTION_POLICY : destroyPolicy; } } Loading @@ -477,7 +477,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see UWSService#getUrlInterpreter() * @see UWSService#getUrlInterpreter() * @see UWSUrl#listJobs(String) * @see UWSUrl#listJobs(String) */ */ public UWSUrl getUrl(){ public UWSUrl getUrl() { if (uws == null || uws.getUrlInterpreter() == null) if (uws == null || uws.getUrlInterpreter() == null) return null; return null; else else Loading @@ -489,7 +489,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @return JobList name. * @return JobList name. */ */ public final String getName(){ public final String getName() { return name; return name; } } Loading @@ -501,7 +501,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @return The requested job or <i>null</i> if there is no job with the * @return The requested job or <i>null</i> if there is no job with the * given ID. * given ID. */ */ public final UWSJob getJob(String jobID){ public final UWSJob getJob(String jobID) { return jobsList.get(jobID); return jobsList.get(jobID); } } Loading @@ -519,18 +519,18 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @throws UWSException If the given user is not allowed to read the content * @throws UWSException If the given user is not allowed to read the content * of this jobs list or to read the specified job. * of this jobs list or to read the specified job. */ */ public UWSJob getJob(String jobID, JobOwner user) throws UWSException{ public UWSJob getJob(String jobID, JobOwner user) throws UWSException { if (user != null && !user.hasReadPermission(this)) if (user != null && !user.hasReadPermission(this)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.readPermissionDenied(user, true, getName())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.readPermissionDenied(user, true, getName())); // Get the specified job: // Get the specified job: UWSJob job = jobsList.get(jobID); UWSJob job = jobsList.get(jobID); // Check the right of the specified user to see the job: // Check the right of the specified user to see the job: if (user != null && job != null && job.getOwner() != null){ if (user != null && job != null && job.getOwner() != null) { JobOwner owner = job.getOwner(); JobOwner owner = job.getOwner(); if (!owner.equals(user) && !user.hasReadPermission(job)) if (!owner.equals(user) && !user.hasReadPermission(job)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.readPermissionDenied(user, false, job.getJobId())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.readPermissionDenied(user, false, job.getJobId())); } } return job; return job; Loading @@ -543,7 +543,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @see #iterator() * @see #iterator() */ */ public final Iterator<UWSJob> getJobs(){ public final Iterator<UWSJob> getJobs() { return iterator(); return iterator(); } } Loading @@ -558,26 +558,26 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * or a NullIterator if the specified owner/user has no job * or a NullIterator if the specified owner/user has no job * or an iterator on all the jobs if <i>ownerId</i> is <i>null</i>. * or an iterator on all the jobs if <i>ownerId</i> is <i>null</i>. */ */ public Iterator<UWSJob> getJobs(JobOwner user){ public Iterator<UWSJob> getJobs(JobOwner user) { if (user == null) if (user == null) return iterator(); return iterator(); else{ else { if (ownerJobs.containsKey(user)) if (ownerJobs.containsKey(user)) return ownerJobs.get(user).values().iterator(); return ownerJobs.get(user).values().iterator(); else else return new Iterator<UWSJob>(){ return new Iterator<UWSJob>() { @Override @Override public boolean hasNext(){ public boolean hasNext() { return false; return false; } } @Override @Override public UWSJob next(){ public UWSJob next() { return null; return null; } } @Override @Override public void remove(){ public void remove() { ; ; } } }; }; Loading @@ -590,7 +590,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see java.lang.Iterable#iterator() * @see java.lang.Iterable#iterator() */ */ @Override @Override public final Iterator<UWSJob> iterator(){ public final Iterator<UWSJob> iterator() { return jobsList.values().iterator(); return jobsList.values().iterator(); } } Loading @@ -599,7 +599,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @return Number of jobs. * @return Number of jobs. */ */ public final int getNbJobs(){ public final int getNbJobs() { return jobsList.size(); return jobsList.size(); } } Loading @@ -611,10 +611,10 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @return Number of jobs that the given owner/user has, * @return Number of jobs that the given owner/user has, * or the number of all jobs if <i>user</i> is <i>null</i>. * or the number of all jobs if <i>user</i> is <i>null</i>. */ */ public final int getNbJobs(JobOwner user){ public final int getNbJobs(JobOwner user) { if (user == null) if (user == null) return getNbJobs(); return getNbJobs(); else{ else { if (ownerJobs.containsKey(user)) if (ownerJobs.containsKey(user)) return ownerJobs.get(user).size(); return ownerJobs.get(user).size(); else else Loading @@ -627,7 +627,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @return An iterator on owners. * @return An iterator on owners. */ */ public final Iterator<JobOwner> getUsers(){ public final Iterator<JobOwner> getUsers() { return ownerJobs.keySet().iterator(); return ownerJobs.keySet().iterator(); } } Loading @@ -636,7 +636,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @return The number of job owners. * @return The number of job owners. */ */ public final int getNbUsers(){ public final int getNbUsers() { return ownerJobs.size(); return ownerJobs.size(); } } Loading @@ -651,11 +651,11 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @return All the corresponding jobs. * @return All the corresponding jobs. */ */ public final List<UWSJob> searchJobs(String runID){ public final List<UWSJob> searchJobs(String runID) { ArrayList<UWSJob> foundJobs = new ArrayList<UWSJob>(); ArrayList<UWSJob> foundJobs = new ArrayList<UWSJob>(); runID = (runID != null) ? runID.trim() : runID; runID = (runID != null) ? runID.trim() : runID; if (runID != null && !runID.isEmpty()){ if (runID != null && !runID.isEmpty()) { for(UWSJob job : this) for(UWSJob job : this) if (job.getRunId().equalsIgnoreCase(runID)) if (job.getRunId().equalsIgnoreCase(runID)) foundJobs.add(job); foundJobs.add(job); Loading Loading @@ -683,27 +683,27 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see DestructionManager#update(UWSJob) * @see DestructionManager#update(UWSJob) * @see UWSJob#applyPhaseParam(JobOwner) * @see UWSJob#applyPhaseParam(JobOwner) */ */ public synchronized String addNewJob(final UWSJob j) throws UWSException{ public synchronized String addNewJob(final UWSJob j) throws UWSException { if (uws == null) if (uws == null) throw new IllegalStateException("Jobs can not be added to this job list until this job list is linked to a UWS!"); throw new IllegalStateException("Jobs can not be added to this job list until this job list is linked to a UWS!"); else if (j == null || jobsList.containsKey(j.getJobId())){ else if (j == null || jobsList.containsKey(j.getJobId())) { return null; return null; }else{ } else { JobOwner owner = j.getOwner(); JobOwner owner = j.getOwner(); // Check the WRITE permission of the owner of this job: // Check the WRITE permission of the owner of this job: if (owner != null && !owner.hasWritePermission(this)) if (owner != null && !owner.hasWritePermission(this)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(owner, true, getName())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(owner, true, getName())); // Set its job list: // Set its job list: j.setJobList(this); j.setJobList(this); // Add the job to the jobs list: // Add the job to the jobs list: jobsList.put(j.getJobId(), j); jobsList.put(j.getJobId(), j); if (owner != null){ if (owner != null) { // Index also this job in function of its owner: // Index also this job in function of its owner: if (!ownerJobs.containsKey(owner)) if (!ownerJobs.containsKey(owner)) ownerJobs.put(owner, new ConcurrentHashMap<String,UWSJob>()); ownerJobs.put(owner, new ConcurrentHashMap<String, UWSJob>()); ownerJobs.get(owner).put(j.getJobId(), j); ownerJobs.get(owner).put(j.getJobId(), j); } } Loading Loading @@ -744,10 +744,10 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @since 4.3 * @since 4.3 */ */ public boolean archiveJob(final String jobId){ public boolean archiveJob(final String jobId) { UWSJob job = getJob(jobId); UWSJob job = getJob(jobId); if (job != null){ if (job != null) { // Archive the job: // Archive the job: job.archive(); job.archive(); Loading @@ -756,7 +756,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { uws.getBackupManager().saveOwner(job.getOwner()); uws.getBackupManager().saveOwner(job.getOwner()); return true; return true; }else } else return false; return false; } } Loading @@ -781,13 +781,13 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @since 4.3 * @since 4.3 */ */ public boolean archiveJob(final String jobId, final JobOwner user) throws UWSException{ public boolean archiveJob(final String jobId, final JobOwner user) throws UWSException { if (user != null){ if (user != null) { if (!user.hasWritePermission(this)) if (!user.hasWritePermission(this)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(user, true, getName())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(user, true, getName())); UWSJob job = getJob(jobId); UWSJob job = getJob(jobId); if (job != null && job.getOwner() != null && !user.equals(job.getOwner()) && !user.hasWritePermission(job)) if (job != null && job.getOwner() != null && !user.equals(job.getOwner()) && !user.hasWritePermission(job)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(user, false, jobId)); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(user, false, jobId)); } } return archiveJob(jobId); return archiveJob(jobId); } } Loading @@ -806,7 +806,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @see DestructionManager#update(UWSJob) * @see DestructionManager#update(UWSJob) */ */ public final void updateDestruction(UWSJob job){ public final void updateDestruction(UWSJob job) { if (destructionManager != null && job != null && job.getJobList() != null && job.getJobList().equals(this)) if (destructionManager != null && job != null && job.getJobList() != null && job.getJobList().equals(this)) destructionManager.update(job); destructionManager.update(job); } } Loading @@ -821,14 +821,14 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @see DestructionManager#remove(UWSJob) * @see DestructionManager#remove(UWSJob) */ */ protected UWSJob removeJob(final String jobId){ protected UWSJob removeJob(final String jobId) { // Remove the specified job: // Remove the specified job: UWSJob removedJob = (jobId == null) ? null : jobsList.remove(jobId); UWSJob removedJob = (jobId == null) ? null : jobsList.remove(jobId); if (removedJob != null){ if (removedJob != null) { // Clear its owner index: // Clear its owner index: JobOwner owner = removedJob.getOwner(); JobOwner owner = removedJob.getOwner(); if (owner != null && ownerJobs.containsKey(owner)){ if (owner != null && ownerJobs.containsKey(owner)) { ownerJobs.get(owner).remove(jobId); ownerJobs.get(owner).remove(jobId); if (ownerJobs.get(owner).isEmpty()) if (ownerJobs.get(owner).isEmpty()) ownerJobs.remove(owner); ownerJobs.remove(owner); Loading @@ -838,7 +838,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { if (destructionManager != null) if (destructionManager != null) destructionManager.remove(removedJob); destructionManager.remove(removedJob); return removedJob; return removedJob; }else } else return null; return null; } } Loading Loading @@ -878,7 +878,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see UWSBackupManager#saveOwner(JobOwner) * @see UWSBackupManager#saveOwner(JobOwner) * @see #archiveJob(String) * @see #archiveJob(String) */ */ public boolean destroyJob(final String jobId){ public boolean destroyJob(final String jobId) { // Get the corresponding job and return immediately if none can be found: // Get the corresponding job and return immediately if none can be found: UWSJob job = getJob(jobId); UWSJob job = getJob(jobId); if (job == null) if (job == null) Loading @@ -904,11 +904,11 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * - policy = ALWAYS_DELETE, * - policy = ALWAYS_DELETE, * - policy = ARCHIVE_ON_DATE and the destruction date is not * - policy = ARCHIVE_ON_DATE and the destruction date is not * yet reached. */ * yet reached. */ if (job.getPhase() == ExecutionPhase.ARCHIVED || destructionPolicy == JobDestructionPolicy.ALWAYS_DELETE || (destructionPolicy == JobDestructionPolicy.ARCHIVE_ON_DATE && !dateReached)){ if (job.getPhase() == ExecutionPhase.ARCHIVED || destructionPolicy == JobDestructionPolicy.ALWAYS_DELETE || (destructionPolicy == JobDestructionPolicy.ARCHIVE_ON_DATE && !dateReached)) { // Remove the job: // Remove the job: UWSJob destroyedJob = removeJob(jobId); UWSJob destroyedJob = removeJob(jobId); if (destroyedJob != null){ if (destroyedJob != null) { // Clear associated resources: // Clear associated resources: destroyedJob.clearResources(); destroyedJob.clearResources(); Loading Loading @@ -945,13 +945,13 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * content of this jobs list or to destroy the * content of this jobs list or to destroy the * specified job. * specified job. */ */ public boolean destroyJob(final String jobId, final JobOwner user) throws UWSException{ public boolean destroyJob(final String jobId, final JobOwner user) throws UWSException { if (user != null){ if (user != null) { if (!user.hasWritePermission(this)) if (!user.hasWritePermission(this)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(user, true, getName())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(user, true, getName())); UWSJob job = getJob(jobId); UWSJob job = getJob(jobId); if (job != null && job.getOwner() != null && !user.equals(job.getOwner()) && !user.hasWritePermission(job)) if (job != null && job.getOwner() != null && !user.equals(job.getOwner()) && !user.hasWritePermission(job)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(user, false, jobId)); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(user, false, jobId)); } } return destroyJob(jobId); return destroyJob(jobId); } } Loading @@ -972,7 +972,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @see #destroyJob(String) * @see #destroyJob(String) */ */ public synchronized void clear(){ public synchronized void clear() { ArrayList<String> jobIDs = new ArrayList<String>(jobsList.keySet()); ArrayList<String> jobIDs = new ArrayList<String>(jobsList.keySet()); for(String id : jobIDs) for(String id : jobIDs) destroyJob(id); destroyJob(id); Loading @@ -989,13 +989,13 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see #clear() * @see #clear() * @see #destroyJob(String) * @see #destroyJob(String) */ */ public synchronized void clear(JobOwner owner) throws UWSException{ public synchronized void clear(JobOwner owner) throws UWSException { if (owner == null) if (owner == null) clear(); clear(); else if (!owner.hasWritePermission(this)) else if (!owner.hasWritePermission(this)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(owner, true, getName())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(owner, true, getName())); else{ else { if (ownerJobs.containsKey(owner)){ if (ownerJobs.containsKey(owner)) { ArrayList<String> jobIDs = new ArrayList<String>(ownerJobs.get(owner).keySet()); ArrayList<String> jobIDs = new ArrayList<String>(ownerJobs.get(owner).keySet()); for(String id : jobIDs) for(String id : jobIDs) destroyJob(id); destroyJob(id); Loading Loading @@ -1028,18 +1028,18 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @since 4.3 * @since 4.3 */ */ public void serialize(ServletOutputStream output, UWSSerializer serializer, JobOwner owner, JobListRefiner listRefiner) throws UWSException, IOException, Exception{ public void serialize(ServletOutputStream output, UWSSerializer serializer, JobOwner owner, JobListRefiner listRefiner) throws UWSException, IOException, Exception { if (output == null) if (output == null) throw new NullPointerException("Missing serialization output stream!"); throw new NullPointerException("Missing serialization output stream!"); if (owner != null && !owner.hasReadPermission(this)) if (owner != null && !owner.hasReadPermission(this)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(owner, true, getName())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(owner, true, getName())); String serialization = serializer.getJobList(this, owner, listRefiner, true); String serialization = serializer.getJobList(this, owner, listRefiner, true); if (serialization != null){ if (serialization != null) { output.print(serialization); output.print(serialization); output.flush(); output.flush(); }else } else throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Incorrect serialization value (=NULL) ! => impossible to serialize " + toString() + "."); throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Incorrect serialization value (=NULL) ! => impossible to serialize " + toString() + "."); } } Loading @@ -1047,15 +1047,15 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { /* INHERITED METHODS */ /* INHERITED METHODS */ /* ***************** */ /* ***************** */ @Override @Override public String serialize(UWSSerializer serializer, JobOwner user) throws UWSException, Exception{ public String serialize(UWSSerializer serializer, JobOwner user) throws UWSException, Exception { if (user != null && !user.hasReadPermission(this)) if (user != null && !user.hasReadPermission(this)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(user, true, getName())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(user, true, getName())); return serializer.getJobList(this, user, true); return serializer.getJobList(this, user, true); } } @Override @Override public String toString(){ public String toString() { return "JOB_LIST {name: \"" + getName() + "\"; nbJobs: " + jobsList.size() + "}"; return "JOB_LIST {name: \"" + getName() + "\"; nbJobs: " + jobsList.size() + "}"; } } Loading Loading
src/uws/job/JobList.java +84 −84 Original line number Original line Diff line number Diff line Loading @@ -16,7 +16,7 @@ package uws.job; * You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * * * Copyright 2012-2018 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Copyright 2012-2020 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Astronomisches Rechen Institut (ARI) * Astronomisches Rechen Institut (ARI) */ */ Loading Loading @@ -175,7 +175,7 @@ import uws.service.log.UWSLog.LogLevel; * </i></p> * </i></p> * * * @author Grégory Mantelet (CDS;ARI) * @author Grégory Mantelet (CDS;ARI) * @version 4.3 (10/2017) * @version 4.5 (07/2020) * * * @see UWSJob * @see UWSJob */ */ Loading @@ -190,10 +190,10 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { private final String name; private final String name; /** <b>[Required]</b> List of jobs. */ /** <b>[Required]</b> List of jobs. */ protected final Map<String,UWSJob> jobsList; protected final Map<String, UWSJob> jobsList; /** <b>[Required]</b> List of jobs per owner. */ /** <b>[Required]</b> List of jobs per owner. */ protected final Map<JobOwner,Map<String,UWSJob>> ownerJobs; protected final Map<JobOwner, Map<String, UWSJob>> ownerJobs; /** The destruction manager to use to take into account the destructionTime /** The destruction manager to use to take into account the destructionTime * field of contained jobs. */ * field of contained jobs. */ Loading Loading @@ -226,7 +226,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @see #JobList(String, ExecutionManager) * @see #JobList(String, ExecutionManager) */ */ public JobList(String jobListName) throws NullPointerException{ public JobList(String jobListName) throws NullPointerException { this(jobListName, null, new DefaultDestructionManager()); this(jobListName, null, new DefaultDestructionManager()); } } Loading @@ -241,7 +241,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * or empty * or empty * or if no execution manager is provided. * or if no execution manager is provided. */ */ public JobList(String jobListName, ExecutionManager executionManager) throws NullPointerException{ public JobList(String jobListName, ExecutionManager executionManager) throws NullPointerException { this(jobListName, executionManager, new DefaultDestructionManager()); this(jobListName, executionManager, new DefaultDestructionManager()); } } Loading @@ -257,7 +257,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * or empty * or empty * or if no destruction manager is provided. * or if no destruction manager is provided. */ */ public JobList(String jobListName, DestructionManager destructionManager) throws NullPointerException{ public JobList(String jobListName, DestructionManager destructionManager) throws NullPointerException { this(jobListName, new DefaultExecutionManager(), destructionManager); this(jobListName, new DefaultExecutionManager(), destructionManager); } } Loading @@ -276,18 +276,18 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * or if no execution manager and destruction * or if no execution manager and destruction * manager are provided. * manager are provided. */ */ public JobList(String jobListName, ExecutionManager executionManager, DestructionManager destructionManager) throws NullPointerException{ public JobList(String jobListName, ExecutionManager executionManager, DestructionManager destructionManager) throws NullPointerException { if (jobListName == null) if (jobListName == null) throw new NullPointerException("Missing job list name ! => Impossible to build the job list."); throw new NullPointerException("Missing job list name ! => Impossible to build the job list."); else{ else { jobListName = jobListName.trim(); jobListName = jobListName.trim(); if (jobListName.length() == 0) if (jobListName.length() == 0) throw new NullPointerException("Missing job list name ! => Impossible to build the job list."); throw new NullPointerException("Missing job list name ! => Impossible to build the job list."); } } name = jobListName; name = jobListName; jobsList = new ConcurrentHashMap<String,UWSJob>(); jobsList = new ConcurrentHashMap<String, UWSJob>(); ownerJobs = new ConcurrentHashMap<JobOwner,Map<String,UWSJob>>(); ownerJobs = new ConcurrentHashMap<JobOwner, Map<String, UWSJob>>(); this.executionManager = executionManager; this.executionManager = executionManager; Loading @@ -306,7 +306,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @return Its UWS or <i>null</i> if this jobs list is not yet part of a * @return Its UWS or <i>null</i> if this jobs list is not yet part of a * specific UWS). * specific UWS). */ */ public final UWS getUWS(){ public final UWS getUWS() { return uws; return uws; } } Loading @@ -325,7 +325,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * with a UWS (different from the given * with a UWS (different from the given * one) and contains some jobs. * one) and contains some jobs. */ */ public final void setUWS(UWS newUws) throws IllegalStateException{ public final void setUWS(UWS newUws) throws IllegalStateException { if (newUws == null) if (newUws == null) return; return; else if (newUws.equals(uws)) else if (newUws.equals(uws)) Loading @@ -345,7 +345,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see UWS#getLogger() * @see UWS#getLogger() * @see UWSToolBox#getDefaultLogger() * @see UWSToolBox#getDefaultLogger() */ */ public UWSLog getLogger(){ public UWSLog getLogger() { if (getUWS() != null && getUWS().getLogger() != null) if (getUWS() != null && getUWS().getLogger() != null) return getUWS().getLogger(); return getUWS().getLogger(); else else Loading @@ -362,7 +362,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @return Its destruction manager. * @return Its destruction manager. */ */ public final DestructionManager getDestructionManager(){ public final DestructionManager getDestructionManager() { return destructionManager; return destructionManager; } } Loading @@ -385,14 +385,14 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see DestructionManager#remove(UWSJob) * @see DestructionManager#remove(UWSJob) * @see DestructionManager#update(UWSJob) * @see DestructionManager#update(UWSJob) */ */ public final void setDestructionManager(DestructionManager newManager){ public final void setDestructionManager(DestructionManager newManager) { if (newManager == null) if (newManager == null) return; return; DestructionManager oldManager = destructionManager; DestructionManager oldManager = destructionManager; destructionManager = newManager; destructionManager = newManager; for(UWSJob job : this){ for(UWSJob job : this) { oldManager.remove(job); oldManager.remove(job); destructionManager.update(job); destructionManager.update(job); } } Loading @@ -403,8 +403,8 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @return The used execution manager. * @return The used execution manager. */ */ public final ExecutionManager getExecutionManager(){ public final ExecutionManager getExecutionManager() { if (executionManager == null){ if (executionManager == null) { if (uws == null) if (uws == null) executionManager = new DefaultExecutionManager(); executionManager = new DefaultExecutionManager(); else else Loading @@ -427,16 +427,16 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see ExecutionManager#remove(UWSJob) * @see ExecutionManager#remove(UWSJob) * @see ExecutionManager#execute(UWSJob) * @see ExecutionManager#execute(UWSJob) */ */ public synchronized final void setExecutionManager(final ExecutionManager manager){ public synchronized final void setExecutionManager(final ExecutionManager manager) { if (manager == null) if (manager == null) return; return; ExecutionManager oldManager = executionManager; ExecutionManager oldManager = executionManager; executionManager = manager; executionManager = manager; if (oldManager != null){ if (oldManager != null) { for(UWSJob job : this){ for(UWSJob job : this) { if (job.getPhase() != ExecutionPhase.PENDING && !job.isFinished()){ if (job.getPhase() != ExecutionPhase.PENDING && !job.isFinished()) { oldManager.remove(job); oldManager.remove(job); executionManager.execute(job); executionManager.execute(job); } } Loading @@ -451,7 +451,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @since 4.3 * @since 4.3 */ */ public final JobDestructionPolicy getDestroyPolicy(){ public final JobDestructionPolicy getDestroyPolicy() { return destructionPolicy; return destructionPolicy; } } Loading @@ -465,7 +465,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @since 4.3 * @since 4.3 */ */ public final void setDestructionPolicy(JobDestructionPolicy destroyPolicy){ public final void setDestructionPolicy(JobDestructionPolicy destroyPolicy) { this.destructionPolicy = (destroyPolicy == null) ? DEFAULT_JOB_DESTRUCTION_POLICY : destroyPolicy; this.destructionPolicy = (destroyPolicy == null) ? DEFAULT_JOB_DESTRUCTION_POLICY : destroyPolicy; } } Loading @@ -477,7 +477,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see UWSService#getUrlInterpreter() * @see UWSService#getUrlInterpreter() * @see UWSUrl#listJobs(String) * @see UWSUrl#listJobs(String) */ */ public UWSUrl getUrl(){ public UWSUrl getUrl() { if (uws == null || uws.getUrlInterpreter() == null) if (uws == null || uws.getUrlInterpreter() == null) return null; return null; else else Loading @@ -489,7 +489,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @return JobList name. * @return JobList name. */ */ public final String getName(){ public final String getName() { return name; return name; } } Loading @@ -501,7 +501,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @return The requested job or <i>null</i> if there is no job with the * @return The requested job or <i>null</i> if there is no job with the * given ID. * given ID. */ */ public final UWSJob getJob(String jobID){ public final UWSJob getJob(String jobID) { return jobsList.get(jobID); return jobsList.get(jobID); } } Loading @@ -519,18 +519,18 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @throws UWSException If the given user is not allowed to read the content * @throws UWSException If the given user is not allowed to read the content * of this jobs list or to read the specified job. * of this jobs list or to read the specified job. */ */ public UWSJob getJob(String jobID, JobOwner user) throws UWSException{ public UWSJob getJob(String jobID, JobOwner user) throws UWSException { if (user != null && !user.hasReadPermission(this)) if (user != null && !user.hasReadPermission(this)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.readPermissionDenied(user, true, getName())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.readPermissionDenied(user, true, getName())); // Get the specified job: // Get the specified job: UWSJob job = jobsList.get(jobID); UWSJob job = jobsList.get(jobID); // Check the right of the specified user to see the job: // Check the right of the specified user to see the job: if (user != null && job != null && job.getOwner() != null){ if (user != null && job != null && job.getOwner() != null) { JobOwner owner = job.getOwner(); JobOwner owner = job.getOwner(); if (!owner.equals(user) && !user.hasReadPermission(job)) if (!owner.equals(user) && !user.hasReadPermission(job)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.readPermissionDenied(user, false, job.getJobId())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.readPermissionDenied(user, false, job.getJobId())); } } return job; return job; Loading @@ -543,7 +543,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @see #iterator() * @see #iterator() */ */ public final Iterator<UWSJob> getJobs(){ public final Iterator<UWSJob> getJobs() { return iterator(); return iterator(); } } Loading @@ -558,26 +558,26 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * or a NullIterator if the specified owner/user has no job * or a NullIterator if the specified owner/user has no job * or an iterator on all the jobs if <i>ownerId</i> is <i>null</i>. * or an iterator on all the jobs if <i>ownerId</i> is <i>null</i>. */ */ public Iterator<UWSJob> getJobs(JobOwner user){ public Iterator<UWSJob> getJobs(JobOwner user) { if (user == null) if (user == null) return iterator(); return iterator(); else{ else { if (ownerJobs.containsKey(user)) if (ownerJobs.containsKey(user)) return ownerJobs.get(user).values().iterator(); return ownerJobs.get(user).values().iterator(); else else return new Iterator<UWSJob>(){ return new Iterator<UWSJob>() { @Override @Override public boolean hasNext(){ public boolean hasNext() { return false; return false; } } @Override @Override public UWSJob next(){ public UWSJob next() { return null; return null; } } @Override @Override public void remove(){ public void remove() { ; ; } } }; }; Loading @@ -590,7 +590,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see java.lang.Iterable#iterator() * @see java.lang.Iterable#iterator() */ */ @Override @Override public final Iterator<UWSJob> iterator(){ public final Iterator<UWSJob> iterator() { return jobsList.values().iterator(); return jobsList.values().iterator(); } } Loading @@ -599,7 +599,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @return Number of jobs. * @return Number of jobs. */ */ public final int getNbJobs(){ public final int getNbJobs() { return jobsList.size(); return jobsList.size(); } } Loading @@ -611,10 +611,10 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @return Number of jobs that the given owner/user has, * @return Number of jobs that the given owner/user has, * or the number of all jobs if <i>user</i> is <i>null</i>. * or the number of all jobs if <i>user</i> is <i>null</i>. */ */ public final int getNbJobs(JobOwner user){ public final int getNbJobs(JobOwner user) { if (user == null) if (user == null) return getNbJobs(); return getNbJobs(); else{ else { if (ownerJobs.containsKey(user)) if (ownerJobs.containsKey(user)) return ownerJobs.get(user).size(); return ownerJobs.get(user).size(); else else Loading @@ -627,7 +627,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @return An iterator on owners. * @return An iterator on owners. */ */ public final Iterator<JobOwner> getUsers(){ public final Iterator<JobOwner> getUsers() { return ownerJobs.keySet().iterator(); return ownerJobs.keySet().iterator(); } } Loading @@ -636,7 +636,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @return The number of job owners. * @return The number of job owners. */ */ public final int getNbUsers(){ public final int getNbUsers() { return ownerJobs.size(); return ownerJobs.size(); } } Loading @@ -651,11 +651,11 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @return All the corresponding jobs. * @return All the corresponding jobs. */ */ public final List<UWSJob> searchJobs(String runID){ public final List<UWSJob> searchJobs(String runID) { ArrayList<UWSJob> foundJobs = new ArrayList<UWSJob>(); ArrayList<UWSJob> foundJobs = new ArrayList<UWSJob>(); runID = (runID != null) ? runID.trim() : runID; runID = (runID != null) ? runID.trim() : runID; if (runID != null && !runID.isEmpty()){ if (runID != null && !runID.isEmpty()) { for(UWSJob job : this) for(UWSJob job : this) if (job.getRunId().equalsIgnoreCase(runID)) if (job.getRunId().equalsIgnoreCase(runID)) foundJobs.add(job); foundJobs.add(job); Loading Loading @@ -683,27 +683,27 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see DestructionManager#update(UWSJob) * @see DestructionManager#update(UWSJob) * @see UWSJob#applyPhaseParam(JobOwner) * @see UWSJob#applyPhaseParam(JobOwner) */ */ public synchronized String addNewJob(final UWSJob j) throws UWSException{ public synchronized String addNewJob(final UWSJob j) throws UWSException { if (uws == null) if (uws == null) throw new IllegalStateException("Jobs can not be added to this job list until this job list is linked to a UWS!"); throw new IllegalStateException("Jobs can not be added to this job list until this job list is linked to a UWS!"); else if (j == null || jobsList.containsKey(j.getJobId())){ else if (j == null || jobsList.containsKey(j.getJobId())) { return null; return null; }else{ } else { JobOwner owner = j.getOwner(); JobOwner owner = j.getOwner(); // Check the WRITE permission of the owner of this job: // Check the WRITE permission of the owner of this job: if (owner != null && !owner.hasWritePermission(this)) if (owner != null && !owner.hasWritePermission(this)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(owner, true, getName())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(owner, true, getName())); // Set its job list: // Set its job list: j.setJobList(this); j.setJobList(this); // Add the job to the jobs list: // Add the job to the jobs list: jobsList.put(j.getJobId(), j); jobsList.put(j.getJobId(), j); if (owner != null){ if (owner != null) { // Index also this job in function of its owner: // Index also this job in function of its owner: if (!ownerJobs.containsKey(owner)) if (!ownerJobs.containsKey(owner)) ownerJobs.put(owner, new ConcurrentHashMap<String,UWSJob>()); ownerJobs.put(owner, new ConcurrentHashMap<String, UWSJob>()); ownerJobs.get(owner).put(j.getJobId(), j); ownerJobs.get(owner).put(j.getJobId(), j); } } Loading Loading @@ -744,10 +744,10 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @since 4.3 * @since 4.3 */ */ public boolean archiveJob(final String jobId){ public boolean archiveJob(final String jobId) { UWSJob job = getJob(jobId); UWSJob job = getJob(jobId); if (job != null){ if (job != null) { // Archive the job: // Archive the job: job.archive(); job.archive(); Loading @@ -756,7 +756,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { uws.getBackupManager().saveOwner(job.getOwner()); uws.getBackupManager().saveOwner(job.getOwner()); return true; return true; }else } else return false; return false; } } Loading @@ -781,13 +781,13 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @since 4.3 * @since 4.3 */ */ public boolean archiveJob(final String jobId, final JobOwner user) throws UWSException{ public boolean archiveJob(final String jobId, final JobOwner user) throws UWSException { if (user != null){ if (user != null) { if (!user.hasWritePermission(this)) if (!user.hasWritePermission(this)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(user, true, getName())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(user, true, getName())); UWSJob job = getJob(jobId); UWSJob job = getJob(jobId); if (job != null && job.getOwner() != null && !user.equals(job.getOwner()) && !user.hasWritePermission(job)) if (job != null && job.getOwner() != null && !user.equals(job.getOwner()) && !user.hasWritePermission(job)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(user, false, jobId)); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(user, false, jobId)); } } return archiveJob(jobId); return archiveJob(jobId); } } Loading @@ -806,7 +806,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @see DestructionManager#update(UWSJob) * @see DestructionManager#update(UWSJob) */ */ public final void updateDestruction(UWSJob job){ public final void updateDestruction(UWSJob job) { if (destructionManager != null && job != null && job.getJobList() != null && job.getJobList().equals(this)) if (destructionManager != null && job != null && job.getJobList() != null && job.getJobList().equals(this)) destructionManager.update(job); destructionManager.update(job); } } Loading @@ -821,14 +821,14 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @see DestructionManager#remove(UWSJob) * @see DestructionManager#remove(UWSJob) */ */ protected UWSJob removeJob(final String jobId){ protected UWSJob removeJob(final String jobId) { // Remove the specified job: // Remove the specified job: UWSJob removedJob = (jobId == null) ? null : jobsList.remove(jobId); UWSJob removedJob = (jobId == null) ? null : jobsList.remove(jobId); if (removedJob != null){ if (removedJob != null) { // Clear its owner index: // Clear its owner index: JobOwner owner = removedJob.getOwner(); JobOwner owner = removedJob.getOwner(); if (owner != null && ownerJobs.containsKey(owner)){ if (owner != null && ownerJobs.containsKey(owner)) { ownerJobs.get(owner).remove(jobId); ownerJobs.get(owner).remove(jobId); if (ownerJobs.get(owner).isEmpty()) if (ownerJobs.get(owner).isEmpty()) ownerJobs.remove(owner); ownerJobs.remove(owner); Loading @@ -838,7 +838,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { if (destructionManager != null) if (destructionManager != null) destructionManager.remove(removedJob); destructionManager.remove(removedJob); return removedJob; return removedJob; }else } else return null; return null; } } Loading Loading @@ -878,7 +878,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see UWSBackupManager#saveOwner(JobOwner) * @see UWSBackupManager#saveOwner(JobOwner) * @see #archiveJob(String) * @see #archiveJob(String) */ */ public boolean destroyJob(final String jobId){ public boolean destroyJob(final String jobId) { // Get the corresponding job and return immediately if none can be found: // Get the corresponding job and return immediately if none can be found: UWSJob job = getJob(jobId); UWSJob job = getJob(jobId); if (job == null) if (job == null) Loading @@ -904,11 +904,11 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * - policy = ALWAYS_DELETE, * - policy = ALWAYS_DELETE, * - policy = ARCHIVE_ON_DATE and the destruction date is not * - policy = ARCHIVE_ON_DATE and the destruction date is not * yet reached. */ * yet reached. */ if (job.getPhase() == ExecutionPhase.ARCHIVED || destructionPolicy == JobDestructionPolicy.ALWAYS_DELETE || (destructionPolicy == JobDestructionPolicy.ARCHIVE_ON_DATE && !dateReached)){ if (job.getPhase() == ExecutionPhase.ARCHIVED || destructionPolicy == JobDestructionPolicy.ALWAYS_DELETE || (destructionPolicy == JobDestructionPolicy.ARCHIVE_ON_DATE && !dateReached)) { // Remove the job: // Remove the job: UWSJob destroyedJob = removeJob(jobId); UWSJob destroyedJob = removeJob(jobId); if (destroyedJob != null){ if (destroyedJob != null) { // Clear associated resources: // Clear associated resources: destroyedJob.clearResources(); destroyedJob.clearResources(); Loading Loading @@ -945,13 +945,13 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * content of this jobs list or to destroy the * content of this jobs list or to destroy the * specified job. * specified job. */ */ public boolean destroyJob(final String jobId, final JobOwner user) throws UWSException{ public boolean destroyJob(final String jobId, final JobOwner user) throws UWSException { if (user != null){ if (user != null) { if (!user.hasWritePermission(this)) if (!user.hasWritePermission(this)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(user, true, getName())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(user, true, getName())); UWSJob job = getJob(jobId); UWSJob job = getJob(jobId); if (job != null && job.getOwner() != null && !user.equals(job.getOwner()) && !user.hasWritePermission(job)) if (job != null && job.getOwner() != null && !user.equals(job.getOwner()) && !user.hasWritePermission(job)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(user, false, jobId)); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(user, false, jobId)); } } return destroyJob(jobId); return destroyJob(jobId); } } Loading @@ -972,7 +972,7 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @see #destroyJob(String) * @see #destroyJob(String) */ */ public synchronized void clear(){ public synchronized void clear() { ArrayList<String> jobIDs = new ArrayList<String>(jobsList.keySet()); ArrayList<String> jobIDs = new ArrayList<String>(jobsList.keySet()); for(String id : jobIDs) for(String id : jobIDs) destroyJob(id); destroyJob(id); Loading @@ -989,13 +989,13 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * @see #clear() * @see #clear() * @see #destroyJob(String) * @see #destroyJob(String) */ */ public synchronized void clear(JobOwner owner) throws UWSException{ public synchronized void clear(JobOwner owner) throws UWSException { if (owner == null) if (owner == null) clear(); clear(); else if (!owner.hasWritePermission(this)) else if (!owner.hasWritePermission(this)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(owner, true, getName())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(owner, true, getName())); else{ else { if (ownerJobs.containsKey(owner)){ if (ownerJobs.containsKey(owner)) { ArrayList<String> jobIDs = new ArrayList<String>(ownerJobs.get(owner).keySet()); ArrayList<String> jobIDs = new ArrayList<String>(ownerJobs.get(owner).keySet()); for(String id : jobIDs) for(String id : jobIDs) destroyJob(id); destroyJob(id); Loading Loading @@ -1028,18 +1028,18 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { * * * @since 4.3 * @since 4.3 */ */ public void serialize(ServletOutputStream output, UWSSerializer serializer, JobOwner owner, JobListRefiner listRefiner) throws UWSException, IOException, Exception{ public void serialize(ServletOutputStream output, UWSSerializer serializer, JobOwner owner, JobListRefiner listRefiner) throws UWSException, IOException, Exception { if (output == null) if (output == null) throw new NullPointerException("Missing serialization output stream!"); throw new NullPointerException("Missing serialization output stream!"); if (owner != null && !owner.hasReadPermission(this)) if (owner != null && !owner.hasReadPermission(this)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(owner, true, getName())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(owner, true, getName())); String serialization = serializer.getJobList(this, owner, listRefiner, true); String serialization = serializer.getJobList(this, owner, listRefiner, true); if (serialization != null){ if (serialization != null) { output.print(serialization); output.print(serialization); output.flush(); output.flush(); }else } else throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Incorrect serialization value (=NULL) ! => impossible to serialize " + toString() + "."); throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, "Incorrect serialization value (=NULL) ! => impossible to serialize " + toString() + "."); } } Loading @@ -1047,15 +1047,15 @@ public class JobList extends SerializableUWSObject implements Iterable<UWSJob> { /* INHERITED METHODS */ /* INHERITED METHODS */ /* ***************** */ /* ***************** */ @Override @Override public String serialize(UWSSerializer serializer, JobOwner user) throws UWSException, Exception{ public String serialize(UWSSerializer serializer, JobOwner user) throws UWSException, Exception { if (user != null && !user.hasReadPermission(this)) if (user != null && !user.hasReadPermission(this)) throw new UWSException(UWSException.PERMISSION_DENIED, UWSExceptionFactory.writePermissionDenied(user, true, getName())); throw new UWSException(UWSException.FORBIDDEN, UWSExceptionFactory.writePermissionDenied(user, true, getName())); return serializer.getJobList(this, user, true); return serializer.getJobList(this, user, true); } } @Override @Override public String toString(){ public String toString() { return "JOB_LIST {name: \"" + getName() + "\"; nbJobs: " + jobsList.size() + "}"; return "JOB_LIST {name: \"" + getName() + "\"; nbJobs: " + jobsList.size() + "}"; } } Loading