1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
/******************************************************************************
This source file is part of the MoleQueue project.
Copyright 2012 Kitware, Inc.
This source code is released under the New BSD License, (the "License").
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
******************************************************************************/
#ifndef MOLEQUEUEGLOBAL_H
#define MOLEQUEUEGLOBAL_H
#include <QtCore/QHash>
#include <QtCore/QMetaType>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <limits>
namespace MoleQueue
{
/// Type for various ids
typedef qint64 IdType;
/// Constant value used for invalid ids
const IdType InvalidId = (std::numeric_limits<IdType>::max)();
/// Type for list queue/program names. Key is queue, value is list of supported
/// programs
typedef QHash<QString, QStringList> QueueListType;
/**
* Enumeration defining states that jobs are allowed to be in.
*/
enum JobState {
/// Unknown status
Unknown = -1,
/// Initial state of job, should never be entered.
None = 0,
/// Job has been accepted by the server and is being prepared (Writing input files, etc).
Accepted,
/// Job is being queued locally, either waiting for local execution or remote submission.
QueuedLocal,
/// Job has been submitted to a remote queuing system.
Submitted,
/// Job is pending execution on a remote queuing system.
QueuedRemote,
/// Job is running locally.
RunningLocal,
/// Job is running remotely.
RunningRemote,
/// Job has completed.
Finished,
/// Job has been terminated at a user request.
Canceled,
/// Job has been terminated due to an error.
Error
};
/**
* Convert a JobState value to a string.
*
* @param state JobState
* @return C string
*/
inline const char * jobStateToString(JobState state)
{
switch (state)
{
case None:
return "None";
case Accepted:
return "Accepted";
case QueuedLocal:
return "QueuedLocal";
case Submitted:
return "Submitted";
case QueuedRemote:
return "QueuedRemote";
case RunningLocal:
return "RunningLocal";
case RunningRemote:
return "RunningRemote";
case Finished:
return "Finished";
case Canceled:
return "Canceled";
case Error:
return "Error";
default:
case Unknown:
return "Unknown";
}
}
/**
* Convert a JobState value to a string that may be displayed in a GUI.
*
* @param state JobState
* @return C string
*/
inline const char * jobStateToGuiString(JobState state)
{
switch (state)
{
case None:
return "None";
case Accepted:
return "Accepted";
case QueuedLocal:
return "Queued local";
case Submitted:
return "Submitted";
case QueuedRemote:
return "Queued remote";
case RunningLocal:
return "Running local";
case RunningRemote:
return "Running remote";
case Finished:
return "Finished";
case Canceled:
return "Canceled";
case Error:
return "Error";
default:
case Unknown:
return "Unknown";
}
}
/**
* Convert a string to a JobState value.
*
* @param state JobState string
* @return JobState
*/
inline JobState stringToJobState(const char *str)
{
if (qstrcmp(str, "None") == 0)
return None;
else if (qstrcmp(str, "Accepted") == 0)
return Accepted;
else if (qstrcmp(str, "QueuedLocal") == 0)
return QueuedLocal;
else if (qstrcmp(str, "Submitted") == 0)
return Submitted;
else if (qstrcmp(str, "QueuedRemote") == 0)
return QueuedRemote;
else if (qstrcmp(str, "RunningLocal") == 0)
return RunningLocal;
else if (qstrcmp(str, "RunningRemote") == 0)
return RunningRemote;
else if (qstrcmp(str, "Finished") == 0)
return Finished;
else if (qstrcmp(str, "Canceled") == 0)
return Canceled;
else if (qstrcmp(str, "Error") == 0)
return Error;
else
return Unknown;
}
/// @overload
inline JobState stringToJobState(const QByteArray &str)
{
return stringToJobState(str.constData());
}
/// @overload
inline JobState stringToJobState(const QString &str)
{
return stringToJobState(qPrintable(str));
}
/**
* Enumeration defining possible error codes.
*/
enum ErrorCode {
/// No error occurred.
NoError = 0,
/// Requested queue does not exist.
InvalidQueue,
/// Requested program does not exist on queue.
InvalidProgram,
/// Job with specified MoleQueue id does not exist.
InvalidMoleQueueId,
/// Job is not in the proper state for the requested operation
InvalidJobState
};
/// Default time in between remote queue updates in minutes.
const int DEFAULT_REMOTE_QUEUE_UPDATE_INTERVAL = 3;
/// Default number of processor cores for a job
const int DEFAULT_NUM_CORES = 1;
/// Default walltime limit for a job
const int DEFAULT_MAX_WALLTIME = 1440;
// Valid names for queues/programs
const char VALID_NAME_REG_EXP[] = "[0-9A-za-z()[\\]{}]"
"[0-9A-Za-z()[\\]{}\\-_+=.@ ]*";
} // end namespace MoleQueue
Q_DECLARE_METATYPE(MoleQueue::IdType)
Q_DECLARE_METATYPE(MoleQueue::QueueListType)
Q_DECLARE_METATYPE(MoleQueue::JobState)
Q_DECLARE_METATYPE(MoleQueue::ErrorCode)
#endif // MOLEQUEUEGLOBAL_H
|