Skip to content

Commit c199bcc

Browse files
Invert address translation table: map public addresses to private (#676)
## Usage and product changes NOTE: The address translation table now represents mapping _from_ the desired connection addresses to the addresses the cloud servers are configured with. This change does not impact users of TypeDB Core or TypeDB Cloud through the TypeDB Cloud Platform (https://cloud.typedb.com/) --------- Co-authored-by: Haikal Pribadi <[email protected]>
1 parent 295e7c6 commit c199bcc

File tree

35 files changed

+217
-165
lines changed

35 files changed

+217
-165
lines changed

.factory/automation.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ config:
2626
build:
2727
quality:
2828
filter:
29-
owner: vaticle
29+
owner: typedb
3030
branch: [master, development]
3131
dependency-analysis:
3232
image: vaticle-ubuntu-22.04
@@ -125,7 +125,7 @@ build:
125125
machine: 8-core-32-gb
126126
image: vaticle-ubuntu-20.04 # Ubuntu 20.04 has GLIBC version 2.31 (2020) which we should verify to compile against
127127
filter:
128-
owner: vaticle
128+
owner: typedb
129129
branch: [master, development]
130130
dependencies:
131131
- build
@@ -149,7 +149,7 @@ build:
149149
machine: 8-core-32-gb
150150
image: vaticle-ubuntu-20.04 # Ubuntu 20.04 has GLIBC version 2.31 (2020) which we should verify to compile against
151151
filter:
152-
owner: vaticle
152+
owner: typedb
153153
branch: [master, development]
154154
dependencies:
155155
- build
@@ -509,7 +509,7 @@ build:
509509
sync-dependencies:
510510
image: vaticle-ubuntu-22.04
511511
filter:
512-
owner: vaticle
512+
owner: typedb
513513
branch: [master, development]
514514
dependencies:
515515
- build
@@ -546,7 +546,7 @@ build:
546546

547547
release:
548548
filter:
549-
owner: vaticle
549+
owner: typedb
550550
branch: [master]
551551
validation:
552552
validate-dependencies:

c/src/concept/concept.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
use std::ffi::c_char;
2121

22-
use chrono::NaiveDateTime;
22+
use chrono::DateTime;
2323
use typedb_driver::{
2424
concept::{
2525
Annotation, Attribute, AttributeType, Concept, Entity, EntityType, Relation, RelationType, RoleType, Value,
@@ -56,7 +56,7 @@ pub extern "C" fn value_new_string(string: *const c_char) -> *mut Concept {
5656
/// Creates a new ``Value`` object of the specified datetime value.
5757
#[no_mangle]
5858
pub extern "C" fn value_new_date_time_from_millis(millis: i64) -> *mut Concept {
59-
release(Concept::Value(Value::DateTime(NaiveDateTime::from_timestamp_millis(millis).unwrap())))
59+
release(Concept::Value(Value::DateTime(DateTime::from_timestamp_millis(millis).unwrap().naive_utc())))
6060
}
6161

6262
/// Returns <code>true</code> if the value which this ``Value`` concept holds is of type <code>boolean</code>.
@@ -143,7 +143,7 @@ pub extern "C" fn value_get_string(value: *const Concept) -> *mut c_char {
143143
#[no_mangle]
144144
pub extern "C" fn value_get_date_time_as_millis(value: *const Concept) -> i64 {
145145
if let Value::DateTime(date_time) = borrow_as_value(value) {
146-
date_time.timestamp_millis()
146+
date_time.and_utc().timestamp_millis()
147147
} else {
148148
unreachable!("Attempting to unwrap a non-datetime {:?} as datetime", borrow_as_value(value))
149149
}

c/src/connection.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ pub extern "C" fn connection_open_cloud(
5252
/// Open a TypeDB Driver to TypeDB Cloud server(s), using provided address translation, with
5353
/// the provided credential.
5454
///
55-
/// @param advertised_addresses A null-terminated array holding the address(es) the TypeDB server(s)
56-
/// are configured to advertise
57-
/// @param translated_addresses A null-terminated array holding the address(es) of the TypeDB server(s)
55+
/// @param public_addresses A null-terminated array holding the address(es) of the TypeDB server(s)
5856
/// the driver will connect to. This array <i>must</i> have the same length as <code>advertised_addresses</code>
57+
/// @param private_addresses A null-terminated array holding the address(es) the TypeDB server(s)
58+
/// are configured to advertise
5959
/// @param credential The <code>Credential</code> to connect with
6060
#[no_mangle]
6161
pub extern "C" fn connection_open_cloud_translated(
62-
advertised_addresses: *const *const c_char,
63-
translated_addresses: *const *const c_char,
62+
public_addresses: *const *const c_char,
63+
private_addresses: *const *const c_char,
6464
credential: *const Credential,
6565
) -> *mut Connection {
66-
let addresses = string_array_view(advertised_addresses).zip_eq(string_array_view(translated_addresses)).collect();
66+
let addresses = string_array_view(public_addresses).zip_eq(string_array_view(private_addresses)).collect();
6767
try_release(Connection::new_cloud_with_translation(addresses, borrow(credential).clone()))
6868
}
6969

cpp/include/typedb/connection/driver.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ class Driver {
8585
* Driver::cloudDriver(addresses, credential);
8686
* </pre>
8787
*
88-
* @param addresses The address(es) of the TypeDB server(s) or translation map from addresses
89-
* received from the TypeDB server(s) to addresses to be used by the driver for connection
88+
* @param addresses The address(es) of the TypeDB server(s) or translation map from addresses to be used
89+
* by the driver for connection to addresses received from the TypeDB server(s)
9090
* @param credential The Credential to connect with
9191
*/
9292
static Driver cloudDriver(const std::vector<std::string>& addresses, const Credential& credential);

cpp/lib/connection/driver.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ Driver Driver::cloudDriver(const std::vector<std::string>& addresses, const Cred
4747
}
4848

4949
Driver Driver::cloudDriver(const std::unordered_map<std::string, std::string>& addressTranslation, const Credential& credential) {
50-
std::vector<const char*> advertisedAddressesNative;
51-
std::vector<const char*> translatedAddressesNative;
52-
for (auto& [advertised, translated] : addressTranslation) {
53-
advertisedAddressesNative.push_back(advertised.c_str());
54-
translatedAddressesNative.push_back(translated.c_str());
50+
std::vector<const char*> publicAddressesNative;
51+
std::vector<const char*> privateAddressesNative;
52+
for (auto& [publicAddress, privateAddress] : addressTranslation) {
53+
publicAddressesNative.push_back(publicAddress.c_str());
54+
privateAddressesNative.push_back(privateAddress.c_str());
5555
}
56-
advertisedAddressesNative.push_back(nullptr);
57-
translatedAddressesNative.push_back(nullptr);
56+
publicAddressesNative.push_back(nullptr);
57+
privateAddressesNative.push_back(nullptr);
5858
auto p = _native::connection_open_cloud_translated(
59-
advertisedAddressesNative.data(),
60-
translatedAddressesNative.data(),
59+
publicAddressesNative.data(),
60+
privateAddressesNative.data(),
6161
credential.getNative()
6262
);
6363
DriverException::check_and_throw();

cpp/test/behaviour/steps/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,4 @@ int main(int argc, char** argv) {
5656
&TypeDB::BDD::testHooks);
5757
driver.loadFeature(argv[1]);
5858
return driver.runAllTests();
59-
return 0;
6059
}

cpp/test/cucumber/include/cucumber_bdd/runner.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class TestRunner : public TestRunnerBase {
7171
void afterAllTests() override {
7272
if (hooks != nullptr) hooks->afterAll();
7373
}
74+
7475
bool skipScenario(const cucumber::messages::pickle& scenario) override {
7576
return (hooks != nullptr) ? hooks->skipScenario(scenario) : false;
7677
}

cpp/test/cucumber/lib/runner.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void TestRunnerBase::loadFeature(const std::string& path) {
5151

5252
if (doc.feature.has_value()) {
5353
for (cucumber::messages::pickle scenario : compiler.compile(doc, path)) {
54-
if (skipScenario(scenario)) {
54+
if (skipScenario(scenario) || scenario.steps.empty()) {
5555
DEBUGONLY(std::cout << "Skipping scenario: " << scenario.name << std::endl)
5656
} else {
5757
DEBUGONLY(std::cout << "Registering scenario: " << scenario.name << std::endl)
@@ -64,8 +64,9 @@ void TestRunnerBase::loadFeature(const std::string& path) {
6464

6565
int TestRunnerBase::runAllTests() {
6666
beforeAllTests();
67-
return RUN_ALL_TESTS();
67+
int ret = RUN_ALL_TESTS();
6868
afterAllTests();
69+
return ret;
6970
}
7071

7172
} // namespace cucumber_bdd

csharp/Connection/TypeDBDriver.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ private static Pinvoke.Connection OpenCloud(IDictionary<string, string> addressT
8080
{
8181
try
8282
{
83-
string[] advertisedAddresses = new string[addressTranslation.Count];
84-
string[] translatedAddresses = new string[addressTranslation.Count];
83+
string[] publicAddresses = new string[addressTranslation.Count];
84+
string[] privateAddresses = new string[addressTranslation.Count];
8585
int index = 0;
8686
foreach (KeyValuePair<string, string> translation in addressTranslation)
8787
{
88-
advertisedAddresses[index] = translation.Key;
89-
translatedAddresses[index] = translation.Value;
88+
publicAddresses[index] = translation.Key;
89+
privateAddresses[index] = translation.Value;
9090
index++;
9191
}
92-
return Pinvoke.typedb_driver.connection_open_cloud_translated(advertisedAddresses, translatedAddresses, credential.NativeObject);
92+
return Pinvoke.typedb_driver.connection_open_cloud_translated(publicAddresses, privateAddresses, credential.NativeObject);
9393
}
9494
catch (Pinvoke.Error e)
9595
{

csharp/Drivers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static ITypeDBDriver CloudDriver(string address, TypeDBCredential credent
7171
* </pre>
7272
*
7373
* @param addresses The address(es) of the TypeDB server(s) or translation map from addresses
74-
* received from the TypeDB server(s) to addresses to be used by the driver for connection
74+
* to be used by the driver for connection to addresses received from the TypeDB server(s)
7575
* @param credential The credential to connect with
7676
*/
7777
public static ITypeDBDriver CloudDriver(ICollection<string> addresses, TypeDBCredential credential)

0 commit comments

Comments
 (0)