couchbase 3.0.0.alpha.3-universal-darwin-19 → 3.0.0.alpha.4-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.
- checksums.yaml +4 -4
- data/.github/workflows/tests-6.0.3.yml +4 -1
- data/.github/workflows/tests-dev-preview.yml +4 -1
- data/.github/workflows/tests.yml +4 -1
- data/README.md +1 -1
- data/bin/check-cluster +31 -0
- data/bin/init-cluster +16 -4
- data/examples/analytics.rb +221 -0
- data/examples/managing_analytics_indexes.rb +72 -0
- data/examples/managing_view_indexes.rb +54 -0
- data/examples/search_with_consistency.rb +84 -0
- data/examples/view.rb +50 -0
- data/ext/.clang-tidy +1 -0
- data/ext/build_version.hxx.in +1 -1
- data/ext/couchbase/bucket.hxx +0 -1
- data/ext/couchbase/couchbase.cxx +1421 -55
- data/ext/couchbase/io/dns_client.hxx +215 -0
- data/ext/couchbase/io/dns_codec.hxx +207 -0
- data/ext/couchbase/io/dns_config.hxx +116 -0
- data/ext/couchbase/io/dns_message.hxx +558 -0
- data/ext/couchbase/io/http_session.hxx +16 -4
- data/ext/couchbase/io/mcbp_session.hxx +2 -1
- data/ext/couchbase/mutation_token.hxx +1 -1
- data/ext/couchbase/operations.hxx +19 -0
- data/ext/couchbase/operations/analytics_dataset_create.hxx +117 -0
- data/ext/couchbase/operations/analytics_dataset_drop.hxx +103 -0
- data/ext/couchbase/operations/analytics_dataset_get_all.hxx +107 -0
- data/ext/couchbase/operations/analytics_dataverse_create.hxx +104 -0
- data/ext/couchbase/operations/analytics_dataverse_drop.hxx +104 -0
- data/ext/couchbase/operations/analytics_get_pending_mutations.hxx +91 -0
- data/ext/couchbase/operations/analytics_index_create.hxx +128 -0
- data/ext/couchbase/operations/analytics_index_drop.hxx +110 -0
- data/ext/couchbase/operations/analytics_index_get_all.hxx +106 -0
- data/ext/couchbase/operations/analytics_link_connect.hxx +102 -0
- data/ext/couchbase/operations/analytics_link_disconnect.hxx +101 -0
- data/ext/couchbase/operations/design_document.hxx +59 -0
- data/ext/couchbase/operations/document_analytics.hxx +293 -0
- data/ext/couchbase/operations/document_query.hxx +2 -2
- data/ext/couchbase/operations/document_search.hxx +19 -1
- data/ext/couchbase/operations/document_view.hxx +227 -0
- data/ext/couchbase/operations/search_index.hxx +17 -0
- data/ext/couchbase/operations/search_index_control_ingest.hxx +3 -1
- data/ext/couchbase/operations/view_index_drop.hxx +67 -0
- data/ext/couchbase/operations/view_index_get.hxx +90 -0
- data/ext/couchbase/operations/view_index_get_all.hxx +125 -0
- data/ext/couchbase/operations/view_index_upsert.hxx +87 -0
- data/ext/couchbase/service_type.hxx +38 -1
- data/ext/couchbase/timeout_defaults.hxx +3 -1
- data/ext/couchbase/utils/connection_string.hxx +231 -0
- data/ext/couchbase/version.hxx +1 -1
- data/ext/test/main.cxx +3 -12
- data/lib/couchbase/analytics_options.rb +165 -0
- data/lib/couchbase/bucket.rb +49 -0
- data/lib/couchbase/cluster.rb +46 -207
- data/lib/couchbase/management/analytics_index_manager.rb +138 -24
- data/lib/couchbase/management/view_index_manager.rb +63 -10
- data/lib/couchbase/query_options.rb +219 -0
- data/lib/couchbase/search_options.rb +6 -6
- data/lib/couchbase/version.rb +1 -1
- data/lib/couchbase/view_options.rb +155 -0
- metadata +34 -2
@@ -0,0 +1,104 @@
|
|
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
|
+
|
24
|
+
namespace couchbase::operations
|
25
|
+
{
|
26
|
+
struct analytics_dataverse_drop_response {
|
27
|
+
struct problem {
|
28
|
+
std::uint32_t code;
|
29
|
+
std::string message;
|
30
|
+
};
|
31
|
+
|
32
|
+
std::string client_context_id;
|
33
|
+
std::error_code ec;
|
34
|
+
std::string status{};
|
35
|
+
std::vector<problem> errors{};
|
36
|
+
};
|
37
|
+
|
38
|
+
struct analytics_dataverse_drop_request {
|
39
|
+
using response_type = analytics_dataverse_drop_response;
|
40
|
+
using encoded_request_type = io::http_request;
|
41
|
+
using encoded_response_type = io::http_response;
|
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 dataverse_name;
|
49
|
+
|
50
|
+
bool ignore_if_does_not_exist{ false };
|
51
|
+
|
52
|
+
void encode_to(encoded_request_type& encoded)
|
53
|
+
{
|
54
|
+
std::string if_exists_clause = ignore_if_does_not_exist ? "IF EXISTS" : "";
|
55
|
+
|
56
|
+
tao::json::value body{
|
57
|
+
{ "statement", fmt::format("DROP DATAVERSE `{}` {}", dataverse_name, if_exists_clause) },
|
58
|
+
};
|
59
|
+
encoded.headers["content-type"] = "application/json";
|
60
|
+
encoded.method = "POST";
|
61
|
+
encoded.path = "/analytics/service";
|
62
|
+
encoded.body = tao::json::to_string(body);
|
63
|
+
}
|
64
|
+
};
|
65
|
+
|
66
|
+
analytics_dataverse_drop_response
|
67
|
+
make_response(std::error_code ec,
|
68
|
+
analytics_dataverse_drop_request& request,
|
69
|
+
analytics_dataverse_drop_request::encoded_response_type encoded)
|
70
|
+
{
|
71
|
+
analytics_dataverse_drop_response response{ request.client_context_id, ec };
|
72
|
+
if (!ec) {
|
73
|
+
auto payload = tao::json::from_string(encoded.body);
|
74
|
+
response.status = payload.at("status").get_string();
|
75
|
+
|
76
|
+
if (response.status != "success") {
|
77
|
+
bool dataverse_does_not_exist = false;
|
78
|
+
|
79
|
+
auto* errors = payload.find("errors");
|
80
|
+
if (errors != nullptr && errors->is_array()) {
|
81
|
+
for (const auto& error : errors->get_array()) {
|
82
|
+
analytics_dataverse_drop_response::problem err{
|
83
|
+
error.at("code").as<std::uint32_t>(),
|
84
|
+
error.at("msg").get_string(),
|
85
|
+
};
|
86
|
+
switch (err.code) {
|
87
|
+
case 24034: /* Cannot find dataverse with name [string] */
|
88
|
+
dataverse_does_not_exist = true;
|
89
|
+
break;
|
90
|
+
}
|
91
|
+
response.errors.emplace_back(err);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
if (dataverse_does_not_exist) {
|
95
|
+
response.ec = std::make_error_code(error::analytics_errc::dataverse_not_found);
|
96
|
+
} else {
|
97
|
+
response.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
return response;
|
102
|
+
}
|
103
|
+
|
104
|
+
} // namespace couchbase::operations
|
@@ -0,0 +1,91 @@
|
|
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
|
+
|
24
|
+
namespace couchbase::operations
|
25
|
+
{
|
26
|
+
struct analytics_get_pending_mutations_response {
|
27
|
+
struct problem {
|
28
|
+
std::uint32_t code;
|
29
|
+
std::string message;
|
30
|
+
};
|
31
|
+
|
32
|
+
std::string client_context_id;
|
33
|
+
std::error_code ec;
|
34
|
+
std::string status{};
|
35
|
+
std::vector<problem> errors{};
|
36
|
+
std::map<std::string, std::uint64_t> stats{};
|
37
|
+
};
|
38
|
+
|
39
|
+
struct analytics_get_pending_mutations_request {
|
40
|
+
using response_type = analytics_get_pending_mutations_response;
|
41
|
+
using encoded_request_type = io::http_request;
|
42
|
+
using encoded_response_type = io::http_response;
|
43
|
+
|
44
|
+
static const inline service_type type = service_type::analytics;
|
45
|
+
|
46
|
+
std::string client_context_id{ uuid::to_string(uuid::random()) };
|
47
|
+
std::chrono::milliseconds timeout{ timeout_defaults::management_timeout };
|
48
|
+
|
49
|
+
void encode_to(encoded_request_type& encoded)
|
50
|
+
{
|
51
|
+
encoded.method = "GET";
|
52
|
+
encoded.path = "/analytics/node/agg/stats/remaining";
|
53
|
+
}
|
54
|
+
};
|
55
|
+
|
56
|
+
analytics_get_pending_mutations_response
|
57
|
+
make_response(std::error_code ec,
|
58
|
+
analytics_get_pending_mutations_request& request,
|
59
|
+
analytics_get_pending_mutations_request::encoded_response_type encoded)
|
60
|
+
{
|
61
|
+
analytics_get_pending_mutations_response response{ request.client_context_id, ec };
|
62
|
+
if (!ec) {
|
63
|
+
auto payload = tao::json::from_string(encoded.body);
|
64
|
+
if (encoded.status_code == 200) {
|
65
|
+
if (payload.is_object()) {
|
66
|
+
for (const auto& entry : payload.get_object()) {
|
67
|
+
std::string dataverse = entry.first + ".";
|
68
|
+
for (const auto& stats : entry.second.get_object()) {
|
69
|
+
std::string dataset = dataverse + stats.first;
|
70
|
+
response.stats.emplace(dataset, stats.second.get_unsigned());
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
return response;
|
75
|
+
}
|
76
|
+
auto* errors = payload.find("errors");
|
77
|
+
if (errors != nullptr && errors->is_array()) {
|
78
|
+
for (const auto& error : errors->get_array()) {
|
79
|
+
analytics_get_pending_mutations_response::problem err{
|
80
|
+
error.at("code").as<std::uint32_t>(),
|
81
|
+
error.at("msg").get_string(),
|
82
|
+
};
|
83
|
+
response.errors.emplace_back(err);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
response.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
87
|
+
}
|
88
|
+
return response;
|
89
|
+
}
|
90
|
+
|
91
|
+
} // namespace couchbase::operations
|
@@ -0,0 +1,128 @@
|
|
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
|
+
|
24
|
+
namespace couchbase::operations
|
25
|
+
{
|
26
|
+
struct analytics_index_create_response {
|
27
|
+
struct problem {
|
28
|
+
std::uint32_t code;
|
29
|
+
std::string message;
|
30
|
+
};
|
31
|
+
|
32
|
+
std::string client_context_id;
|
33
|
+
std::error_code ec;
|
34
|
+
std::string status{};
|
35
|
+
std::vector<problem> errors{};
|
36
|
+
};
|
37
|
+
|
38
|
+
struct analytics_index_create_request {
|
39
|
+
using response_type = analytics_index_create_response;
|
40
|
+
using encoded_request_type = io::http_request;
|
41
|
+
using encoded_response_type = io::http_response;
|
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 dataverse_name{ "Default" };
|
49
|
+
std::string dataset_name;
|
50
|
+
std::string index_name;
|
51
|
+
std::map<std::string, std::string> fields;
|
52
|
+
|
53
|
+
bool ignore_if_exists{ false };
|
54
|
+
|
55
|
+
void encode_to(encoded_request_type& encoded)
|
56
|
+
{
|
57
|
+
std::string if_not_exists_clause = ignore_if_exists ? "IF NOT EXISTS" : "";
|
58
|
+
std::vector<std::string> field_specs;
|
59
|
+
field_specs.reserve(fields.size());
|
60
|
+
for (const auto& entry : fields) {
|
61
|
+
field_specs.emplace_back(entry.first + ": " + entry.second);
|
62
|
+
}
|
63
|
+
|
64
|
+
tao::json::value body{
|
65
|
+
{ "statement",
|
66
|
+
fmt::format("CREATE INDEX {} `{}` ON `{}`.`{}` ({})",
|
67
|
+
if_not_exists_clause,
|
68
|
+
index_name,
|
69
|
+
dataverse_name,
|
70
|
+
dataset_name,
|
71
|
+
fmt::join(field_specs, ",")) },
|
72
|
+
};
|
73
|
+
encoded.headers["content-type"] = "application/json";
|
74
|
+
encoded.method = "POST";
|
75
|
+
encoded.path = "/analytics/service";
|
76
|
+
encoded.body = tao::json::to_string(body);
|
77
|
+
}
|
78
|
+
};
|
79
|
+
|
80
|
+
analytics_index_create_response
|
81
|
+
make_response(std::error_code ec, analytics_index_create_request& request, analytics_index_create_request::encoded_response_type encoded)
|
82
|
+
{
|
83
|
+
analytics_index_create_response response{ request.client_context_id, ec };
|
84
|
+
if (!ec) {
|
85
|
+
auto payload = tao::json::from_string(encoded.body);
|
86
|
+
response.status = payload.at("status").get_string();
|
87
|
+
|
88
|
+
if (response.status != "success") {
|
89
|
+
bool index_exists = false;
|
90
|
+
bool dataset_not_found = false;
|
91
|
+
bool link_not_found = false;
|
92
|
+
|
93
|
+
auto* errors = payload.find("errors");
|
94
|
+
if (errors != nullptr && errors->is_array()) {
|
95
|
+
for (const auto& error : errors->get_array()) {
|
96
|
+
analytics_index_create_response::problem err{
|
97
|
+
error.at("code").as<std::uint32_t>(),
|
98
|
+
error.at("msg").get_string(),
|
99
|
+
};
|
100
|
+
switch (err.code) {
|
101
|
+
case 24048: /* An index with this name [string] already exists */
|
102
|
+
index_exists = true;
|
103
|
+
break;
|
104
|
+
case 24025: /* Cannot find dataset with name [string] in dataverse [string] */
|
105
|
+
dataset_not_found = true;
|
106
|
+
break;
|
107
|
+
case 24006: /* Link [string] does not exist */
|
108
|
+
link_not_found = true;
|
109
|
+
break;
|
110
|
+
}
|
111
|
+
response.errors.emplace_back(err);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
if (index_exists) {
|
115
|
+
response.ec = std::make_error_code(error::common_errc::index_exists);
|
116
|
+
} else if (dataset_not_found) {
|
117
|
+
response.ec = std::make_error_code(error::analytics_errc::dataset_not_found);
|
118
|
+
} else if (link_not_found) {
|
119
|
+
response.ec = std::make_error_code(error::analytics_errc::link_not_found);
|
120
|
+
} else {
|
121
|
+
response.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
return response;
|
126
|
+
}
|
127
|
+
|
128
|
+
} // namespace couchbase::operations
|
@@ -0,0 +1,110 @@
|
|
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
|
+
|
24
|
+
namespace couchbase::operations
|
25
|
+
{
|
26
|
+
struct analytics_index_drop_response {
|
27
|
+
struct problem {
|
28
|
+
std::uint32_t code;
|
29
|
+
std::string message;
|
30
|
+
};
|
31
|
+
|
32
|
+
std::string client_context_id;
|
33
|
+
std::error_code ec;
|
34
|
+
std::string status{};
|
35
|
+
std::vector<problem> errors{};
|
36
|
+
};
|
37
|
+
|
38
|
+
struct analytics_index_drop_request {
|
39
|
+
using response_type = analytics_index_drop_response;
|
40
|
+
using encoded_request_type = io::http_request;
|
41
|
+
using encoded_response_type = io::http_response;
|
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 dataverse_name{ "Default" };
|
49
|
+
std::string dataset_name;
|
50
|
+
std::string index_name;
|
51
|
+
|
52
|
+
bool ignore_if_does_not_exist{ false };
|
53
|
+
|
54
|
+
void encode_to(encoded_request_type& encoded)
|
55
|
+
{
|
56
|
+
std::string if_exists_clause = ignore_if_does_not_exist ? "IF EXISTS" : "";
|
57
|
+
|
58
|
+
tao::json::value body{
|
59
|
+
{ "statement", fmt::format("DROP INDEX `{}`.`{}`.`{}` {}", dataverse_name, dataset_name, index_name, if_exists_clause) },
|
60
|
+
};
|
61
|
+
encoded.headers["content-type"] = "application/json";
|
62
|
+
encoded.method = "POST";
|
63
|
+
encoded.path = "/analytics/service";
|
64
|
+
encoded.body = tao::json::to_string(body);
|
65
|
+
}
|
66
|
+
};
|
67
|
+
|
68
|
+
analytics_index_drop_response
|
69
|
+
make_response(std::error_code ec, analytics_index_drop_request& request, analytics_index_drop_request::encoded_response_type encoded)
|
70
|
+
{
|
71
|
+
analytics_index_drop_response response{ request.client_context_id, ec };
|
72
|
+
if (!ec) {
|
73
|
+
auto payload = tao::json::from_string(encoded.body);
|
74
|
+
response.status = payload.at("status").get_string();
|
75
|
+
|
76
|
+
if (response.status != "success") {
|
77
|
+
bool index_does_not_exist = false;
|
78
|
+
bool dataset_not_found = false;
|
79
|
+
|
80
|
+
auto* errors = payload.find("errors");
|
81
|
+
if (errors != nullptr && errors->is_array()) {
|
82
|
+
for (const auto& error : errors->get_array()) {
|
83
|
+
analytics_index_drop_response::problem err{
|
84
|
+
error.at("code").as<std::uint32_t>(),
|
85
|
+
error.at("msg").get_string(),
|
86
|
+
};
|
87
|
+
switch (err.code) {
|
88
|
+
case 24047: /* Cannot find index with name [string] */
|
89
|
+
index_does_not_exist = true;
|
90
|
+
break;
|
91
|
+
case 24025: /* Cannot find dataset with name [string] in dataverse [string] */
|
92
|
+
dataset_not_found = true;
|
93
|
+
break;
|
94
|
+
}
|
95
|
+
response.errors.emplace_back(err);
|
96
|
+
}
|
97
|
+
}
|
98
|
+
if (index_does_not_exist) {
|
99
|
+
response.ec = std::make_error_code(error::common_errc::index_not_found);
|
100
|
+
} else if (dataset_not_found) {
|
101
|
+
response.ec = std::make_error_code(error::analytics_errc::dataset_not_found);
|
102
|
+
} else {
|
103
|
+
response.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}
|
107
|
+
return response;
|
108
|
+
}
|
109
|
+
|
110
|
+
} // namespace couchbase::operations
|
@@ -0,0 +1,106 @@
|
|
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
|
+
|
24
|
+
namespace couchbase::operations
|
25
|
+
{
|
26
|
+
struct analytics_index_get_all_response {
|
27
|
+
struct index {
|
28
|
+
std::string name;
|
29
|
+
std::string dataverse_name;
|
30
|
+
std::string dataset_name;
|
31
|
+
bool is_primary;
|
32
|
+
};
|
33
|
+
|
34
|
+
struct problem {
|
35
|
+
std::uint32_t code;
|
36
|
+
std::string message;
|
37
|
+
};
|
38
|
+
|
39
|
+
std::string client_context_id;
|
40
|
+
std::error_code ec;
|
41
|
+
std::string status{};
|
42
|
+
std::vector<index> indexes{};
|
43
|
+
std::vector<problem> errors{};
|
44
|
+
};
|
45
|
+
|
46
|
+
struct analytics_index_get_all_request {
|
47
|
+
using response_type = analytics_index_get_all_response;
|
48
|
+
using encoded_request_type = io::http_request;
|
49
|
+
using encoded_response_type = io::http_response;
|
50
|
+
|
51
|
+
static const inline service_type type = service_type::analytics;
|
52
|
+
|
53
|
+
std::string client_context_id{ uuid::to_string(uuid::random()) };
|
54
|
+
std::chrono::milliseconds timeout{ timeout_defaults::management_timeout };
|
55
|
+
|
56
|
+
void encode_to(encoded_request_type& encoded)
|
57
|
+
{
|
58
|
+
tao::json::value body{
|
59
|
+
{ "statement", "SELECT d.* FROM Metadata.`Index` d WHERE d.DataverseName <> \"Metadata\"" },
|
60
|
+
};
|
61
|
+
|
62
|
+
encoded.headers["content-type"] = "application/json";
|
63
|
+
encoded.method = "POST";
|
64
|
+
encoded.path = "/analytics/service";
|
65
|
+
encoded.body = tao::json::to_string(body);
|
66
|
+
}
|
67
|
+
};
|
68
|
+
|
69
|
+
analytics_index_get_all_response
|
70
|
+
make_response(std::error_code ec, analytics_index_get_all_request& request, analytics_index_get_all_request::encoded_response_type encoded)
|
71
|
+
{
|
72
|
+
analytics_index_get_all_response response{ request.client_context_id, ec };
|
73
|
+
|
74
|
+
if (!ec) {
|
75
|
+
auto payload = tao::json::from_string(encoded.body);
|
76
|
+
response.status = payload.at("status").get_string();
|
77
|
+
if (response.status == "success") {
|
78
|
+
auto* results = payload.find("results");
|
79
|
+
if (results != nullptr && results->is_array()) {
|
80
|
+
for (const auto& res : results->get_array()) {
|
81
|
+
analytics_index_get_all_response::index idx;
|
82
|
+
idx.name = res.at("IndexName").get_string();
|
83
|
+
idx.dataverse_name = res.at("DataverseName").get_string();
|
84
|
+
idx.dataset_name = res.at("DatasetName").get_string();
|
85
|
+
idx.is_primary = res.at("IsPrimary").get_boolean();
|
86
|
+
response.indexes.emplace_back(idx);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
} else {
|
90
|
+
auto* errors = payload.find("errors");
|
91
|
+
if (errors != nullptr && errors->is_array()) {
|
92
|
+
for (const auto& error : errors->get_array()) {
|
93
|
+
analytics_index_get_all_response::problem err{
|
94
|
+
error.at("code").as<std::uint32_t>(),
|
95
|
+
error.at("msg").get_string(),
|
96
|
+
};
|
97
|
+
response.errors.emplace_back(err);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
response.ec = std::make_error_code(error::common_errc::internal_server_failure);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
return response;
|
104
|
+
}
|
105
|
+
|
106
|
+
} // namespace couchbase::operations
|