Last active
April 12, 2019 23:01
-
-
Save borrrden/af4ff2f450b221bd2bbc0da5b0bceb20 to your computer and use it in GitHub Desktop.
Trying to run some inserts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// _username and _password are passed in and cluster is created as follows | |
_cluster = new Cluster(new ClientConfiguration | |
{ | |
Servers = new List<Uri> {url} | |
}); | |
// Create the buckets and users, names is a list of strings | |
var authenticator = new ClassicAuthenticator(_username, _password); | |
foreach (var name in names) { | |
authenticator.AddBucketCredential(name, _password); | |
} | |
_cluster.Authenticate(authenticator); | |
using (var manager = _cluster.CreateManager()) { | |
var info = await manager.ClusterInfoAsync().ConfigureAwait(false); | |
if (!info.Success) { | |
throw info.Exception; | |
} | |
var perBucket = info.Value.Pools().StorageTotals.Ram.QuotaTotal / names.Count; | |
foreach (var name in names) { | |
await manager.RemoveBucketAsync(name).ConfigureAwait(false); | |
var result = await manager.CreateBucketAsync(new BucketSettings | |
{ | |
RamQuota = (uint) (perBucket / 1024 / 1024), | |
Name = name, | |
ReplicaNumber = ReplicaNumber.Zero | |
}).ConfigureAwait(false); | |
// Trying various roles here, and I was hoping for just one but I think it will have to be multiple in the end | |
result = await manager.UpsertUserAsync(AuthenticationDomain.Local, name, _password, roles: new Role { BucketName = name, Name = "query_manage_index" }).ConfigureAwait(false); | |
} | |
} | |
// Try to run the entries of 'insert.json', 'json' is the content of the file | |
var jsonObj = JsonConvert.DeserializeObject<IReadOnlyList<IReadOnlyDictionary<string, string>>>(json); | |
foreach (var entry in jsonObj) { | |
var query = new QueryRequest(entry["statements"]); | |
// This never succeeds. Without ClassicAuthenticator it will say I have to use ClassicAuthenticator, then without the proper roles | |
// (which I think full_bucket_access should cover, but it does not) it will inform me of such. With 'query_manage_index' this call | |
// times out and returns "no server available" or a similar message | |
var result = await _cluster.QueryAsync<object>(query); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ "statements":"CREATE PRIMARY INDEX ON orders USING VIEW"} , | |
{ "statements":"INSERT INTO orders (KEY,VALUE) VALUES(\"1234_select_func\", {\"type\": \"order\", \"orderlines\": [{\"qty\": 2, \"productId\": \"coffee01\"}, {\"qty\": 1, \"productId\": \"tea111\"}], \"custId\": \"customer312\", \"id\": \"1234\", \"test_id\" : \"select_func\" })" } , | |
{ "statements":"INSERT INTO orders (KEY,VALUE) VALUES(\"1200_select_func\", {\"type\": \"order\", \"orderlines\": [{\"qty\": 1, \"productId\": \"coffee01\"}, {\"qty\": 1, \"productId\": \"sugar22\"}], \"custId\": \"customer18\", \"id\": \"1200\", \"shipped-on\": \"2012/01/02\", \"test_id\" : \"select_func\" })" } , | |
{ "statements":"INSERT INTO orders (KEY,VALUE) VALUES(\"1235_select_func\", {\"type\": \"order\", \"orderlines\": [{\"qty\": 1, \"productId\": \"tea111\"}, {\"qty\": 1, \"productId\": \"sugar22\"}], \"custId\": \"customer12\", \"id\": \"1235\", \"test_id\" : \"select_func\" })" }, | |
{ "statements":"INSERT INTO orders (KEY,VALUE) VALUES(\"1236_select_func\", {\"type\": \"order\", \"orderlines\": [{\"qty\": 1, \"productId\": \"coffee01\"}, {\"qty\": 1, \"productId\": \"sugar22\"}], \"custId\": \"customer38\", \"id\": \"1236\", \"shipped-on\": null, \"test_id\" : \"select_func\" })" } | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment