msfabricpysdkcore 0.0.12__py3-none-any.whl → 0.1.1__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.
- msfabricpysdkcore/admin_item.py +18 -44
- msfabricpysdkcore/admin_workspace.py +13 -60
- msfabricpysdkcore/adminapi.py +400 -429
- msfabricpysdkcore/client.py +115 -1
- msfabricpysdkcore/coreapi.py +2553 -763
- msfabricpysdkcore/deployment_pipeline.py +34 -146
- msfabricpysdkcore/domain.py +20 -219
- msfabricpysdkcore/environment.py +13 -171
- msfabricpysdkcore/item.py +63 -198
- msfabricpysdkcore/job_instance.py +8 -22
- msfabricpysdkcore/lakehouse.py +9 -118
- msfabricpysdkcore/long_running_operation.py +7 -37
- msfabricpysdkcore/onelakeshortcut.py +7 -21
- msfabricpysdkcore/otheritems.py +66 -91
- msfabricpysdkcore/spark_custom_pool.py +7 -47
- msfabricpysdkcore/tests/test_admin_apis.py +21 -1
- msfabricpysdkcore/tests/test_datapipelines.py +14 -17
- msfabricpysdkcore/tests/test_deployment_pipeline.py +3 -3
- msfabricpysdkcore/tests/test_domains.py +4 -3
- msfabricpysdkcore/tests/test_environments.py +51 -2
- msfabricpysdkcore/tests/test_evenhouses.py +48 -0
- msfabricpysdkcore/tests/test_evenstreams.py +1 -1
- msfabricpysdkcore/tests/test_external_data_shares.py +51 -0
- msfabricpysdkcore/tests/test_items.py +80 -0
- msfabricpysdkcore/tests/test_kql_queryset.py +50 -0
- msfabricpysdkcore/tests/test_kqldatabases.py +1 -1
- msfabricpysdkcore/tests/test_lakehouse.py +86 -0
- msfabricpysdkcore/tests/test_ml_experiments.py +48 -0
- msfabricpysdkcore/tests/test_ml_models.py +48 -0
- msfabricpysdkcore/tests/test_notebooks.py +58 -0
- msfabricpysdkcore/tests/test_one_lake_data_access_security.py +65 -0
- msfabricpysdkcore/tests/test_other_items.py +46 -0
- msfabricpysdkcore/tests/test_reports.py +53 -0
- msfabricpysdkcore/tests/test_semantic_model.py +51 -0
- msfabricpysdkcore/tests/test_spark.py +7 -5
- msfabricpysdkcore/tests/test_sparkjobdefinition.py +1 -1
- msfabricpysdkcore/tests/test_warehouses.py +51 -0
- msfabricpysdkcore/tests/test_workspaces_capacities.py +7 -4
- msfabricpysdkcore/workspace.py +397 -1121
- {msfabricpysdkcore-0.0.12.dist-info → msfabricpysdkcore-0.1.1.dist-info}/METADATA +110 -8
- msfabricpysdkcore-0.1.1.dist-info/RECORD +52 -0
- {msfabricpysdkcore-0.0.12.dist-info → msfabricpysdkcore-0.1.1.dist-info}/WHEEL +1 -1
- msfabricpysdkcore-0.0.12.dist-info/RECORD +0 -39
- {msfabricpysdkcore-0.0.12.dist-info → msfabricpysdkcore-0.1.1.dist-info}/LICENSE +0 -0
- {msfabricpysdkcore-0.0.12.dist-info → msfabricpysdkcore-0.1.1.dist-info}/top_level.txt +0 -0
msfabricpysdkcore/environment.py
CHANGED
@@ -1,9 +1,4 @@
|
|
1
|
-
import json
|
2
|
-
import requests
|
3
|
-
from time import sleep
|
4
|
-
|
5
1
|
from msfabricpysdkcore.item import Item
|
6
|
-
from msfabricpysdkcore.long_running_operation import check_long_running_operation
|
7
2
|
|
8
3
|
class Environment(Item):
|
9
4
|
"""Class to represent a item in Microsoft Fabric"""
|
@@ -11,48 +6,19 @@ class Environment(Item):
|
|
11
6
|
def __init__(self, id, display_name, type, workspace_id, auth, properties = None, definition=None, description=""):
|
12
7
|
super().__init__(id, display_name, type, workspace_id, auth, properties, definition, description)
|
13
8
|
|
14
|
-
def from_dict(item_dict,
|
9
|
+
def from_dict(item_dict, core_client):
|
15
10
|
return Environment(id=item_dict['id'], display_name=item_dict['displayName'], type=item_dict['type'], workspace_id=item_dict['workspaceId'],
|
16
11
|
properties=item_dict.get('properties', None),
|
17
12
|
definition=item_dict.get('definition', None), description=item_dict.get('description', ""),
|
18
|
-
auth=
|
13
|
+
auth=core_client)
|
19
14
|
|
20
|
-
# GET https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/environments/{environmentId}/sparkcompute
|
21
15
|
def get_published_settings(self):
|
22
16
|
"""Get the published settings of the environment"""
|
23
|
-
|
24
|
-
|
25
|
-
for _ in range(10):
|
26
|
-
response = requests.get(url=url, headers=self.auth.get_headers())
|
27
|
-
if response.status_code == 429:
|
28
|
-
print("Too many requests, waiting 10 seconds")
|
29
|
-
sleep(10)
|
30
|
-
continue
|
31
|
-
if response.status_code not in (200, 429):
|
32
|
-
raise Exception(f"Error getting published settings: {response.status_code}, {response.text}")
|
33
|
-
break
|
34
|
-
|
35
|
-
resp_json = json.loads(response.text)
|
36
|
-
return resp_json
|
17
|
+
return self.core_client.get_published_settings(self.workspace_id, self.id)
|
37
18
|
|
38
|
-
# GET https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/environments/{environmentId}/staging/sparkcompute
|
39
|
-
|
40
19
|
def get_staging_settings(self):
|
41
20
|
"""Get the staging settings of the environment"""
|
42
|
-
|
43
|
-
|
44
|
-
for _ in range(10):
|
45
|
-
response = requests.get(url=url, headers=self.auth.get_headers())
|
46
|
-
if response.status_code == 429:
|
47
|
-
print("Too many requests, waiting 10 seconds")
|
48
|
-
sleep(10)
|
49
|
-
continue
|
50
|
-
if response.status_code not in (200, 429):
|
51
|
-
raise Exception(f"Error getting staging settings: {response.status_code}, {response.text}")
|
52
|
-
break
|
53
|
-
|
54
|
-
resp_json = json.loads(response.text)
|
55
|
-
return resp_json
|
21
|
+
return self.core_client.get_staging_settings(self.workspace_id, self.id)
|
56
22
|
|
57
23
|
|
58
24
|
def update_staging_settings(self,
|
@@ -60,150 +26,26 @@ class Environment(Item):
|
|
60
26
|
executor_cores = None, executor_memory = None, instance_pool = None,
|
61
27
|
runtime_version = None, spark_properties = None):
|
62
28
|
"""Update the staging settings of the environment"""
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
body['driverCores'] = driver_cores
|
67
|
-
if driver_memory is not None:
|
68
|
-
body['driverMemory'] = driver_memory
|
69
|
-
if dynamic_executor_allocation is not None:
|
70
|
-
body['dynamicExecutorAllocation'] = dynamic_executor_allocation
|
71
|
-
if executor_cores is not None:
|
72
|
-
body['executorCores'] = executor_cores
|
73
|
-
if executor_memory is not None:
|
74
|
-
body['executorMemory'] = executor_memory
|
75
|
-
if instance_pool is not None:
|
76
|
-
body['instancePool'] = instance_pool
|
77
|
-
if runtime_version is not None:
|
78
|
-
body['runtimeVersion'] = runtime_version
|
79
|
-
if spark_properties is not None:
|
80
|
-
body['sparkProperties'] = spark_properties
|
81
|
-
|
82
|
-
|
83
|
-
for _ in range(10):
|
84
|
-
response = requests.patch(url=url, headers=self.auth.get_headers(), json=body)
|
85
|
-
if response.status_code == 429:
|
86
|
-
print("Too many requests, waiting 10 seconds")
|
87
|
-
sleep(10)
|
88
|
-
continue
|
89
|
-
if response.status_code not in (200, 429):
|
90
|
-
raise Exception(f"Error updating staging settings: {response.status_code}, {response.text}")
|
91
|
-
break
|
92
|
-
|
93
|
-
return json.loads(response.text)
|
94
|
-
|
95
|
-
# GET https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/environments/{environmentId}/libraries
|
29
|
+
return self.core_client.update_staging_settings(self.workspace_id, self.id, driver_cores, driver_memory,
|
30
|
+
dynamic_executor_allocation, executor_cores, executor_memory,
|
31
|
+
instance_pool, runtime_version, spark_properties)
|
96
32
|
|
97
33
|
def get_published_libraries(self):
|
98
34
|
"""Get the published libraries of the environment"""
|
99
|
-
|
100
|
-
|
101
|
-
for _ in range(10):
|
102
|
-
response = requests.get(url=url, headers=self.auth.get_headers())
|
103
|
-
if response.status_code == 429:
|
104
|
-
print("Too many requests, waiting 10 seconds")
|
105
|
-
sleep(10)
|
106
|
-
continue
|
107
|
-
if response.status_code not in (200, 429):
|
108
|
-
raise Exception(f"Error getting published libraries: {response.status_code}, {response.text}")
|
109
|
-
break
|
110
|
-
|
111
|
-
resp_json = json.loads(response.text)
|
112
|
-
return resp_json
|
35
|
+
return self.core_client.get_published_libraries(self.workspace_id, self.id)
|
113
36
|
|
114
|
-
# GET https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/environments/{environmentId}/staging/libraries
|
115
|
-
|
116
37
|
def get_staging_libraries(self):
|
117
38
|
"""Get the staging libraries of the environment"""
|
118
|
-
|
119
|
-
|
120
|
-
for _ in range(10):
|
121
|
-
response = requests.get(url=url, headers=self.auth.get_headers())
|
122
|
-
if response.status_code == 429:
|
123
|
-
print("Too many requests, waiting 10 seconds")
|
124
|
-
sleep(10)
|
125
|
-
continue
|
126
|
-
if response.status_code not in (200, 429):
|
127
|
-
raise Exception(f"Error getting staging libraries: {response.status_code}, {response.text}")
|
128
|
-
break
|
129
|
-
|
130
|
-
resp_json = json.loads(response.text)
|
131
|
-
return resp_json
|
39
|
+
return self.core_client.get_staging_libraries(self.workspace_id, self.id)
|
132
40
|
|
133
|
-
|
134
41
|
def upload_staging_library(self, file_path):
|
135
|
-
|
136
|
-
raise NotImplementedError("Not implemented yet")
|
137
|
-
# url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.workspace_id}/environments/{self.id}/staging/libraries"
|
138
|
-
|
139
|
-
# for _ in range(10):
|
140
|
-
# response = requests.post(url=url, files={'file': file_path}, headers=self.auth.get_headers())
|
141
|
-
# if response.status_code == 429:
|
142
|
-
# print("Too many requests, waiting 10 seconds")
|
143
|
-
# sleep(10)
|
144
|
-
# continue
|
145
|
-
# if response.status_code not in (200, 429):
|
146
|
-
# raise Exception(f"Error uploading staging libraries: {response.status_code}, {response.text}")
|
147
|
-
# break
|
148
|
-
|
149
|
-
# return json.loads(response.text)
|
42
|
+
return self.core_client.upload_staging_library(self.workspace_id, self.id, file_path)
|
150
43
|
|
151
|
-
# DELETE https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/environments/{environmentId}/staging/libraries?libraryToDelete={libraryToDelete}
|
152
|
-
|
153
44
|
def delete_staging_library(self, library_to_delete):
|
154
|
-
|
155
|
-
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.workspace_id}/environments/{self.id}/staging/libraries?libraryToDelete={library_to_delete}"
|
156
|
-
|
157
|
-
for _ in range(10):
|
158
|
-
response = requests.delete(url=url, headers=self.auth.get_headers())
|
159
|
-
if response.status_code == 429:
|
160
|
-
print("Too many requests, waiting 10 seconds")
|
161
|
-
sleep(10)
|
162
|
-
continue
|
163
|
-
if response.status_code not in (200, 429):
|
164
|
-
raise Exception(f"Error deleting staging libraries: {response.status_code}, {response.text}")
|
165
|
-
break
|
166
|
-
|
167
|
-
return response.text
|
45
|
+
return self.core_client.delete_staging_library(self.workspace_id, self.id, library_to_delete)
|
168
46
|
|
169
|
-
# POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/environments/{environmentId}/staging/publish
|
170
|
-
|
171
47
|
def publish_environment(self):
|
172
|
-
|
173
|
-
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.workspace_id}/environments/{self.id}/staging/publish"
|
174
|
-
|
175
|
-
for _ in range(10):
|
176
|
-
response = requests.post(url=url, headers=self.auth.get_headers())
|
177
|
-
if response.status_code == 429:
|
178
|
-
print("Too many requests, waiting 10 seconds")
|
179
|
-
sleep(10)
|
180
|
-
continue
|
181
|
-
if response.status_code == 202:
|
182
|
-
publish_info = check_long_running_operation(response.headers, self.auth)
|
183
|
-
return publish_info
|
184
|
-
if response.status_code not in (200, 429):
|
185
|
-
raise Exception(f"Error publishing staging: {response.status_code}, {response.text}")
|
186
|
-
break
|
187
|
-
|
188
|
-
resp_dict = json.loads(response.text)
|
189
|
-
return resp_dict
|
190
|
-
|
191
|
-
|
192
|
-
# POST https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/environments/{environmentId}/staging/cancelPublish
|
48
|
+
return self.core_client.publish_environment(self.workspace_id, self.id)
|
193
49
|
|
194
50
|
def cancel_publish(self):
|
195
|
-
|
196
|
-
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.workspace_id}/environments/{self.id}/staging/cancelPublish"
|
197
|
-
|
198
|
-
for _ in range(10):
|
199
|
-
response = requests.post(url=url, headers=self.auth.get_headers())
|
200
|
-
if response.status_code == 429:
|
201
|
-
print("Too many requests, waiting 10 seconds")
|
202
|
-
sleep(10)
|
203
|
-
continue
|
204
|
-
if response.status_code not in (200, 429):
|
205
|
-
raise Exception(f"Error canceling publishing: {response.status_code}, {response.text}")
|
206
|
-
break
|
207
|
-
|
208
|
-
resp_dict = json.loads(response.text)
|
209
|
-
return resp_dict
|
51
|
+
return self.core_client.cancel_publish(self.workspace_id, self.id)
|
msfabricpysdkcore/item.py
CHANGED
@@ -1,16 +1,11 @@
|
|
1
1
|
import json
|
2
|
-
import requests
|
3
|
-
from time import sleep
|
4
|
-
|
5
|
-
from msfabricpysdkcore.onelakeshortcut import OneLakeShortcut
|
6
|
-
from msfabricpysdkcore.job_instance import JobInstance
|
7
|
-
from msfabricpysdkcore.long_running_operation import check_long_running_operation
|
8
2
|
|
3
|
+
from msfabricpysdkcore.coreapi import FabricClientCore
|
9
4
|
|
10
5
|
class Item:
|
11
6
|
"""Class to represent a item in Microsoft Fabric"""
|
12
7
|
|
13
|
-
def __init__(self, id, display_name, type, workspace_id,
|
8
|
+
def __init__(self, id, display_name, type, workspace_id, core_client: FabricClientCore, properties = None, definition=None, description="") -> None:
|
14
9
|
|
15
10
|
self.id = id
|
16
11
|
self.display_name = display_name
|
@@ -20,7 +15,7 @@ class Item:
|
|
20
15
|
self.properties = properties
|
21
16
|
self.workspace_id = workspace_id
|
22
17
|
|
23
|
-
self.
|
18
|
+
self.core_client = core_client
|
24
19
|
|
25
20
|
def __str__(self) -> str:
|
26
21
|
"""Return a string representation of the workspace object"""
|
@@ -38,234 +33,104 @@ class Item:
|
|
38
33
|
def __repr__(self) -> str:
|
39
34
|
return self.__str__()
|
40
35
|
|
41
|
-
def from_dict(item_dict,
|
36
|
+
def from_dict(item_dict, core_client):
|
42
37
|
"""Create Item object from dictionary"""
|
43
38
|
|
44
39
|
return Item(id=item_dict['id'], display_name=item_dict['displayName'], type=item_dict['type'], workspace_id=item_dict['workspaceId'],
|
45
40
|
properties=item_dict.get('properties', None),
|
46
|
-
definition=item_dict.get('definition', None), description=item_dict.get('description', ""),
|
41
|
+
definition=item_dict.get('definition', None), description=item_dict.get('description', ""), core_client=core_client)
|
47
42
|
|
48
43
|
def delete(self, type = None):
|
49
44
|
"""Delete the workspace item"""
|
50
45
|
|
51
|
-
|
52
|
-
if type:
|
53
|
-
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.workspace_id}/{type}/{self.id}"
|
54
|
-
for _ in range(10):
|
55
|
-
response = requests.delete(url=url, headers=self.auth.get_headers())
|
56
|
-
if response.status_code == 429:
|
57
|
-
print("Too many requests, waiting 10 seconds")
|
58
|
-
sleep(10)
|
59
|
-
continue
|
60
|
-
if response.status_code not in (200, 429):
|
61
|
-
raise Exception(f"Error deleting item: {response.status_code}, {response.text}")
|
62
|
-
break
|
63
|
-
|
64
|
-
return response.status_code
|
46
|
+
return self.core_client.delete_item(self.workspace_id, self.id, type=type)
|
65
47
|
|
66
48
|
def get_definition(self, type = None, format = None):
|
67
49
|
"""Get the definition of the item"""
|
68
|
-
|
69
|
-
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.workspace_id}/items/{self.id}/getDefinition"
|
70
|
-
if type:
|
71
|
-
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.workspace_id}/{type}/{self.id}/getDefinition"
|
50
|
+
resp_dict = self.core_client.get_item_definition(self.workspace_id, self.id, type=type, format=format)
|
72
51
|
|
73
|
-
if format:
|
74
|
-
url += f"?format={format}"
|
75
|
-
|
76
|
-
for _ in range(10):
|
77
|
-
response = requests.post(url=url, headers=self.auth.get_headers())
|
78
|
-
if response.status_code == 429:
|
79
|
-
print("Too many requests, waiting 10 seconds")
|
80
|
-
sleep(10)
|
81
|
-
continue
|
82
|
-
if response.status_code == 202:
|
83
|
-
operation_result = check_long_running_operation( response.headers, self.auth)
|
84
|
-
self.definition = operation_result['definition']
|
85
|
-
return operation_result
|
86
|
-
|
87
|
-
if response.status_code not in (200, 202, 429):
|
88
|
-
print(response.status_code)
|
89
|
-
print(response.text)
|
90
|
-
raise Exception(f"Error getting item definition: {response.text}")
|
91
|
-
break
|
92
|
-
|
93
|
-
resp_dict = json.loads(response.text)
|
94
52
|
self.definition = resp_dict['definition']
|
95
53
|
return resp_dict
|
96
|
-
|
97
|
-
def update(self, display_name = None, description = None, type = None):
|
98
|
-
"""Update the item"""
|
99
|
-
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.workspace_id}/items/{self.id}"
|
100
|
-
if type:
|
101
|
-
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.workspace_id}/{type}/{self.id}"
|
102
54
|
|
103
|
-
payload = dict()
|
104
|
-
if display_name:
|
105
|
-
payload['displayName'] = display_name
|
106
|
-
if description:
|
107
|
-
payload['description'] = description
|
108
|
-
for _ in range(10):
|
109
|
-
response = requests.patch(url=url, headers=self.auth.get_headers(), json=payload)
|
110
|
-
if response.status_code == 429:
|
111
|
-
print("Too many requests, waiting 10 seconds")
|
112
|
-
sleep(10)
|
113
|
-
continue
|
114
|
-
if response.status_code not in (200, 429):
|
115
|
-
print(response.status_code)
|
116
|
-
print(response.text)
|
117
55
|
|
118
|
-
|
119
|
-
|
56
|
+
def update(self, display_name = None, description = None, type = None, return_item="Default"):
|
57
|
+
"""Update the item"""
|
58
|
+
|
59
|
+
resp_dict = self.core_client.update_item(workspace_id=self.workspace_id, item_id=self.id,
|
60
|
+
display_name=display_name, description=description, type=type,
|
61
|
+
return_item=return_item)
|
120
62
|
if display_name:
|
121
|
-
self.display_name =
|
63
|
+
self.display_name = display_name
|
122
64
|
if description:
|
123
|
-
self.description =
|
65
|
+
self.description = description
|
124
66
|
|
125
|
-
return
|
67
|
+
return resp_dict
|
126
68
|
|
127
69
|
def update_definition(self, definition, type = None):
|
128
70
|
"""Update the item definition"""
|
129
|
-
|
130
|
-
|
131
|
-
if type:
|
132
|
-
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.workspace_id}/{type}/{self.id}/updateDefinition"
|
133
|
-
|
134
|
-
payload = {
|
135
|
-
'definition': definition
|
136
|
-
}
|
137
|
-
for _ in range(10):
|
138
|
-
response = requests.post(url=url, headers=self.auth.get_headers(), json=payload)
|
139
|
-
if response.status_code == 429:
|
140
|
-
print("Too many requests, waiting 10 seconds")
|
141
|
-
sleep(10)
|
142
|
-
continue
|
143
|
-
if response.status_code == 202:
|
144
|
-
check_long_running_operation( response.headers, self.auth)
|
145
|
-
if response.status_code not in (200, 202, 429):
|
146
|
-
print(response.status_code)
|
147
|
-
print(response.text)
|
71
|
+
response = self.core_client.update_item_definition(workspace_id=self.workspace_id, item_id=self.id,
|
72
|
+
definition=definition, type=type)
|
148
73
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
self.definition = payload['definition']
|
153
|
-
return self
|
74
|
+
self.definition = definition
|
75
|
+
return response
|
154
76
|
|
155
|
-
|
156
|
-
"""Get the shortcut in the item"""
|
157
|
-
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.workspace_id}/items/{self.id}/shortcuts/{path}/{name}"
|
158
|
-
|
159
|
-
for _ in range(10):
|
160
|
-
response = requests.get(url=url, headers=self.auth.get_headers())
|
161
|
-
if response.status_code == 429:
|
162
|
-
print("Too many requests, waiting 10 seconds")
|
163
|
-
sleep(10)
|
164
|
-
continue
|
165
|
-
if response.status_code not in (200, 429):
|
166
|
-
print(response.status_code)
|
167
|
-
print(response.text)
|
168
|
-
|
169
|
-
raise Exception(f"Error getting shortcut: {response.text}")
|
170
|
-
break
|
77
|
+
# Shortcut
|
171
78
|
|
172
|
-
shortcut_dict = json.loads(response.text)
|
173
|
-
shortcut_dict['workspaceId'] = self.workspace_id
|
174
|
-
shortcut_dict['itemId'] = self.id
|
175
|
-
return OneLakeShortcut.from_dict(shortcut_dict,
|
176
|
-
auth = self.auth)
|
177
|
-
|
178
79
|
def create_shortcut(self, path, name, target):
|
179
80
|
"""Create a shortcut in the item"""
|
180
|
-
|
181
|
-
|
182
|
-
body = {'name': name,
|
183
|
-
'path': path,
|
184
|
-
'target': target}
|
185
|
-
|
186
|
-
for _ in range(10):
|
187
|
-
response = requests.post(url=url, headers=self.auth.get_headers(), json=body)
|
188
|
-
if response.status_code == 429:
|
189
|
-
print("Too many requests, waiting 10 seconds")
|
190
|
-
sleep(10)
|
191
|
-
continue
|
192
|
-
if response.status_code not in (201, 429):
|
193
|
-
print(response.status_code)
|
194
|
-
print(response.text)
|
195
|
-
|
196
|
-
raise Exception(f"Error creating shortcut: {response.text}")
|
197
|
-
break
|
198
|
-
|
199
|
-
shortcut_dict = json.loads(response.text)
|
200
|
-
shortcut_dict['workspaceId'] = self.workspace_id
|
201
|
-
shortcut_dict['itemId'] = self.id
|
202
|
-
return OneLakeShortcut.from_dict(shortcut_dict,
|
203
|
-
auth = self.auth)
|
81
|
+
return self.core_client.create_shortcut(workspace_id=self.workspace_id, item_id=self.id,
|
82
|
+
path=path, name=name, target=target)
|
204
83
|
|
205
84
|
def delete_shortcut(self, path, name):
|
206
85
|
"""Delete the shortcut in the item"""
|
207
|
-
return self.
|
86
|
+
return self.core_client.delete_shortcut(workspace_id=self.workspace_id, item_id=self.id,
|
87
|
+
path=path, name=name)
|
88
|
+
|
89
|
+
def get_shortcut(self, path, name):
|
90
|
+
"""Get the shortcut in the item"""
|
91
|
+
return self.core_client.get_shortcut(workspace_id=self.workspace_id, item_id=self.id,
|
92
|
+
path=path, name=name)
|
208
93
|
|
209
94
|
|
210
|
-
|
211
|
-
"""Run an on demand job on the item"""
|
95
|
+
# Job Scheduler
|
212
96
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
97
|
+
def cancel_item_job_instance(self, job_instance_id):
|
98
|
+
"""Cancel a job instance ofjob the item"""
|
99
|
+
return self.core_client.cancel_item_job_instance(workspace_id=self.workspace_id, item_id=self.id,
|
100
|
+
job_instance_id=job_instance_id)
|
101
|
+
|
102
|
+
def get_item_job_instance(self, job_instance_id):
|
103
|
+
"""Get the job instance of the item"""
|
104
|
+
return self.core_client.get_item_job_instance(workspace_id=self.workspace_id, item_id=self.id,
|
105
|
+
job_instance_id=job_instance_id)
|
218
106
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
else:
|
223
|
-
response = requests.post(url=url, headers=self.auth.get_headers())
|
224
|
-
if response.status_code == 429:
|
225
|
-
print("Too many requests, waiting 10 seconds")
|
226
|
-
sleep(10)
|
227
|
-
continue
|
107
|
+
def run_on_demand_item_job(self, job_type, execution_data = None):
|
108
|
+
return self.core_client.run_on_demand_item_job(workspace_id=self.workspace_id, item_id=self.id,
|
109
|
+
job_type=job_type, execution_data=execution_data)
|
228
110
|
|
229
|
-
|
230
|
-
|
231
|
-
print(response.text)
|
111
|
+
|
112
|
+
# External Data Shares
|
232
113
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
job_instance = self.get_item_job_instance(job_instance_id=job_instance_id)
|
237
|
-
return job_instance
|
114
|
+
def create_external_data_share(self, paths, recipient):
|
115
|
+
return self.core_client.create_external_data_share(workspace_id=self.workspace_id, item_id=self.id,
|
116
|
+
paths=paths, recipient=recipient)
|
238
117
|
|
239
|
-
def
|
240
|
-
|
118
|
+
def get_external_data_share(self, external_data_share_id):
|
119
|
+
return self.core_client.get_external_data_share(workspace_id=self.workspace_id, item_id=self.id,
|
120
|
+
external_data_share_id=external_data_share_id)
|
241
121
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
continue
|
249
|
-
if response.status_code not in (200, 429):
|
250
|
-
print(response.status_code)
|
251
|
-
print(response.text)
|
122
|
+
def list_external_data_shares_in_item(self):
|
123
|
+
return self.core_client.list_external_data_shares_in_item(workspace_id=self.workspace_id, item_id=self.id)
|
124
|
+
|
125
|
+
def revoke_external_data_share(self, external_data_share_id):
|
126
|
+
return self.core_client.revoke_external_data_share(workspace_id=self.workspace_id, item_id=self.id,
|
127
|
+
external_data_share_id=external_data_share_id)
|
252
128
|
|
253
|
-
|
254
|
-
break
|
129
|
+
# One Lake data access security
|
255
130
|
|
256
|
-
|
257
|
-
|
258
|
-
job_dict['itemId'] = self.id
|
259
|
-
return JobInstance.from_dict(job_dict, auth=self.auth)
|
260
|
-
|
261
|
-
def cancel_item_job_instance(self, job_instance_id):
|
262
|
-
"""Cancel a job instance ofjob the item"""
|
263
|
-
return self.get_item_job_instance(job_instance_id=job_instance_id).cancel()
|
264
|
-
|
265
|
-
def list_tables(self):
|
266
|
-
raise NotImplementedError("List tables only works on Lakehouse Items")
|
131
|
+
def list_data_access_roles(self):
|
132
|
+
return self.core_client.list_data_access_roles(workspace_id=self.workspace_id, item_id=self.id)
|
267
133
|
|
268
|
-
def
|
269
|
-
|
270
|
-
|
271
|
-
raise NotImplementedError("Load table only works on Lakehouse Items")
|
134
|
+
def create_or_update_data_access_roles(self, data_access_roles, dryrun = False, etag_match = None):
|
135
|
+
return self.core_client.create_or_update_data_access_roles(workspace_id=self.workspace_id, item_id=self.id,
|
136
|
+
data_access_roles=data_access_roles, dryrun=dryrun, etag_match=etag_match)
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import json
|
2
|
-
import
|
3
|
-
from time import sleep
|
2
|
+
from msfabricpysdkcore.coreapi import FabricClientCore
|
4
3
|
|
5
4
|
class JobInstance:
|
6
5
|
"""Class to represent a job instance in Microsoft Fabric"""
|
7
6
|
|
8
|
-
def __init__(self, id, item_id, workspace_id,
|
7
|
+
def __init__(self, id, item_id, workspace_id, core_client: FabricClientCore, job_type, invoke_type, status, root_activity_id,
|
9
8
|
start_time_utc, end_time_utc, failureReason):
|
10
9
|
|
11
10
|
self.id = id
|
@@ -19,7 +18,7 @@ class JobInstance:
|
|
19
18
|
self.end_time_utc = end_time_utc
|
20
19
|
self.failureReason = failureReason
|
21
20
|
|
22
|
-
self.
|
21
|
+
self.core_client = core_client
|
23
22
|
|
24
23
|
|
25
24
|
def __str__(self) -> str:
|
@@ -41,28 +40,15 @@ class JobInstance:
|
|
41
40
|
def __repr__(self) -> str:
|
42
41
|
return self.__str__()
|
43
42
|
|
44
|
-
def from_dict(job_dict,
|
43
|
+
def from_dict(job_dict, core_client):
|
45
44
|
"""Create JobInstance object from dictionary"""
|
46
45
|
return JobInstance(id=job_dict['id'], item_id=job_dict['itemId'], workspace_id=job_dict['workspaceId'],
|
47
46
|
job_type=job_dict['jobType'], invoke_type=job_dict['invokeType'], status=job_dict['status'],
|
48
47
|
root_activity_id=job_dict['rootActivityId'], start_time_utc=job_dict['startTimeUtc'],
|
49
|
-
end_time_utc=job_dict['endTimeUtc'], failureReason=job_dict['failureReason'],
|
48
|
+
end_time_utc=job_dict['endTimeUtc'], failureReason=job_dict['failureReason'], core_client=core_client)
|
50
49
|
|
51
50
|
def cancel(self):
|
52
51
|
"""Cancel the job instance"""
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
if response.status_code == 429:
|
57
|
-
print("Too many requests, waiting 10 seconds")
|
58
|
-
sleep(10)
|
59
|
-
continue
|
60
|
-
|
61
|
-
if response.status_code not in (202, 429):
|
62
|
-
print(response.status_code)
|
63
|
-
print(response.text)
|
64
|
-
|
65
|
-
raise Exception(f"Error running on demand job: {response.text}")
|
66
|
-
break
|
67
|
-
|
68
|
-
return response.status_code
|
52
|
+
return self.core_client.cancel_item_job_instance(workspace_id=self.workspace_id,
|
53
|
+
item_id=self.item_id,
|
54
|
+
job_instance_id=self.id)
|