RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
Response.hpp
1 /*
2  * Response.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 
25 #ifndef LAUNCHER_PLUGINS_RESPONSE_HPP
26 #define LAUNCHER_PLUGINS_RESPONSE_HPP
27 
28 #include <Noncopyable.hpp>
29 
30 #include <vector>
31 
32 #include <PImpl.hpp>
33 #include <api/Job.hpp>
34 #include <api/ResponseTypes.hpp>
35 #include <api/stream/AbstractOutputStream.hpp>
36 
37 namespace rstudio {
38 namespace launcher_plugins {
39 namespace json {
40 
41 class Object;
42 
43 } // namespace json
44 } // namespace launcher_plugins
45 } // namespace rstudio
46 
47 namespace rstudio {
48 namespace launcher_plugins {
49 namespace api {
50 
51 struct JobSourceConfiguration;
52 
56 class Response : public Noncopyable
57 {
58 public:
62  virtual ~Response() = default;
63 
69  virtual json::Object toJson() const;
70 
71 protected:
79  enum class Type
80  {
82  ERROR = -1,
83 
85  HEARTBEAT = 0,
86 
88  BOOTSTRAP = 1,
89 
91  JOB_STATE = 2,
92 
94  JOB_STATUS = 3,
95 
97  CONTROL_JOB = 4,
98 
100  JOB_OUTPUT = 5,
101 
103  JOB_RESOURCE_UTIL = 6,
104 
106  JOB_NETWORK = 7,
107 
109  CLUSTER_INFO = 8,
110  };
111 
118  Response(Type in_responseType, uint64_t in_requestId);
119 
120 private:
121  // The private implementation of Response.
122  PRIVATE_IMPL(m_responseImpl);
123 };
124 
129 {
130 public:
136  json::Object toJson() const override;
137 
138 protected:
145  MultiStreamResponse(Type in_responseType, StreamSequences in_sequences);
146 
147 private:
148  // The private implementation of MultiStreamResponse
149  PRIVATE_IMPL(m_streamResponseImpl);
150 };
151 
155 class ErrorResponse final : public Response
156 {
157 public:
165  enum class Type
166  {
167  INVALID_RESPONSE = -1,
168  UNKNOWN = 0,
169  REQUEST_NOT_SUPPORTED = 1,
170  INVALID_REQUEST = 2,
171  JOB_NOT_FOUND = 3,
172  PLUGIN_RESTARTED = 4,
173  TIMEOUT = 5,
174  JOB_NOT_RUNNING = 6,
175  JOB_OUTPUT_NOT_FOUND = 7,
176  INVALID_JOB_STATE = 8,
177  JOB_CONTROL_FAILURE = 9,
178  UNSUPPORTED_VERSION = 10,
179  };
180 
188  ErrorResponse(uint64_t in_requestId, Type in_errorType, std::string in_errorMessage);
189 
195  json::Object toJson() const override;
196 
197 private:
198  // The private implementation of ErrorResponse.
199  PRIVATE_IMPL(m_impl);
200 };
201 
206 class HeartbeatResponse final : public Response
207 {
208 public:
213 };
214 
219 class BootstrapResponse final : public Response
220 {
221 public:
227  explicit BootstrapResponse(uint64_t in_requestId);
228 
234  json::Object toJson() const override;
235 };
236 
241 class JobStateResponse final : public Response
242 {
243 public:
253  uint64_t in_requestId,
254  JobList in_jobs,
255  Optional<std::set<std::string> > in_jobFields = Optional<std::set<std::string> >());
256 
262  json::Object toJson() const override;
263 
264 private:
265  // The private implementation of ClusterInfoResponse
266  PRIVATE_IMPL(m_impl);
267 };
268 
273 {
274 public:
281  JobStatusResponse(StreamSequences in_sequences, const JobPtr& in_job);
282 
288  json::Object toJson() const override;
289 
290 private:
291  // The private implementation of JobStatusResponse.
292  PRIVATE_IMPL(m_impl);
293 };
294 
298 class ControlJobResponse final : public Response
299 {
300 public:
308  ControlJobResponse(uint64_t in_requestId, std::string in_statusMessage, bool in_isComplete);
309 
310 
316  json::Object toJson() const override;
317 
318 private:
319  // The private implementation of ControlJobResponse
320  PRIVATE_IMPL(m_impl);
321 };
322 
326 class OutputStreamResponse final : public Response
327 {
328 public:
338  uint64_t in_requestId,
339  uint64_t in_sequenceId,
340  std::string in_output,
341  OutputType in_outputType);
342 
350  uint64_t in_requestId,
351  uint64_t in_sequenceId);
352 
358  json::Object toJson() const override;
359 
360 private:
361  // The private implementation of OutputStreamResponse
362  PRIVATE_IMPL(m_impl);
363 };
364 
369 {
370 public:
379  StreamSequences in_sequences,
380  const ResourceUtilData& in_resourceData,
381  bool in_isComplete);
382 
388  json::Object toJson() const override;
389 
390 private:
391  // The private implementation of ResourceUtilStreamResponse
392  PRIVATE_IMPL(m_impl);
393 };
394 
399 class NetworkResponse final : public Response
400 {
401 public:
408  NetworkResponse(uint64_t in_requestId, NetworkInfo in_networkInfo);
414  json::Object toJson() const override;
415 
416 private:
417  // The private implementation of NetworkResponse
418  PRIVATE_IMPL(m_impl);
419 };
420 
425  class ClusterInfoResponse final : public Response
426  {
427  public:
434  ClusterInfoResponse(uint64_t in_requestId, const JobSourceConfiguration& in_configuration);
435 
441  json::Object toJson() const override;
442 
443  private:
444  // The private implementation of ClusterInfoResponse
445  PRIVATE_IMPL(m_impl);
446 };
447 
448 } // namespace api
449 } // namespace launcher_plugins
450 } // namespace rstudio
451 
452 #endif
rstudio::launcher_plugins::api::Response::Type::CLUSTER_INFO
rstudio::launcher_plugins::api::Response::Type
Type
Definition: Response.hpp:79
rstudio::launcher_plugins::api::NetworkInfo
Represents the network information for a job.
Definition: ResponseTypes.hpp:129
rstudio::launcher_plugins::api::Response::Type::JOB_STATUS
rstudio::launcher_plugins::api::JobStateResponse::toJson
json::Object toJson() const override
Converts this job state response to a JSON object.
rstudio::launcher_plugins::api::Response::toJson
virtual json::Object toJson() const
Converts this response to a JSON object.
rstudio::launcher_plugins::api::Response::Type::JOB_NETWORK
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::NetworkResponse::NetworkResponse
NetworkResponse(uint64_t in_requestId, NetworkInfo in_networkInfo)
Constructor.
rstudio::launcher_plugins::api::HeartbeatResponse::HeartbeatResponse
HeartbeatResponse()
Constructor.
rstudio::launcher_plugins::api::ResourceUtilStreamResponse
Class which represents a Resource Utilization Stream response for a specific job.
Definition: Response.hpp:368
rstudio::launcher_plugins::api::ControlJobResponse::toJson
json::Object toJson() const override
Converts this control job response to a JSON object.
rstudio::launcher_plugins::api::MultiStreamResponse::toJson
json::Object toJson() const override
Converts this MultiStreamResponse to a JSON object.
rstudio::launcher_plugins::api::JobStateResponse
Class which represents a job state response which can be sent to the Launcher in response to a get or...
Definition: Response.hpp:241
rstudio::launcher_plugins::api::ResourceUtilData
Represents the current resource utilization of a job.
Definition: ResponseTypes.hpp:111
rstudio::launcher_plugins::api::Response::Type::JOB_OUTPUT
rstudio::launcher_plugins::api::Response::Type::ERROR
rstudio::launcher_plugins::api::ErrorResponse::ErrorResponse
ErrorResponse(uint64_t in_requestId, Type in_errorType, std::string in_errorMessage)
Constructor.
rstudio::launcher_plugins::api::MultiStreamResponse::MultiStreamResponse
MultiStreamResponse(Type in_responseType, StreamSequences in_sequences)
Constructor.
rstudio::launcher_plugins::api::OutputStreamResponse
Class which represents a Job Output Stream response for a specific job.
Definition: Response.hpp:326
rstudio::launcher_plugins::api::ClusterInfoResponse::toJson
json::Object toJson() const override
Converts this cluster info response to a JSON object.
rstudio::launcher_plugins::api::BootstrapResponse
Class which represents a bootstrap response which can be sent to the Launcher in response to a bootst...
Definition: Response.hpp:219
rstudio::launcher_plugins::api::ControlJobResponse::ControlJobResponse
ControlJobResponse(uint64_t in_requestId, std::string in_statusMessage, bool in_isComplete)
Constructor.
rstudio::launcher_plugins::api::ErrorResponse
Class which represents an error response which can be sent to the Launcher in response to any request...
Definition: Response.hpp:155
rstudio::launcher_plugins::api::NetworkResponse::toJson
json::Object toJson() const override
Converts this cluster info response to a JSON object.
rstudio::launcher_plugins::api::ClusterInfoResponse
Class which represents a cluster info response which should be sent to the Launcher in response to a ...
Definition: Response.hpp:425
rstudio::launcher_plugins::api::ResourceUtilStreamResponse::toJson
json::Object toJson() const override
Converts this resource utilization stream response to a JSON object.
rstudio::launcher_plugins::api::OutputStreamResponse::toJson
json::Object toJson() const override
Converts this output stream response to a JSON object.
rstudio::launcher_plugins::api::OutputStreamResponse::OutputStreamResponse
OutputStreamResponse(uint64_t in_requestId, uint64_t in_sequenceId, std::string in_output, OutputType in_outputType)
Constructor.
rstudio::launcher_plugins::api::BootstrapResponse::BootstrapResponse
BootstrapResponse(uint64_t in_requestId)
Constructor.
rstudio::launcher_plugins::api::MultiStreamResponse
Base class for responses which are returned to multiple stream requests.
Definition: Response.hpp:128
rstudio::launcher_plugins::api::Response::Type::BOOTSTRAP
rstudio::launcher_plugins::api::JobStatusResponse
Class which represents a Job Status Stream, either for all jobs or for a specific job.
Definition: Response.hpp:272
rstudio::launcher_plugins::api::JobStateResponse::JobStateResponse
JobStateResponse(uint64_t in_requestId, JobList in_jobs, Optional< std::set< std::string > > in_jobFields=Optional< std::set< std::string > >())
Constructor.
rstudio::launcher_plugins::api::Response::Type::HEARTBEAT
rstudio::launcher_plugins::api::Response::Type::CONTROL_JOB
rstudio::launcher_plugins::api::JobSourceConfiguration
Describes the capabilities and configuration of this Job Source.
Definition: IJobSource.hpp:77
rstudio::launcher_plugins::api::ResourceUtilStreamResponse::ResourceUtilStreamResponse
ResourceUtilStreamResponse(StreamSequences in_sequences, const ResourceUtilData &in_resourceData, bool in_isComplete)
Constructor.
rstudio::launcher_plugins::api::Response
Represents the common components of all responses which can be sent the RStudio Launcher.
Definition: Response.hpp:56
rstudio::launcher_plugins::api::JobStatusResponse::JobStatusResponse
JobStatusResponse(StreamSequences in_sequences, const JobPtr &in_job)
Constructor.
rstudio::launcher_plugins::api::ClusterInfoResponse::ClusterInfoResponse
ClusterInfoResponse(uint64_t in_requestId, const JobSourceConfiguration &in_configuration)
Constructor.
rstudio::launcher_plugins::api::JobStatusResponse::toJson
json::Object toJson() const override
Converts this job status response to a JSON object.
rstudio::launcher_plugins::api::BootstrapResponse::toJson
json::Object toJson() const override
Converts this bootstrap response to a JSON object.
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::Response::~Response
virtual ~Response()=default
Virtual destructor to allow for inheritance.
rstudio::launcher_plugins::api::Response::Response
Response(Type in_responseType, uint64_t in_requestId)
Constructor.
rstudio::launcher_plugins::api::NetworkResponse
Class which represents a network information response which should be sent to the Launcher in respons...
Definition: Response.hpp:399
rstudio::launcher_plugins::api::HeartbeatResponse
Class which represents a heartbeat response which should be sent to the Launcher every configured hea...
Definition: Response.hpp:206
rstudio::launcher_plugins::api::ErrorResponse::toJson
json::Object toJson() const override
Converts this error response to a JSON object.
rstudio::launcher_plugins::api::Response::Type::JOB_RESOURCE_UTIL
rstudio::launcher_plugins::api::Response::Type::JOB_STATE
rstudio::launcher_plugins::api::ControlJobResponse
Class which represents the result of a control job operation.
Definition: Response.hpp:298