RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
Request.hpp
1 /*
2  * Request.hpp
3  *
4  * Copyright (C) 2019-20 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant to the terms of a commercial license agreement
7  * with RStudio, then this program is licensed to you under the following terms:
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
10  * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
11  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23 
24 #ifndef LAUNCHER_PLUGINS_REQUEST_HPP
25 #define LAUNCHER_PLUGINS_REQUEST_HPP
26 
27 #include <Noncopyable.hpp>
28 
29 #include <set>
30 #include <vector>
31 
32 #include <PImpl.hpp>
33 #include <Optional.hpp>
34 #include <api/Job.hpp>
35 #include <api/stream/AbstractOutputStream.hpp>
36 #include <system/DateTime.hpp>
37 
38 namespace rstudio {
39 namespace launcher_plugins {
40 
41 class Error;
42 
43 namespace json {
44 
45 class Object;
46 
47 } // namespace json
48 
49 namespace system {
50 
51 class User;
52 
53 } // namespace system
54 } // namespace launcher_plugins
55 } // namespace rstudio
56 
57 namespace rstudio {
58 namespace launcher_plugins {
59 namespace api {
60 
64 class Request : public Noncopyable
65 {
66 public:
76  enum class Type
77  {
79  HEARTBEAT = 0,
80 
82  BOOTSTRAP = 1,
83 
85  SUBMIT_JOB = 2,
86 
88  GET_JOB = 3,
89 
91  GET_JOB_STATUS = 4,
92 
94  CONTROL_JOB = 5,
95 
97  GET_JOB_OUTPUT = 6,
98 
101 
103  GET_JOB_NETWORK = 8,
104 
106  GET_CLUSTER_INFO = 9,
107 
109  INVALID
110  };
111 
115  virtual ~Request() = default;
116 
125  static Error fromJson(const json::Object& in_requestJson, std::shared_ptr<Request>& out_request);
126 
132  uint64_t getId() const;
133 
139  Type getType() const;
140 
141 protected:
148  explicit Request(Type in_requestType, const json::Object& in_requestJson);
149 
150  // The private implementation of Request
151  PRIVATE_IMPL(m_baseImpl);
152 };
153 
157 class UserRequest : public Request
158 {
159 public:
168  const system::User& getUser() const;
169 
177  const std::string& getRequestUsername() const;
178 
179 protected:
186  explicit UserRequest(Request::Type in_type, const json::Object& in_requestJson);
187 
188 private:
189  // The private implementation of UserRequest.
190  PRIVATE_IMPL(m_userImpl);
191 
192  friend class Request;
193 };
194 
198 class JobIdRequest : public UserRequest
199 {
200 public:
206  const std::string& getJobId() const;
212  const std::string& getEncodedJobId() const;
213 
214 protected:
221  JobIdRequest(Request::Type in_type, const json::Object& in_requestJson);
222 
223 private:
224  // The private implementation of JobIdRequest.
225  PRIVATE_IMPL(m_jobIdImpl);
226 };
227 
231 class BootstrapRequest final : public Request
232 {
233 public:
239  int getMajorVersion() const;
240 
246  int getMinorVersion() const;
247 
253  int getPatchNumber() const;
254 
255 private:
261  explicit BootstrapRequest(const json::Object& in_requestJson);
262 
263  // The private implementation of BootstrapRequest.
264  PRIVATE_IMPL(m_impl);
265 
266  friend class Request;
267 };
268 
272 class SubmitJobRequest final : public UserRequest
273 {
274 public:
280  JobPtr getJob();
281 
282 private:
288  explicit SubmitJobRequest(const json::Object& in_requestJson);
289 
290  // The private implementation of SubmitJobRequest
291  PRIVATE_IMPL(m_impl);
292 
293  friend class Request;
294 };
295 
299 class JobStateRequest final : public JobIdRequest
300 {
301 public:
311  Error getEndTime(Optional<system::DateTime>& out_endTime) const;
312 
322 
333  Error getStartTime(Optional<system::DateTime>& out_endTime) const;
334 
345  Error getStatusSet(Optional<std::set<Job::State> >& out_statuses) const;
346 
354  const Optional<std::set<std::string> >& getTagSet() const;
355 
356 private:
362  explicit JobStateRequest(const json::Object& in_requestJson);
363 
364  // The private implementation of JobStateRequest
365  PRIVATE_IMPL(m_impl);
366 
367  friend class Request;
368 };
369 
373 class JobStatusRequest final : public JobIdRequest
374 {
375 public:
381  bool isCancelRequest() const;
382 
383 private:
389  explicit JobStatusRequest(const json::Object& in_requestJson);
390 
391  // The private implementation of JobStatusRequest
392  PRIVATE_IMPL(m_impl);
393 
394  friend class Request;
395 };
396 
400 class ControlJobRequest final : public JobIdRequest
401 {
402 public:
407  enum class Operation
408  {
410  FIRST = 0,
411  SUSPEND = 0,
412 
414  RESUME = 1,
415 
417  STOP = 2,
418 
420  KILL = 3,
421 
423  CANCEL = 4,
424 
426  INVALID
427  };
428 
434  Operation getOperation() const;
435 
436 private:
442  explicit ControlJobRequest(const json::Object& in_requestJson);
443 
444  // The private implementation of ControlJobRequest
445  PRIVATE_IMPL(m_impl);
446 
447  friend class Request;
448 };
449 
453 class OutputStreamRequest final : public JobIdRequest
454 {
455 public:
456 
462  OutputType getStreamType() const;
463 
469  bool isCancelRequest() const;
470 
471 private:
477  explicit OutputStreamRequest(const json::Object& in_requestJson);
478 
479  // The private implementation of OutputStreamRequest
480  PRIVATE_IMPL(m_impl);
481 
482  friend class Request;
483 
484 };
485 
490 {
491 public:
497  bool isCancelRequest() const;
498 
499 private:
505  explicit ResourceUtilStreamRequest(const json::Object& in_requestJson);
506 
507  // The private implementation of ResourceUtilStreamRequest
508  PRIVATE_IMPL(m_impl);
509 
510  friend class Request;
511 };
512 
516 class NetworkRequest final : public JobIdRequest
517 {
518 private:
524  explicit NetworkRequest(const json::Object& in_requestJson);
525 
526  friend class Request;
527 };
528 
537 std::ostream& operator<<(std::ostream& in_ostream, Request::Type in_type);
538 
539 } // namespace api
540 } // namespace launcher_plugins
541 } // namespace rstudio
542 
543 #endif
rstudio::launcher_plugins::api::Request::Type::GET_JOB_RESOURCE_UTIL
rstudio::launcher_plugins::api::Request::Type::INVALID
rstudio::launcher_plugins::json::Object
Class which represents a specific type of JSON Value: a JSON object.
Definition: Json.hpp:687
rstudio::launcher_plugins::api::JobStateRequest::getStatusSet
Error getStatusSet(Optional< std::set< Job::State > > &out_statuses) const
Gets the set of Job statuses by which to filter the returned list of jobs.
rstudio::launcher_plugins::api::ControlJobRequest::Operation::INVALID
rstudio::launcher_plugins::api::JobIdRequest::JobIdRequest
JobIdRequest(Request::Type in_type, const json::Object &in_requestJson)
Constructor.
rstudio::launcher_plugins::api::Request::getType
Type getType() const
Gets the request type.
rstudio::launcher_plugins::api::NetworkRequest
Request from the Launcher to get the network information for a job.
Definition: Request.hpp:516
rstudio::launcher_plugins::api::ResourceUtilStreamRequest
Request from the launcher to begin or end a Resource Utilization Stream.
Definition: Request.hpp:489
rstudio::launcher_plugins::system::User
Class which represents a system user.
Definition: User.hpp:55
rstudio::launcher_plugins::api::BootstrapRequest::getPatchNumber
int getPatchNumber() const
Gets the patch number of the RStudio Launcher that sent this bootstrap request.
rstudio::launcher_plugins::api::ControlJobRequest::getOperation
Operation getOperation() const
Gets the control job action which should be taken.
rstudio::launcher_plugins::api::BootstrapRequest::getMinorVersion
int getMinorVersion() const
Gets the minor version of the RStudio Launcher that sent this bootstrap request.
rstudio::launcher_plugins::api::Request::~Request
virtual ~Request()=default
Virtual destructor for inheritance.
rstudio::launcher_plugins::api::ControlJobRequest::Operation::KILL
rstudio::launcher_plugins::api::JobStateRequest
Represents a job state request received from the Launcher.
Definition: Request.hpp:299
rstudio::launcher_plugins::api::ControlJobRequest::Operation::CANCEL
rstudio::launcher_plugins::api::Request::Request
Request(Type in_requestType, const json::Object &in_requestJson)
Constructor.
rstudio::launcher_plugins::api::SubmitJobRequest
Represents a submit job request from the Launcher.
Definition: Request.hpp:272
rstudio::launcher_plugins::api::Request::Type::GET_JOB
rstudio::launcher_plugins::api::OutputStreamRequest::getStreamType
OutputType getStreamType() const
Gets the type of Output that should be streamed.
rstudio::launcher_plugins::api::JobStatusRequest::isCancelRequest
bool isCancelRequest() const
Gets whether the Job Status Stream should be started (false) or ended (true).
rstudio::launcher_plugins::api::Request::Type::HEARTBEAT
rstudio::launcher_plugins::api::Request::Type::CONTROL_JOB
rstudio::launcher_plugins::api::JobIdRequest::getEncodedJobId
const std::string & getEncodedJobId() const
Gets the ID of the job for which this request was made.
rstudio::launcher_plugins::api::Request::Type::GET_CLUSTER_INFO
rstudio::launcher_plugins::api::Request::getId
uint64_t getId() const
Gets the ID of this request.
rstudio::launcher_plugins::api::ControlJobRequest::Operation::RESUME
rstudio::launcher_plugins::api::BootstrapRequest::getMajorVersion
int getMajorVersion() const
Gets the major version of the RStudio Launcher that sent this bootstrap request.
rstudio::launcher_plugins::api::ResourceUtilStreamRequest::isCancelRequest
bool isCancelRequest() const
Gets whether the Resource Utilization Stream should be started (false) or ended (true).
rstudio::launcher_plugins::api::Request
Base class for all requests which may be received from the Launcher.
Definition: Request.hpp:64
rstudio::launcher_plugins::api::SubmitJobRequest::getJob
JobPtr getJob()
Gets the job that should be submitted to the Job Scheduling System.
rstudio::launcher_plugins::api::ControlJobRequest
Request from the launcher to control the state of a Job.
Definition: Request.hpp:400
rstudio::launcher_plugins::api::ControlJobRequest::Operation
Operation
Definition: Request.hpp:407
rstudio::launcher_plugins::api::OutputStreamRequest
Request from the launcher to begin or end a Job Output Stream.
Definition: Request.hpp:453
rstudio::launcher_plugins::api::JobIdRequest::getJobId
const std::string & getJobId() const
Gets the ID of the job for which this request was made.
rstudio::launcher_plugins::api::JobStateRequest::getTagSet
const Optional< std::set< std::string > > & getTagSet() const
Gets the set of Job tags by which to filter the returned list of jobs.
rstudio::launcher_plugins::api::UserRequest::getUser
const system::User & getUser() const
Gets the user who initiated this request.
rstudio::launcher_plugins::api::ControlJobRequest::Operation::STOP
rstudio::launcher_plugins::Error
Class which represents an error.
Definition: Error.hpp:174
rstudio::launcher_plugins::api::UserRequest
Base class which should be used by the class of requests which require a username.
Definition: Request.hpp:157
rstudio::launcher_plugins::api::BootstrapRequest
Represents a bootstrap request received from the Launcher.
Definition: Request.hpp:231
rstudio::launcher_plugins::api::UserRequest::getRequestUsername
const std::string & getRequestUsername() const
Gets the actual username that was used when the request was submitted.
rstudio::launcher_plugins::api::Request::Type::GET_JOB_NETWORK
rstudio::launcher_plugins::api::JobStateRequest::getEndTime
Error getEndTime(Optional< system::DateTime > &out_endTime) const
Gets the end of the date range for this request.
rstudio::launcher_plugins::api::JobStatusRequest
Request from the launcher to begin or end a Job Status Stream.
Definition: Request.hpp:373
rstudio::launcher_plugins::api::Request::Type::GET_JOB_STATUS
rstudio::launcher_plugins::Noncopyable
Class which can be inherited from to disallow copying of its child classes.
Definition: Noncopyable.hpp:34
rstudio::launcher_plugins::Optional
Container class which represents a value that may or may not be set.
Definition: Optional.hpp:38
rstudio::launcher_plugins::api::JobIdRequest
Base class which should be used for requests that require a Job ID.
Definition: Request.hpp:198
rstudio::launcher_plugins::api::Request::Type::BOOTSTRAP
rstudio::launcher_plugins::api::OutputStreamRequest::isCancelRequest
bool isCancelRequest() const
Gets whether the Job Output Stream should be started (false) or ended (true).
rstudio::launcher_plugins::api::Request::Type::GET_JOB_OUTPUT
rstudio::launcher_plugins::api::JobStateRequest::getFieldSet
const Optional< std::set< std::string > > & getFieldSet() const
Gets the set of Job fields which should be included in the response.
rstudio::launcher_plugins::api::Request::fromJson
static Error fromJson(const json::Object &in_requestJson, std::shared_ptr< Request > &out_request)
Converts a Json::Object into the appropriate Request object.
rstudio::launcher_plugins::api::ControlJobRequest::Operation::FIRST
rstudio::launcher_plugins::api::Request::Type
Type
Definition: Request.hpp:76
rstudio::launcher_plugins::api::JobStateRequest::getStartTime
Error getStartTime(Optional< system::DateTime > &out_endTime) const
Gets the start of the date range for this request.
rstudio::launcher_plugins::api::Request::Type::SUBMIT_JOB
rstudio::launcher_plugins::api::UserRequest::UserRequest
UserRequest(Request::Type in_type, const json::Object &in_requestJson)
Constructor.