Skip to content

Commit ba46343

Browse files
committed
Resolves microsoft#173 - Onboard New Environment API
1 parent 3a57d89 commit ba46343

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

docs/how_to/optional_feature.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ fabric-cicd has an expected default flow; however, there will always be cases wh
66

77
For scenarios that aren't supported by default, fabric-cicd offers `feature-flags`. Below is an exhaustive list of currently supported features.
88

9-
| Flag Name | Description |
10-
| ---------------------------- | --------------------------------------------------- |
11-
| `enable_lakehouse_unpublish` | Set to enable the deletion of Lakehouses |
12-
| `disable_print_identity` | Set to disable printing the executing identity name |
9+
| Flag Name | Description |
10+
| ----------------------------- | --------------------------------------------------- |
11+
| `enable_lakehouse_unpublish` | Set to enable the deletion of Lakehouses |
12+
| `disable_print_identity` | Set to disable printing the executing identity name |
13+
| `disable_legacy_environments` | Set to migrate to new Environment API |
1314

1415
<span class="md-h3-nonanchor">Example</span>
1516

1617
```python
1718
from fabric_cicd import append_feature_flag
1819
append_feature_flag("enable_lakehouse_unpublish")
1920
append_feature_flag("disable_print_identity")
21+
append_feature_flag("disable_legacy_environments")
2022
```
2123

2224
## Debugging

src/fabric_cicd/_common/_fabric_endpoint.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def _handle_response(
182182
url = response.headers.get("Location")
183183
method = "GET"
184184
body = "{}"
185-
response_json = response.json()
185+
response_json = response.json() if response.content else None
186186

187187
if long_running:
188188
status = response_json.get("status")
@@ -204,8 +204,8 @@ def _handle_response(
204204
else:
205205
handle_retry(
206206
attempt=iteration_count - 1,
207-
base_delay=0.5,
208-
response_retry_after=retry_after,
207+
base_delay=kwargs.get("base_delay", 0.5),
208+
response_retry_after=kwargs.get("retry_after", retry_after),
209209
max_retries=kwargs.get("max_retries", 5),
210210
prepend_message="Operation in progress.",
211211
)

src/fabric_cicd/_items/_environment.py

+36-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import dpath
1111
import yaml
1212

13-
from fabric_cicd import FabricWorkspace
13+
from fabric_cicd import FabricWorkspace, constants
1414
from fabric_cicd._common._fabric_endpoint import handle_retry
1515
from fabric_cicd._parameter._utils import check_parameter_structure
1616

@@ -35,7 +35,41 @@ def publish_environments(fabric_workspace_obj: FabricWorkspace) -> None:
3535
item_type=item_type,
3636
skip_publish_logging=True,
3737
)
38-
_publish_environment_metadata(fabric_workspace_obj, item_name=item_name)
38+
39+
if "disable_legacy_environments" in constants.FEATURE_FLAG:
40+
item_guid = fabric_workspace_obj.repository_items[item_type][item_name].guid
41+
_publish_environment(fabric_workspace_obj, item_guid=item_guid)
42+
else: # TODO: remove this when legacy environments are deprecated
43+
logger.warning(
44+
"""The legacy Microsoft Fabric environments API is being deprecated, the rollout is incremental across regions and should be completed April 12th 2025. \r
45+
Use the temporary feature flag below to force a switch to the new API during the rollout period. \r
46+
You will be automatically opted into the new API after the deadline: ref-> https://learn.microsoft.com/en-us/fabric/data-engineering/environment-public-api \n
47+
>>> from fabric_cicd import append_feature_flag
48+
>>> append_feature_flag("disable_legacy_environments")\n"""
49+
)
50+
_publish_environment_metadata(fabric_workspace_obj, item_name=item_name)
51+
52+
53+
def _publish_environment(fabric_workspace_obj: FabricWorkspace, item_guid: str) -> None:
54+
"""
55+
Publishes compute settings and libraries for a given environment item.
56+
57+
Args:
58+
fabric_workspace_obj: The FabricWorkspace object.
59+
item_guid: Guid of the environment item whose compute settings are to be published.
60+
"""
61+
logger.info("Publishing Libraries & Spark Settings")
62+
# Publish updated settings
63+
# https://learn.microsoft.com/en-us/rest/api/fabric/environment/spark-libraries/publish-environment
64+
fabric_workspace_obj.endpoint.invoke(
65+
method="POST",
66+
url=f"{fabric_workspace_obj.base_api_url}/environments/{item_guid}/staging/publish",
67+
base_delay=5,
68+
retry_after=120,
69+
max_retries=20,
70+
)
71+
72+
logger.info("Published")
3973

4074

4175
def _publish_environment_metadata(fabric_workspace_obj: FabricWorkspace, item_name: str) -> None:

src/fabric_cicd/fabric_workspace.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,10 @@ def _publish_item(
416416
metadata_body = {"displayName": item_name, "type": item_type}
417417

418418
# Only shell deployment, no definition support
419-
shell_only_publish = item_type in constants.SHELL_ONLY_PUBLISH
419+
if "disable_legacy_environments" in constants.FEATURE_FLAG:
420+
shell_only_publish = item_type in ["Lakehouse"]
421+
else: # TODO: remove this when legacy environments are deprecated
422+
shell_only_publish = item_type in ["Environment", "Lakehouse"]
420423

421424
if kwargs.get("creation_payload"):
422425
creation_payload = {"creationPayload": kwargs["creation_payload"]}

0 commit comments

Comments
 (0)