couchbase 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/ext/CMakeLists.txt +3 -0
- data/ext/build_version.hxx.in +1 -1
- data/ext/cmake/CompilerWarnings.cmake +1 -0
- data/ext/cmake/PreventInSourceBuilds.cmake +4 -1
- data/ext/couchbase/bucket.hxx +28 -2
- data/ext/couchbase/cluster.hxx +8 -2
- data/ext/couchbase/couchbase.cxx +955 -511
- data/ext/couchbase/error_context/analytics.hxx +46 -0
- data/ext/couchbase/error_context/http.hxx +44 -0
- data/ext/couchbase/error_context/key_value.hxx +47 -0
- data/ext/couchbase/error_context/query.hxx +46 -0
- data/ext/couchbase/error_context/search.hxx +47 -0
- data/ext/couchbase/error_context/view.hxx +47 -0
- data/ext/couchbase/io/dns_codec.hxx +1 -2
- data/ext/couchbase/io/http_command.hxx +16 -3
- data/ext/couchbase/io/http_context.hxx +1 -1
- data/ext/couchbase/io/http_session.hxx +12 -6
- data/ext/couchbase/io/http_session_manager.hxx +25 -24
- data/ext/couchbase/io/mcbp_session.hxx +8 -2
- data/ext/couchbase/io/retry_context.hxx +1 -1
- data/ext/couchbase/operations/analytics_dataset_create.hxx +19 -12
- data/ext/couchbase/operations/analytics_dataset_drop.hxx +18 -10
- data/ext/couchbase/operations/analytics_dataset_get_all.hxx +16 -10
- data/ext/couchbase/operations/analytics_dataverse_create.hxx +18 -11
- data/ext/couchbase/operations/analytics_dataverse_drop.hxx +17 -11
- data/ext/couchbase/operations/analytics_get_pending_mutations.hxx +17 -10
- data/ext/couchbase/operations/analytics_index_create.hxx +17 -11
- data/ext/couchbase/operations/analytics_index_drop.hxx +16 -10
- data/ext/couchbase/operations/analytics_index_get_all.hxx +14 -10
- data/ext/couchbase/operations/analytics_link_connect.hxx +15 -9
- data/ext/couchbase/operations/analytics_link_disconnect.hxx +16 -10
- data/ext/couchbase/operations/bucket_create.hxx +33 -10
- data/ext/couchbase/operations/bucket_drop.hxx +9 -8
- data/ext/couchbase/operations/bucket_flush.hxx +8 -8
- data/ext/couchbase/operations/bucket_get.hxx +15 -10
- data/ext/couchbase/operations/bucket_get_all.hxx +14 -7
- data/ext/couchbase/operations/bucket_settings.hxx +16 -0
- data/ext/couchbase/operations/bucket_update.hxx +32 -10
- data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +6 -6
- data/ext/couchbase/operations/collection_create.hxx +19 -13
- data/ext/couchbase/operations/collection_drop.hxx +18 -12
- data/ext/couchbase/operations/collections_manifest_get.hxx +5 -10
- data/ext/couchbase/operations/document_analytics.hxx +39 -17
- data/ext/couchbase/operations/document_append.hxx +5 -10
- data/ext/couchbase/operations/document_decrement.hxx +5 -10
- data/ext/couchbase/operations/document_exists.hxx +4 -6
- data/ext/couchbase/operations/document_get.hxx +6 -10
- data/ext/couchbase/operations/document_get_and_lock.hxx +4 -9
- data/ext/couchbase/operations/document_get_and_touch.hxx +4 -9
- data/ext/couchbase/operations/document_get_projected.hxx +21 -14
- data/ext/couchbase/operations/document_increment.hxx +5 -10
- data/ext/couchbase/operations/document_insert.hxx +5 -10
- data/ext/couchbase/operations/document_lookup_in.hxx +4 -9
- data/ext/couchbase/operations/document_mutate_in.hxx +7 -12
- data/ext/couchbase/operations/document_prepend.hxx +5 -10
- data/ext/couchbase/operations/document_query.hxx +45 -28
- data/ext/couchbase/operations/document_remove.hxx +5 -10
- data/ext/couchbase/operations/document_replace.hxx +5 -10
- data/ext/couchbase/operations/document_search.hxx +37 -16
- data/ext/couchbase/operations/document_touch.hxx +4 -9
- data/ext/couchbase/operations/document_unlock.hxx +4 -9
- data/ext/couchbase/operations/document_upsert.hxx +5 -10
- data/ext/couchbase/operations/document_view.hxx +29 -13
- data/ext/couchbase/operations/group_drop.hxx +7 -7
- data/ext/couchbase/operations/group_get.hxx +14 -10
- data/ext/couchbase/operations/group_get_all.hxx +14 -8
- data/ext/couchbase/operations/group_upsert.hxx +15 -9
- data/ext/couchbase/operations/http_noop.hxx +5 -5
- data/ext/couchbase/operations/mcbp_noop.hxx +3 -9
- data/ext/couchbase/operations/query_index_build_deferred.hxx +15 -9
- data/ext/couchbase/operations/query_index_create.hxx +16 -10
- data/ext/couchbase/operations/query_index_drop.hxx +16 -10
- data/ext/couchbase/operations/query_index_get_all.hxx +13 -7
- data/ext/couchbase/operations/role_get_all.hxx +14 -8
- data/ext/couchbase/operations/scope_create.hxx +19 -13
- data/ext/couchbase/operations/scope_drop.hxx +17 -11
- data/ext/couchbase/operations/scope_get_all.hxx +15 -10
- data/ext/couchbase/operations/search_get_stats.hxx +5 -5
- data/ext/couchbase/operations/search_index_analyze_document.hxx +25 -13
- data/ext/couchbase/operations/search_index_control_ingest.hxx +23 -11
- data/ext/couchbase/operations/search_index_control_plan_freeze.hxx +23 -11
- data/ext/couchbase/operations/search_index_control_query.hxx +23 -11
- data/ext/couchbase/operations/search_index_drop.hxx +22 -10
- data/ext/couchbase/operations/search_index_get.hxx +22 -10
- data/ext/couchbase/operations/search_index_get_all.hxx +13 -7
- data/ext/couchbase/operations/search_index_get_documents_count.hxx +24 -13
- data/ext/couchbase/operations/search_index_get_stats.hxx +16 -10
- data/ext/couchbase/operations/search_index_upsert.hxx +23 -11
- data/ext/couchbase/operations/user_drop.hxx +8 -8
- data/ext/couchbase/operations/user_get.hxx +14 -10
- data/ext/couchbase/operations/user_get_all.hxx +14 -8
- data/ext/couchbase/operations/user_upsert.hxx +15 -9
- data/ext/couchbase/operations/view_index_drop.hxx +7 -7
- data/ext/couchbase/operations/view_index_get.hxx +15 -9
- data/ext/couchbase/operations/view_index_get_all.hxx +15 -9
- data/ext/couchbase/operations/view_index_upsert.hxx +8 -8
- data/ext/couchbase/origin.hxx +1 -0
- data/ext/couchbase/platform/terminate_handler.cc +12 -8
- data/ext/couchbase/protocol/client_request.hxx +2 -1
- data/ext/couchbase/protocol/client_response.hxx +18 -15
- data/ext/couchbase/protocol/cmd_exists.hxx +1 -0
- data/ext/couchbase/protocol/cmd_get.hxx +1 -1
- data/ext/couchbase/protocol/cmd_mutate_in.hxx +3 -4
- data/ext/couchbase/protocol/enhanced_error_info.hxx +28 -0
- data/ext/couchbase/utils/connection_string.hxx +1 -1
- data/ext/couchbase/version.hxx +1 -1
- data/ext/extconf.rb +1 -1
- data/ext/test/test_native_binary_operations.cxx +18 -18
- data/ext/test/test_native_diagnostics.cxx +2 -2
- data/ext/test/test_native_trivial_crud.cxx +2 -2
- data/ext/third_party/json/include/tao/json/external/pegtl/internal/file_reader.hpp +1 -5
- data/lib/active_support/cache/couchbase_store.rb +362 -0
- data/lib/couchbase.rb +2 -0
- data/lib/couchbase/authenticator.rb +26 -0
- data/lib/couchbase/binary_collection.rb +1 -0
- data/lib/couchbase/bucket.rb +1 -0
- data/lib/couchbase/cluster.rb +51 -27
- data/lib/couchbase/collection.rb +19 -4
- data/lib/couchbase/collection_options.rb +10 -0
- data/lib/couchbase/configuration.rb +57 -0
- data/lib/couchbase/datastructures.rb +6 -0
- data/lib/couchbase/errors.rb +111 -3
- data/lib/couchbase/management.rb +27 -0
- data/lib/couchbase/management/bucket_manager.rb +9 -2
- data/lib/couchbase/management/collection_manager.rb +1 -1
- data/lib/couchbase/management/user_manager.rb +18 -2
- data/lib/couchbase/options.rb +33 -23
- data/lib/couchbase/railtie.rb +45 -0
- data/lib/couchbase/scope.rb +44 -3
- data/lib/couchbase/utils.rb +21 -0
- data/lib/couchbase/utils/time.rb +52 -0
- data/lib/couchbase/version.rb +1 -1
- data/lib/rails/generators/couchbase/config/config_generator.rb +27 -0
- metadata +19 -5
@@ -126,7 +126,7 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
126
126
|
: session_(session)
|
127
127
|
, sasl_([origin = session_->origin_]() -> std::string { return origin.username(); },
|
128
128
|
[origin = session_->origin_]() -> std::string { return origin.password(); },
|
129
|
-
|
129
|
+
session_->origin_.credentials().allowed_sasl_mechanisms)
|
130
130
|
{
|
131
131
|
tao::json::value user_agent{
|
132
132
|
{ "a", couchbase::sdk_id() },
|
@@ -545,11 +545,17 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
545
545
|
|
546
546
|
std::string remote_address() const
|
547
547
|
{
|
548
|
+
if (endpoint_.protocol() == asio::ip::tcp::v6()) {
|
549
|
+
return fmt::format("[{}]:{}", endpoint_address_, endpoint_.port());
|
550
|
+
}
|
548
551
|
return fmt::format("{}:{}", endpoint_address_, endpoint_.port());
|
549
552
|
}
|
550
553
|
|
551
554
|
std::string local_address() const
|
552
555
|
{
|
556
|
+
if (endpoint_.protocol() == asio::ip::tcp::v6()) {
|
557
|
+
return fmt::format("[{}]:{}", local_endpoint_address_, local_endpoint_.port());
|
558
|
+
}
|
553
559
|
return fmt::format("{}:{}", local_endpoint_address_, local_endpoint_.port());
|
554
560
|
}
|
555
561
|
|
@@ -1001,7 +1007,7 @@ class mcbp_session : public std::enable_shared_from_this<mcbp_session>
|
|
1001
1007
|
}
|
1002
1008
|
if (config_->rev && config.rev) {
|
1003
1009
|
if (*config_->rev == *config.rev) {
|
1004
|
-
spdlog::
|
1010
|
+
spdlog::trace("{} received a configuration with identical revision (rev={}), ignoring", log_prefix_, *config.rev);
|
1005
1011
|
return;
|
1006
1012
|
}
|
1007
1013
|
if (*config_->rev > *config.rev) {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
2
|
/*
|
3
|
-
* Copyright 2020 Couchbase, Inc.
|
3
|
+
* Copyright 2020-2021 Couchbase, Inc.
|
4
4
|
*
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
6
|
* you may not use this file except in compliance with the License.
|
@@ -19,6 +19,7 @@
|
|
19
19
|
|
20
20
|
#include <tao/json.hpp>
|
21
21
|
|
22
|
+
#include <error_context/http.hxx>
|
22
23
|
#include <version.hxx>
|
23
24
|
|
24
25
|
namespace couchbase::operations
|
@@ -29,8 +30,7 @@ struct analytics_dataset_create_response {
|
|
29
30
|
std::string message;
|
30
31
|
};
|
31
32
|
|
32
|
-
|
33
|
-
std::error_code ec;
|
33
|
+
error_context::http ctx;
|
34
34
|
std::string status{};
|
35
35
|
std::vector<problem> errors{};
|
36
36
|
};
|
@@ -39,6 +39,7 @@ struct analytics_dataset_create_request {
|
|
39
39
|
using response_type = analytics_dataset_create_response;
|
40
40
|
using encoded_request_type = io::http_request;
|
41
41
|
using encoded_response_type = io::http_response;
|
42
|
+
using error_context_type = error_context::http;
|
42
43
|
|
43
44
|
static const inline service_type type = service_type::analytics;
|
44
45
|
|
@@ -53,7 +54,7 @@ struct analytics_dataset_create_request {
|
|
53
54
|
|
54
55
|
bool ignore_if_exists{ false };
|
55
56
|
|
56
|
-
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context&)
|
57
|
+
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& /* context */)
|
57
58
|
{
|
58
59
|
std::string where_clause = condition ? fmt::format("WHERE {}", *condition) : "";
|
59
60
|
std::string if_not_exists_clause = ignore_if_exists ? "IF NOT EXISTS" : "";
|
@@ -72,13 +73,19 @@ struct analytics_dataset_create_request {
|
|
72
73
|
};
|
73
74
|
|
74
75
|
analytics_dataset_create_response
|
75
|
-
make_response(
|
76
|
-
analytics_dataset_create_request& request
|
76
|
+
make_response(error_context::http&& ctx,
|
77
|
+
analytics_dataset_create_request& /* request */,
|
77
78
|
analytics_dataset_create_request::encoded_response_type&& encoded)
|
78
79
|
{
|
79
|
-
analytics_dataset_create_response response{
|
80
|
-
if (!ec) {
|
81
|
-
|
80
|
+
analytics_dataset_create_response response{ ctx };
|
81
|
+
if (!response.ctx.ec) {
|
82
|
+
tao::json::value payload{};
|
83
|
+
try {
|
84
|
+
payload = tao::json::from_string(encoded.body);
|
85
|
+
} catch (tao::json::pegtl::parse_error& e) {
|
86
|
+
response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
|
87
|
+
return response;
|
88
|
+
}
|
82
89
|
response.status = payload.at("status").get_string();
|
83
90
|
|
84
91
|
if (response.status != "success") {
|
@@ -104,11 +111,11 @@ make_response(std::error_code ec,
|
|
104
111
|
}
|
105
112
|
}
|
106
113
|
if (dataset_exists) {
|
107
|
-
response.ec = std::make_error_code(error::analytics_errc::dataset_exists);
|
114
|
+
response.ctx.ec = std::make_error_code(error::analytics_errc::dataset_exists);
|
108
115
|
} else if (link_not_found) {
|
109
|
-
response.ec = std::make_error_code(error::analytics_errc::link_not_found);
|
116
|
+
response.ctx.ec = std::make_error_code(error::analytics_errc::link_not_found);
|
110
117
|
} else {
|
111
|
-
response.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
118
|
+
response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
112
119
|
}
|
113
120
|
}
|
114
121
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
2
|
/*
|
3
|
-
* Copyright 2020 Couchbase, Inc.
|
3
|
+
* Copyright 2020-2021 Couchbase, Inc.
|
4
4
|
*
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
6
|
* you may not use this file except in compliance with the License.
|
@@ -29,8 +29,7 @@ struct analytics_dataset_drop_response {
|
|
29
29
|
std::string message;
|
30
30
|
};
|
31
31
|
|
32
|
-
|
33
|
-
std::error_code ec;
|
32
|
+
error_context::http ctx;
|
34
33
|
std::string status{};
|
35
34
|
std::vector<problem> errors{};
|
36
35
|
};
|
@@ -39,6 +38,7 @@ struct analytics_dataset_drop_request {
|
|
39
38
|
using response_type = analytics_dataset_drop_response;
|
40
39
|
using encoded_request_type = io::http_request;
|
41
40
|
using encoded_response_type = io::http_response;
|
41
|
+
using error_context_type = error_context::http;
|
42
42
|
|
43
43
|
static const inline service_type type = service_type::analytics;
|
44
44
|
|
@@ -50,7 +50,7 @@ struct analytics_dataset_drop_request {
|
|
50
50
|
|
51
51
|
bool ignore_if_does_not_exist{ false };
|
52
52
|
|
53
|
-
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context&)
|
53
|
+
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& /* context */)
|
54
54
|
{
|
55
55
|
std::string if_exists_clause = ignore_if_does_not_exist ? "IF EXISTS" : "";
|
56
56
|
|
@@ -66,11 +66,19 @@ struct analytics_dataset_drop_request {
|
|
66
66
|
};
|
67
67
|
|
68
68
|
analytics_dataset_drop_response
|
69
|
-
make_response(
|
69
|
+
make_response(error_context::http&& ctx,
|
70
|
+
analytics_dataset_drop_request& /* request */,
|
71
|
+
analytics_dataset_drop_request::encoded_response_type&& encoded)
|
70
72
|
{
|
71
|
-
analytics_dataset_drop_response response{
|
72
|
-
if (!ec) {
|
73
|
-
|
73
|
+
analytics_dataset_drop_response response{ ctx };
|
74
|
+
if (!response.ctx.ec) {
|
75
|
+
tao::json::value payload{};
|
76
|
+
try {
|
77
|
+
payload = tao::json::from_string(encoded.body);
|
78
|
+
} catch (tao::json::pegtl::parse_error& e) {
|
79
|
+
response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
|
80
|
+
return response;
|
81
|
+
}
|
74
82
|
response.status = payload.at("status").get_string();
|
75
83
|
|
76
84
|
if (response.status != "success") {
|
@@ -92,9 +100,9 @@ make_response(std::error_code ec, analytics_dataset_drop_request& request, analy
|
|
92
100
|
}
|
93
101
|
}
|
94
102
|
if (dataset_does_not_exist) {
|
95
|
-
response.ec = std::make_error_code(error::analytics_errc::dataset_not_found);
|
103
|
+
response.ctx.ec = std::make_error_code(error::analytics_errc::dataset_not_found);
|
96
104
|
} else {
|
97
|
-
response.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
105
|
+
response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
98
106
|
}
|
99
107
|
}
|
100
108
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
2
|
/*
|
3
|
-
* Copyright 2020 Couchbase, Inc.
|
3
|
+
* Copyright 2020-2021 Couchbase, Inc.
|
4
4
|
*
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
6
|
* you may not use this file except in compliance with the License.
|
@@ -36,8 +36,7 @@ struct analytics_dataset_get_all_response {
|
|
36
36
|
std::string message;
|
37
37
|
};
|
38
38
|
|
39
|
-
|
40
|
-
std::error_code ec;
|
39
|
+
error_context::http ctx;
|
41
40
|
std::string status{};
|
42
41
|
std::vector<dataset> datasets{};
|
43
42
|
std::vector<problem> errors{};
|
@@ -47,13 +46,14 @@ struct analytics_dataset_get_all_request {
|
|
47
46
|
using response_type = analytics_dataset_get_all_response;
|
48
47
|
using encoded_request_type = io::http_request;
|
49
48
|
using encoded_response_type = io::http_response;
|
49
|
+
using error_context_type = error_context::http;
|
50
50
|
|
51
51
|
static const inline service_type type = service_type::analytics;
|
52
52
|
|
53
53
|
std::string client_context_id{ uuid::to_string(uuid::random()) };
|
54
54
|
std::chrono::milliseconds timeout{ timeout_defaults::management_timeout };
|
55
55
|
|
56
|
-
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context&)
|
56
|
+
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& /* context */)
|
57
57
|
{
|
58
58
|
tao::json::value body{
|
59
59
|
{ "statement", "SELECT d.* FROM Metadata.`Dataset` d WHERE d.DataverseName <> \"Metadata\"" },
|
@@ -67,14 +67,20 @@ struct analytics_dataset_get_all_request {
|
|
67
67
|
};
|
68
68
|
|
69
69
|
analytics_dataset_get_all_response
|
70
|
-
make_response(
|
71
|
-
analytics_dataset_get_all_request& request
|
70
|
+
make_response(error_context::http&& ctx,
|
71
|
+
analytics_dataset_get_all_request& /* request */,
|
72
72
|
analytics_dataset_get_all_request::encoded_response_type&& encoded)
|
73
73
|
{
|
74
|
-
analytics_dataset_get_all_response response{
|
74
|
+
analytics_dataset_get_all_response response{ ctx };
|
75
75
|
|
76
|
-
if (!ec) {
|
77
|
-
|
76
|
+
if (!response.ctx.ec) {
|
77
|
+
tao::json::value payload{};
|
78
|
+
try {
|
79
|
+
payload = tao::json::from_string(encoded.body);
|
80
|
+
} catch (tao::json::pegtl::parse_error& e) {
|
81
|
+
response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
|
82
|
+
return response;
|
83
|
+
}
|
78
84
|
response.status = payload.at("status").get_string();
|
79
85
|
if (response.status == "success") {
|
80
86
|
auto* results = payload.find("results");
|
@@ -99,7 +105,7 @@ make_response(std::error_code ec,
|
|
99
105
|
response.errors.emplace_back(err);
|
100
106
|
}
|
101
107
|
}
|
102
|
-
response.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
108
|
+
response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
103
109
|
}
|
104
110
|
}
|
105
111
|
return response;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
2
|
/*
|
3
|
-
* Copyright 2020 Couchbase, Inc.
|
3
|
+
* Copyright 2020-2021 Couchbase, Inc.
|
4
4
|
*
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
6
|
* you may not use this file except in compliance with the License.
|
@@ -19,6 +19,7 @@
|
|
19
19
|
|
20
20
|
#include <tao/json.hpp>
|
21
21
|
|
22
|
+
#include <error_context/http.hxx>
|
22
23
|
#include <version.hxx>
|
23
24
|
|
24
25
|
namespace couchbase::operations
|
@@ -29,8 +30,7 @@ struct analytics_dataverse_create_response {
|
|
29
30
|
std::string message;
|
30
31
|
};
|
31
32
|
|
32
|
-
|
33
|
-
std::error_code ec;
|
33
|
+
error_context::http ctx;
|
34
34
|
std::string status{};
|
35
35
|
std::vector<problem> errors{};
|
36
36
|
};
|
@@ -39,6 +39,7 @@ struct analytics_dataverse_create_request {
|
|
39
39
|
using response_type = analytics_dataverse_create_response;
|
40
40
|
using encoded_request_type = io::http_request;
|
41
41
|
using encoded_response_type = io::http_response;
|
42
|
+
using error_context_type = error_context::http;
|
42
43
|
|
43
44
|
static const inline service_type type = service_type::analytics;
|
44
45
|
|
@@ -49,7 +50,7 @@ struct analytics_dataverse_create_request {
|
|
49
50
|
|
50
51
|
bool ignore_if_exists{ false };
|
51
52
|
|
52
|
-
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context&)
|
53
|
+
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& /* context */)
|
53
54
|
{
|
54
55
|
std::string if_not_exists_clause = ignore_if_exists ? "IF NOT EXISTS" : "";
|
55
56
|
|
@@ -65,13 +66,19 @@ struct analytics_dataverse_create_request {
|
|
65
66
|
};
|
66
67
|
|
67
68
|
analytics_dataverse_create_response
|
68
|
-
make_response(
|
69
|
-
analytics_dataverse_create_request& request
|
69
|
+
make_response(error_context::http&& ctx,
|
70
|
+
analytics_dataverse_create_request& /* request */,
|
70
71
|
analytics_dataverse_create_request::encoded_response_type&& encoded)
|
71
72
|
{
|
72
|
-
analytics_dataverse_create_response response{
|
73
|
-
if (!ec) {
|
74
|
-
|
73
|
+
analytics_dataverse_create_response response{ ctx };
|
74
|
+
if (!response.ctx.ec) {
|
75
|
+
tao::json::value payload{};
|
76
|
+
try {
|
77
|
+
payload = tao::json::from_string(encoded.body);
|
78
|
+
} catch (tao::json::pegtl::parse_error& e) {
|
79
|
+
response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
|
80
|
+
return response;
|
81
|
+
}
|
75
82
|
response.status = payload.at("status").get_string();
|
76
83
|
|
77
84
|
if (response.status != "success") {
|
@@ -93,9 +100,9 @@ make_response(std::error_code ec,
|
|
93
100
|
}
|
94
101
|
}
|
95
102
|
if (dataverse_exists) {
|
96
|
-
response.ec = std::make_error_code(error::analytics_errc::dataverse_exists);
|
103
|
+
response.ctx.ec = std::make_error_code(error::analytics_errc::dataverse_exists);
|
97
104
|
} else {
|
98
|
-
response.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
105
|
+
response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
99
106
|
}
|
100
107
|
}
|
101
108
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
2
|
/*
|
3
|
-
* Copyright 2020 Couchbase, Inc.
|
3
|
+
* Copyright 2020-2021 Couchbase, Inc.
|
4
4
|
*
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
6
|
* you may not use this file except in compliance with the License.
|
@@ -29,8 +29,7 @@ struct analytics_dataverse_drop_response {
|
|
29
29
|
std::string message;
|
30
30
|
};
|
31
31
|
|
32
|
-
|
33
|
-
std::error_code ec;
|
32
|
+
error_context::http ctx;
|
34
33
|
std::string status{};
|
35
34
|
std::vector<problem> errors{};
|
36
35
|
};
|
@@ -39,6 +38,7 @@ struct analytics_dataverse_drop_request {
|
|
39
38
|
using response_type = analytics_dataverse_drop_response;
|
40
39
|
using encoded_request_type = io::http_request;
|
41
40
|
using encoded_response_type = io::http_response;
|
41
|
+
using error_context_type = error_context::http;
|
42
42
|
|
43
43
|
static const inline service_type type = service_type::analytics;
|
44
44
|
|
@@ -49,7 +49,7 @@ struct analytics_dataverse_drop_request {
|
|
49
49
|
|
50
50
|
bool ignore_if_does_not_exist{ false };
|
51
51
|
|
52
|
-
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context&)
|
52
|
+
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& /* context */)
|
53
53
|
{
|
54
54
|
std::string if_exists_clause = ignore_if_does_not_exist ? "IF EXISTS" : "";
|
55
55
|
|
@@ -65,13 +65,19 @@ struct analytics_dataverse_drop_request {
|
|
65
65
|
};
|
66
66
|
|
67
67
|
analytics_dataverse_drop_response
|
68
|
-
make_response(
|
69
|
-
analytics_dataverse_drop_request& request
|
68
|
+
make_response(error_context::http&& ctx,
|
69
|
+
analytics_dataverse_drop_request& /* request */,
|
70
70
|
analytics_dataverse_drop_request::encoded_response_type&& encoded)
|
71
71
|
{
|
72
|
-
analytics_dataverse_drop_response response{
|
73
|
-
if (!ec) {
|
74
|
-
|
72
|
+
analytics_dataverse_drop_response response{ ctx };
|
73
|
+
if (!response.ctx.ec) {
|
74
|
+
tao::json::value payload{};
|
75
|
+
try {
|
76
|
+
payload = tao::json::from_string(encoded.body);
|
77
|
+
} catch (tao::json::pegtl::parse_error& e) {
|
78
|
+
response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
|
79
|
+
return response;
|
80
|
+
}
|
75
81
|
response.status = payload.at("status").get_string();
|
76
82
|
|
77
83
|
if (response.status != "success") {
|
@@ -93,9 +99,9 @@ make_response(std::error_code ec,
|
|
93
99
|
}
|
94
100
|
}
|
95
101
|
if (dataverse_does_not_exist) {
|
96
|
-
response.ec = std::make_error_code(error::analytics_errc::dataverse_not_found);
|
102
|
+
response.ctx.ec = std::make_error_code(error::analytics_errc::dataverse_not_found);
|
97
103
|
} else {
|
98
|
-
response.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
104
|
+
response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
99
105
|
}
|
100
106
|
}
|
101
107
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
2
|
/*
|
3
|
-
* Copyright 2020 Couchbase, Inc.
|
3
|
+
* Copyright 2020-2021 Couchbase, Inc.
|
4
4
|
*
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
6
|
* you may not use this file except in compliance with the License.
|
@@ -19,6 +19,7 @@
|
|
19
19
|
|
20
20
|
#include <tao/json.hpp>
|
21
21
|
|
22
|
+
#include <error_context/http.hxx>
|
22
23
|
#include <version.hxx>
|
23
24
|
|
24
25
|
namespace couchbase::operations
|
@@ -29,8 +30,7 @@ struct analytics_get_pending_mutations_response {
|
|
29
30
|
std::string message;
|
30
31
|
};
|
31
32
|
|
32
|
-
|
33
|
-
std::error_code ec;
|
33
|
+
error_context::http ctx;
|
34
34
|
std::string status{};
|
35
35
|
std::vector<problem> errors{};
|
36
36
|
std::map<std::string, std::uint64_t> stats{};
|
@@ -40,13 +40,14 @@ struct analytics_get_pending_mutations_request {
|
|
40
40
|
using response_type = analytics_get_pending_mutations_response;
|
41
41
|
using encoded_request_type = io::http_request;
|
42
42
|
using encoded_response_type = io::http_response;
|
43
|
+
using error_context_type = error_context::http;
|
43
44
|
|
44
45
|
static const inline service_type type = service_type::analytics;
|
45
46
|
|
46
47
|
std::string client_context_id{ uuid::to_string(uuid::random()) };
|
47
48
|
std::chrono::milliseconds timeout{ timeout_defaults::management_timeout };
|
48
49
|
|
49
|
-
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context&)
|
50
|
+
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& /* context */)
|
50
51
|
{
|
51
52
|
encoded.method = "GET";
|
52
53
|
encoded.path = "/analytics/node/agg/stats/remaining";
|
@@ -55,13 +56,19 @@ struct analytics_get_pending_mutations_request {
|
|
55
56
|
};
|
56
57
|
|
57
58
|
analytics_get_pending_mutations_response
|
58
|
-
make_response(
|
59
|
-
analytics_get_pending_mutations_request& request
|
59
|
+
make_response(error_context::http&& ctx,
|
60
|
+
analytics_get_pending_mutations_request& /* request */,
|
60
61
|
analytics_get_pending_mutations_request::encoded_response_type&& encoded)
|
61
62
|
{
|
62
|
-
analytics_get_pending_mutations_response response{
|
63
|
-
if (!ec) {
|
64
|
-
|
63
|
+
analytics_get_pending_mutations_response response{ ctx };
|
64
|
+
if (!response.ctx.ec) {
|
65
|
+
tao::json::value payload{};
|
66
|
+
try {
|
67
|
+
payload = tao::json::from_string(encoded.body);
|
68
|
+
} catch (tao::json::pegtl::parse_error& e) {
|
69
|
+
response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
|
70
|
+
return response;
|
71
|
+
}
|
65
72
|
if (encoded.status_code == 200) {
|
66
73
|
if (payload.is_object()) {
|
67
74
|
for (const auto& entry : payload.get_object()) {
|
@@ -84,7 +91,7 @@ make_response(std::error_code ec,
|
|
84
91
|
response.errors.emplace_back(err);
|
85
92
|
}
|
86
93
|
}
|
87
|
-
response.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
94
|
+
response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
88
95
|
}
|
89
96
|
return response;
|
90
97
|
}
|