Databricks C++ SDK 0.2.4
Interact with Databricks via an SDK
Loading...
Searching...
No Matches
compute.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <string>
7#include <vector>
8#include <memory>
9
10namespace databricks {
11 // Forward declaration for dependency injection
12 namespace internal {
13 class IHttpClient;
14 }
15
16 /**
17 * @brief Client for interacting with the Databricks Clusters/Compute API
18 *
19 * The Clusters API allows you to create, manage, and control compute clusters
20 * in your Databricks workspace. This implementation uses Clusters API 2.0.
21 *
22 * Example usage:
23 * @code
24 * databricks::AuthConfig auth = databricks::AuthConfig::from_environment();
25 * databricks::Compute compute(auth);
26 *
27 * // List all compute clusters
28 * auto cluster_list = compute.list_compute();
29 *
30 * // Get specific compute cluster details
31 * auto cluster = compute.get_compute("1234-567890-abcde123");
32 *
33 * // Start a terminated compute cluster
34 * compute.start_compute("1234-567890-abcde123");
35 * @endcode
36 */
37 class Compute {
38 public:
39 /**
40 * @brief Construct a Compute API client
41 * @param auth Authentication configuration with host and token
42 */
43 explicit Compute(const AuthConfig& auth);
44
45 /**
46 * @brief Construct a Compute API client with dependency injection (for testing)
47 * @param http_client Injected HTTP client (use MockHttpClient for unit tests)
48 * @note This constructor is primarily for testing with mock HTTP clients
49 */
50 explicit Compute(std::shared_ptr<internal::IHttpClient> http_client);
51
52 /**
53 * @brief Destructor
54 */
56
57 // Disable copy
58 Compute(const Compute&) = delete;
59 Compute& operator=(const Compute&) = delete;
60
61 /**
62 * @brief List all compute clusters in the workspace
63 *
64 * @return Vector of Cluster objects
65 * @throws std::runtime_error if the API request fails
66 */
67 std::vector<Cluster> list_compute();
68
69 /**
70 * @brief Create a new Spark Cluster
71 *
72 * @param cluster Create a cluster in Databricks with Cluster Configs
73 * @return true if the operation was successful
74 */
75 bool create_compute(const Cluster& cluster_config);
76
77 /**
78 * @brief Get detailed information about a specific compute cluster
79 *
80 * @param cluster_id The unique identifier of the cluster
81 * @return Cluster object with full details
82 * @throws std::runtime_error if the cluster is not found or the API request fails
83 */
84 Cluster get_compute(const std::string& cluster_id);
85
86 /**
87 * @brief Start a terminated compute cluster
88 *
89 * @param cluster_id The unique identifier of the cluster to start
90 * @return true if the operation was successful
91 * @throws std::runtime_error if the API request fails
92 */
93 bool start_compute(const std::string& cluster_id);
94
95 /**
96 * @brief Terminate a running compute cluster
97 *
98 * @param cluster_id The unique identifier of the cluster to terminate
99 * @return true if the operation was successful
100 * @throws std::runtime_error if the API request fails
101 *
102 * @note This stops the cluster but does not permanently delete it.
103 * Terminated clusters can be restarted.
104 */
105 bool terminate_compute(const std::string& cluster_id);
106
107 /**
108 * @brief Restart a compute cluster
109 *
110 * @param cluster_id The unique identifier of the cluster to restart
111 * @return true if the operation was successful
112 * @throws std::runtime_error if the API request fails
113 *
114 * @note This will terminate and then start the cluster with the same configuration.
115 */
116 bool restart_compute(const std::string& cluster_id);
117
118 private:
119 class Impl;
120 std::unique_ptr<Impl> pimpl_;
121
122 bool compute_operation(const std::string& cluster_id, const std::string& endpoint, const std::string& operation_name);
123 static std::vector<Cluster> parse_compute_list(const std::string& json_str);
124 static Cluster parse_compute(const std::string& json_str);
125 };
126} // namespace databricks
Client for interacting with the Databricks Clusters/Compute API.
Definition compute.h:37
bool terminate_compute(const std::string &cluster_id)
Terminate a running compute cluster.
std::vector< Cluster > list_compute()
List all compute clusters in the workspace.
~Compute()
Destructor.
Cluster get_compute(const std::string &cluster_id)
Get detailed information about a specific compute cluster.
Compute & operator=(const Compute &)=delete
bool start_compute(const std::string &cluster_id)
Start a terminated compute cluster.
Compute(const Compute &)=delete
Compute(std::shared_ptr< internal::IHttpClient > http_client)
Construct a Compute API client with dependency injection (for testing)
bool restart_compute(const std::string &cluster_id)
Restart a compute cluster.
bool create_compute(const Cluster &cluster_config)
Create a new Spark Cluster.
Compute(const AuthConfig &auth)
Construct a Compute API client.
Core authentication configuration shared across all Databricks features.
Definition config.h:16
Represents a Databricks cluster.