couchbase 3.1.1 → 3.2.0
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 -1
- data/ext/build_version.hxx.in +1 -1
- data/ext/cmake/Testing.cmake +1 -0
- data/ext/cmake/ThirdPartyDependencies.cmake +6 -0
- data/ext/cmake/VersionInfo.cmake +3 -0
- data/ext/couchbase/bucket.hxx +47 -28
- data/ext/couchbase/cbsasl/client.h +1 -1
- data/ext/couchbase/cbsasl/context.cc +1 -1
- data/ext/couchbase/cbsasl/context.h +3 -3
- data/ext/couchbase/cbsasl/mechanism.cc +5 -8
- data/ext/couchbase/cbsasl/mechanism.h +1 -4
- data/ext/couchbase/cbsasl/plain/plain.cc +1 -1
- data/ext/couchbase/cbsasl/scram-sha/scram-sha.cc +30 -36
- data/ext/couchbase/cluster.hxx +40 -22
- data/ext/couchbase/cluster_options.hxx +7 -1
- data/ext/couchbase/configuration.hxx +37 -16
- data/ext/couchbase/couchbase.cxx +1145 -291
- data/ext/couchbase/error_map.hxx +1 -1
- data/ext/couchbase/errors.hxx +25 -17
- data/ext/couchbase/io/dns_client.hxx +3 -3
- data/ext/couchbase/io/dns_codec.hxx +4 -5
- data/ext/couchbase/io/dns_config.hxx +5 -6
- data/ext/couchbase/io/dns_message.hxx +3 -3
- data/ext/couchbase/io/http_command.hxx +70 -35
- data/ext/couchbase/io/http_session.hxx +4 -3
- data/ext/couchbase/io/http_session_manager.hxx +28 -19
- data/ext/couchbase/io/mcbp_command.hxx +51 -19
- data/ext/couchbase/io/mcbp_context.hxx +1 -1
- data/ext/couchbase/io/mcbp_parser.hxx +4 -4
- data/ext/couchbase/io/mcbp_session.hxx +91 -101
- data/ext/couchbase/io/query_cache.hxx +2 -2
- data/ext/couchbase/io/retry_orchestrator.hxx +2 -4
- data/ext/couchbase/io/retry_reason.hxx +2 -2
- data/ext/couchbase/io/retry_strategy.hxx +1 -6
- data/ext/couchbase/io/streams.hxx +7 -7
- data/ext/couchbase/metrics/logging_meter.hxx +228 -0
- data/ext/couchbase/metrics/logging_meter_options.hxx +28 -0
- data/ext/couchbase/metrics/meter.hxx +49 -0
- data/ext/couchbase/metrics/noop_meter.hxx +43 -0
- data/ext/couchbase/operations/analytics_dataset_create.hxx +16 -12
- data/ext/couchbase/operations/analytics_dataset_drop.hxx +11 -11
- data/ext/couchbase/operations/analytics_dataset_get_all.hxx +6 -6
- data/ext/couchbase/operations/analytics_dataverse_create.hxx +10 -11
- data/ext/couchbase/operations/analytics_dataverse_drop.hxx +10 -11
- data/ext/couchbase/operations/analytics_get_pending_mutations.hxx +9 -11
- data/ext/couchbase/operations/analytics_index_create.hxx +14 -13
- data/ext/couchbase/operations/analytics_index_drop.hxx +18 -12
- data/ext/couchbase/operations/analytics_index_get_all.hxx +8 -6
- data/ext/couchbase/operations/analytics_link.hxx +39 -0
- data/ext/couchbase/operations/analytics_link_azure_blob_external.hxx +145 -0
- data/ext/couchbase/operations/analytics_link_connect.hxx +14 -12
- data/ext/couchbase/operations/analytics_link_couchbase_remote.hxx +220 -0
- data/ext/couchbase/operations/analytics_link_create.hxx +128 -0
- data/ext/couchbase/operations/analytics_link_disconnect.hxx +11 -12
- data/ext/couchbase/operations/analytics_link_drop.hxx +130 -0
- data/ext/couchbase/operations/analytics_link_get_all.hxx +160 -0
- data/ext/couchbase/operations/analytics_link_replace.hxx +128 -0
- data/ext/couchbase/operations/analytics_link_s3_external.hxx +122 -0
- data/ext/couchbase/operations/bucket_create.hxx +8 -8
- data/ext/couchbase/operations/bucket_drop.hxx +5 -5
- data/ext/couchbase/operations/bucket_flush.hxx +5 -5
- data/ext/couchbase/operations/bucket_get.hxx +7 -7
- data/ext/couchbase/operations/bucket_get_all.hxx +7 -5
- data/ext/couchbase/operations/bucket_settings.hxx +40 -49
- data/ext/couchbase/operations/bucket_update.hxx +8 -8
- data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +7 -7
- data/ext/couchbase/operations/collection_create.hxx +11 -11
- data/ext/couchbase/operations/collection_drop.hxx +12 -10
- data/ext/couchbase/operations/collections_manifest_get.hxx +3 -3
- data/ext/couchbase/operations/design_document.hxx +2 -2
- data/ext/couchbase/operations/document_analytics.hxx +29 -36
- data/ext/couchbase/operations/document_append.hxx +3 -3
- data/ext/couchbase/operations/document_decrement.hxx +3 -3
- data/ext/couchbase/operations/document_exists.hxx +2 -2
- data/ext/couchbase/operations/document_get.hxx +3 -3
- data/ext/couchbase/operations/document_get_and_lock.hxx +5 -3
- data/ext/couchbase/operations/document_get_and_touch.hxx +5 -3
- data/ext/couchbase/operations/document_get_projected.hxx +10 -11
- data/ext/couchbase/operations/document_increment.hxx +3 -3
- data/ext/couchbase/operations/document_insert.hxx +3 -3
- data/ext/couchbase/operations/document_lookup_in.hxx +12 -18
- data/ext/couchbase/operations/document_mutate_in.hxx +13 -18
- data/ext/couchbase/operations/document_prepend.hxx +3 -3
- data/ext/couchbase/operations/document_query.hxx +39 -41
- data/ext/couchbase/operations/document_remove.hxx +3 -3
- data/ext/couchbase/operations/document_replace.hxx +3 -3
- data/ext/couchbase/operations/document_search.hxx +56 -61
- data/ext/couchbase/operations/document_touch.hxx +3 -3
- data/ext/couchbase/operations/document_unlock.hxx +3 -3
- data/ext/couchbase/operations/document_upsert.hxx +3 -3
- data/ext/couchbase/operations/document_view.hxx +23 -23
- data/ext/couchbase/operations/group_drop.hxx +5 -5
- data/ext/couchbase/operations/group_get.hxx +7 -7
- data/ext/couchbase/operations/group_get_all.hxx +6 -6
- data/ext/couchbase/operations/group_upsert.hxx +11 -11
- data/ext/couchbase/operations/http_noop.hxx +6 -6
- data/ext/couchbase/operations/mcbp_noop.hxx +3 -3
- data/ext/couchbase/operations/query_index_build_deferred.hxx +6 -6
- data/ext/couchbase/operations/query_index_create.hxx +10 -8
- data/ext/couchbase/operations/query_index_drop.hxx +8 -8
- data/ext/couchbase/operations/query_index_get_all.hxx +43 -39
- data/ext/couchbase/operations/rbac.hxx +40 -63
- data/ext/couchbase/operations/role_get_all.hxx +6 -6
- data/ext/couchbase/operations/scope_create.hxx +10 -10
- data/ext/couchbase/operations/scope_drop.hxx +9 -9
- data/ext/couchbase/operations/scope_get_all.hxx +8 -8
- data/ext/couchbase/operations/search_get_stats.hxx +5 -3
- data/ext/couchbase/operations/search_index.hxx +6 -15
- data/ext/couchbase/operations/search_index_analyze_document.hxx +11 -11
- data/ext/couchbase/operations/search_index_control_ingest.hxx +9 -9
- data/ext/couchbase/operations/search_index_control_plan_freeze.hxx +9 -9
- data/ext/couchbase/operations/search_index_control_query.hxx +9 -9
- data/ext/couchbase/operations/search_index_drop.hxx +11 -9
- data/ext/couchbase/operations/search_index_get.hxx +11 -9
- data/ext/couchbase/operations/search_index_get_all.hxx +11 -11
- data/ext/couchbase/operations/search_index_get_documents_count.hxx +10 -10
- data/ext/couchbase/operations/search_index_get_stats.hxx +10 -8
- data/ext/couchbase/operations/search_index_upsert.hxx +12 -10
- data/ext/couchbase/operations/user_drop.hxx +5 -5
- data/ext/couchbase/operations/user_get.hxx +7 -7
- data/ext/couchbase/operations/user_get_all.hxx +6 -6
- data/ext/couchbase/operations/user_upsert.hxx +9 -9
- data/ext/couchbase/operations/view_index_drop.hxx +10 -10
- data/ext/couchbase/operations/view_index_get.hxx +13 -15
- data/ext/couchbase/operations/view_index_get_all.hxx +17 -20
- data/ext/couchbase/operations/view_index_upsert.hxx +9 -7
- data/ext/couchbase/operations.hxx +4 -0
- data/ext/couchbase/origin.hxx +14 -10
- data/ext/couchbase/platform/backtrace.c +1 -1
- data/ext/couchbase/platform/base64.cc +5 -5
- data/ext/couchbase/platform/base64.h +2 -5
- data/ext/couchbase/protocol/client_opcode.hxx +7 -4
- data/ext/couchbase/protocol/client_request.hxx +2 -2
- data/ext/couchbase/protocol/client_response.hxx +41 -16
- data/ext/couchbase/protocol/cmd_append.hxx +17 -16
- data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +4 -4
- data/ext/couchbase/protocol/cmd_decrement.hxx +10 -11
- data/ext/couchbase/protocol/cmd_exists.hxx +12 -15
- data/ext/couchbase/protocol/cmd_get.hxx +11 -14
- data/ext/couchbase/protocol/cmd_get_and_lock.hxx +10 -12
- data/ext/couchbase/protocol/cmd_get_and_touch.hxx +10 -12
- data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +13 -18
- data/ext/couchbase/protocol/cmd_get_collection_id.hxx +12 -15
- data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +12 -16
- data/ext/couchbase/protocol/cmd_get_error_map.hxx +14 -17
- data/ext/couchbase/protocol/cmd_hello.hxx +8 -10
- data/ext/couchbase/protocol/cmd_increment.hxx +9 -10
- data/ext/couchbase/protocol/cmd_insert.hxx +9 -9
- data/ext/couchbase/protocol/cmd_lookup_in.hxx +12 -13
- data/ext/couchbase/protocol/cmd_mutate_in.hxx +11 -11
- data/ext/couchbase/protocol/cmd_noop.hxx +16 -20
- data/ext/couchbase/protocol/cmd_prepend.hxx +9 -10
- data/ext/couchbase/protocol/cmd_remove.hxx +10 -13
- data/ext/couchbase/protocol/cmd_replace.hxx +7 -7
- data/ext/couchbase/protocol/cmd_sasl_auth.hxx +8 -10
- data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +10 -15
- data/ext/couchbase/protocol/cmd_sasl_step.hxx +10 -12
- data/ext/couchbase/protocol/cmd_select_bucket.hxx +14 -18
- data/ext/couchbase/protocol/cmd_touch.hxx +8 -11
- data/ext/couchbase/protocol/cmd_unlock.hxx +10 -14
- data/ext/couchbase/protocol/cmd_upsert.hxx +8 -8
- data/ext/couchbase/protocol/datatype.hxx +3 -3
- data/ext/couchbase/protocol/durability_level.hxx +2 -2
- data/ext/couchbase/protocol/frame_info_id.hxx +4 -4
- data/ext/couchbase/protocol/hello_feature.hxx +2 -2
- data/ext/couchbase/protocol/magic.hxx +2 -2
- data/ext/couchbase/protocol/server_opcode.hxx +2 -2
- data/ext/couchbase/protocol/server_request.hxx +1 -1
- data/ext/couchbase/protocol/status.hxx +4 -7
- data/ext/couchbase/protocol/unsigned_leb128.h +5 -20
- data/ext/couchbase/service_type.hxx +4 -4
- data/ext/couchbase/tracing/constants.hxx +261 -0
- data/ext/couchbase/tracing/noop_tracer.hxx +50 -0
- data/ext/couchbase/tracing/request_tracer.hxx +77 -0
- data/ext/couchbase/tracing/threshold_logging_options.hxx +64 -0
- data/ext/couchbase/tracing/threshold_logging_tracer.hxx +366 -0
- data/ext/couchbase/utils/byteswap.hxx +1 -1
- data/ext/couchbase/utils/connection_string.hxx +21 -1
- data/ext/couchbase/utils/name_codec.hxx +41 -0
- data/ext/couchbase/utils/url_codec.hxx +236 -0
- data/ext/couchbase/version.hxx +1 -1
- data/ext/test/CMakeLists.txt +1 -0
- data/ext/test/test_native_trivial_query.cxx +60 -0
- data/ext/third_party/hdr_histogram_c/CMakeLists.txt +84 -0
- data/ext/third_party/hdr_histogram_c/COPYING.txt +121 -0
- data/ext/third_party/hdr_histogram_c/LICENSE.txt +41 -0
- data/ext/third_party/hdr_histogram_c/config.cmake.in +6 -0
- data/ext/third_party/hdr_histogram_c/src/CMakeLists.txt +83 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_atomic.h +146 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_encoding.c +322 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_encoding.h +79 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_endian.h +116 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_histogram.c +1196 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_histogram.h +516 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_histogram_log.c +1290 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_histogram_log.h +236 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_histogram_log_no_op.c +171 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_interval_recorder.c +227 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_interval_recorder.h +109 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_malloc.h +19 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_tests.h +22 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_thread.c +108 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_thread.h +55 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_time.c +98 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_time.h +49 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_writer_reader_phaser.c +143 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_writer_reader_phaser.h +51 -0
- data/lib/couchbase/cluster.rb +1 -0
- data/lib/couchbase/errors.rb +3 -0
- data/lib/couchbase/management/analytics_index_manager.rb +920 -226
- data/lib/couchbase/management/bucket_manager.rb +207 -69
- data/lib/couchbase/management/collection_manager.rb +173 -61
- data/lib/couchbase/management/query_index_manager.rb +357 -169
- data/lib/couchbase/options.rb +75 -3
- data/lib/couchbase/scope.rb +102 -0
- data/lib/couchbase/utils/time.rb +4 -0
- data/lib/couchbase/version.rb +6 -6
- metadata +50 -7
@@ -0,0 +1,128 @@
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* Copyright 2020-2021 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 <operations/analytics_link.hxx>
|
23
|
+
#include <utils/name_codec.hxx>
|
24
|
+
|
25
|
+
namespace couchbase::operations
|
26
|
+
{
|
27
|
+
struct analytics_link_create_response {
|
28
|
+
struct problem {
|
29
|
+
std::uint32_t code;
|
30
|
+
std::string message;
|
31
|
+
};
|
32
|
+
|
33
|
+
error_context::http ctx;
|
34
|
+
std::string status{};
|
35
|
+
std::vector<problem> errors{};
|
36
|
+
};
|
37
|
+
|
38
|
+
template<typename analytics_link_type>
|
39
|
+
struct analytics_link_create_request {
|
40
|
+
using response_type = analytics_link_create_response;
|
41
|
+
using encoded_request_type = io::http_request;
|
42
|
+
using encoded_response_type = io::http_response;
|
43
|
+
using error_context_type = error_context::http;
|
44
|
+
|
45
|
+
static const inline service_type type = service_type::analytics;
|
46
|
+
|
47
|
+
std::string client_context_id{ uuid::to_string(uuid::random()) };
|
48
|
+
std::chrono::milliseconds timeout{ timeout_defaults::management_timeout };
|
49
|
+
|
50
|
+
analytics_link_type link{};
|
51
|
+
|
52
|
+
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& /* context */) const
|
53
|
+
{
|
54
|
+
std::error_code ec = link.validate();
|
55
|
+
if (ec) {
|
56
|
+
return ec;
|
57
|
+
}
|
58
|
+
encoded.headers["content-type"] = "application/x-www-form-urlencoded";
|
59
|
+
encoded.headers["accept"] = "application/json";
|
60
|
+
encoded.method = "POST";
|
61
|
+
encoded.path = analytics_link::endpoint_from_link(link);
|
62
|
+
encoded.body = link.encode();
|
63
|
+
return {};
|
64
|
+
}
|
65
|
+
};
|
66
|
+
|
67
|
+
template<typename analytics_link_type>
|
68
|
+
analytics_link_create_response
|
69
|
+
make_response(error_context::http&& ctx,
|
70
|
+
const analytics_link_create_request<analytics_link_type>& /* request */,
|
71
|
+
typename analytics_link_create_request<analytics_link_type>::encoded_response_type&& encoded)
|
72
|
+
{
|
73
|
+
analytics_link_create_response response{ std::move(ctx) };
|
74
|
+
if (!response.ctx.ec) {
|
75
|
+
if (encoded.body.empty() && response.ctx.http_status == 200) {
|
76
|
+
return response;
|
77
|
+
}
|
78
|
+
tao::json::value payload{};
|
79
|
+
try {
|
80
|
+
payload = tao::json::from_string(encoded.body);
|
81
|
+
} catch (const tao::json::pegtl::parse_error&) {
|
82
|
+
auto colon = encoded.body.find(':');
|
83
|
+
if (colon == std::string::npos) {
|
84
|
+
response.ctx.ec = error::common_errc::parsing_failure;
|
85
|
+
return response;
|
86
|
+
}
|
87
|
+
auto code = static_cast<std::uint32_t>(std::stoul(encoded.body, 0));
|
88
|
+
auto msg = encoded.body.substr(colon + 1);
|
89
|
+
response.errors.emplace_back(analytics_link_create_response::problem{ code, msg });
|
90
|
+
}
|
91
|
+
if (payload) {
|
92
|
+
response.status = payload.at("status").get_string();
|
93
|
+
if (response.status != "success") {
|
94
|
+
if (auto* errors = payload.find("errors"); errors != nullptr && errors->is_array()) {
|
95
|
+
for (const auto& error : errors->get_array()) {
|
96
|
+
analytics_link_create_response::problem err{
|
97
|
+
error.at("code").as<std::uint32_t>(),
|
98
|
+
error.at("msg").get_string(),
|
99
|
+
};
|
100
|
+
response.errors.emplace_back(err);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
bool link_exists = false;
|
106
|
+
bool dataverse_does_not_exist = false;
|
107
|
+
for (const auto& err : response.errors) {
|
108
|
+
switch (err.code) {
|
109
|
+
case 24055: /* Link [string] already exists */
|
110
|
+
link_exists = true;
|
111
|
+
break;
|
112
|
+
case 24034: /* Cannot find dataverse with name [string] */
|
113
|
+
dataverse_does_not_exist = true;
|
114
|
+
break;
|
115
|
+
}
|
116
|
+
}
|
117
|
+
if (dataverse_does_not_exist) {
|
118
|
+
response.ctx.ec = error::analytics_errc::dataverse_not_found;
|
119
|
+
} else if (link_exists) {
|
120
|
+
response.ctx.ec = error::analytics_errc::link_exists;
|
121
|
+
} else {
|
122
|
+
response.ctx.ec = error::common_errc::internal_server_failure;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
return response;
|
126
|
+
}
|
127
|
+
|
128
|
+
} // namespace couchbase::operations
|
@@ -19,7 +19,7 @@
|
|
19
19
|
|
20
20
|
#include <tao/json.hpp>
|
21
21
|
|
22
|
-
#include <
|
22
|
+
#include <utils/name_codec.hxx>
|
23
23
|
|
24
24
|
namespace couchbase::operations
|
25
25
|
{
|
@@ -46,12 +46,12 @@ struct analytics_link_disconnect_request {
|
|
46
46
|
std::chrono::milliseconds timeout{ timeout_defaults::management_timeout };
|
47
47
|
|
48
48
|
std::string dataverse_name{ "Default" };
|
49
|
-
std::string link_name;
|
49
|
+
std::string link_name{ "Local" };
|
50
50
|
|
51
|
-
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context&)
|
51
|
+
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& /* context */) const
|
52
52
|
{
|
53
53
|
tao::json::value body{
|
54
|
-
{ "statement", fmt::format("DISCONNECT LINK
|
54
|
+
{ "statement", fmt::format("DISCONNECT LINK {}.`{}`", utils::analytics::uncompound_name(dataverse_name), link_name) },
|
55
55
|
};
|
56
56
|
encoded.headers["content-type"] = "application/json";
|
57
57
|
encoded.method = "POST";
|
@@ -63,16 +63,16 @@ struct analytics_link_disconnect_request {
|
|
63
63
|
|
64
64
|
analytics_link_disconnect_response
|
65
65
|
make_response(error_context::http&& ctx,
|
66
|
-
analytics_link_disconnect_request
|
66
|
+
const analytics_link_disconnect_request& /* request */,
|
67
67
|
analytics_link_disconnect_request::encoded_response_type&& encoded)
|
68
68
|
{
|
69
|
-
analytics_link_disconnect_response response{ ctx };
|
69
|
+
analytics_link_disconnect_response response{ std::move(ctx) };
|
70
70
|
if (!response.ctx.ec) {
|
71
71
|
tao::json::value payload{};
|
72
72
|
try {
|
73
73
|
payload = tao::json::from_string(encoded.body);
|
74
|
-
} catch (tao::json::pegtl::parse_error& e) {
|
75
|
-
response.ctx.ec =
|
74
|
+
} catch (const tao::json::pegtl::parse_error& e) {
|
75
|
+
response.ctx.ec = error::common_errc::parsing_failure;
|
76
76
|
return response;
|
77
77
|
}
|
78
78
|
response.status = payload.at("status").get_string();
|
@@ -80,8 +80,7 @@ make_response(error_context::http&& ctx,
|
|
80
80
|
if (response.status != "success") {
|
81
81
|
bool link_not_found = false;
|
82
82
|
|
83
|
-
auto* errors = payload.find("errors");
|
84
|
-
if (errors != nullptr && errors->is_array()) {
|
83
|
+
if (auto* errors = payload.find("errors"); errors != nullptr && errors->is_array()) {
|
85
84
|
for (const auto& error : errors->get_array()) {
|
86
85
|
analytics_link_disconnect_response::problem err{
|
87
86
|
error.at("code").as<std::uint32_t>(),
|
@@ -96,9 +95,9 @@ make_response(error_context::http&& ctx,
|
|
96
95
|
}
|
97
96
|
}
|
98
97
|
if (link_not_found) {
|
99
|
-
response.ctx.ec =
|
98
|
+
response.ctx.ec = error::analytics_errc::link_not_found;
|
100
99
|
} else {
|
101
|
-
response.ctx.ec =
|
100
|
+
response.ctx.ec = error::common_errc::internal_server_failure;
|
102
101
|
}
|
103
102
|
}
|
104
103
|
}
|
@@ -0,0 +1,130 @@
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* Copyright 2020-2021 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 <utils/url_codec.hxx>
|
23
|
+
|
24
|
+
namespace couchbase::operations
|
25
|
+
{
|
26
|
+
struct analytics_link_drop_response {
|
27
|
+
struct problem {
|
28
|
+
std::uint32_t code;
|
29
|
+
std::string message;
|
30
|
+
};
|
31
|
+
|
32
|
+
error_context::http ctx;
|
33
|
+
std::string status{};
|
34
|
+
std::vector<problem> errors{};
|
35
|
+
};
|
36
|
+
|
37
|
+
struct analytics_link_drop_request {
|
38
|
+
using response_type = analytics_link_drop_response;
|
39
|
+
using encoded_request_type = io::http_request;
|
40
|
+
using encoded_response_type = io::http_response;
|
41
|
+
using error_context_type = error_context::http;
|
42
|
+
|
43
|
+
static const inline service_type type = service_type::analytics;
|
44
|
+
|
45
|
+
std::string client_context_id{ uuid::to_string(uuid::random()) };
|
46
|
+
std::chrono::milliseconds timeout{ timeout_defaults::management_timeout };
|
47
|
+
|
48
|
+
std::string link_name{};
|
49
|
+
std::string dataverse_name{};
|
50
|
+
|
51
|
+
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& /* context */) const
|
52
|
+
{
|
53
|
+
encoded.headers["content-type"] = "application/x-www-form-urlencoded";
|
54
|
+
encoded.headers["accept"] = "application/json";
|
55
|
+
encoded.method = "DELETE";
|
56
|
+
if (std::count(dataverse_name.begin(), dataverse_name.end(), '/') == 0) {
|
57
|
+
std::map<std::string, std::string> values{
|
58
|
+
{ "dataverse", dataverse_name },
|
59
|
+
{ "name", link_name },
|
60
|
+
};
|
61
|
+
encoded.body = utils::string_codec::v2::form_encode(values);
|
62
|
+
encoded.path = "/analytics/link";
|
63
|
+
} else {
|
64
|
+
encoded.path = fmt::format("/analytics/link/{}/{}", utils::string_codec::v2::path_escape(dataverse_name), link_name);
|
65
|
+
}
|
66
|
+
return {};
|
67
|
+
}
|
68
|
+
};
|
69
|
+
|
70
|
+
analytics_link_drop_response
|
71
|
+
make_response(error_context::http&& ctx,
|
72
|
+
const analytics_link_drop_request& /* request */,
|
73
|
+
typename analytics_link_drop_request::encoded_response_type&& encoded)
|
74
|
+
{
|
75
|
+
analytics_link_drop_response response{ std::move(ctx) };
|
76
|
+
if (!response.ctx.ec) {
|
77
|
+
if (encoded.body.empty() && response.ctx.http_status == 200) {
|
78
|
+
return response;
|
79
|
+
}
|
80
|
+
tao::json::value payload{};
|
81
|
+
try {
|
82
|
+
payload = tao::json::from_string(encoded.body);
|
83
|
+
} catch (const tao::json::pegtl::parse_error&) {
|
84
|
+
auto colon = encoded.body.find(':');
|
85
|
+
if (colon == std::string::npos) {
|
86
|
+
response.ctx.ec = error::common_errc::parsing_failure;
|
87
|
+
return response;
|
88
|
+
}
|
89
|
+
auto code = static_cast<std::uint32_t>(std::stoul(encoded.body, 0));
|
90
|
+
auto msg = encoded.body.substr(colon + 1);
|
91
|
+
response.errors.emplace_back(analytics_link_drop_response::problem{ code, msg });
|
92
|
+
}
|
93
|
+
if (payload) {
|
94
|
+
response.status = payload.at("status").get_string();
|
95
|
+
if (response.status != "success") {
|
96
|
+
if (auto* errors = payload.find("errors"); errors != nullptr && errors->is_array()) {
|
97
|
+
for (const auto& error : errors->get_array()) {
|
98
|
+
analytics_link_drop_response::problem err{
|
99
|
+
error.at("code").as<std::uint32_t>(),
|
100
|
+
error.at("msg").get_string(),
|
101
|
+
};
|
102
|
+
response.errors.emplace_back(err);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}
|
107
|
+
bool link_not_found = false;
|
108
|
+
bool dataverse_does_not_exist = false;
|
109
|
+
for (const auto& err : response.errors) {
|
110
|
+
switch (err.code) {
|
111
|
+
case 24006: /* Link [string] does not exist */
|
112
|
+
link_not_found = true;
|
113
|
+
break;
|
114
|
+
case 24034: /* Cannot find dataverse with name [string] */
|
115
|
+
dataverse_does_not_exist = true;
|
116
|
+
break;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
if (dataverse_does_not_exist) {
|
120
|
+
response.ctx.ec = error::analytics_errc::dataverse_not_found;
|
121
|
+
} else if (link_not_found) {
|
122
|
+
response.ctx.ec = error::analytics_errc::link_not_found;
|
123
|
+
} else {
|
124
|
+
response.ctx.ec = error::common_errc::internal_server_failure;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
return response;
|
128
|
+
}
|
129
|
+
|
130
|
+
} // namespace couchbase::operations
|
@@ -0,0 +1,160 @@
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* Copyright 2020-2021 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 <utils/url_codec.hxx>
|
23
|
+
#include <operations/analytics_link.hxx>
|
24
|
+
|
25
|
+
namespace couchbase::operations
|
26
|
+
{
|
27
|
+
struct analytics_link_get_all_response {
|
28
|
+
struct problem {
|
29
|
+
std::uint32_t code;
|
30
|
+
std::string message;
|
31
|
+
};
|
32
|
+
|
33
|
+
error_context::http ctx;
|
34
|
+
std::string status{};
|
35
|
+
std::vector<problem> errors{};
|
36
|
+
|
37
|
+
std::vector<analytics_link::couchbase_remote> couchbase{};
|
38
|
+
std::vector<analytics_link::s3_external> s3{};
|
39
|
+
std::vector<analytics_link::azure_blob_external> azure_blob{};
|
40
|
+
};
|
41
|
+
|
42
|
+
struct analytics_link_get_all_request {
|
43
|
+
using response_type = analytics_link_get_all_response;
|
44
|
+
using encoded_request_type = io::http_request;
|
45
|
+
using encoded_response_type = io::http_response;
|
46
|
+
using error_context_type = error_context::http;
|
47
|
+
|
48
|
+
static const inline service_type type = service_type::analytics;
|
49
|
+
|
50
|
+
std::string client_context_id{ uuid::to_string(uuid::random()) };
|
51
|
+
std::chrono::milliseconds timeout{ timeout_defaults::management_timeout };
|
52
|
+
|
53
|
+
std::string link_type{};
|
54
|
+
std::string link_name{};
|
55
|
+
std::string dataverse_name{};
|
56
|
+
|
57
|
+
[[nodiscard]] std::error_code encode_to(encoded_request_type& encoded, http_context& /* context */) const
|
58
|
+
{
|
59
|
+
std::map<std::string, std::string> values{};
|
60
|
+
|
61
|
+
encoded.headers["content-type"] = "application/x-www-form-urlencoded";
|
62
|
+
encoded.headers["accept"] = "application/json";
|
63
|
+
encoded.method = "GET";
|
64
|
+
if (!link_type.empty()) {
|
65
|
+
values["type"] = link_type;
|
66
|
+
}
|
67
|
+
if (std::count(dataverse_name.begin(), dataverse_name.end(), '/') == 0) {
|
68
|
+
if (!dataverse_name.empty()) {
|
69
|
+
values["dataverse"] = dataverse_name;
|
70
|
+
if (!link_name.empty()) {
|
71
|
+
values["name"] = link_name;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
encoded.path = "/analytics/link";
|
75
|
+
} else {
|
76
|
+
if (link_name.empty()) {
|
77
|
+
encoded.path = fmt::format("/analytics/link/{}", utils::string_codec::v2::path_escape(dataverse_name));
|
78
|
+
} else {
|
79
|
+
encoded.path = fmt::format("/analytics/link/{}/{}", utils::string_codec::v2::path_escape(dataverse_name), link_name);
|
80
|
+
}
|
81
|
+
}
|
82
|
+
encoded.body = utils::string_codec::v2::form_encode(values);
|
83
|
+
return {};
|
84
|
+
}
|
85
|
+
};
|
86
|
+
|
87
|
+
analytics_link_get_all_response
|
88
|
+
make_response(error_context::http&& ctx,
|
89
|
+
const analytics_link_get_all_request& /* request */,
|
90
|
+
typename analytics_link_get_all_request::encoded_response_type&& encoded)
|
91
|
+
{
|
92
|
+
analytics_link_get_all_response response{ std::move(ctx) };
|
93
|
+
if (!response.ctx.ec) {
|
94
|
+
if (encoded.body.empty() && response.ctx.http_status == 200) {
|
95
|
+
return response;
|
96
|
+
}
|
97
|
+
tao::json::value payload{};
|
98
|
+
try {
|
99
|
+
payload = tao::json::from_string(encoded.body);
|
100
|
+
} catch (const tao::json::pegtl::parse_error&) {
|
101
|
+
auto colon = encoded.body.find(':');
|
102
|
+
if (colon == std::string::npos) {
|
103
|
+
response.ctx.ec = error::common_errc::parsing_failure;
|
104
|
+
return response;
|
105
|
+
}
|
106
|
+
auto code = static_cast<std::uint32_t>(std::stoul(encoded.body, 0));
|
107
|
+
auto msg = encoded.body.substr(colon + 1);
|
108
|
+
response.errors.emplace_back(analytics_link_get_all_response::problem{ code, msg });
|
109
|
+
}
|
110
|
+
if (payload) {
|
111
|
+
if (payload.is_object()) {
|
112
|
+
response.status = payload.at("status").get_string();
|
113
|
+
if (response.status != "success") {
|
114
|
+
if (auto* errors = payload.find("errors"); errors != nullptr && errors->is_array()) {
|
115
|
+
for (const auto& error : errors->get_array()) {
|
116
|
+
analytics_link_get_all_response::problem err{
|
117
|
+
error.at("code").as<std::uint32_t>(),
|
118
|
+
error.at("msg").get_string(),
|
119
|
+
};
|
120
|
+
response.errors.emplace_back(err);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
} else if (payload.is_array()) {
|
125
|
+
for (const auto& link : payload.get_array()) {
|
126
|
+
const std::string& type = link.at("type").get_string();
|
127
|
+
if (type == "couchbase") {
|
128
|
+
response.couchbase.emplace_back(link.as<analytics_link::couchbase_remote>());
|
129
|
+
} else if (type == "s3") {
|
130
|
+
response.s3.emplace_back(link.as<analytics_link::s3_external>());
|
131
|
+
} else if (type == "azureblob") {
|
132
|
+
response.azure_blob.emplace_back(link.as<analytics_link::azure_blob_external>());
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
bool link_not_found = false;
|
138
|
+
bool dataverse_does_not_exist = false;
|
139
|
+
for (const auto& err : response.errors) {
|
140
|
+
switch (err.code) {
|
141
|
+
case 24006: /* Link [string] does not exist */
|
142
|
+
link_not_found = true;
|
143
|
+
break;
|
144
|
+
case 24034: /* Cannot find dataverse with name [string] */
|
145
|
+
dataverse_does_not_exist = true;
|
146
|
+
break;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
if (dataverse_does_not_exist) {
|
150
|
+
response.ctx.ec = error::analytics_errc::dataverse_not_found;
|
151
|
+
} else if (link_not_found) {
|
152
|
+
response.ctx.ec = error::analytics_errc::link_not_found;
|
153
|
+
} else if (response.ctx.http_status != 200) {
|
154
|
+
response.ctx.ec = error::common_errc::internal_server_failure;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
return response;
|
158
|
+
}
|
159
|
+
|
160
|
+
} // namespace couchbase::operations
|