couchbase 3.0.0.alpha.1-universal-darwin-19 → 3.0.0.alpha.2-universal-darwin-19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests-6.0.3.yml +49 -0
  3. data/.github/workflows/tests.yml +47 -0
  4. data/.gitmodules +3 -0
  5. data/.idea/dictionaries/gem_terms.xml +5 -0
  6. data/.idea/inspectionProfiles/Project_Default.xml +1 -0
  7. data/.idea/vcs.xml +1 -0
  8. data/Gemfile +1 -0
  9. data/README.md +55 -2
  10. data/Rakefile +18 -0
  11. data/bin/init-cluster +62 -0
  12. data/bin/setup +1 -0
  13. data/couchbase.gemspec +3 -2
  14. data/examples/crud.rb +1 -2
  15. data/examples/managing_buckets.rb +47 -0
  16. data/examples/managing_collections.rb +58 -0
  17. data/examples/managing_query_indexes.rb +63 -0
  18. data/examples/query.rb +3 -2
  19. data/examples/query_with_consistency.rb +76 -0
  20. data/examples/subdocument.rb +23 -1
  21. data/ext/.clang-format +1 -1
  22. data/ext/.idea/dictionaries/couchbase_terms.xml +2 -0
  23. data/ext/.idea/vcs.xml +1 -0
  24. data/ext/CMakeLists.txt +30 -12
  25. data/ext/build_version.hxx.in +26 -0
  26. data/ext/couchbase/bucket.hxx +69 -8
  27. data/ext/couchbase/cluster.hxx +70 -54
  28. data/ext/couchbase/collections_manifest.hxx +3 -3
  29. data/ext/couchbase/configuration.hxx +14 -0
  30. data/ext/couchbase/couchbase.cxx +2044 -383
  31. data/ext/couchbase/{operations/document_id.hxx → document_id.hxx} +5 -4
  32. data/ext/couchbase/io/http_message.hxx +5 -1
  33. data/ext/couchbase/io/http_parser.hxx +2 -1
  34. data/ext/couchbase/io/http_session.hxx +6 -3
  35. data/ext/couchbase/io/{binary_message.hxx → mcbp_message.hxx} +15 -12
  36. data/ext/couchbase/io/mcbp_parser.hxx +99 -0
  37. data/ext/couchbase/io/{key_value_session.hxx → mcbp_session.hxx} +200 -95
  38. data/ext/couchbase/io/session_manager.hxx +37 -22
  39. data/ext/couchbase/mutation_token.hxx +2 -1
  40. data/ext/couchbase/operations.hxx +38 -8
  41. data/ext/couchbase/operations/bucket_create.hxx +138 -0
  42. data/ext/couchbase/operations/bucket_drop.hxx +65 -0
  43. data/ext/couchbase/operations/bucket_flush.hxx +65 -0
  44. data/ext/couchbase/operations/bucket_get.hxx +69 -0
  45. data/ext/couchbase/operations/bucket_get_all.hxx +62 -0
  46. data/ext/couchbase/operations/bucket_settings.hxx +111 -0
  47. data/ext/couchbase/operations/bucket_update.hxx +115 -0
  48. data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +60 -0
  49. data/ext/couchbase/operations/collection_create.hxx +86 -0
  50. data/ext/couchbase/operations/collection_drop.hxx +82 -0
  51. data/ext/couchbase/operations/command.hxx +10 -10
  52. data/ext/couchbase/operations/document_decrement.hxx +80 -0
  53. data/ext/couchbase/operations/document_exists.hxx +80 -0
  54. data/ext/couchbase/operations/{get.hxx → document_get.hxx} +4 -2
  55. data/ext/couchbase/operations/document_get_and_lock.hxx +64 -0
  56. data/ext/couchbase/operations/document_get_and_touch.hxx +64 -0
  57. data/ext/couchbase/operations/document_increment.hxx +80 -0
  58. data/ext/couchbase/operations/document_insert.hxx +74 -0
  59. data/ext/couchbase/operations/{lookup_in.hxx → document_lookup_in.hxx} +2 -2
  60. data/ext/couchbase/operations/{mutate_in.hxx → document_mutate_in.hxx} +11 -2
  61. data/ext/couchbase/operations/{query.hxx → document_query.hxx} +101 -6
  62. data/ext/couchbase/operations/document_remove.hxx +67 -0
  63. data/ext/couchbase/operations/document_replace.hxx +76 -0
  64. data/ext/couchbase/operations/{upsert.hxx → document_touch.hxx} +14 -14
  65. data/ext/couchbase/operations/{remove.hxx → document_unlock.hxx} +12 -10
  66. data/ext/couchbase/operations/document_upsert.hxx +74 -0
  67. data/ext/couchbase/operations/query_index_build_deferred.hxx +85 -0
  68. data/ext/couchbase/operations/query_index_create.hxx +134 -0
  69. data/ext/couchbase/operations/query_index_drop.hxx +108 -0
  70. data/ext/couchbase/operations/query_index_get_all.hxx +106 -0
  71. data/ext/couchbase/operations/scope_create.hxx +81 -0
  72. data/ext/couchbase/operations/scope_drop.hxx +79 -0
  73. data/ext/couchbase/operations/scope_get_all.hxx +72 -0
  74. data/ext/couchbase/protocol/client_opcode.hxx +35 -0
  75. data/ext/couchbase/protocol/client_request.hxx +56 -9
  76. data/ext/couchbase/protocol/client_response.hxx +52 -15
  77. data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +81 -0
  78. data/ext/couchbase/protocol/cmd_decrement.hxx +187 -0
  79. data/ext/couchbase/protocol/cmd_exists.hxx +171 -0
  80. data/ext/couchbase/protocol/cmd_get.hxx +31 -8
  81. data/ext/couchbase/protocol/cmd_get_and_lock.hxx +142 -0
  82. data/ext/couchbase/protocol/cmd_get_and_touch.hxx +142 -0
  83. data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +16 -3
  84. data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +16 -3
  85. data/ext/couchbase/protocol/cmd_get_error_map.hxx +16 -3
  86. data/ext/couchbase/protocol/cmd_hello.hxx +24 -8
  87. data/ext/couchbase/protocol/cmd_increment.hxx +187 -0
  88. data/ext/couchbase/protocol/cmd_info.hxx +1 -0
  89. data/ext/couchbase/protocol/cmd_insert.hxx +172 -0
  90. data/ext/couchbase/protocol/cmd_lookup_in.hxx +28 -13
  91. data/ext/couchbase/protocol/cmd_mutate_in.hxx +65 -13
  92. data/ext/couchbase/protocol/cmd_remove.hxx +59 -4
  93. data/ext/couchbase/protocol/cmd_replace.hxx +172 -0
  94. data/ext/couchbase/protocol/cmd_sasl_auth.hxx +15 -3
  95. data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +15 -3
  96. data/ext/couchbase/protocol/cmd_sasl_step.hxx +15 -3
  97. data/ext/couchbase/protocol/cmd_select_bucket.hxx +14 -2
  98. data/ext/couchbase/protocol/cmd_touch.hxx +102 -0
  99. data/ext/couchbase/protocol/cmd_unlock.hxx +95 -0
  100. data/ext/couchbase/protocol/cmd_upsert.hxx +50 -14
  101. data/ext/couchbase/protocol/durability_level.hxx +67 -0
  102. data/ext/couchbase/protocol/frame_info_id.hxx +187 -0
  103. data/ext/couchbase/protocol/hello_feature.hxx +137 -0
  104. data/ext/couchbase/protocol/server_opcode.hxx +57 -0
  105. data/ext/couchbase/protocol/server_request.hxx +122 -0
  106. data/ext/couchbase/protocol/unsigned_leb128.h +15 -15
  107. data/ext/couchbase/utils/byteswap.hxx +1 -2
  108. data/ext/couchbase/utils/url_codec.hxx +225 -0
  109. data/ext/couchbase/version.hxx +3 -1
  110. data/ext/extconf.rb +4 -1
  111. data/ext/test/main.cxx +37 -113
  112. data/ext/third_party/snappy/.appveyor.yml +36 -0
  113. data/ext/third_party/snappy/.gitignore +8 -0
  114. data/ext/third_party/snappy/.travis.yml +98 -0
  115. data/ext/third_party/snappy/AUTHORS +1 -0
  116. data/ext/third_party/snappy/CMakeLists.txt +345 -0
  117. data/ext/third_party/snappy/CONTRIBUTING.md +26 -0
  118. data/ext/third_party/snappy/COPYING +54 -0
  119. data/ext/third_party/snappy/NEWS +188 -0
  120. data/ext/third_party/snappy/README.md +148 -0
  121. data/ext/third_party/snappy/cmake/SnappyConfig.cmake.in +33 -0
  122. data/ext/third_party/snappy/cmake/config.h.in +59 -0
  123. data/ext/third_party/snappy/docs/README.md +72 -0
  124. data/ext/third_party/snappy/format_description.txt +110 -0
  125. data/ext/third_party/snappy/framing_format.txt +135 -0
  126. data/ext/third_party/snappy/snappy-c.cc +90 -0
  127. data/ext/third_party/snappy/snappy-c.h +138 -0
  128. data/ext/third_party/snappy/snappy-internal.h +315 -0
  129. data/ext/third_party/snappy/snappy-sinksource.cc +121 -0
  130. data/ext/third_party/snappy/snappy-sinksource.h +182 -0
  131. data/ext/third_party/snappy/snappy-stubs-internal.cc +42 -0
  132. data/ext/third_party/snappy/snappy-stubs-internal.h +493 -0
  133. data/ext/third_party/snappy/snappy-stubs-public.h.in +63 -0
  134. data/ext/third_party/snappy/snappy-test.cc +613 -0
  135. data/ext/third_party/snappy/snappy-test.h +526 -0
  136. data/ext/third_party/snappy/snappy.cc +1770 -0
  137. data/ext/third_party/snappy/snappy.h +209 -0
  138. data/ext/third_party/snappy/snappy_compress_fuzzer.cc +60 -0
  139. data/ext/third_party/snappy/snappy_uncompress_fuzzer.cc +58 -0
  140. data/ext/third_party/snappy/snappy_unittest.cc +1512 -0
  141. data/ext/third_party/snappy/testdata/alice29.txt +3609 -0
  142. data/ext/third_party/snappy/testdata/asyoulik.txt +4122 -0
  143. data/ext/third_party/snappy/testdata/baddata1.snappy +0 -0
  144. data/ext/third_party/snappy/testdata/baddata2.snappy +0 -0
  145. data/ext/third_party/snappy/testdata/baddata3.snappy +0 -0
  146. data/ext/third_party/snappy/testdata/fireworks.jpeg +0 -0
  147. data/ext/third_party/snappy/testdata/geo.protodata +0 -0
  148. data/ext/third_party/snappy/testdata/html +1 -0
  149. data/ext/third_party/snappy/testdata/html_x_4 +1 -0
  150. data/ext/third_party/snappy/testdata/kppkn.gtb +0 -0
  151. data/ext/third_party/snappy/testdata/lcet10.txt +7519 -0
  152. data/ext/third_party/snappy/testdata/paper-100k.pdf +600 -2
  153. data/ext/third_party/snappy/testdata/plrabn12.txt +10699 -0
  154. data/ext/third_party/snappy/testdata/urls.10K +10000 -0
  155. data/lib/couchbase/binary_collection.rb +33 -76
  156. data/lib/couchbase/binary_collection_options.rb +94 -0
  157. data/lib/couchbase/bucket.rb +9 -3
  158. data/lib/couchbase/cluster.rb +161 -23
  159. data/lib/couchbase/collection.rb +108 -191
  160. data/lib/couchbase/collection_options.rb +430 -0
  161. data/lib/couchbase/errors.rb +136 -134
  162. data/lib/couchbase/json_transcoder.rb +32 -0
  163. data/lib/couchbase/management/analytics_index_manager.rb +185 -9
  164. data/lib/couchbase/management/bucket_manager.rb +84 -33
  165. data/lib/couchbase/management/collection_manager.rb +166 -1
  166. data/lib/couchbase/management/query_index_manager.rb +261 -0
  167. data/lib/couchbase/management/search_index_manager.rb +291 -0
  168. data/lib/couchbase/management/user_manager.rb +12 -10
  169. data/lib/couchbase/management/view_index_manager.rb +151 -1
  170. data/lib/couchbase/mutation_state.rb +11 -1
  171. data/lib/couchbase/scope.rb +4 -4
  172. data/lib/couchbase/version.rb +1 -1
  173. metadata +113 -18
  174. data/.travis.yml +0 -7
  175. data/ext/couchbase/io/binary_parser.hxx +0 -64
  176. data/lib/couchbase/results.rb +0 -307
@@ -52,7 +52,9 @@ class session_manager
52
52
  std::string hostname;
53
53
  std::uint16_t port = 0;
54
54
  std::tie(hostname, port) = next_node(type);
55
- Expects(port != 0); // FIXME: service_not_available
55
+ if (port == 0) {
56
+ return nullptr;
57
+ }
56
58
  config_.nodes.size();
57
59
  auto session = std::make_shared<http_session>(client_id_, ctx_, username, password, hostname, std::to_string(port));
58
60
  busy_sessions_[type].push_back(session);
@@ -71,27 +73,40 @@ class session_manager
71
73
  private:
72
74
  std::pair<std::string, std::uint16_t> next_node(service_type type)
73
75
  {
74
- auto cur_index = next_index_;
75
- next_index_ = (next_index_ + 1) % config_.nodes.size();
76
- auto& node = config_.nodes[cur_index];
77
- switch (type) {
78
- case service_type::query:
79
- return { node.hostname, node.services_plain.query.value_or(0) };
80
-
81
- case service_type::analytics:
82
- return { node.hostname, node.services_plain.analytics.value_or(0) };
83
-
84
- case service_type::search:
85
- return { node.hostname, node.services_plain.search.value_or(0) };
86
-
87
- case service_type::views:
88
- return { node.hostname, node.services_plain.views.value_or(0) };
89
-
90
- case service_type::management:
91
- return { node.hostname, node.services_plain.management.value_or(0) };
92
-
93
- case service_type::kv:
94
- return { node.hostname, node.services_plain.key_value.value_or(0) };
76
+ auto candidates = config_.nodes.size();
77
+ while (candidates > 0) {
78
+ --candidates;
79
+ auto& node = config_.nodes[next_index_];
80
+ next_index_ = (next_index_ + 1) % config_.nodes.size();
81
+ std::uint16_t port = 0;
82
+ switch (type) {
83
+ case service_type::query:
84
+ port = node.services_plain.query.value_or(0);
85
+ break;
86
+
87
+ case service_type::analytics:
88
+ port = node.services_plain.analytics.value_or(0);
89
+ break;
90
+
91
+ case service_type::search:
92
+ port = node.services_plain.search.value_or(0);
93
+ break;
94
+
95
+ case service_type::views:
96
+ port = node.services_plain.views.value_or(0);
97
+ break;
98
+
99
+ case service_type::management:
100
+ port = node.services_plain.management.value_or(0);
101
+ break;
102
+
103
+ case service_type::kv:
104
+ port = node.services_plain.key_value.value_or(0);
105
+ break;
106
+ }
107
+ if (port != 0) {
108
+ return { node.hostname, port };
109
+ }
95
110
  }
96
111
  return { "", 0 };
97
112
  }
@@ -23,6 +23,7 @@ struct mutation_token {
23
23
  uint64_t partition_uuid{ 0 };
24
24
  uint64_t sequence_number{ 0 };
25
25
  uint16_t partition_id{ 0 };
26
+ std::string bucket_name {};
26
27
  };
27
28
  } // namespace couchbase
28
29
 
@@ -31,7 +32,7 @@ struct fmt::formatter : formatter {
31
32
  template<typename FormatContext>
32
33
  auto format(const couchbase::mutation_token& token, FormatContext& ctx)
33
34
  {
34
- format_to(ctx.out(), "{}:{}:{}", token.partition_id, token.partition_uuid, token.sequence_number);
35
+ format_to(ctx.out(), "{}:{}:{}:{}", token.bucket_name, token.partition_id, token.partition_uuid, token.sequence_number);
35
36
  return formatter<std::string>::format("", ctx);
36
37
  }
37
38
  };
@@ -17,13 +17,43 @@
17
17
 
18
18
  #pragma once
19
19
 
20
- #include <operations/document_id.hxx>
21
- #include <operations/get.hxx>
22
- #include <operations/upsert.hxx>
23
- #include <operations/remove.hxx>
24
- #include <operations/lookup_in.hxx>
25
- #include <operations/mutate_in.hxx>
26
-
27
- #include <operations/query.hxx>
20
+ #include <document_id.hxx>
21
+
22
+ #include <operations/document_get.hxx>
23
+ #include <operations/document_get_and_lock.hxx>
24
+ #include <operations/document_get_and_touch.hxx>
25
+ #include <operations/document_insert.hxx>
26
+ #include <operations/document_upsert.hxx>
27
+ #include <operations/document_replace.hxx>
28
+ #include <operations/document_remove.hxx>
29
+ #include <operations/document_lookup_in.hxx>
30
+ #include <operations/document_mutate_in.hxx>
31
+ #include <operations/document_touch.hxx>
32
+ #include <operations/document_exists.hxx>
33
+ #include <operations/document_unlock.hxx>
34
+ #include <operations/document_increment.hxx>
35
+ #include <operations/document_decrement.hxx>
36
+
37
+ #include <operations/document_query.hxx>
38
+
39
+ #include <operations/bucket_get_all.hxx>
40
+ #include <operations/bucket_get.hxx>
41
+ #include <operations/bucket_drop.hxx>
42
+ #include <operations/bucket_flush.hxx>
43
+ #include <operations/bucket_create.hxx>
44
+ #include <operations/bucket_update.hxx>
45
+
46
+ #include <operations/scope_get_all.hxx>
47
+ #include <operations/scope_create.hxx>
48
+ #include <operations/scope_drop.hxx>
49
+ #include <operations/collection_create.hxx>
50
+ #include <operations/collection_drop.hxx>
51
+
52
+ #include <operations/cluster_developer_preview_enable.hxx>
53
+
54
+ #include <operations/query_index_get_all.hxx>
55
+ #include <operations/query_index_drop.hxx>
56
+ #include <operations/query_index_create.hxx>
57
+ #include <operations/query_index_build_deferred.hxx>
28
58
 
29
59
  #include <operations/command.hxx>
@@ -0,0 +1,138 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #include <tao/json.hpp>
21
+
22
+ #include <version.hxx>
23
+ #include <operations/bucket_settings.hxx>
24
+ #include <utils/url_codec.hxx>
25
+
26
+ namespace couchbase::operations
27
+ {
28
+
29
+ struct bucket_create_response {
30
+ std::error_code ec;
31
+ std::string error_message{};
32
+ };
33
+
34
+ struct bucket_create_request {
35
+ using response_type = bucket_create_response;
36
+ using encoded_request_type = io::http_request;
37
+ using encoded_response_type = io::http_response;
38
+
39
+ static const inline service_type type = service_type::management;
40
+
41
+ bucket_settings bucket{};
42
+
43
+ void encode_to(encoded_request_type& encoded)
44
+ {
45
+ encoded.method = "POST";
46
+ encoded.path = fmt::format("/pools/default/buckets");
47
+
48
+ encoded.headers["content-type"] = "application/x-www-form-urlencoded";
49
+ encoded.body.append(fmt::format("name={}", utils::string_codec::form_encode(bucket.name)));
50
+ switch (bucket.bucket_type) {
51
+ case bucket_settings::bucket_type::couchbase:
52
+ encoded.body.append("&bucketType=couchbase");
53
+ break;
54
+ case bucket_settings::bucket_type::memcached:
55
+ encoded.body.append("&bucketType=memcached");
56
+ break;
57
+ case bucket_settings::bucket_type::ephemeral:
58
+ encoded.body.append("&bucketType=ephemeral");
59
+ break;
60
+ case bucket_settings::bucket_type::unknown:
61
+ break;
62
+ }
63
+ encoded.body.append(fmt::format("&ramQuotaMB={}", bucket.ram_quota_mb));
64
+ encoded.body.append(fmt::format("&replicaNumber={}", bucket.num_replicas));
65
+ encoded.body.append(fmt::format("&maxTTL={}", bucket.max_expiry));
66
+ encoded.body.append(fmt::format("&replicaIndex={}", bucket.replica_indexes ? "1" : "0"));
67
+ encoded.body.append(fmt::format("&flushEnabled={}", bucket.flush_enabled ? "1" : "0"));
68
+ switch (bucket.ejection_policy) {
69
+ case bucket_settings::ejection_policy::full:
70
+ encoded.body.append("&evictionPolicy=fullEviction");
71
+ break;
72
+ case bucket_settings::ejection_policy::value_only:
73
+ encoded.body.append("&evictionPolicy=valueOnly");
74
+ break;
75
+ case bucket_settings::ejection_policy::unknown:
76
+ break;
77
+ }
78
+ switch (bucket.compression_mode) {
79
+ case bucket_settings::compression_mode::off:
80
+ encoded.body.append("&compressionMode=off");
81
+ break;
82
+ case bucket_settings::compression_mode::active:
83
+ encoded.body.append("&compressionMode=active");
84
+ break;
85
+ case bucket_settings::compression_mode::passive:
86
+ encoded.body.append("&compressionMode=passive");
87
+ break;
88
+ case bucket_settings::compression_mode::unknown:
89
+ break;
90
+ }
91
+ switch (bucket.conflict_resolution_type) {
92
+ case bucket_settings::conflict_resolution_type::timestamp:
93
+ encoded.body.append("&conflictResolutionType=lww");
94
+ break;
95
+ case bucket_settings::conflict_resolution_type::sequence_number:
96
+ encoded.body.append("&conflictResolutionType=seqno");
97
+ break;
98
+ case bucket_settings::conflict_resolution_type::unknown:
99
+ break;
100
+ }
101
+ }
102
+ };
103
+
104
+ bucket_create_response
105
+ make_response(std::error_code ec, bucket_create_request&, bucket_create_request::encoded_response_type encoded)
106
+ {
107
+ bucket_create_response response{ ec };
108
+ if (!ec) {
109
+ switch (encoded.status_code) {
110
+ case 404:
111
+ response.ec = std::make_error_code(error::common_errc::bucket_not_found);
112
+ break;
113
+ case 400: {
114
+ response.ec = std::make_error_code(error::common_errc::invalid_argument);
115
+ auto payload = tao::json::from_string(encoded.body);
116
+ auto* errors = payload.find("errors");
117
+ if (errors != nullptr) {
118
+ std::vector<std::string> error_list{};
119
+ for (auto& err : errors->get_object()) {
120
+ error_list.emplace_back(err.second.get_string());
121
+ }
122
+ if (!error_list.empty()) {
123
+ response.error_message = fmt::format("{}", fmt::join(error_list.begin(), error_list.end(), ". "));
124
+ }
125
+ }
126
+ } break;
127
+ case 200:
128
+ case 202:
129
+ break;
130
+ default:
131
+ response.ec = std::make_error_code(error::common_errc::internal_server_failure);
132
+ break;
133
+ }
134
+ }
135
+ return response;
136
+ }
137
+
138
+ } // namespace couchbase::operations
@@ -0,0 +1,65 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #include <tao/json.hpp>
21
+
22
+ namespace couchbase::operations
23
+ {
24
+
25
+ struct bucket_drop_response {
26
+ std::error_code ec;
27
+ };
28
+
29
+ struct bucket_drop_request {
30
+ using response_type = bucket_drop_response;
31
+ using encoded_request_type = io::http_request;
32
+ using encoded_response_type = io::http_response;
33
+
34
+ static const inline service_type type = service_type::management;
35
+
36
+ std::string name;
37
+
38
+ void encode_to(encoded_request_type& encoded)
39
+ {
40
+ encoded.method = "DELETE";
41
+ encoded.path = fmt::format("/pools/default/buckets/{}", name);
42
+ }
43
+ };
44
+
45
+ bucket_drop_response
46
+ make_response(std::error_code ec, bucket_drop_request&, bucket_drop_request::encoded_response_type encoded)
47
+ {
48
+ bucket_drop_response response{ ec };
49
+ if (!ec) {
50
+ switch (encoded.status_code) {
51
+ case 404:
52
+ response.ec = std::make_error_code(error::common_errc::bucket_not_found);
53
+ break;
54
+ case 200:
55
+ response.ec = {};
56
+ break;
57
+ default:
58
+ response.ec = std::make_error_code(error::common_errc::internal_server_failure);
59
+ break;
60
+ }
61
+ }
62
+ return response;
63
+ }
64
+
65
+ } // namespace couchbase::operations
@@ -0,0 +1,65 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #include <tao/json.hpp>
21
+
22
+ namespace couchbase::operations
23
+ {
24
+
25
+ struct bucket_flush_response {
26
+ std::error_code ec;
27
+ };
28
+
29
+ struct bucket_flush_request {
30
+ using response_type = bucket_flush_response;
31
+ using encoded_request_type = io::http_request;
32
+ using encoded_response_type = io::http_response;
33
+
34
+ static const inline service_type type = service_type::management;
35
+
36
+ std::string name;
37
+
38
+ void encode_to(encoded_request_type& encoded)
39
+ {
40
+ encoded.method = "POST";
41
+ encoded.path = fmt::format("/pools/default/buckets/{}/controller/doFlush", name);
42
+ }
43
+ };
44
+
45
+ bucket_flush_response
46
+ make_response(std::error_code ec, bucket_flush_request&, bucket_flush_request::encoded_response_type encoded)
47
+ {
48
+ bucket_flush_response response{ ec };
49
+ if (!ec) {
50
+ switch (encoded.status_code) {
51
+ case 404:
52
+ response.ec = std::make_error_code(error::common_errc::bucket_not_found);
53
+ break;
54
+ case 200:
55
+ response.ec = {};
56
+ break;
57
+ default:
58
+ response.ec = std::make_error_code(error::common_errc::internal_server_failure);
59
+ break;
60
+ }
61
+ }
62
+ return response;
63
+ }
64
+
65
+ } // namespace couchbase::operations
@@ -0,0 +1,69 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #include <tao/json.hpp>
21
+
22
+ #include <version.hxx>
23
+ #include <operations/bucket_settings.hxx>
24
+
25
+ namespace couchbase::operations
26
+ {
27
+
28
+ struct bucket_get_response {
29
+ std::error_code ec;
30
+ bucket_settings bucket{};
31
+ };
32
+
33
+ struct bucket_get_request {
34
+ using response_type = bucket_get_response;
35
+ using encoded_request_type = io::http_request;
36
+ using encoded_response_type = io::http_response;
37
+
38
+ static const inline service_type type = service_type::management;
39
+
40
+ std::string name;
41
+
42
+ void encode_to(encoded_request_type& encoded)
43
+ {
44
+ encoded.method = "GET";
45
+ encoded.path = fmt::format("/pools/default/buckets/{}", name);
46
+ }
47
+ };
48
+
49
+ bucket_get_response
50
+ make_response(std::error_code ec, bucket_get_request&, bucket_get_request::encoded_response_type encoded)
51
+ {
52
+ bucket_get_response response{ ec };
53
+ if (!ec) {
54
+ switch (encoded.status_code) {
55
+ case 404:
56
+ response.ec = std::make_error_code(error::common_errc::bucket_not_found);
57
+ break;
58
+ case 200:
59
+ response.bucket = tao::json::from_string(encoded.body).as<bucket_settings>();
60
+ break;
61
+ default:
62
+ response.ec = std::make_error_code(error::common_errc::internal_server_failure);
63
+ break;
64
+ }
65
+ }
66
+ return response;
67
+ }
68
+
69
+ } // namespace couchbase::operations