cosmotech-acceleration-library 1.1.0__py3-none-any.whl → 2.1.0rc1__py3-none-any.whl

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.
Files changed (120) hide show
  1. cosmotech/coal/__init__.py +1 -1
  2. cosmotech/coal/aws/__init__.py +1 -9
  3. cosmotech/coal/aws/s3.py +181 -214
  4. cosmotech/coal/azure/__init__.py +5 -5
  5. cosmotech/coal/azure/adx/__init__.py +24 -10
  6. cosmotech/coal/azure/adx/auth.py +2 -2
  7. cosmotech/coal/azure/adx/ingestion.py +10 -14
  8. cosmotech/coal/azure/adx/query.py +1 -1
  9. cosmotech/coal/azure/adx/runner.py +13 -14
  10. cosmotech/coal/azure/adx/store.py +5 -86
  11. cosmotech/coal/azure/adx/tables.py +2 -2
  12. cosmotech/coal/azure/adx/utils.py +2 -2
  13. cosmotech/coal/azure/blob.py +20 -26
  14. cosmotech/coal/azure/storage.py +3 -3
  15. cosmotech/coal/cosmotech_api/__init__.py +0 -28
  16. cosmotech/coal/cosmotech_api/apis/__init__.py +14 -0
  17. cosmotech/coal/cosmotech_api/apis/dataset.py +222 -0
  18. cosmotech/coal/cosmotech_api/apis/meta.py +25 -0
  19. cosmotech/coal/cosmotech_api/apis/organization.py +24 -0
  20. cosmotech/coal/cosmotech_api/apis/run.py +38 -0
  21. cosmotech/coal/cosmotech_api/apis/runner.py +75 -0
  22. cosmotech/coal/cosmotech_api/apis/solution.py +23 -0
  23. cosmotech/coal/cosmotech_api/apis/workspace.py +108 -0
  24. cosmotech/coal/cosmotech_api/objects/__init__.py +9 -0
  25. cosmotech/coal/cosmotech_api/objects/connection.py +125 -0
  26. cosmotech/coal/cosmotech_api/objects/parameters.py +127 -0
  27. cosmotech/coal/postgresql/runner.py +58 -41
  28. cosmotech/coal/postgresql/store.py +56 -15
  29. cosmotech/coal/postgresql/utils.py +255 -0
  30. cosmotech/coal/singlestore/store.py +3 -2
  31. cosmotech/coal/store/__init__.py +16 -13
  32. cosmotech/coal/store/output/__init__.py +0 -0
  33. cosmotech/coal/store/output/aws_channel.py +74 -0
  34. cosmotech/coal/store/output/az_storage_channel.py +33 -0
  35. cosmotech/coal/store/output/channel_interface.py +38 -0
  36. cosmotech/coal/store/output/channel_spliter.py +61 -0
  37. cosmotech/coal/store/output/postgres_channel.py +37 -0
  38. cosmotech/coal/store/pandas.py +1 -1
  39. cosmotech/coal/store/pyarrow.py +2 -2
  40. cosmotech/coal/store/store.py +4 -7
  41. cosmotech/coal/utils/configuration.py +197 -0
  42. cosmotech/coal/utils/decorator.py +4 -7
  43. cosmotech/csm_data/commands/adx_send_data.py +1 -1
  44. cosmotech/csm_data/commands/adx_send_runnerdata.py +3 -2
  45. cosmotech/csm_data/commands/api/api.py +6 -19
  46. cosmotech/csm_data/commands/api/postgres_send_runner_metadata.py +20 -16
  47. cosmotech/csm_data/commands/api/run_load_data.py +15 -52
  48. cosmotech/csm_data/commands/api/wsf_load_file.py +13 -16
  49. cosmotech/csm_data/commands/api/wsf_send_file.py +11 -14
  50. cosmotech/csm_data/commands/az_storage_upload.py +3 -2
  51. cosmotech/csm_data/commands/s3_bucket_delete.py +16 -15
  52. cosmotech/csm_data/commands/s3_bucket_download.py +16 -16
  53. cosmotech/csm_data/commands/s3_bucket_upload.py +16 -14
  54. cosmotech/csm_data/commands/store/dump_to_azure.py +3 -2
  55. cosmotech/csm_data/commands/store/dump_to_postgresql.py +3 -2
  56. cosmotech/csm_data/commands/store/dump_to_s3.py +18 -16
  57. cosmotech/csm_data/commands/store/list_tables.py +3 -2
  58. cosmotech/csm_data/commands/store/load_csv_folder.py +10 -4
  59. cosmotech/csm_data/commands/store/load_from_singlestore.py +3 -2
  60. cosmotech/csm_data/commands/store/output.py +35 -0
  61. cosmotech/csm_data/commands/store/reset.py +8 -3
  62. cosmotech/csm_data/commands/store/store.py +3 -3
  63. cosmotech/csm_data/main.py +4 -4
  64. cosmotech/csm_data/utils/decorators.py +4 -3
  65. cosmotech/translation/coal/en-US/coal/cosmotech_api/initialization.yml +8 -0
  66. cosmotech/translation/coal/en-US/coal/services/dataset.yml +10 -14
  67. cosmotech/translation/coal/en-US/coal/store/output/data_interface.yml +1 -0
  68. cosmotech/translation/coal/en-US/coal/store/output/split.yml +6 -0
  69. cosmotech/translation/coal/en-US/coal/utils/configuration.yml +2 -0
  70. cosmotech/translation/csm_data/en-US/csm_data/commands/store/output.yml +7 -0
  71. {cosmotech_acceleration_library-1.1.0.dist-info → cosmotech_acceleration_library-2.1.0rc1.dist-info}/METADATA +29 -33
  72. cosmotech_acceleration_library-2.1.0rc1.dist-info/RECORD +153 -0
  73. {cosmotech_acceleration_library-1.1.0.dist-info → cosmotech_acceleration_library-2.1.0rc1.dist-info}/WHEEL +1 -1
  74. cosmotech/coal/azure/functions.py +0 -72
  75. cosmotech/coal/cosmotech_api/connection.py +0 -96
  76. cosmotech/coal/cosmotech_api/dataset/__init__.py +0 -26
  77. cosmotech/coal/cosmotech_api/dataset/converters.py +0 -164
  78. cosmotech/coal/cosmotech_api/dataset/download/__init__.py +0 -19
  79. cosmotech/coal/cosmotech_api/dataset/download/adt.py +0 -119
  80. cosmotech/coal/cosmotech_api/dataset/download/common.py +0 -140
  81. cosmotech/coal/cosmotech_api/dataset/download/file.py +0 -229
  82. cosmotech/coal/cosmotech_api/dataset/download/twingraph.py +0 -185
  83. cosmotech/coal/cosmotech_api/dataset/upload.py +0 -41
  84. cosmotech/coal/cosmotech_api/dataset/utils.py +0 -132
  85. cosmotech/coal/cosmotech_api/parameters.py +0 -48
  86. cosmotech/coal/cosmotech_api/run.py +0 -25
  87. cosmotech/coal/cosmotech_api/run_data.py +0 -173
  88. cosmotech/coal/cosmotech_api/run_template.py +0 -108
  89. cosmotech/coal/cosmotech_api/runner/__init__.py +0 -28
  90. cosmotech/coal/cosmotech_api/runner/data.py +0 -38
  91. cosmotech/coal/cosmotech_api/runner/datasets.py +0 -416
  92. cosmotech/coal/cosmotech_api/runner/download.py +0 -135
  93. cosmotech/coal/cosmotech_api/runner/metadata.py +0 -42
  94. cosmotech/coal/cosmotech_api/runner/parameters.py +0 -157
  95. cosmotech/coal/cosmotech_api/twin_data_layer.py +0 -512
  96. cosmotech/coal/cosmotech_api/workspace.py +0 -127
  97. cosmotech/coal/utils/postgresql.py +0 -236
  98. cosmotech/coal/utils/semver.py +0 -6
  99. cosmotech/csm_data/commands/api/rds_load_csv.py +0 -90
  100. cosmotech/csm_data/commands/api/rds_send_csv.py +0 -74
  101. cosmotech/csm_data/commands/api/rds_send_store.py +0 -74
  102. cosmotech/csm_data/commands/api/runtemplate_load_handler.py +0 -66
  103. cosmotech/csm_data/commands/api/tdl_load_files.py +0 -76
  104. cosmotech/csm_data/commands/api/tdl_send_files.py +0 -82
  105. cosmotech/orchestrator_plugins/csm-data/templates/api/rds_load_csv.json +0 -27
  106. cosmotech/orchestrator_plugins/csm-data/templates/api/rds_send_csv.json +0 -27
  107. cosmotech/orchestrator_plugins/csm-data/templates/api/rds_send_store.json +0 -27
  108. cosmotech/orchestrator_plugins/csm-data/templates/api/runtemplate_load_handler.json +0 -27
  109. cosmotech/orchestrator_plugins/csm-data/templates/api/tdl_load_files.json +0 -32
  110. cosmotech/orchestrator_plugins/csm-data/templates/api/tdl_send_files.json +0 -27
  111. cosmotech/translation/coal/en-US/coal/cosmotech_api/run_data.yml +0 -2
  112. cosmotech/translation/csm_data/en-US/csm_data/commands/api/rds_load_csv.yml +0 -13
  113. cosmotech/translation/csm_data/en-US/csm_data/commands/api/rds_send_csv.yml +0 -12
  114. cosmotech/translation/csm_data/en-US/csm_data/commands/api/rds_send_store.yml +0 -12
  115. cosmotech/translation/csm_data/en-US/csm_data/commands/api/tdl_load_files.yml +0 -14
  116. cosmotech/translation/csm_data/en-US/csm_data/commands/api/tdl_send_files.yml +0 -18
  117. cosmotech_acceleration_library-1.1.0.dist-info/RECORD +0 -171
  118. {cosmotech_acceleration_library-1.1.0.dist-info → cosmotech_acceleration_library-2.1.0rc1.dist-info}/entry_points.txt +0 -0
  119. {cosmotech_acceleration_library-1.1.0.dist-info → cosmotech_acceleration_library-2.1.0rc1.dist-info}/licenses/LICENSE +0 -0
  120. {cosmotech_acceleration_library-1.1.0.dist-info → cosmotech_acceleration_library-2.1.0rc1.dist-info}/top_level.txt +0 -0
@@ -5,10 +5,10 @@
5
5
  # etc., to any person is prohibited unless it has been previously and
6
6
  # specifically authorized by written means by Cosmo Tech.
7
7
 
8
+ import pandas as pd
8
9
  import pyarrow
9
10
 
10
11
  from cosmotech.coal.store.store import Store
11
- import pandas as pd
12
12
 
13
13
 
14
14
  def store_dataframe(
@@ -5,10 +5,10 @@
5
5
  # etc., to any person is prohibited unless it has been previously and
6
6
  # specifically authorized by written means by Cosmo Tech.
7
7
 
8
- from cosmotech.coal.store.store import Store
9
-
10
8
  import pyarrow as pa
11
9
 
10
+ from cosmotech.coal.store.store import Store
11
+
12
12
 
13
13
  def store_table(
14
14
  table_name: str,
@@ -5,14 +5,14 @@
5
5
  # etc., to any person is prohibited unless it has been previously and
6
6
  # specifically authorized by written means by Cosmo Tech.
7
7
 
8
- import os
9
8
  import pathlib
10
9
 
11
10
  import pyarrow
12
11
  from adbc_driver_sqlite import dbapi
12
+ from cosmotech.orchestrator.utils.translate import T
13
13
 
14
+ from cosmotech.coal.utils.configuration import Configuration
14
15
  from cosmotech.coal.utils.logger import LOGGER
15
- from cosmotech.orchestrator.utils.translate import T
16
16
 
17
17
 
18
18
  class Store:
@@ -20,11 +20,8 @@ class Store:
20
20
  def sanitize_column(column_name: str) -> str:
21
21
  return column_name.replace(" ", "_")
22
22
 
23
- def __init__(
24
- self,
25
- reset=False,
26
- store_location: pathlib.Path = pathlib.Path(os.environ.get("CSM_PARAMETERS_ABSOLUTE_PATH", ".")),
27
- ):
23
+ def __init__(self, reset=False, configuration: Configuration = Configuration()):
24
+ store_location = configuration.safe_get("coal.store", ".")
28
25
  self.store_location = pathlib.Path(store_location) / ".coal/store"
29
26
  self.store_location.mkdir(parents=True, exist_ok=True)
30
27
  self._tables = dict()
@@ -0,0 +1,197 @@
1
+ import os
2
+ import tomllib
3
+
4
+ from cosmotech.orchestrator.utils.translate import T
5
+
6
+ from cosmotech.coal.utils.logger import LOGGER
7
+
8
+
9
+ class ReferenceKeyError(KeyError):
10
+ pass
11
+
12
+
13
+ class Dotdict(dict):
14
+ """dot.notation access to dictionary attributes"""
15
+
16
+ def __setattr__(self, key, val):
17
+ dd = Dotdict(val, root=self.root) if isinstance(val, dict) else val
18
+ self.__setitem__(key, dd)
19
+
20
+ def __getattr__(self, key):
21
+ _v = self.__getitem__(key)
22
+ if isinstance(_v, str) and _v.startswith("$"):
23
+ _r = self.root
24
+ try:
25
+ for _p in _v[1:].split("."):
26
+ _r = _r.__getattr__(_p)
27
+ return _r
28
+ except (KeyError, AttributeError):
29
+ LOGGER.warning(f"dotdict Ref {_v} doesn't exist")
30
+ raise ReferenceKeyError(_v)
31
+ return _v
32
+
33
+ __delattr__ = dict.__delitem__
34
+
35
+ def __init__(self, dct=dict(), root=None):
36
+ object.__setattr__(self, "root", self if root is None else root)
37
+
38
+ def update(data):
39
+ if isinstance(data, dict):
40
+ return Dotdict(data, root=self.root)
41
+ elif isinstance(data, list):
42
+ return [update(d) for d in data]
43
+ return data
44
+
45
+ for k, v in dct.items():
46
+ self.__setattr__(k, update(v))
47
+
48
+ def merge(self, d):
49
+ for k, v in d.items():
50
+ if isinstance(v, Dotdict) and k in self:
51
+ self[k].merge(v)
52
+ else:
53
+ # this trigger dict to dotdict conversion at merge
54
+ self.__setattr__(k, v)
55
+
56
+
57
+ class Configuration(Dotdict):
58
+ # Env var set by the cosmotech api at runtime
59
+ API_ENV_DICT = {
60
+ "secrets": {
61
+ "cosmotech": {
62
+ "twin_cache": {
63
+ "host": "TWIN_CACHE_HOST",
64
+ "port": "TWIN_CACHE_PORT",
65
+ "password": "TWIN_CACHE_PASSWORD",
66
+ "username": "TWIN_CACHE_USERNAME",
67
+ },
68
+ "idp": {
69
+ "base_url": "IDP_BASE_URL",
70
+ "tenant_id": "IDP_TENANT_ID",
71
+ "client_id": "IDP_CLIENT_ID",
72
+ "client_secret": "IDP_CLIENT_SECRET",
73
+ },
74
+ "api": {"url": "CSM_API_URL", "scope": "CSM_API_SCOPE"},
75
+ "dataset_absolute_path": "CSM_DATASET_ABSOLUTE_PATH",
76
+ "parameters_absolute_path": "CSM_PARAMETERS_ABSOLUTE_PATH",
77
+ "organization_id": "CSM_ORGANIZATION_ID",
78
+ "workspace_id": "CSM_WORKSPACE_ID",
79
+ "runner_id": "CSM_RUNNER_ID",
80
+ "run_id": "CSM_RUN_ID",
81
+ "run_template_id": "CSM_RUN_TEMPLATE_ID",
82
+ }
83
+ }
84
+ }
85
+ # HARD CODED ENVVAR CONVERSION
86
+ CONVERSION_DICT = {
87
+ "secrets": {
88
+ "log_level": "LOG_LEVEL",
89
+ "s3": {
90
+ "access_key_id": "AWS_ACCESS_KEY_ID",
91
+ "endpoint_url": "AWS_ENDPOINT_URL",
92
+ "secret_access_key": "AWS_SECRET_ACCESS_KEY",
93
+ "bucket_name": "CSM_DATA_BUCKET_NAME",
94
+ "bucket_prefix": "CSM_DATA_BUCKET_PREFIX",
95
+ "ca_bundle": "CSM_S3_CA_BUNDLE",
96
+ },
97
+ "azure": {
98
+ "account_name": "AZURE_ACCOUNT_NAME",
99
+ "client_id": "AZURE_CLIENT_ID",
100
+ "client_secret": "AZURE_CLIENT_SECRET",
101
+ "container_name": "AZURE_CONTAINER_NAME",
102
+ "data_explorer_database_name": "AZURE_DATA_EXPLORER_DATABASE_NAME",
103
+ "data_explorer_resource_ingest_uri": "AZURE_DATA_EXPLORER_RESOURCE_INGEST_URI",
104
+ "data_explorer_resource_uri": "AZURE_DATA_EXPLORER_RESOURCE_URI",
105
+ "storage_blob_name": "AZURE_STORAGE_BLOB_NAME",
106
+ "data_blob_prefix": "CSM_DATA_BLOB_PREFIX",
107
+ "data_prefix": "CSM_DATA_PREFIX",
108
+ "storage_sas_url": "AZURE_STORAGE_SAS_URL",
109
+ "tenant_id": "AZURE_TENANT_ID",
110
+ },
111
+ "cosmotech": {
112
+ "data_adx_tag": "CSM_DATA_ADX_TAG",
113
+ "data_adx_wait_ingestion": "CSM_DATA_ADX_WAIT_INGESTION",
114
+ "send_datawarehouse_datasets": "CSM_SEND_DATAWAREHOUSE_DATASETS",
115
+ "send_datawarehouse_parameters": "CSM_SEND_DATAWAREHOUSE_PARAMETERS",
116
+ },
117
+ "postgres": {
118
+ "db_name": "POSTGRES_DB_NAME",
119
+ "db_schema": "POSTGRES_DB_SCHEMA",
120
+ "port": "POSTGRES_HOST_PORT",
121
+ "host": "POSTGRES_HOST_URI",
122
+ "user_name": "POSTGRES_USER_NAME",
123
+ "user_password": "POSTGRES_USER_PASSWORD",
124
+ "password_encoding": "CSM_PSQL_FORCE_PASSWORD_ENCODING",
125
+ },
126
+ "single_store": {
127
+ "db": "SINGLE_STORE_DB",
128
+ "host": "SINGLE_STORE_HOST",
129
+ "password": "SINGLE_STORE_PASSWORD",
130
+ "port": "SINGLE_STORE_PORT",
131
+ "tables": "SINGLE_STORE_TABLES",
132
+ "username": "SINGLE_STORE_USERNAME",
133
+ },
134
+ },
135
+ }
136
+
137
+ # HARD CODED configmap mount path set in K8s simulation pod by API run function
138
+ K8S_CONFIG = "/mnt/coal/coal-config.toml"
139
+
140
+ def __init__(self, dct: dict = None):
141
+ if isinstance(dct, Dotdict):
142
+ super().__init__(dct, root=dct.root)
143
+ elif isinstance(dct, dict):
144
+ super().__init__(dct)
145
+ elif config_path := os.environ.get("CONFIG_FILE_PATH", default=None):
146
+ with open(config_path, "rb") as config:
147
+ super().__init__(tomllib.load(config))
148
+ elif os.path.isfile(self.K8S_CONFIG):
149
+ with open(self.K8S_CONFIG, "rb") as config:
150
+ super().__init__(tomllib.load(config))
151
+ else:
152
+ LOGGER.info(T("coal.utils.configuration.no_config_file"))
153
+ super().__init__(self.CONVERSION_DICT)
154
+
155
+ # add envvar set by the API
156
+ self.merge(Dotdict(self.API_ENV_DICT))
157
+
158
+ if "secrets" in self:
159
+ self.secrets = self._env_swap_recusion(self.secrets)
160
+ # set secret section back to respective section
161
+ self.merge(self.secrets)
162
+ del self.secrets
163
+
164
+ # add coal.store default value if ont define
165
+ if self.safe_get("coal.store") is None:
166
+ self.merge({"coal": {"store": "$cosmotech.parameters_absolute_path"}})
167
+
168
+ # convert value to env
169
+ def _env_swap_recusion(self, dic):
170
+ for k, v in dic.items():
171
+ if isinstance(v, Dotdict):
172
+ dic[k] = self._env_swap_recusion(v)
173
+ dic[k] = {k: v for k, v in dic[k].items() if v is not None}
174
+ elif isinstance(v, list):
175
+ dic[k] = list(self._env_swap_recusion(_v) for _v in v)
176
+ elif isinstance(v, str):
177
+ dic[k] = os.environ.get(v)
178
+ # remove value not found
179
+ dic = {k: v for k, v in dic.items() if v}
180
+ return dic
181
+
182
+ def merge_in(self, dic):
183
+ trans_dic = self._env_swap_recusion(dic)
184
+ self.merge(trans_dic)
185
+
186
+ def safe_get(self, key, default=None):
187
+ try:
188
+ _r = self
189
+ for _k in key.split("."):
190
+ _r = _r.__getattr__(_k)
191
+ return _r
192
+ except (KeyError, AttributeError) as err:
193
+ LOGGER.debug(f"{err} not found; returning {default}")
194
+ return default
195
+
196
+
197
+ ENVIRONMENT_CONFIGURATION = Configuration()
@@ -1,10 +1,10 @@
1
1
  import time
2
-
3
2
  from functools import wraps
4
3
 
5
- from cosmotech.coal.utils.logger import LOGGER
6
4
  from cosmotech.orchestrator.utils.translate import T
7
5
 
6
+ from cosmotech.coal.utils.logger import LOGGER
7
+
8
8
 
9
9
  def timed(operation, debug=False):
10
10
  def decorator(func):
@@ -13,11 +13,8 @@ def timed(operation, debug=False):
13
13
  process_start = time.time()
14
14
  r = func(*args, **kwargs)
15
15
  process_time = time.time() - process_start
16
- msg = T("coal.common.timing.operation_completed").format(operation=operation, time=process_time)
17
- if debug:
18
- LOGGER.debug(msg)
19
- else:
20
- LOGGER.info(msg)
16
+ log_function = LOGGER.debug if debug else LOGGER.info
17
+ log_function(T("coal.common.timing.operation_completed").format(operation=operation, time=process_time))
21
18
  return r
22
19
 
23
20
  return wrapper
@@ -7,7 +7,7 @@
7
7
  from cosmotech.orchestrator.utils.translate import T
8
8
 
9
9
  from cosmotech.csm_data.utils.click import click
10
- from cosmotech.csm_data.utils.decorators import web_help, translate_help
10
+ from cosmotech.csm_data.utils.decorators import translate_help, web_help
11
11
 
12
12
 
13
13
  @click.command()
@@ -5,10 +5,11 @@
5
5
  # etc., to any person is prohibited unless it has been previously and
6
6
  # specifically authorized by written means by Cosmo Tech.
7
7
 
8
- from cosmotech.csm_data.utils.click import click
9
- from cosmotech.csm_data.utils.decorators import web_help, translate_help
10
8
  from cosmotech.orchestrator.utils.translate import T
11
9
 
10
+ from cosmotech.csm_data.utils.click import click
11
+ from cosmotech.csm_data.utils.decorators import translate_help, web_help
12
+
12
13
 
13
14
  @click.command()
14
15
  @web_help("csm-data/adx-send-runner-data")
@@ -4,25 +4,18 @@
4
4
  # Any use, reproduction, translation, broadcasting, transmission, distribution,
5
5
  # etc., to any person is prohibited unless it has been previously and
6
6
  # specifically authorized by written means by Cosmo Tech.
7
+ from cosmotech.orchestrator.utils.translate import T
8
+
9
+ from cosmotech.coal.cosmotech_api.objects.connection import Connection
10
+ from cosmotech.coal.utils.logger import LOGGER
7
11
  from cosmotech.csm_data.commands.api.postgres_send_runner_metadata import (
8
12
  postgres_send_runner_metadata,
9
13
  )
10
- from cosmotech.csm_data.commands.api.rds_load_csv import rds_load_csv
11
- from cosmotech.csm_data.commands.api.rds_send_csv import rds_send_csv
12
- from cosmotech.csm_data.commands.api.rds_send_store import rds_send_store
13
14
  from cosmotech.csm_data.commands.api.run_load_data import run_load_data
14
- from cosmotech.csm_data.commands.api.runtemplate_load_handler import (
15
- runtemplate_load_handler,
16
- )
17
- from cosmotech.csm_data.commands.api.tdl_load_files import tdl_load_files
18
- from cosmotech.csm_data.commands.api.tdl_send_files import tdl_send_files
19
15
  from cosmotech.csm_data.commands.api.wsf_load_file import wsf_load_file
20
16
  from cosmotech.csm_data.commands.api.wsf_send_file import wsf_send_file
21
17
  from cosmotech.csm_data.utils.click import click
22
18
  from cosmotech.csm_data.utils.decorators import translate_help, web_help
23
- from cosmotech.coal.cosmotech_api.connection import get_api_client
24
- from cosmotech.coal.utils.logger import LOGGER
25
- from cosmotech.orchestrator.utils.translate import T
26
19
 
27
20
 
28
21
  @click.group(invoke_without_command=True)
@@ -32,19 +25,13 @@ from cosmotech.orchestrator.utils.translate import T
32
25
  def api(ctx: click.Context):
33
26
  if ctx.invoked_subcommand is None:
34
27
  try:
35
- api_client, description = get_api_client()
36
- LOGGER.info(T("coal.cosmotech_api.connection.found_valid").format(type=description))
28
+ connection = Connection()
29
+ LOGGER.info(T("coal.cosmotech_api.connection.found_valid").format(type=connection.api_type))
37
30
  except EnvironmentError:
38
31
  raise click.Abort()
39
32
 
40
33
 
41
- api.add_command(rds_send_csv, "rds-send-csv")
42
- api.add_command(rds_send_store, "rds-send-store")
43
- api.add_command(rds_load_csv, "rds-load-csv")
44
34
  api.add_command(wsf_send_file, "wsf-send-file")
45
35
  api.add_command(wsf_load_file, "wsf-load-file")
46
- api.add_command(tdl_send_files, "tdl-send-files")
47
- api.add_command(tdl_load_files, "tdl-load-files")
48
- api.add_command(runtemplate_load_handler, "runtemplate-load-handler")
49
36
  api.add_command(run_load_data, "run-load-data")
50
37
  api.add_command(postgres_send_runner_metadata, "postgres-send-runner-metadata")
@@ -5,10 +5,11 @@
5
5
  # etc., to any person is prohibited unless it has been previously and
6
6
  # specifically authorized by written means by Cosmo Tech.
7
7
 
8
- from cosmotech.csm_data.utils.click import click
9
- from cosmotech.csm_data.utils.decorators import web_help, translate_help
10
8
  from cosmotech.orchestrator.utils.translate import T
11
9
 
10
+ from cosmotech.csm_data.utils.click import click
11
+ from cosmotech.csm_data.utils.decorators import translate_help, web_help
12
+
12
13
 
13
14
  @click.command()
14
15
  @web_help("csm-data/api/postgres-send-runner-metadata")
@@ -93,7 +94,7 @@ from cosmotech.orchestrator.utils.translate import T
93
94
  @click.option(
94
95
  "--encode-password/--no-encode-password",
95
96
  "force_encode",
96
- help=T("csm_data.commands.store.postgres_send_runner_metadata.parameters.encode_password"),
97
+ help=T("csm_data.commands.api.postgres_send_runner_metadata.parameters.encode_password"),
97
98
  envvar="CSM_PSQL_FORCE_PASSWORD_ENCODING",
98
99
  show_envvar=True,
99
100
  default=True,
@@ -115,17 +116,20 @@ def postgres_send_runner_metadata(
115
116
  ):
116
117
  # Import the function at the start of the command
117
118
  from cosmotech.coal.postgresql import send_runner_metadata_to_postgresql
119
+ from cosmotech.coal.utils.configuration import Configuration
120
+
121
+ _c = Configuration()
122
+ _c.postgres.host = postgres_host
123
+ _c.postgres.port = postgres_port
124
+ _c.postgres.db_name = postgres_db
125
+ _c.postgres.db_schema = postgres_schema
126
+ _c.postgres.user_name = postgres_user
127
+ _c.postgres.user_password = postgres_password
128
+ _c.postgres.password_encoding = force_encode
129
+ _c.postgres.table_prefix = table_prefix
130
+
131
+ _c.cosmotech.organization_id = organization_id
132
+ _c.cosmotech.workspace_id = workspace_id
133
+ _c.cosmotech.runner_id = runner_id
118
134
 
119
- send_runner_metadata_to_postgresql(
120
- organization_id=organization_id,
121
- workspace_id=workspace_id,
122
- runner_id=runner_id,
123
- table_prefix=table_prefix,
124
- postgres_host=postgres_host,
125
- postgres_port=postgres_port,
126
- postgres_db=postgres_db,
127
- postgres_schema=postgres_schema,
128
- postgres_user=postgres_user,
129
- postgres_password=postgres_password,
130
- force_encode=force_encode,
131
- )
135
+ send_runner_metadata_to_postgresql(_c)
@@ -5,11 +5,12 @@
5
5
  # etc., to any person is prohibited unless it has been previously and
6
6
  # specifically authorized by written means by Cosmo Tech.
7
7
 
8
- from cosmotech.csm_data.utils.click import click
9
- from cosmotech.csm_data.utils.decorators import require_env
10
- from cosmotech.csm_data.utils.decorators import web_help, translate_help
11
8
  from cosmotech.orchestrator.utils.translate import T
12
9
 
10
+ from cosmotech.coal.utils.configuration import Configuration
11
+ from cosmotech.csm_data.utils.click import click
12
+ from cosmotech.csm_data.utils.decorators import require_env, translate_help, web_help
13
+
13
14
 
14
15
  @click.command()
15
16
  @click.option(
@@ -52,38 +53,6 @@ from cosmotech.orchestrator.utils.translate import T
52
53
  help=T("csm_data.commands.api.run_load_data.parameters.parameters_absolute_path"),
53
54
  required=True,
54
55
  )
55
- @click.option(
56
- "--write-json/--no-write-json",
57
- envvar="WRITE_JSON",
58
- show_envvar=True,
59
- default=True,
60
- show_default=True,
61
- help=T("csm_data.commands.api.run_load_data.parameters.write_json"),
62
- )
63
- @click.option(
64
- "--write-csv/--no-write-csv",
65
- envvar="WRITE_CSV",
66
- show_envvar=True,
67
- default=False,
68
- show_default=True,
69
- help=T("csm_data.commands.api.run_load_data.parameters.write_csv"),
70
- )
71
- @click.option(
72
- "--fetch-dataset/--no-fetch-dataset",
73
- envvar="FETCH_DATASET",
74
- show_envvar=True,
75
- default=True,
76
- show_default=True,
77
- help=T("csm_data.commands.api.run_load_data.parameters.fetch_dataset"),
78
- )
79
- @click.option(
80
- "--parallel/--no-parallel",
81
- envvar="FETCH_DATASETS_IN_PARALLEL",
82
- show_envvar=True,
83
- default=True,
84
- show_default=True,
85
- help=T("csm_data.commands.api.run_load_data.parameters.parallel"),
86
- )
87
56
  @require_env("CSM_API_SCOPE", "The identification scope of a Cosmotech API")
88
57
  @require_env("CSM_API_URL", "The URL to a Cosmotech API")
89
58
  @web_help("csm-data/api/run-load-data")
@@ -94,26 +63,20 @@ def run_load_data(
94
63
  organization_id: str,
95
64
  dataset_absolute_path: str,
96
65
  parameters_absolute_path: str,
97
- write_json: bool,
98
- write_csv: bool,
99
- fetch_dataset: bool,
100
- parallel: bool,
101
66
  ):
102
67
  # Import the function at the start of the command
103
- from cosmotech.coal.cosmotech_api.runner.download import download_runner_data
68
+ from cosmotech.coal.cosmotech_api.apis.runner import RunnerApi
69
+
70
+ _configuration = Configuration()
71
+ _configuration.cosmotech.organization_id = organization_id
72
+ _configuration.cosmotech.workspace_id = workspace_id
73
+ _configuration.cosmotech.runner_id = runner_id
74
+ _configuration.cosmotech.parameters_absolute_path = parameters_absolute_path
75
+ _configuration.cosmotech.dataset_absolute_path = dataset_absolute_path
76
+
77
+ _r = RunnerApi(_configuration)
104
78
 
105
- return download_runner_data(
106
- organization_id=organization_id,
107
- workspace_id=workspace_id,
108
- runner_id=runner_id,
109
- parameter_folder=parameters_absolute_path,
110
- dataset_folder=dataset_absolute_path,
111
- read_files=False,
112
- parallel=parallel,
113
- write_json=write_json,
114
- write_csv=write_csv,
115
- fetch_dataset=fetch_dataset,
116
- )
79
+ return _r.download_runner_data(download_datasets=True)
117
80
 
118
81
 
119
82
  if __name__ == "__main__":
@@ -6,10 +6,11 @@
6
6
  # specifically authorized by written means by Cosmo Tech.
7
7
  import pathlib
8
8
 
9
- from cosmotech.csm_data.utils.click import click
10
- from cosmotech.csm_data.utils.decorators import web_help, translate_help
11
9
  from cosmotech.orchestrator.utils.translate import T
12
10
 
11
+ from cosmotech.csm_data.utils.click import click
12
+ from cosmotech.csm_data.utils.decorators import translate_help, web_help
13
+
13
14
 
14
15
  @click.command()
15
16
  @click.option(
@@ -50,19 +51,15 @@ from cosmotech.orchestrator.utils.translate import T
50
51
  @web_help("csm-data/api/wsf-load-file")
51
52
  @translate_help("csm_data.commands.api.wsf_load_file.description")
52
53
  def wsf_load_file(organization_id, workspace_id, workspace_path: str, target_folder: str):
54
+ from cosmotech.coal.cosmotech_api.apis.workspace import WorkspaceApi
53
55
 
54
- from cosmotech.coal.cosmotech_api.connection import get_api_client
55
- from cosmotech.coal.cosmotech_api.workspace import download_workspace_file
56
- from cosmotech.coal.cosmotech_api.workspace import list_workspace_files
57
-
58
- with get_api_client()[0] as api_client:
59
- target_list = list_workspace_files(api_client, organization_id, workspace_id, workspace_path)
56
+ ws_api = WorkspaceApi()
57
+ target_list = ws_api.list_filtered_workspace_files(organization_id, workspace_id, workspace_path)
60
58
 
61
- for target in target_list:
62
- download_workspace_file(
63
- api_client,
64
- organization_id,
65
- workspace_id,
66
- target,
67
- pathlib.Path(target_folder),
68
- )
59
+ for target in target_list:
60
+ ws_api.download_workspace_file(
61
+ organization_id,
62
+ workspace_id,
63
+ target,
64
+ pathlib.Path(target_folder),
65
+ )
@@ -5,10 +5,11 @@
5
5
  # etc., to any person is prohibited unless it has been previously and
6
6
  # specifically authorized by written means by Cosmo Tech.
7
7
 
8
- from cosmotech.csm_data.utils.click import click
9
- from cosmotech.csm_data.utils.decorators import web_help, translate_help
10
8
  from cosmotech.orchestrator.utils.translate import T
11
9
 
10
+ from cosmotech.csm_data.utils.click import click
11
+ from cosmotech.csm_data.utils.decorators import translate_help, web_help
12
+
12
13
 
13
14
  @click.command()
14
15
  @click.option(
@@ -55,16 +56,12 @@ from cosmotech.orchestrator.utils.translate import T
55
56
  @web_help("csm-data/api/wsf-send-file")
56
57
  @translate_help("csm_data.commands.api.wsf_send_file.description")
57
58
  def wsf_send_file(organization_id, workspace_id, file_path, workspace_path: str, overwrite: bool):
59
+ from cosmotech.coal.cosmotech_api.apis.workspace import WorkspaceApi
58
60
 
59
- from cosmotech.coal.cosmotech_api.connection import get_api_client
60
- from cosmotech.coal.cosmotech_api.workspace import upload_workspace_file
61
-
62
- with get_api_client()[0] as api_client:
63
- upload_workspace_file(
64
- api_client,
65
- organization_id,
66
- workspace_id,
67
- file_path,
68
- workspace_path,
69
- overwrite,
70
- )
61
+ WorkspaceApi().upload_workspace_file(
62
+ organization_id,
63
+ workspace_id,
64
+ file_path,
65
+ workspace_path,
66
+ overwrite,
67
+ )
@@ -5,10 +5,11 @@
5
5
  # etc., to any person is prohibited unless it has been previously and
6
6
  # specifically authorized by written means by Cosmo Tech.
7
7
 
8
- from cosmotech.csm_data.utils.click import click
9
- from cosmotech.csm_data.utils.decorators import web_help, translate_help
10
8
  from cosmotech.orchestrator.utils.translate import T
11
9
 
10
+ from cosmotech.csm_data.utils.click import click
11
+ from cosmotech.csm_data.utils.decorators import translate_help, web_help
12
+
12
13
 
13
14
  @click.command()
14
15
  @click.option(
@@ -7,10 +7,11 @@
7
7
 
8
8
  from typing import Optional
9
9
 
10
- from cosmotech.csm_data.utils.click import click
11
- from cosmotech.csm_data.utils.decorators import web_help, translate_help
12
10
  from cosmotech.orchestrator.utils.translate import T
13
11
 
12
+ from cosmotech.csm_data.utils.click import click
13
+ from cosmotech.csm_data.utils.decorators import translate_help, web_help
14
+
14
15
 
15
16
  @click.command()
16
17
  @click.option(
@@ -88,20 +89,20 @@ def s3_bucket_delete(
88
89
  ssl_cert_bundle: Optional[str] = None,
89
90
  ):
90
91
  # Import the functions at the start of the command
91
- from cosmotech.coal.aws.s3 import create_s3_resource, delete_objects
92
+ from cosmotech.coal.aws import S3
93
+ from cosmotech.coal.utils.configuration import Configuration
92
94
 
93
95
  # Create S3 resource
94
- s3_resource = create_s3_resource(
95
- endpoint_url=endpoint_url,
96
- access_id=access_id,
97
- secret_key=secret_key,
98
- use_ssl=use_ssl,
99
- ssl_cert_bundle=ssl_cert_bundle,
100
- )
96
+ _c = Configuration()
97
+ _c.s3.bucket_name = bucket_name
98
+ _c.s3.endpoint_url = endpoint_url
99
+ _c.s3.access_key_id = access_id
100
+ _c.s3.secret_access_key = secret_key
101
+ _c.s3.bucket_prefix = file_prefix
102
+ _c.s3.use_ssl = use_ssl
103
+ _c.s3.ssl_cert_bundle = ssl_cert_bundle
104
+
105
+ _s3 = S3(_c)
101
106
 
102
107
  # Delete objects
103
- delete_objects(
104
- bucket_name=bucket_name,
105
- s3_resource=s3_resource,
106
- file_prefix=file_prefix,
107
- )
108
+ _s3.delete_objects()