Created
January 22, 2025 13:32
-
-
Save MarkPryceMaherMSFT/30a6d645780db020f0f28530cca0fc95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"cells":[{"cell_type":"code","source":["import sempy.fabric as fabric\n","from sempy.fabric.exceptions import FabricHTTPException, WorkspaceNotFoundException\n","\n","\n","# GET https://api.fabric.microsoft.com/v1/workspaces/<your workspace ID>/mirroredDatabases\n","client = fabric.FabricRestClient()\n","\n","tenant_id=spark.conf.get(\"trident.tenant.id\")\n","workspace_id=spark.conf.get(\"trident.workspace.id\")\n","lakehouse_id=spark.conf.get(\"trident.lakehouse.id\")\n","lakehouse_name=spark.conf.get(\"trident.lakehouse.name\")\n","\n","# This is the SQL endpoint I want to sync with the lakehouse, this needs to be the GUI\n","mirrorlist = fabric.FabricRestClient().get(f\"/v1/workspaces/{workspace_id}/mirroredDatabases\").json()\n","display(mirrorlist)\n","\n"],"outputs":[],"execution_count":null,"metadata":{"microsoft":{"language":"python","language_group":"synapse_pyspark"}},"id":"6e1f1904-59c9-40d7-b575-00132b1829eb"},{"cell_type":"code","source":["\n","mirroreddatabaseid = \"\" ## this is the first ID from output above\n","\n","# Stop Mirroring\n","#POST https://api.fabric.microsoft.com/v1/workspaces/<your workspace ID>/mirroredDatabases/<mirrored database ID>/stopMirroring\n","stop = f\"v1/workspaces/{workspace_id}/mirroredDatabases/{mirroreddatabaseid}/stopMirroring\" \n","response = client.post(stop)\n","display(response)\n"],"outputs":[{"output_type":"display_data","data":{"application/vnd.livy.statement-meta+json":{"spark_pool":null,"statement_id":9,"statement_ids":[9],"state":"finished","livy_statement_state":"available","session_id":"ecaa02bd-adf6-46fb-99d1-c64888ae1dd1","normalized_state":"finished","queued_time":"2025-01-22T13:27:47.4993497Z","session_start_time":null,"execution_start_time":"2025-01-22T13:27:47.66729Z","execution_finish_time":"2025-01-22T13:27:51.8117522Z","parent_msg_id":"064a9a6e-6d2f-4fba-a2c8-b8aaa4f4630a"},"text/plain":"StatementMeta(, ecaa02bd-adf6-46fb-99d1-c64888ae1dd1, 9, Finished, Available, Finished)"},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"<Response [200]>"},"metadata":{}}],"execution_count":7,"metadata":{"microsoft":{"language":"python","language_group":"synapse_pyspark"}},"id":"9db0a0e3-566b-4d9a-82e0-33a733f91ed1"},{"cell_type":"code","source":["\n","# Start\n","# POST https://api.fabric.microsoft.com/v1/workspaces/<your workspace ID>/mirroredDatabases/<mirrored database ID>/startMirroring\n","\n","start = f\"v1/workspaces/{workspace_id}/mirroredDatabases/{mirroreddatabaseid}/startMirroring\" \n","response = client.post(start)\n","display(response)\n"],"outputs":[{"output_type":"display_data","data":{"application/vnd.livy.statement-meta+json":{"spark_pool":null,"statement_id":10,"statement_ids":[10],"state":"finished","livy_statement_state":"available","session_id":"ecaa02bd-adf6-46fb-99d1-c64888ae1dd1","normalized_state":"finished","queued_time":"2025-01-22T13:27:57.6823961Z","session_start_time":null,"execution_start_time":"2025-01-22T13:27:57.8487976Z","execution_finish_time":"2025-01-22T13:27:59.7434698Z","parent_msg_id":"e32fb1e1-9445-4c3d-b232-bc9682e467c5"},"text/plain":"StatementMeta(, ecaa02bd-adf6-46fb-99d1-c64888ae1dd1, 10, Finished, Available, Finished)"},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"<Response [200]>"},"metadata":{}}],"execution_count":8,"metadata":{"microsoft":{"language":"python","language_group":"synapse_pyspark"}},"id":"4b45f1f8-0b0b-43de-825b-c1c51cae0e3a"}],"metadata":{"kernel_info":{"name":"synapse_pyspark"},"kernelspec":{"name":"synapse_pyspark","language":"Python","display_name":"Synapse PySpark"},"language_info":{"name":"python"},"microsoft":{"language":"python","language_group":"synapse_pyspark","ms_spell_check":{"ms_spell_check_language":"en"}},"nteract":{"version":"[email protected]"},"spark_compute":{"compute_id":"/trident/default","session_options":{"conf":{"spark.synapse.nbs.session.timeout":"1200000"}}},"dependencies":{"lakehouse":{"default_lakehouse":"5b489503-4b3b-4fe3-aef7-ac8bdf09211e","known_lakehouses":[{"id":"5b489503-4b3b-4fe3-aef7-ac8bdf09211e"}],"default_lakehouse_name":"Backup_LH","default_lakehouse_workspace_id":"be3544c2-423d-46f9-b8bc-50b7c1fd7296"}}},"nbformat":4,"nbformat_minor":5} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment