Debian Codegraph @

avogadro/molequeue/client/jobobject.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_MOLEQUEUE_JOBOBJECT_H
7 #define AVOGADRO_MOLEQUEUE_JOBOBJECT_H
8
9 #include "avogadromolequeueexport.h"
10
11 #include <QtCore/QJsonObject>
12
13 #include <QtCore/QString>
14 #include <QtCore/QVariant>
15
16 namespace Avogadro {
17 namespace MoleQueue {
18
19 /**
20 * @class JobObject jobobject.h <molequeue/client/jobobject.h>
21 * @brief Simple client-side representation for a MoleQueue job.
22 * @author Marcus D. Hanwell
23 *
24 * The Job class provides a simple interface to the client side representation
25 * of a job to be submitted to MoleQueue. Any fields that are not set/present
26 * will be omitted entirely, or set to default values by MoleQueue. The internal
27 * representation of a job (and the transport used) is JSON.
28 *
29 * The Job class and data structure is very lightweight, and designed to be
30 * easily copied, modified and passed around.
31 */
32
33 class AVOGADROMOLEQUEUE_EXPORT JobObject
34 {
35 public:
36 JobObject();
37 ~JobObject();
38
39 /** Set the @p value of the specified @p key. */
40 void setValue(const QString& key, const QVariant& value);
41
42 /** Get the value of the specified @p key. If the key is not set, return
43 * @p defaultValue. */
44 QVariant value(const QString& key,
45 const QVariant& defaultValue = QVariant()) const;
46
47 /**
48 * Set the job up using the supplied JSON object. This replaces all previous
49 * settings that may have been applied.
50 */
51 void fromJson(const QJsonObject& jsonObject) { m_value = jsonObject; }
52
53 /** Get the JSON object with the current job settings in it. */
54 QJsonObject json() const { return m_value; }
55
56 /**
57 * Set the queue that the job should be submitted to. This must be a valid
58 * queue name discovered using the client API.
59 */
60 void setQueue(const QString& queueName);
61
62 /**
63 * Get the name of the queue that the job will be submitted to. An empty
64 * string means that no queue has been set.
65 */
66 QString queue() const;
67
68 /**
69 * Set the program that the job should be submitted to. This must be a valid
70 * program in a valid queue as discovered using the client API.
71 */
72 void setProgram(const QString& programName);
73
74 /**
75 * Get the name of the program that the job will be submitted to. An empty
76 * string means that no program has been set.
77 */
78 QString program() const;
79
80 /**
81 * Set the description of the job, this is free text.
82 */
83 void setDescription(const QString& descriptionText);
84
85 /**
86 * Get the description of the job.
87 */
88 QString description() const;
89
90 /**
91 * @brief Set the input file for the job.
92 * @param fileName The file name as it will appear in the working directory.
93 * @param contents The contents of the file specified.
94 */
95 void setInputFile(const QString& fileName, const QString& contents);
96
97 /**
98 * Set the input file for the job, the file will be copied and the file name
99 * used in the working directory of the job submission.
100 * \param path The full path to the input file.
101 */
102 void setInputFile(const QString& path);
103
104 /**
105 * Set the input file using a JSON object. This must conform to the file
106 * specification.
107 * @param file A JSON object employing file specification to specify input.
108 */
109 void setInputFile(const QJsonObject& file);
110
111 /**
112 * Get the input file for the job. This is a JSON object using the file spec.
113 */
114 QJsonObject inputFile() const;
115
116 /**
117 * Append an additional input file for the job.
118 * @param fileName The file name as it will appear in the working directory.
119 * @param contents The contents of the file specified.
120 */
121 void appendAdditionalInputFile(const QString& fileName,
122 const QString& contents);
123
124 /**
125 * Append an additional input file for the job, the file will be copied and
126 * the file name used in the working directory of the job submission.
127 * @param path The full path to the input file.
128 */
129 void appendAdditionalInputFile(const QString& path);
130
131 /**
132 * Set the additional input file using a JSON object. This must conform to the
133 * file specification.
134 * @param files A JSON array employing file specification to specify input.
135 */
136 void setAdditionalInputFiles(const QJsonArray& files);
137
138 /** Clear additional input files. */
139 void clearAdditionalInputFiles();
140
141 /**
142 * Get the additional input files for the job. This is a JSON object using the
143 * file spec.
144 */
145 QJsonArray additionalInputFiles() const;
146
147 protected:
148 QJsonObject m_value;
149
150 /**
151 * Generate a filespec JSON object form the supplied file name and contents.
152 */
153 QJsonObject fileSpec(const QString& fileName, const QString& contents);
154
155 /**
156 * Generate a filespec JSON object form the supplied file path (must exist).
157 */
158 QJsonObject fileSpec(const QString& path);
159 };
160
161 } // End namespace MoleQueue
162 } // End namespace Avogadro
163
164 #endif // AVOGADRO_MOLEQUEUE_JOBOBJECT_H