RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
LocalJobSource.hpp
1 /*
2  * LocalJobSource.hpp
3  *
4  * Copyright (C) 2020 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_LOCAL_JOB_SOURCE_HPP
25 #define LAUNCHER_PLUGINS_LOCAL_JOB_SOURCE_HPP
26 
27 #include <api/IJobSource.hpp>
28 
29 #include <vector>
30 
31 #include <api/Job.hpp>
32 #include <jobs/AbstractJobRepository.hpp>
33 #include <jobs/JobStatusNotifier.hpp>
34 
35 #include "LocalJobRepository.hpp"
36 #include "LocalSecureCookie.hpp"
37 #include "LocalJobRunner.hpp"
38 
39 namespace rstudio {
40 namespace launcher_plugins {
41 namespace local {
42 
47 {
48 public:
58  std::string in_hostname,
59  jobs::JobStatusNotifierPtr in_jobStatusNotifier,
60  std::shared_ptr<LocalJobRepository> in_jobRepository);
61 
70  Error initialize() override;
71 
84  bool cancelJob(api::JobPtr in_job, bool& out_isComplete, std::string& out_statusMessage) override;
85 
96  Error getConfiguration(const system::User&, api::JobSourceConfiguration& out_configuration) const override;
97 
106  Error getNetworkInfo(api::JobPtr in_job, api::NetworkInfo& out_networkInfo) const override;
107 
121  bool killJob(api::JobPtr in_job, bool& out_isComplete, std::string& out_statusMessage) override;
122 
136  bool resumeJob(api::JobPtr in_job, bool& out_isComplete, std::string& out_statusMessage) override;
137 
151  bool stopJob(api::JobPtr in_job, bool& out_isComplete, std::string& out_statusMessage) override;
152 
167  bool suspendJob(api::JobPtr in_job, bool& out_isComplete, std::string& out_statusMessage) override;
168 
178  Error submitJob(api::JobPtr io_job, bool& out_wasInvalidRequest) const override;
179 
193  api::OutputType in_outputType,
194  api::JobPtr in_job,
195  api::AbstractOutputStream::OnOutput in_onOutput,
197  api::AbstractOutputStream::OnError in_onError,
198  api::OutputStreamPtr& out_outputStream) override;
199 
210  api::ConstJobPtr in_job,
211  comms::AbstractLauncherCommunicatorPtr in_launcherCommunicator,
212  api::AbstractResourceStreamPtr& out_resourceStream) override;
213 
214 private:
216  const std::string m_hostname;
217 
219  std::shared_ptr<LocalJobRunner> m_jobRunner;
220 };
221 
222 } // namespace local
223 } // namespace launcher_plugins
224 } // namespace rstudio
225 
226 #endif
rstudio::launcher_plugins::api::NetworkInfo
Represents the network information for a job.
Definition: ResponseTypes.hpp:129
rstudio::launcher_plugins::local::LocalJobSource::createResourceStream
Error createResourceStream(api::ConstJobPtr in_job, comms::AbstractLauncherCommunicatorPtr in_launcherCommunicator, api::AbstractResourceStreamPtr &out_resourceStream) override
Creates a resource utilization metric stream for the specified job.
rstudio::launcher_plugins::local::LocalJobSource::getNetworkInfo
Error getNetworkInfo(api::JobPtr in_job, api::NetworkInfo &out_networkInfo) const override
Gets the network information for the specified job.
rstudio::launcher_plugins::local::LocalJobSource::stopJob
bool stopJob(api::JobPtr in_job, bool &out_isComplete, std::string &out_statusMessage) override
Stops a running job.
rstudio::launcher_plugins::system::User
Class which represents a system user.
Definition: User.hpp:55
rstudio::launcher_plugins::local::LocalJobSource::getConfiguration
Error getConfiguration(const system::User &, api::JobSourceConfiguration &out_configuration) const override
Gets the configuration and capabilities of the Local Job Source.
rstudio::launcher_plugins::api::AbstractOutputStream::OnComplete
std::function< void(uint64_t)> OnComplete
Definition: AbstractOutputStream.hpp:66
rstudio::launcher_plugins::local::LocalJobSource::submitJob
Error submitJob(api::JobPtr io_job, bool &out_wasInvalidRequest) const override
Runs a job on the local instance.
rstudio::launcher_plugins::local::LocalJobSource::cancelJob
bool cancelJob(api::JobPtr in_job, bool &out_isComplete, std::string &out_statusMessage) override
Cancels a pending job.
rstudio::launcher_plugins::Error
Class which represents an error.
Definition: Error.hpp:174
rstudio::launcher_plugins::local::LocalJobSource::resumeJob
bool resumeJob(api::JobPtr in_job, bool &out_isComplete, std::string &out_statusMessage) override
Resumes a suspended job.
rstudio::launcher_plugins::api::JobSourceConfiguration
Describes the capabilities and configuration of this Job Source.
Definition: IJobSource.hpp:77
rstudio::launcher_plugins::local::LocalJobSource
Class which is responsible for running and retrieving information about jobs on the Local system.
Definition: LocalJobSource.hpp:46
rstudio::launcher_plugins::api::IJobSource
Generic interface for communicating with a Job Source. Implementation is plugin specific.
Definition: IJobSource.hpp:99
rstudio::launcher_plugins::local::LocalJobSource::initialize
Error initialize() override
Initializes the Local Job Source.
rstudio::launcher_plugins::local::LocalJobSource::killJob
bool killJob(api::JobPtr in_job, bool &out_isComplete, std::string &out_statusMessage) override
Forcibly kills a running job.
rstudio::launcher_plugins::local::LocalJobSource::suspendJob
bool suspendJob(api::JobPtr in_job, bool &out_isComplete, std::string &out_statusMessage) override
Suspends a running job.
rstudio::launcher_plugins::local::LocalJobSource::LocalJobSource
LocalJobSource(std::string in_hostname, jobs::JobStatusNotifierPtr in_jobStatusNotifier, std::shared_ptr< LocalJobRepository > in_jobRepository)
Constructor.
rstudio::launcher_plugins::local::LocalJobSource::createOutputStream
Error createOutputStream(api::OutputType in_outputType, api::JobPtr in_job, api::AbstractOutputStream::OnOutput in_onOutput, api::AbstractOutputStream::OnComplete in_onComplete, api::AbstractOutputStream::OnError in_onError, api::OutputStreamPtr &out_outputStream) override
Creates a file output stream for the specified job.