couchbase 3.0.0.alpha.1 → 3.0.0.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests-6.0.3.yml +49 -0
- data/.github/workflows/tests.yml +47 -0
- data/.gitmodules +3 -0
- data/.idea/dictionaries/gem_terms.xml +5 -0
- data/.idea/inspectionProfiles/Project_Default.xml +1 -0
- data/.idea/vcs.xml +1 -0
- data/Gemfile +1 -0
- data/README.md +55 -2
- data/Rakefile +18 -0
- data/bin/init-cluster +62 -0
- data/bin/setup +1 -0
- data/couchbase.gemspec +3 -2
- data/examples/crud.rb +1 -2
- data/examples/managing_buckets.rb +47 -0
- data/examples/managing_collections.rb +58 -0
- data/examples/managing_query_indexes.rb +63 -0
- data/examples/query.rb +3 -2
- data/examples/query_with_consistency.rb +76 -0
- data/examples/subdocument.rb +23 -1
- data/ext/.clang-format +1 -1
- data/ext/.idea/dictionaries/couchbase_terms.xml +2 -0
- data/ext/.idea/vcs.xml +1 -0
- data/ext/CMakeLists.txt +30 -12
- data/ext/build_version.hxx.in +26 -0
- data/ext/couchbase/bucket.hxx +69 -8
- data/ext/couchbase/cluster.hxx +70 -54
- data/ext/couchbase/collections_manifest.hxx +3 -3
- data/ext/couchbase/configuration.hxx +14 -0
- data/ext/couchbase/couchbase.cxx +2044 -383
- data/ext/couchbase/{operations/document_id.hxx → document_id.hxx} +5 -4
- data/ext/couchbase/io/http_message.hxx +5 -1
- data/ext/couchbase/io/http_parser.hxx +2 -1
- data/ext/couchbase/io/http_session.hxx +6 -3
- data/ext/couchbase/io/{binary_message.hxx → mcbp_message.hxx} +15 -12
- data/ext/couchbase/io/mcbp_parser.hxx +99 -0
- data/ext/couchbase/io/{key_value_session.hxx → mcbp_session.hxx} +200 -95
- data/ext/couchbase/io/session_manager.hxx +37 -22
- data/ext/couchbase/mutation_token.hxx +2 -1
- data/ext/couchbase/operations.hxx +38 -8
- data/ext/couchbase/operations/bucket_create.hxx +138 -0
- data/ext/couchbase/operations/bucket_drop.hxx +65 -0
- data/ext/couchbase/operations/bucket_flush.hxx +65 -0
- data/ext/couchbase/operations/bucket_get.hxx +69 -0
- data/ext/couchbase/operations/bucket_get_all.hxx +62 -0
- data/ext/couchbase/operations/bucket_settings.hxx +111 -0
- data/ext/couchbase/operations/bucket_update.hxx +115 -0
- data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +60 -0
- data/ext/couchbase/operations/collection_create.hxx +86 -0
- data/ext/couchbase/operations/collection_drop.hxx +82 -0
- data/ext/couchbase/operations/command.hxx +10 -10
- data/ext/couchbase/operations/document_decrement.hxx +80 -0
- data/ext/couchbase/operations/document_exists.hxx +80 -0
- data/ext/couchbase/operations/{get.hxx → document_get.hxx} +4 -2
- data/ext/couchbase/operations/document_get_and_lock.hxx +64 -0
- data/ext/couchbase/operations/document_get_and_touch.hxx +64 -0
- data/ext/couchbase/operations/document_increment.hxx +80 -0
- data/ext/couchbase/operations/document_insert.hxx +74 -0
- data/ext/couchbase/operations/{lookup_in.hxx → document_lookup_in.hxx} +2 -2
- data/ext/couchbase/operations/{mutate_in.hxx → document_mutate_in.hxx} +11 -2
- data/ext/couchbase/operations/{query.hxx → document_query.hxx} +101 -6
- data/ext/couchbase/operations/document_remove.hxx +67 -0
- data/ext/couchbase/operations/document_replace.hxx +76 -0
- data/ext/couchbase/operations/{upsert.hxx → document_touch.hxx} +14 -14
- data/ext/couchbase/operations/{remove.hxx → document_unlock.hxx} +12 -10
- data/ext/couchbase/operations/document_upsert.hxx +74 -0
- data/ext/couchbase/operations/query_index_build_deferred.hxx +85 -0
- data/ext/couchbase/operations/query_index_create.hxx +134 -0
- data/ext/couchbase/operations/query_index_drop.hxx +108 -0
- data/ext/couchbase/operations/query_index_get_all.hxx +106 -0
- data/ext/couchbase/operations/scope_create.hxx +81 -0
- data/ext/couchbase/operations/scope_drop.hxx +79 -0
- data/ext/couchbase/operations/scope_get_all.hxx +72 -0
- data/ext/couchbase/protocol/client_opcode.hxx +35 -0
- data/ext/couchbase/protocol/client_request.hxx +56 -9
- data/ext/couchbase/protocol/client_response.hxx +52 -15
- data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +81 -0
- data/ext/couchbase/protocol/cmd_decrement.hxx +187 -0
- data/ext/couchbase/protocol/cmd_exists.hxx +171 -0
- data/ext/couchbase/protocol/cmd_get.hxx +31 -8
- data/ext/couchbase/protocol/cmd_get_and_lock.hxx +142 -0
- data/ext/couchbase/protocol/cmd_get_and_touch.hxx +142 -0
- data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +16 -3
- data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +16 -3
- data/ext/couchbase/protocol/cmd_get_error_map.hxx +16 -3
- data/ext/couchbase/protocol/cmd_hello.hxx +24 -8
- data/ext/couchbase/protocol/cmd_increment.hxx +187 -0
- data/ext/couchbase/protocol/cmd_info.hxx +1 -0
- data/ext/couchbase/protocol/cmd_insert.hxx +172 -0
- data/ext/couchbase/protocol/cmd_lookup_in.hxx +28 -13
- data/ext/couchbase/protocol/cmd_mutate_in.hxx +65 -13
- data/ext/couchbase/protocol/cmd_remove.hxx +59 -4
- data/ext/couchbase/protocol/cmd_replace.hxx +172 -0
- data/ext/couchbase/protocol/cmd_sasl_auth.hxx +15 -3
- data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +15 -3
- data/ext/couchbase/protocol/cmd_sasl_step.hxx +15 -3
- data/ext/couchbase/protocol/cmd_select_bucket.hxx +14 -2
- data/ext/couchbase/protocol/cmd_touch.hxx +102 -0
- data/ext/couchbase/protocol/cmd_unlock.hxx +95 -0
- data/ext/couchbase/protocol/cmd_upsert.hxx +50 -14
- data/ext/couchbase/protocol/durability_level.hxx +67 -0
- data/ext/couchbase/protocol/frame_info_id.hxx +187 -0
- data/ext/couchbase/protocol/hello_feature.hxx +137 -0
- data/ext/couchbase/protocol/server_opcode.hxx +57 -0
- data/ext/couchbase/protocol/server_request.hxx +122 -0
- data/ext/couchbase/protocol/unsigned_leb128.h +15 -15
- data/ext/couchbase/utils/byteswap.hxx +1 -2
- data/ext/couchbase/utils/url_codec.hxx +225 -0
- data/ext/couchbase/version.hxx +3 -1
- data/ext/extconf.rb +4 -1
- data/ext/test/main.cxx +37 -113
- data/ext/third_party/snappy/.appveyor.yml +36 -0
- data/ext/third_party/snappy/.gitignore +8 -0
- data/ext/third_party/snappy/.travis.yml +98 -0
- data/ext/third_party/snappy/AUTHORS +1 -0
- data/ext/third_party/snappy/CMakeLists.txt +345 -0
- data/ext/third_party/snappy/CONTRIBUTING.md +26 -0
- data/ext/third_party/snappy/COPYING +54 -0
- data/ext/third_party/snappy/NEWS +188 -0
- data/ext/third_party/snappy/README.md +148 -0
- data/ext/third_party/snappy/cmake/SnappyConfig.cmake.in +33 -0
- data/ext/third_party/snappy/cmake/config.h.in +59 -0
- data/ext/third_party/snappy/docs/README.md +72 -0
- data/ext/third_party/snappy/format_description.txt +110 -0
- data/ext/third_party/snappy/framing_format.txt +135 -0
- data/ext/third_party/snappy/snappy-c.cc +90 -0
- data/ext/third_party/snappy/snappy-c.h +138 -0
- data/ext/third_party/snappy/snappy-internal.h +315 -0
- data/ext/third_party/snappy/snappy-sinksource.cc +121 -0
- data/ext/third_party/snappy/snappy-sinksource.h +182 -0
- data/ext/third_party/snappy/snappy-stubs-internal.cc +42 -0
- data/ext/third_party/snappy/snappy-stubs-internal.h +493 -0
- data/ext/third_party/snappy/snappy-stubs-public.h.in +63 -0
- data/ext/third_party/snappy/snappy-test.cc +613 -0
- data/ext/third_party/snappy/snappy-test.h +526 -0
- data/ext/third_party/snappy/snappy.cc +1770 -0
- data/ext/third_party/snappy/snappy.h +209 -0
- data/ext/third_party/snappy/snappy_compress_fuzzer.cc +60 -0
- data/ext/third_party/snappy/snappy_uncompress_fuzzer.cc +58 -0
- data/ext/third_party/snappy/snappy_unittest.cc +1512 -0
- data/ext/third_party/snappy/testdata/alice29.txt +3609 -0
- data/ext/third_party/snappy/testdata/asyoulik.txt +4122 -0
- data/ext/third_party/snappy/testdata/baddata1.snappy +0 -0
- data/ext/third_party/snappy/testdata/baddata2.snappy +0 -0
- data/ext/third_party/snappy/testdata/baddata3.snappy +0 -0
- data/ext/third_party/snappy/testdata/fireworks.jpeg +0 -0
- data/ext/third_party/snappy/testdata/geo.protodata +0 -0
- data/ext/third_party/snappy/testdata/html +1 -0
- data/ext/third_party/snappy/testdata/html_x_4 +1 -0
- data/ext/third_party/snappy/testdata/kppkn.gtb +0 -0
- data/ext/third_party/snappy/testdata/lcet10.txt +7519 -0
- data/ext/third_party/snappy/testdata/paper-100k.pdf +600 -2
- data/ext/third_party/snappy/testdata/plrabn12.txt +10699 -0
- data/ext/third_party/snappy/testdata/urls.10K +10000 -0
- data/lib/couchbase/binary_collection.rb +33 -76
- data/lib/couchbase/binary_collection_options.rb +94 -0
- data/lib/couchbase/bucket.rb +9 -3
- data/lib/couchbase/cluster.rb +161 -23
- data/lib/couchbase/collection.rb +108 -191
- data/lib/couchbase/collection_options.rb +430 -0
- data/lib/couchbase/errors.rb +136 -134
- data/lib/couchbase/json_transcoder.rb +32 -0
- data/lib/couchbase/management/analytics_index_manager.rb +185 -9
- data/lib/couchbase/management/bucket_manager.rb +84 -33
- data/lib/couchbase/management/collection_manager.rb +166 -1
- data/lib/couchbase/management/query_index_manager.rb +261 -0
- data/lib/couchbase/management/search_index_manager.rb +291 -0
- data/lib/couchbase/management/user_manager.rb +12 -10
- data/lib/couchbase/management/view_index_manager.rb +151 -1
- data/lib/couchbase/mutation_state.rb +11 -1
- data/lib/couchbase/scope.rb +4 -4
- data/lib/couchbase/version.rb +1 -1
- metadata +113 -18
- data/.travis.yml +0 -7
- data/ext/couchbase/io/binary_parser.hxx +0 -64
- 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
|
-
|
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
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
|
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 <
|
21
|
-
|
22
|
-
#include <operations/
|
23
|
-
#include <operations/
|
24
|
-
#include <operations/
|
25
|
-
#include <operations/
|
26
|
-
|
27
|
-
#include <operations/
|
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
|