Skip to content
Snippets Groups Projects
Commit 0467dbb1 authored by gmantele's avatar gmantele
Browse files

[UWS] Add the new Execution Phase `ARCHIVED` and check phase transitions.

A JUnit test case has been added in order to check that all possible phase
transitions are respecting the UWS-1.1 standard. However, there is anyway
a bit more freedom for some of them:

    - it is possible to go to and come from UNKNOWN at any time, whatever is
	  the source or target phase.

	- it is possible to go to ERROR or ABORTED from the phases HELD and
	  SUSPENDED. This fact was not specified in the State Machine figure of the
	  UWS standard but the following sentence at section
	  "2.1.3 Execution Phase" (page 7) should allow that:
	  "At any time before the COMPLETED phase a job may either be ABORTED or
	   may suffer an ERROR."

	- the UWS-1.1 document has an inconsistency about the HELD phase. At
	  section "2.1.3 Execution Phase" (page 7), the following sentence implies
	  that it is only possible to go to HELD from PENDING (because it would not
	  be possible to queue the job). And so, when PHASE=RUN is sent by the UWS
      client, if now possible, the job should go in phase QUEUED. However the
	  State Machine figure suggests that it is possible to go to HELD only from
	  EXECUTING and that a PHASE=RUN would make the job go back to EXECUTING (if
	  now possible). Because of this inconsistency, the UWSLibrary made possible
	  the following transitions: PENDING/EXECUTING->HELD->QUEUED/EXECUTING.

(note: a figure illustrating the phase transitions supported by the
       UWSLibrary-4.3 has been created in the directory `img` of the
	   UWS-Tutorial website under the file name `state_machine.png`...which of
	   course will be visible only when uwslib-4.3 will be released)

Besides, this commit also include almost a full rewriting of the Javadoc of
JobPhase and ExecutionPhase. The Javadoc of UWSJob has just been reformated
so that comments do not exceed 80 (+2) characters. This reformating aims to
improve the human reading of the Javadoc while looking at the source files ;
however this should not affect much the HTML version of the Javadoc.
parent a8d98f64
No related branches found
No related tags found
No related merge requests found
...@@ -2,21 +2,21 @@ package uws; ...@@ -2,21 +2,21 @@ package uws;
/* /*
* This file is part of UWSLibrary. * This file is part of UWSLibrary.
* *
* UWSLibrary is free software: you can redistribute it and/or modify * UWSLibrary is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* UWSLibrary is distributed in the hope that it will be useful, * UWSLibrary is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* 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,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
* Astronomisches Rechen Institut (ARI) * Astronomisches Rechen Institut (ARI)
*/ */
...@@ -25,10 +25,10 @@ import uws.job.user.JobOwner; ...@@ -25,10 +25,10 @@ import uws.job.user.JobOwner;
/** /**
* Let's creating the common exceptions of a UWS service. * Let's creating the common exceptions of a UWS service.
* *
* @author Gr&eacute;gory Mantelet (CDS;ARI) * @author Gr&eacute;gory Mantelet (CDS;ARI)
* @version 4.1 (09/2014) * @version 4.3 (09/2017)
* *
* @see UWSException * @see UWSException
*/ */
public final class UWSExceptionFactory { public final class UWSExceptionFactory {
...@@ -54,7 +54,7 @@ public final class UWSExceptionFactory { ...@@ -54,7 +54,7 @@ public final class UWSExceptionFactory {
} }
public final static String incorrectPhaseTransition(final String jobID, final ExecutionPhase fromPhase, final ExecutionPhase toPhase, final String consequence){ public final static String incorrectPhaseTransition(final String jobID, final ExecutionPhase fromPhase, final ExecutionPhase toPhase, final String consequence){
return "Incorrect phase transition ! => the job " + jobID + " is in the phase " + fromPhase + ". It can not go to " + toPhase + "." + appendMessage(consequence); return "Incorrect phase transition! => the job " + jobID + " is in the phase " + fromPhase + ". It can not go to " + toPhase + "." + appendMessage(consequence);
} }
public final static String readPermissionDenied(final JobOwner user, final boolean jobList, final String containerName){ public final static String readPermissionDenied(final JobOwner user, final boolean jobList, final String containerName){
...@@ -62,7 +62,7 @@ public final class UWSExceptionFactory { ...@@ -62,7 +62,7 @@ public final class UWSExceptionFactory {
} }
public final static String readPermissionDenied(final JobOwner user, final boolean jobList, final String containerName, final String consequence){ public final static String readPermissionDenied(final JobOwner user, final boolean jobList, final String containerName, final String consequence){
return user.getID() + ((user.getPseudo() == null) ? "" : (" (alias " + user.getPseudo() + ")")) + " is not allowed to read the content of the " + (jobList ? "jobs list" : "job") + " \"" + containerName + "\" !" + appendMessage(consequence); return user.getID() + ((user.getPseudo() == null) ? "" : (" (alias " + user.getPseudo() + ")")) + " is not allowed to read the content of the " + (jobList ? "jobs list" : "job") + " \"" + containerName + "\"!" + appendMessage(consequence);
} }
public final static String writePermissionDenied(final JobOwner user, final boolean jobList, final String containerName){ public final static String writePermissionDenied(final JobOwner user, final boolean jobList, final String containerName){
...@@ -70,7 +70,7 @@ public final class UWSExceptionFactory { ...@@ -70,7 +70,7 @@ public final class UWSExceptionFactory {
} }
public final static String writePermissionDenied(final JobOwner user, final boolean jobList, final String containerName, final String consequence){ public final static String writePermissionDenied(final JobOwner user, final boolean jobList, final String containerName, final String consequence){
return user.getID() + ((user.getPseudo() == null) ? "" : (" (alias " + user.getPseudo() + ")")) + " is not allowed to update the content of the " + (jobList ? "jobs list" : "job") + " \"" + containerName + "\" !" + appendMessage(consequence); return user.getID() + ((user.getPseudo() == null) ? "" : (" (alias " + user.getPseudo() + ")")) + " is not allowed to update the content of the " + (jobList ? "jobs list" : "job") + " \"" + containerName + "\"!" + appendMessage(consequence);
} }
public final static String executePermissionDenied(final JobOwner user, final String jobID){ public final static String executePermissionDenied(final JobOwner user, final String jobID){
...@@ -78,7 +78,7 @@ public final class UWSExceptionFactory { ...@@ -78,7 +78,7 @@ public final class UWSExceptionFactory {
} }
public final static String executePermissionDenied(final JobOwner user, final String jobID, final String consequence){ public final static String executePermissionDenied(final JobOwner user, final String jobID, final String consequence){
return user.getID() + ((user.getPseudo() == null) ? "" : (" (alias " + user.getPseudo() + ")")) + " is not allowed to execute/abort the job \"" + jobID + "\" !" + appendMessage(consequence); return user.getID() + ((user.getPseudo() == null) ? "" : (" (alias " + user.getPseudo() + ")")) + " is not allowed to execute/abort the job \"" + jobID + "\"!" + appendMessage(consequence);
} }
public final static String jobModificationForbidden(final String jobId, final ExecutionPhase phase, final String parameter){ public final static String jobModificationForbidden(final String jobId, final ExecutionPhase phase, final String parameter){
...@@ -87,9 +87,9 @@ public final class UWSExceptionFactory { ...@@ -87,9 +87,9 @@ public final class UWSExceptionFactory {
public final static String jobModificationForbidden(final String jobId, final ExecutionPhase phase, final String parameter, final String consequence){ public final static String jobModificationForbidden(final String jobId, final ExecutionPhase phase, final String parameter, final String consequence){
if (parameter != null && !parameter.trim().isEmpty()) if (parameter != null && !parameter.trim().isEmpty())
return "Impossible to change the parameter \"" + parameter + "\" of the job " + jobId + ((phase != null) ? (" (phase: " + phase + ")") : "") + " !" + appendMessage(consequence); return "Impossible to change the parameter \"" + parameter + "\" of the job " + jobId + ((phase != null) ? (" (phase: " + phase + ")") : "") + "!" + appendMessage(consequence);
else else
return "Impossible to change the parameters of the job " + jobId + ((phase != null) ? (" (phase: " + phase + ")") : "") + " !" + appendMessage(consequence); return "Impossible to change the parameters of the job " + jobId + ((phase != null) ? (" (phase: " + phase + ")") : "") + "!" + appendMessage(consequence);
} }
} }
...@@ -2,70 +2,214 @@ package uws.job; ...@@ -2,70 +2,214 @@ package uws.job;
/* /*
* This file is part of UWSLibrary. * This file is part of UWSLibrary.
* *
* UWSLibrary is free software: you can redistribute it and/or modify * UWSLibrary is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* UWSLibrary is distributed in the hope that it will be useful, * UWSLibrary is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* 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 - UDS/Centre de Données astronomiques de Strasbourg (CDS) * Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
* Astronomisches Rechen Institut (ARI)
*/ */
/** /**
* <p>A job is treated as a state machine where the Execution Phase is the job state. The phases are:</p> * A job is treated as a state machine where the Execution Phase is the job
* <ul> * state. This enum class gathers all Execution Phases declared by the IVOA
* <li>{@link #PENDING}: the job is accepted by the service but not yet committed for * since UWS-1.1.
* execution by the client. In this state, the job quote can be read
* and evaluated. This is the state into which a job enters when it
* is first created.</li>
*
* <li>{@link #QUEUED}: the job is committed for execution by the client but the service
* has not yet assigned it to a processor. No Results are produced in
* this phase.</li>
*
* <li>{@link #EXECUTING}: the job has been assigned to a processor. Results may be produced
* at any time during this phase.</li>
*
* <li>{@link #COMPLETED}: the execution of the job is over. The Results may be collected.</li>
*
* <li>{@link #ERROR}: the job failed to complete. No further work will be done nor Results
* produced. Results may be unavailable or available but invalid; either
* way the Results should not be trusted.</li>
* *
* <li>{@link #ABORTED}: the job has been manually aborted by the user, or the system has * <p>
* aborted the job due to lack of or overuse of resources.</li> * The transitions of the state machine described by the IVOA are implemented
* in a different class: {@link JobPhase}.
* </p>
* *
* <li>{@link #UNKNOWN}: the job is in an unknown state.</li> * @see JobPhase
* *
* <li>{@link #HELD}: The job is HELD pending execution and will not automatically be * @author Gr&eacute;gory Mantelet (CDS;ARI)
* executed (cf pending).</li> * @version 4.3 (09/2017)
*
* <li>{@link #SUSPENDED}: The job has been suspended by the system during execution. This might
* be because of temporary lack of resource. The UWS will automatically
* resume the job into the EXECUTING phase without any intervention
* when resource becomes available.</li>
* </ul>
*
* @see UWSJob
*
* @author Gr&eacute;gory Mantelet (CDS)
* @version 02/2011
*/ */
public enum ExecutionPhase{ public enum ExecutionPhase{
PENDING, QUEUED, EXECUTING, COMPLETED, ERROR, ABORTED, UNKNOWN, HELD, SUSPENDED; /**
* The job is accepted by the service but not yet committed for execution by
* the client. In this state, the job quote can be read and evaluated. This
* is the state into which a job enters when it is first created.
*
* <p><b>Allowed previous phases:</b> <i>none</i>.</p>
*
* <p><b>Possible next phases:</b>
* {@link #HELD}, {@link #QUEUED}, {@link #ABORTED} or {@link #ERROR}.
* </p>
*/
PENDING,
/**
* The job is committed for execution by the client but the service has not
* yet assigned it to a processor. No Results are produced in this phase.
*
* <p><b>Allowed previous phases:</b>
* {@link #PENDING} or {@link #HELD}.
* </p>
*
* <p><b>Possible next phases:</b>
* {@link #EXECUTING}, {@link #ABORTED} or {@link #ERROR}.
* </p>
*/
QUEUED,
/**
* The job has been assigned to a processor. Results may be produced at any
* time during this phase.
*
* <p><b>Allowed previous phases:</b>
* {@link #QUEUED}, {@link #HELD} or {@link #SUSPENDED}.
* </p>
*
* <p><b>Possible next phases:</b>
* {@link #HELD}, {@link #SUSPENDED}, {@link #COMPLETED}, {@link #ABORTED}
* or {@link #ERROR}.
* </p>
*/
EXECUTING,
/**
* The execution of the job is over. The Results may be collected.
*
* <p><b>Allowed previous phases:</b>
* {@link #EXECUTING}.
* </p>
*
* <p><b>Possible next phases:</b>
* {@link #ARCHIVED}.
* </p>
*/
COMPLETED,
/**
* The job failed to complete. No further work will be done nor Results
* produced. Results may be unavailable or available but invalid; either
* way the Results should not be trusted.
*
* <p><b>Allowed previous phases:</b>
* {@link #EXECUTING}, {@link #QUEUED} or {@link #PENDING}.
* </p>
*
* <p><b>Possible next phases:</b>
* {@link #ARCHIVED}.
* </p>
*/
ERROR,
/**
* The job has been manually aborted by the user, or the system has aborted
* the job due to lack of or overuse of resources.
*
* <p><b>Allowed previous phases:</b>
* {@link #PENDING}, {@link #QUEUED}, {@link #EXECUTING}, {@link #HELD} or
* {@link #SUSPENDED}.
* </p>
*
* <p><b>Possible next phases:</b>
* {@link #ARCHIVED}.
* </p>
*/
ABORTED,
/**
* The job is in an unknown state.
*
* <p><i>Note:
* If the UWS reports an UNKNOWN phase, then all the client can do is
* re-query the phase until a known phase is reported.
* </i></p>
*
* <p><b>Allowed previous phases:</b> <i>any</i>.</p>
*
* <p><b>Possible next phases:</b> <i>any</i>.</p>
*/
UNKNOWN,
/**
* The job is HELD pending execution and will not automatically be executed
* (cf {@link #PENDING}).
*
* <p><i>Note:
* A UWS may place a job in a HELD phase on receipt of a PHASE=RUN request
* if for some reason the job cannot be immediately queued - in this case
* it is the responsibility of the client to request PHASE=RUN again at
* some later time.
* </i></p>
*
* <p><b>Allowed previous phases:</b>
* {@link #PENDING} or {@link #EXECUTING}.
* </p>
*
* <p><b>Possible next phases:</b>
* {@link #QUEUED}, {@link #EXECUTING}, {@link #ABORTED} or {@link #ERROR}.
* </p>
*/
HELD,
/**
* The job has been suspended by the system during execution. This might be
* because of temporary lack of resource. The UWS will automatically resume
* the job into the EXECUTING phase without any intervention when resource
* becomes available.
*
* <p><b>Allowed previous phases:</b>
* {@link #EXECUTING}.
* </p>
*
* <p><b>Possible next phases:</b>
* {@link #EXECUTING}, {@link #ABORTED} or {@link #ERROR}.
* </p>
*/
SUSPENDED,
/**
* At destruction time the results associated with a job have been deleted
* to free up resource, but the metadata associated with the job have been
* retained. This is an alternative that the server may choose in contrast
* to completely destroying all record of the job to allow a longer
* historical record of the existence of the job to be kept that would
* otherwise be the case if limited result storage resources forces
* destruction.
*
* <p><b>Allowed previous phases:</b>
* {@link #ABORTED}, {@link #COMPLETED} or {@link #ERROR}.
* </p>
*
* <p><b>Possible next phases:</b> <i>none</i>.</p>
*
* @since 4.3 */
ARCHIVED;
/**
* Get the label of the given Execution Phase.
*
* <p><i>Note:
* The reverse operation is {@link #getPhase(String)}.
* </i></p>
*
* @param ph An Execution Phase.
*
* @return The label of the given phase,
* or {@link #UNKNOWN} if NULL is given.
*/
public static final String getStr(ExecutionPhase ph){ public static final String getStr(ExecutionPhase ph){
return (ph == null) ? ExecutionPhase.UNKNOWN.name() : ph.name(); return (ph == null) ? ExecutionPhase.UNKNOWN.name() : ph.name();
} }
/**
* Get the Execution Phase corresponding to the given label.
*
* <p><i>Note:
* The reverse operation is {@link #getStr(ExecutionPhase)}.
* </i></p>
*
* @param phStr Label of the Execution Phase to resolve.
*
* @return The corresponding {@link ExecutionPhase},
* or {@link #UNKNOWN} if the given String is NULL
* or does not match any legal Execution Phase.
*/
public static final ExecutionPhase getPhase(String phStr){ public static final ExecutionPhase getPhase(String phStr){
try{ try{
return valueOf(phStr); return valueOf(phStr);
......
...@@ -2,21 +2,21 @@ package uws.job; ...@@ -2,21 +2,21 @@ package uws.job;
/* /*
* This file is part of UWSLibrary. * This file is part of UWSLibrary.
* *
* UWSLibrary is free software: you can redistribute it and/or modify * UWSLibrary is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* UWSLibrary is distributed in the hope that it will be useful, * UWSLibrary is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* 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,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
* Astronomisches Rechen Institut (ARI) * Astronomisches Rechen Institut (ARI)
*/ */
...@@ -26,12 +26,12 @@ import uws.UWSException; ...@@ -26,12 +26,12 @@ import uws.UWSException;
import uws.UWSExceptionFactory; import uws.UWSExceptionFactory;
/** /**
* An instance of this class represents the current execution phase of a given job, * An instance of this class represents the current execution phase of a given
* and it describes the transitions between the different phases. * job, and it describes the transitions between the different phases.
* *
* @author Gr&eacute;gory Mantelet (CDS;ARI) * @author Gr&eacute;gory Mantelet (CDS;ARI)
* @version 4.1 (08/2014) * @version 4.3 (09/2017)
* *
* @see ExecutionPhase * @see ExecutionPhase
* @see UWSJob * @see UWSJob
*/ */
...@@ -46,9 +46,10 @@ public class JobPhase implements Serializable { ...@@ -46,9 +46,10 @@ public class JobPhase implements Serializable {
/** /**
* Builds the phase manager of the given job. * Builds the phase manager of the given job.
* *
* @param j The job whose the execution phase must be represented by the built JobPhase instance. * @param j The job whose the execution phase must be represented by the
* * built JobPhase instance.
*
* @throws NullPointerException If the given job is <i>null</i>. * @throws NullPointerException If the given job is <i>null</i>.
*/ */
public JobPhase(UWSJob j) throws NullPointerException{ public JobPhase(UWSJob j) throws NullPointerException{
...@@ -59,7 +60,7 @@ public class JobPhase implements Serializable { ...@@ -59,7 +60,7 @@ public class JobPhase implements Serializable {
/** /**
* Gets the job whose the execution phase is represented by this object. * Gets the job whose the execution phase is represented by this object.
* *
* @return The associated job. * @return The associated job.
*/ */
public final UWSJob getJob(){ public final UWSJob getJob(){
...@@ -68,7 +69,7 @@ public class JobPhase implements Serializable { ...@@ -68,7 +69,7 @@ public class JobPhase implements Serializable {
/** /**
* Gets the current phase of the job. * Gets the current phase of the job.
* *
* @return The current job phase. * @return The current job phase.
*/ */
public final ExecutionPhase getPhase(){ public final ExecutionPhase getPhase(){
...@@ -76,12 +77,14 @@ public class JobPhase implements Serializable { ...@@ -76,12 +77,14 @@ public class JobPhase implements Serializable {
} }
/** /**
* Lets changing the current phase of the associated job considering the order of execution phases. * Lets changing the current phase of the associated job considering the
* * order of execution phases.
* @param p The new execution phase. *
* * @param p The new execution phase.
* @throws UWSException If the given phase is <i>null</i> or if the phase transition is forbidden. *
* * @throws UWSException If the given phase is <i>null</i> or if the phase
* transition is forbidden.
*
* @see #setPhase(ExecutionPhase, boolean) * @see #setPhase(ExecutionPhase, boolean)
*/ */
public final void setPhase(ExecutionPhase p) throws UWSException{ public final void setPhase(ExecutionPhase p) throws UWSException{
...@@ -89,17 +92,19 @@ public class JobPhase implements Serializable { ...@@ -89,17 +92,19 @@ public class JobPhase implements Serializable {
} }
/** /**
* <p>Lets changing the current phase of the associated job considering or not the order of execution phases.</p> * Lets changing the current phase of the associated job considering or
* * not the order of execution phases.
*
* <p><i>Note: * <p><i>Note:
* If the given phase is <i>null</i>, nothing is done. * If the given phase is <i>null</i>, nothing is done.
* </i></p> * </i></p>
* *
* @param p The new phase. * @param p The new phase.
* @param force <i>true</i> to ignore the phases order, <i>false</i> otherwise. * @param force <i>true</i> to ignore the phases order,
* * <i>false</i> otherwise.
*
* @throws UWSException If the phase transition is forbidden. * @throws UWSException If the phase transition is forbidden.
* *
* @see #setPendingPhase(boolean) * @see #setPendingPhase(boolean)
* @see #setQueuedPhase(boolean) * @see #setQueuedPhase(boolean)
* @see #setExecutingPhase(boolean) * @see #setExecutingPhase(boolean)
...@@ -108,6 +113,7 @@ public class JobPhase implements Serializable { ...@@ -108,6 +113,7 @@ public class JobPhase implements Serializable {
* @see #setErrorPhase(boolean) * @see #setErrorPhase(boolean)
* @see #setHeldPhase(boolean) * @see #setHeldPhase(boolean)
* @see #setSuspendedPhase(boolean) * @see #setSuspendedPhase(boolean)
* @see #setArchivedPhase(boolean)
* @see #setUnknownPhase(boolean) * @see #setUnknownPhase(boolean)
*/ */
public void setPhase(ExecutionPhase p, boolean force) throws UWSException{ public void setPhase(ExecutionPhase p, boolean force) throws UWSException{
...@@ -140,6 +146,9 @@ public class JobPhase implements Serializable { ...@@ -140,6 +146,9 @@ public class JobPhase implements Serializable {
case SUSPENDED: case SUSPENDED:
setSuspendedPhase(force); setSuspendedPhase(force);
break; break;
case ARCHIVED:
setArchivedPhase(force);
break;
case UNKNOWN: case UNKNOWN:
default: default:
setUnknownPhase(force); setUnknownPhase(force);
...@@ -149,172 +158,215 @@ public class JobPhase implements Serializable { ...@@ -149,172 +158,215 @@ public class JobPhase implements Serializable {
/** /**
* Changes the current phase to {@link ExecutionPhase#PENDING PENDING}. * Changes the current phase to {@link ExecutionPhase#PENDING PENDING}.
* *
* @param force <i>true</i> to ignore the phases order, <i>false</i> otherwise. * @param force <i>true</i> to ignore the phases order,
* * <i>false</i> otherwise.
* @throws UWSException If this phase transition is forbidden <i>(by default: IF force=false AND currentPhase != PENDING or UNKNOWN)</i>. *
* @throws UWSException If this phase transition is forbidden
* <i>(by default: IF force=false
* AND currentPhase != PENDING and UNKNOWN)</i>.
*/ */
protected void setPendingPhase(boolean force) throws UWSException{ protected void setPendingPhase(boolean force) throws UWSException{
if (!force && phase != ExecutionPhase.PENDING && phase != ExecutionPhase.UNKNOWN) if (!force && phase != ExecutionPhase.PENDING && phase != ExecutionPhase.UNKNOWN)
throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.PENDING)); throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.PENDING));
phase = ExecutionPhase.PENDING; phase = ExecutionPhase.PENDING;
} }
/** /**
* Changes the current phase to {@link ExecutionPhase#QUEUED QUEUED}. * Changes the current phase to {@link ExecutionPhase#QUEUED QUEUED}.
* *
* @param force <i>true</i> to ignore the phases order, <i>false</i> otherwise. * @param force <i>true</i> to ignore the phases order,
* * <i>false</i> otherwise.
* @throws UWSException If this phase transition is forbidden <i>(by default: IF force=false AND currentPhase != QUEUED or HELD or PENDING or UNKNOWN)</i>. *
* @throws UWSException If this phase transition is forbidden
* <i>(by default: IF force=false
* AND currentPhase != QUEUED, HELD, PENDING
* and UNKNOWN)</i>.
*/ */
protected void setQueuedPhase(boolean force) throws UWSException{ protected void setQueuedPhase(boolean force) throws UWSException{
if (force) if (!force && phase != ExecutionPhase.QUEUED && phase != ExecutionPhase.HELD && phase != ExecutionPhase.PENDING && phase != ExecutionPhase.UNKNOWN)
phase = ExecutionPhase.QUEUED; throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.QUEUED));
else{ phase = ExecutionPhase.QUEUED;
if (phase != ExecutionPhase.QUEUED && phase != ExecutionPhase.HELD && phase != ExecutionPhase.PENDING && phase != ExecutionPhase.UNKNOWN)
throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.QUEUED));
phase = ExecutionPhase.QUEUED;
}
} }
/** /**
* Changes the current phase to {@link ExecutionPhase#EXECUTING EXECUTING}. * Changes the current phase to {@link ExecutionPhase#EXECUTING EXECUTING}.
* *
* @param force <i>true</i> to ignore the phases order, <i>false</i> otherwise. * @param force <i>true</i> to ignore the phases order,
* * <i>false</i> otherwise.
* @throws UWSException If this phase transition is forbidden <i>(by default: IF force=false AND currentPhase != EXECUTING or SUSPENDED or QUEUED or UNKNOWN)</i>. *
* @throws UWSException If this phase transition is forbidden
* <i>(by default: IF force=false
* AND currentPhase != EXECUTING, HELD, SUSPENDED,
* QUEUED and UNKNOWN)</i>.
*/ */
protected void setExecutingPhase(boolean force) throws UWSException{ protected void setExecutingPhase(boolean force) throws UWSException{
if (force) if (!force && phase != ExecutionPhase.EXECUTING && phase != ExecutionPhase.HELD && phase != ExecutionPhase.SUSPENDED && phase != ExecutionPhase.QUEUED && phase != ExecutionPhase.UNKNOWN)
phase = ExecutionPhase.EXECUTING; throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.EXECUTING));
else{ phase = ExecutionPhase.EXECUTING;
if (phase != ExecutionPhase.EXECUTING && phase != ExecutionPhase.SUSPENDED && phase != ExecutionPhase.PENDING && phase != ExecutionPhase.QUEUED && phase != ExecutionPhase.UNKNOWN)
throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.EXECUTING));
phase = ExecutionPhase.EXECUTING;
}
} }
/** /**
* Changes the current phase to {@link ExecutionPhase#COMPLETED COMPLETED}. * Changes the current phase to {@link ExecutionPhase#COMPLETED COMPLETED}.
* *
* @param force <i>true</i> to ignore the phases order, <i>false</i> otherwise. * @param force <i>true</i> to ignore the phases order,
* * <i>false</i> otherwise.
* @throws UWSException If this phase transition is forbidden <i>(by default: IF force=false AND currentPhase != COMPLETED or EXECUTING or UNKNOWN)</i>. *
* @throws UWSException If this phase transition is forbidden
* <i>(by default: IF force=false
* AND currentPhase != COMPLETED, EXECUTING
* and UNKNOWN)</i>.
*/ */
protected void setCompletedPhase(boolean force) throws UWSException{ protected void setCompletedPhase(boolean force) throws UWSException{
if (force) if (!force && phase != ExecutionPhase.COMPLETED && phase != ExecutionPhase.EXECUTING && phase != ExecutionPhase.UNKNOWN)
phase = ExecutionPhase.COMPLETED; throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.COMPLETED));
else{ phase = ExecutionPhase.COMPLETED;
if (phase != ExecutionPhase.COMPLETED && phase != ExecutionPhase.EXECUTING && phase != ExecutionPhase.UNKNOWN)
throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.COMPLETED));
phase = ExecutionPhase.COMPLETED;
}
} }
/** /**
* Changes the current phase to {@link ExecutionPhase#ABORTED ABORTED}. * Changes the current phase to {@link ExecutionPhase#ABORTED ABORTED}.
* *
* @param force <i>true</i> to ignore the phases order, <i>false</i> otherwise. * @param force <i>true</i> to ignore the phases order,
* * <i>false</i> otherwise.
* @throws UWSException If this phase transition is forbidden <i>(by default: IF force=false AND currentPhase = COMPLETED or ERROR)</i>. *
* @throws UWSException If this phase transition is forbidden
* <i>(by default: IF force=false
* AND currentPhase = COMPLETED, ERROR
* or ARCHIVED)</i>.
*/ */
protected void setAbortedPhase(boolean force) throws UWSException{ protected void setAbortedPhase(boolean force) throws UWSException{
if (force) if (!force && (phase == ExecutionPhase.COMPLETED || phase == ExecutionPhase.ERROR || phase == ExecutionPhase.ARCHIVED))
phase = ExecutionPhase.ABORTED; throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.ABORTED));
else{ phase = ExecutionPhase.ABORTED;
if (phase == ExecutionPhase.COMPLETED || phase == ExecutionPhase.ERROR)
throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.ABORTED));
phase = ExecutionPhase.ABORTED;
}
} }
/** /**
* Changes the current phase to {@link ExecutionPhase#ERROR ERROR}. * Changes the current phase to {@link ExecutionPhase#ERROR ERROR}.
* *
* @param force <i>true</i> to ignore the phases order, <i>false</i> otherwise. * @param force <i>true</i> to ignore the phases order,
* * <i>false</i> otherwise.
* @throws UWSException If this phase transition is forbidden <i>(by default: IF force=false AND currentPhase = COMPLETED or ABORTED)</i>. *
* @throws UWSException If this phase transition is forbidden
* <i>(by default: IF force=false
* AND currentPhase = COMPLETED, ABORTED
* or ARCHIVED)</i>.
*/ */
protected void setErrorPhase(boolean force) throws UWSException{ protected void setErrorPhase(boolean force) throws UWSException{
if (force) if (!force && (phase == ExecutionPhase.COMPLETED || phase == ExecutionPhase.ABORTED || phase == ExecutionPhase.ARCHIVED))
phase = ExecutionPhase.ERROR; throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.ERROR));
else{ phase = ExecutionPhase.ERROR;
if (phase == ExecutionPhase.COMPLETED || phase == ExecutionPhase.ABORTED)
throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.ERROR));
phase = ExecutionPhase.ERROR;
}
} }
/** /**
* Changes the current phase to {@link ExecutionPhase#HELD HELD}. * Changes the current phase to {@link ExecutionPhase#HELD HELD}.
* *
* @param force <i>true</i> to ignore the phases order, <i>false</i> otherwise. * @param force <i>true</i> to ignore the phases order,
* * <i>false</i> otherwise.
* @throws UWSException If this phase transition is forbidden <i>(by default: IF force=false AND currentPhase != HELD or PENDING or UNKNOWN)</i>. *
* @throws UWSException If this phase transition is forbidden
* <i>(by default: IF force=false
* AND currentPhase != HELD, PENDING, EXECUTING
* and UNKNOWN)</i>.
*/ */
protected void setHeldPhase(boolean force) throws UWSException{ protected void setHeldPhase(boolean force) throws UWSException{
if (!force && phase != ExecutionPhase.HELD && phase != ExecutionPhase.PENDING && phase != ExecutionPhase.UNKNOWN) if (!force && phase != ExecutionPhase.HELD && phase != ExecutionPhase.PENDING && phase != ExecutionPhase.EXECUTING && phase != ExecutionPhase.UNKNOWN)
throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.HELD)); throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.HELD));
phase = ExecutionPhase.HELD; phase = ExecutionPhase.HELD;
} }
/** /**
* Changes the current phase to {@link ExecutionPhase#SUSPENDED SUSPENDED}. * Changes the current phase to {@link ExecutionPhase#SUSPENDED SUSPENDED}.
* *
* @param force <i>true</i> to ignore the phases order, <i>false</i> otherwise. * @param force <i>true</i> to ignore the phases order,
* * <i>false</i> otherwise.
* @throws UWSException By default, never ! *
* @throws UWSException If this phase transition is forbidden
* <i>(by default: IF force=false
* AND currentPhase != SUSPENDED, EXECUTING
* and UNKNOWN)</i>.
*/ */
protected void setSuspendedPhase(boolean force) throws UWSException{ protected void setSuspendedPhase(boolean force) throws UWSException{
if (!force && phase != ExecutionPhase.SUSPENDED && phase != ExecutionPhase.EXECUTING && phase != ExecutionPhase.UNKNOWN)
throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.SUSPENDED));
phase = ExecutionPhase.SUSPENDED; phase = ExecutionPhase.SUSPENDED;
} }
/**
* Changes the current phase to {@link ExecutionPhase#ARCHIVED ARCHIVED}.
*
* @param force <i>true</i> to ignore the phases order,
* <i>false</i> otherwise.
*
* @throws UWSException If this phase transition is forbidden
* <i>(by default: IF force=false
* AND currentPhase != ARCHIVED, COMPLETED, ABORTED,
* and UNKNOWN)</i>.
*
* @since 4.3
*/
protected void setArchivedPhase(boolean force) throws UWSException{
if (!force && phase != ExecutionPhase.ARCHIVED && phase != ExecutionPhase.COMPLETED && phase != ExecutionPhase.ABORTED && phase != ExecutionPhase.ERROR && phase != ExecutionPhase.UNKNOWN)
throw new UWSException(UWSException.BAD_REQUEST, UWSExceptionFactory.incorrectPhaseTransition(job.getJobId(), phase, ExecutionPhase.ARCHIVED));
phase = ExecutionPhase.ARCHIVED;
}
/** /**
* Changes the current phase to {@link ExecutionPhase#UNKNOWN UNKNOWN}. * Changes the current phase to {@link ExecutionPhase#UNKNOWN UNKNOWN}.
* *
* @param force <i>true</i> to ignore the phases order, <i>false</i> otherwise. * @param force <i>true</i> to ignore the phases order,
* * <i>false</i> otherwise.
* @throws UWSException By default, never ! *
* @throws UWSException By default, never!
*/ */
protected void setUnknownPhase(boolean force) throws UWSException{ protected void setUnknownPhase(boolean force) throws UWSException{
phase = ExecutionPhase.UNKNOWN; phase = ExecutionPhase.UNKNOWN;
} }
/** /**
* <p>Indicates whether the job attributes (except errors and results) can be updated, considering its current phase.</p> * Indicates whether the job attributes (except errors and results) can be
* * updated, considering its current phase.
* <p><i><u>Note:</u> By default, it returns TRUE only if the current phase is equals to {@link ExecutionPhase#PENDING PENDING} !</i></p> *
* * <p><i>Note:
* @return <i>true</i> if the job can be updated, <i>false</i> otherwise. * By default, it returns TRUE only if the current phase is equals to
* {@link ExecutionPhase#PENDING PENDING}!
* </i></p>
*
* @return <i>true</i> if the job can be updated,
* <i>false</i> otherwise.
*/ */
public boolean isJobUpdatable(){ public boolean isJobUpdatable(){
return phase == ExecutionPhase.PENDING; return phase == ExecutionPhase.PENDING;
} }
/** /**
* <p>Indicates whether the job is finished or not, considering its current phase.</p> * Indicates whether the job is finished or not, considering its current
* * phase.
* <p><i><u>Note:</u> By default, it returns TRUE only if the current phase is either {@link ExecutionPhase#COMPLETED COMPLETED}, *
* {@link ExecutionPhase#ABORTED ABORTED} or {@link ExecutionPhase#ERROR ERROR} !</i></p> * <p><i>Note:
* * By default, it returns TRUE only if the current phase is either
* @return <i>true</i> if the job is finished, <i>false</i> otherwise. * {@link ExecutionPhase#COMPLETED COMPLETED},
* {@link ExecutionPhase#ABORTED ABORTED},
* {@link ExecutionPhase#ERROR ERROR}
* or {@link ExecutionPhase#ARCHIVED ARCHIVED}!
* </i></p>
*
* @return <i>true</i> if the job is finished,
* <i>false</i> otherwise.
*/ */
public boolean isFinished(){ public boolean isFinished(){
return phase == ExecutionPhase.COMPLETED || phase == ExecutionPhase.ABORTED || phase == ExecutionPhase.ERROR; return phase == ExecutionPhase.COMPLETED || phase == ExecutionPhase.ABORTED || phase == ExecutionPhase.ERROR || phase == ExecutionPhase.ARCHIVED;
} }
/** /**
* <p>Indicates whether the job is executing, considering its current phase.</p> * Indicates whether the job is executing, considering its current phase.
* *
* <p><i><u>Note:</u> By default, it returns TRUE only if the current phase is {@link ExecutionPhase#EXECUTING EXECUTING} !</i></p> * <p><i>Note:
* * By default, it returns TRUE only if the current phase is
* @return <i>true</i> if the job is executing, <i>false</i> otherwise. * {@link ExecutionPhase#EXECUTING EXECUTING}!
* </i></p>
*
* @return <i>true</i> if the job is executing,
* <i>false</i> otherwise.
*/ */
public boolean isExecuting(){ public boolean isExecuting(){
return phase == ExecutionPhase.EXECUTING; return phase == ExecutionPhase.EXECUTING;
......
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment