Skip to content

Commit 38483d7

Browse files
authored
Merge pull request #579 from aperture-data/release-0.4.45
Release 0.4.45
2 parents 653bd4e + f290472 commit 38483d7

File tree

20 files changed

+281
-53
lines changed

20 files changed

+281
-53
lines changed

.github/workflows/develop.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ jobs:
6161
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
6262
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
6363
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
64+
RUNNER_NAME: ${{ runner.name }}
65+
ADB_REPO: aperturedata/aperturedb
66+
ADB_TAG: vci_develop
67+
LENZ_REPO: aperturedata/lenz
68+
LENZ_TAG: vci_develop
6469
run: BUILD_COMPLETE=true ./ci.sh
6570
shell: bash
6671

.github/workflows/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ jobs:
6161
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
6262
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
6363
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
64+
RUNNER_NAME: ${{ runner.name }}
65+
ADB_REPO: aperturedata/aperturedb
66+
ADB_TAG: vci_develop
67+
LENZ_REPO: aperturedata/lenz
68+
LENZ_TAG: vci_develop
6469
run: BUILD_COMPLETE=true ./ci.sh
6570
shell: bash
6671

.github/workflows/pr.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,14 @@ jobs:
3535
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
3636
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
3737
GCP_SERVICE_ACCOUNT_KEY: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
38-
run: RUN_TESTS=true NO_PUSH=true BRANCH_NAME=${{ github.event.pull_request.head.ref }} TARGET_BRANCH_NAME=${{ github.event.pull_request.base.ref }} ./ci.sh
38+
RUNNER_NAME: ${{ runner.name }}
39+
RUN_TESTS: true
40+
NO_PUSH: true
41+
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
42+
TARGET_BRANCH_NAME: ${{ github.event.pull_request.base.ref }}
43+
ADB_REPO: aperturedata/aperturedb
44+
ADB_TAG: vci_develop
45+
LENZ_REPO: aperturedata/lenz
46+
LENZ_TAG: vci_develop
47+
run: ./ci.sh
3948
shell: bash

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,4 @@ docker/pytorch-gpu/aperturedata/*
153153

154154
.aperturedb
155155
test/data/
156+
test/aperturedb/certificate/

README.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ or an installation with only the core part of the SDK
1818
pip install aperturedb
1919
```
2020

21-
A complete [reference](https://docs.aperturedata.io/category/aperturedb-python-sdk) of this SDK is available on the offical [ApertureDB Documentation](https://docs.aperturedata.io)
21+
A complete [reference](https://docs.aperturedata.io/category/aperturedb-python-sdk) of this SDK is available on the official [ApertureDB Documentation](https://docs.aperturedata.io)
2222

2323

2424
# Development setup
@@ -31,7 +31,34 @@ pip install -e .[dev]
3131

3232

3333
# Running tests
34-
The tests are inside the `test` dir.
34+
The tests are inside the `test` dir. Currently these get run in Linux container. Refer to `docker/tests` and `test/run_test_container` for details. Following explanation assumes that the current working directory is `test`.
35+
36+
The tests bring up a set of components in an isolated network, namely:
37+
- aperturedb-community
38+
- lenz
39+
- nginx
40+
- ca (for initial provisioning of certificates)
41+
- webui
42+
43+
44+
To connect to this setup, the ports are exposed to the host as follows:
45+
- 55556 for TCP connection to aperturedb (via lenz).
46+
- 8087 for HTTP connection to aperturedb (via nginx).
47+
48+
49+
50+
This can be done manually as:
51+
```bash
52+
docker compose up -d
53+
```
54+
55+
## Changes to run the tests in development environment.
56+
Edit the file `test/dbinfo.py` to loook like the following.
57+
- DB_TCP_HOST = `localhost`
58+
- DB_REST_HOST = `localhost`
59+
- DB_TCP_PORT = `55556`
60+
- DB_REST_PORT = `8087`
61+
3562

3663
All the tests can be run with:
3764

@@ -43,9 +70,23 @@ bash run_test.sh
4370
Running specific tests can be accomplished by invoking it with pytest as follows:
4471

4572
```bash
46-
cd test && docker compose up -d && PROJECT=aperturedata KAGGLE_username=ci KAGGLE_key=dummy coverage run -m pytest test_Session.py -v --log-cli-level=DEBUG
73+
PROJECT=aperturedata KAGGLE_username=ci KAGGLE_key=dummy coverage run -m pytest test_Session.py -v -s --log-cli-level=DEBUG
4774
```
4875

76+
**NOTE:The running environment is assumed to be Linux x86_64. There might be certain changes required for them to be run on MacOS or Windows python environments.**
77+
78+
## Certain Environment variables that affect the runtime beaviour of the SDK.
79+
80+
These can be used as debugging aids.
81+
82+
| Variable | type | Comments | Default value |
83+
| --- | --- | --- | --- |
84+
|ADB_DEBUGGABLE | boolean | allows the application to register a fault handler that dumps a trace when SIGUSR1 is sent to the process | not set |
85+
|LOG_FILE_LEVEL | <a href="https://docs.python.org/3/library/logging.html#logging-levels">log levels</a> | The threshold for emitting log messages into the error<timestamp>.log file | WARN |
86+
|LOG_CONSOLE_LEVEL | <a href="https://docs.python.org/3/library/logging.html#logging-levels">log levels</a> | The threshold for emitting log messages into stdout | ERROR |
87+
|ADB_LOG_FILE | string | custom file path for the LOG file | not set|
88+
89+
4990
# Reporting bugs
5091
Any error in the functionality / documentation / tests maybe reported by creating a
5192
[github issue](https://github.com/aperture-data/aperturedb-python/issues).

aperturedb/CommonLibrary.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,20 @@ def _store_config(config: Configuration, name: str):
153153

154154
def create_connector(
155155
name: Optional[str] = None,
156+
key: Optional[str] = None,
156157
create_config_for_colab_secret=True,
157158
) -> Connector:
158159
"""
159160
**Create a connector to the database.**
160161
161162
This function chooses a configuration in the folowing order:
162-
1. The configuration named by the `name` parameter.
163-
2. The configuration described in the `APERTUREDB_JSON` environment variable.
164-
3. The configuration described in the `APERTUREDB_JSON` Google Colab secret.
165-
4. The configuration described in the `APERTUREDB_JSON` secret in a `.env` file.
166-
5. The configuration named by the `APERTUREDB_CONFIG` environment variable.
167-
6. The active configuration.
163+
1. The configuration named by the `name` parameter or `key` parameter
164+
2. The configuration described in the `APERTUREDB_KEY` environment variable.
165+
3. The configuration described in the `APERTUREDB_JSON` environment variable.
166+
4. The configuration described in the `APERTUREDB_JSON` Google Colab secret.
167+
5. The configuration described in the `APERTUREDB_JSON` secret in a `.env` file.
168+
6. The configuration named by the `APERTUREDB_CONFIG` environment variable.
169+
7. The active configuration.
168170
169171
If there are both global and local configurations with the same name, the global configuration is preferred.
170172
@@ -197,9 +199,19 @@ def lookup_config_by_name(name: str, source: str) -> Configuration:
197199
return configs["local"][name]
198200
assert False, f"Configuration '{name}' not found ({source})."
199201

200-
if name is not None:
202+
if key is not None:
203+
if name is not None:
204+
raise ValueError(
205+
"Specify only name or key when creating a connector")
206+
logger.info(f"Using configuration from key parameter")
207+
config = Configuration.reinflate(key)
208+
elif name is not None:
201209
logger.info(f"Using configuration '{name}' explicitly")
202210
config = lookup_config_by_name(name, "explicit")
211+
elif (data := os.environ.get("APERTUREDB_KEY")) is not None and data != "":
212+
logger.info(
213+
f"Using configuration from APERTUREDB_KEY environment variable")
214+
config = Configuration.reinflate(data)
203215
elif (data := os.environ.get("APERTUREDB_JSON")) is not None and data != "":
204216
logger.info(
205217
f"Using configuration from APERTUREDB_JSON environment variable")

aperturedb/Configuration.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
from dataclasses import dataclass
22

3+
import json
4+
from base64 import b64encode, b64decode
5+
6+
APERTURE_CLOUD = ".cloud.aperturedata.io"
7+
AD_CLOUD_SCHEME = "adbc://"
8+
39

410
@dataclass(repr=False)
511
class Configuration:
@@ -22,3 +28,35 @@ class Configuration:
2228
def __repr__(self) -> str:
2329
mode = "REST" if self.use_rest else "TCP"
2430
return f"[{self.host}:{self.port} as {self.username} using {mode} with SSL={self.use_ssl}]"
31+
32+
def deflate(self) -> list:
33+
deflate_version = 1
34+
host = self.host
35+
if host.endswith(APERTURE_CLOUD):
36+
host = "adbc://{}".format(host[:-1 * len(APERTURE_CLOUD)])
37+
as_list = [deflate_version, host, self.port, self.username, self.password, self.name, int(self.use_ssl),
38+
int(self.use_rest), int(self.use_keepalive),
39+
self.retry_interval_seconds, self.retry_max_attempts]
40+
simplified = json.dumps(as_list)
41+
encoded_key = b64encode(simplified.encode('utf-8')).decode('utf-8')
42+
return encoded_key
43+
44+
@classmethod
45+
def reinflate(cls, encoded_key: list) -> object:
46+
decoded_key = b64decode(encoded_key.encode('utf-8'))
47+
as_list = json.loads(decoded_key.decode('utf-8'))
48+
if as_list[0] != 1:
49+
raise ValueError(f"version identifier of configuration was"
50+
"{as_list[0]}, which is not supported")
51+
host, port, username, password, name, use_ssl, \
52+
use_rest, use_keepalive, retry_interval_seconds, \
53+
retry_max_attempts = as_list[1:]
54+
if host.startswith(AD_CLOUD_SCHEME):
55+
host = host[len(AD_CLOUD_SCHEME):] + APERTURE_CLOUD
56+
use_ssl = bool(use_ssl)
57+
use_rest = bool(use_rest)
58+
use_keepaliave = bool(use_keepalive)
59+
c = Configuration(
60+
host, port, username, password, name, use_ssl, use_rest, use_keepalive,
61+
retry_interval_seconds, retry_max_attempts)
62+
return c

aperturedb/Connector.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class Connector(object):
103103
and it means that disconnections are detected sooner.
104104
Turn this off to reduce traffic on high-cost network connections.
105105
Configuration (config): Configuration object to use for connection.
106+
str (key): Apeture Key, configuration as a deflated compressed string
106107
"""
107108

108109
def __init__(self, host="localhost", port=55555,
@@ -113,7 +114,8 @@ def __init__(self, host="localhost", port=55555,
113114
use_keepalive=True,
114115
retry_interval_seconds=1,
115116
retry_max_attempts=3,
116-
config: Optional[Configuration] = None):
117+
config: Optional[Configuration] = None,
118+
key: Optional[str] = None):
117119
"""
118120
Constructor for the Connector class.
119121
"""
@@ -126,7 +128,9 @@ def __init__(self, host="localhost", port=55555,
126128
# after the last query
127129
self.query_connection_error_suppression_delta = timedelta(seconds=30)
128130

129-
if config is None:
131+
if key is not None:
132+
self.config = Configuration.reinflate(key)
133+
elif config is None:
130134
self.host = host
131135
self.port = port
132136
self.use_ssl = use_ssl

aperturedb/ConnectorRest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import logging
3333

3434
from types import SimpleNamespace
35+
from typing import Optional
3536
from aperturedb.Connector import Connector
3637
from aperturedb.Configuration import Configuration
3738

@@ -53,12 +54,14 @@ class ConnectorRest(Connector):
5354
str (password): Password to specify while connecting to ApertureDB.
5455
str (token): Token to use while connecting to the database.
5556
bool (use_ssl): Use SSL to encrypt communication with the database.
57+
str (key): Apeture Key, configuration as a deflated compressed string
5658
"""
5759

5860
def __init__(self, host="localhost", port=None,
5961
user="", password="", token="",
6062
use_ssl=True, shared_data=None,
61-
config: Configuration = None):
63+
config: Optional[Configuration] = None,
64+
key: Optional[str] = None):
6265
self.use_keepalive = False
6366
super().__init__(
6467
host=host,
@@ -68,7 +71,8 @@ def __init__(self, host="localhost", port=None,
6871
token=token,
6972
use_ssl=use_ssl,
7073
shared_data=shared_data,
71-
config=config)
74+
config=config,
75+
key=key)
7276

7377
# A Convenience feature to not require the port
7478
# Relies on common ports for http and https, but can be overriden

aperturedb/Utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,8 @@ def user_log_message(self, message: str, level: str = "INFO") -> None:
910910
self.execute(q)
911911

912912

913-
def create_connector():
913+
def create_connector(name=None, key=None):
914914
from aperturedb.CommonLibrary import create_connector, issue_deprecation_warning
915915
issue_deprecation_warning("Utils.create_connector",
916916
"CommonLibrary.create_connector")
917-
return create_connector()
917+
return create_connector(name=name, key=key)

0 commit comments

Comments
 (0)