Skip to content

Commit

Permalink
feat(plugin): store source app (#17892)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurijmikhalevich authored Jun 22, 2023
1 parent a789917 commit 60f2e3a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requirements/app/base.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lightning-cloud >=0.5.34
lightning-cloud >=0.5.37
packaging
typing-extensions >=4.0.0, <=4.4.0
deepdiff >=5.7.0, <6.3.1
Expand Down
6 changes: 6 additions & 0 deletions src/lightning/app/plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(self) -> None:
self.project_id = ""
self.cloudspace_id = ""
self.cluster_id = ""
self.source_app = ""

def run(self, *args: str, **kwargs: str) -> Optional[List[_Action]]:
"""Override with the logic to execute on the cloudspace."""
Expand Down Expand Up @@ -85,6 +86,7 @@ def run_job(self, name: str, app_entrypoint: str, env_vars: Dict[str, str] = {})
cloudspace_id=self.cloudspace_id,
name=name,
cluster_id=self.cluster_id,
source_app=self.source_app,
)
# Return a relative URL so it can be used with the NavigateTo action.
return url.replace(constants.get_lightning_cloud_url(), "")
Expand All @@ -94,7 +96,9 @@ def _setup(
project_id: str,
cloudspace_id: str,
cluster_id: str,
source_app: str,
) -> None:
self.source_app = source_app
self.project_id = project_id
self.cloudspace_id = cloudspace_id
self.cluster_id = cluster_id
Expand All @@ -107,6 +111,7 @@ class _Run(BaseModel):
cloudspace_id: str
cluster_id: str
plugin_arguments: Dict[str, str]
source_app: str


def _run_plugin(run: _Run) -> Dict[str, Any]:
Expand Down Expand Up @@ -162,6 +167,7 @@ def _run_plugin(run: _Run) -> Dict[str, Any]:
project_id=run.project_id,
cloudspace_id=run.cloudspace_id,
cluster_id=run.cluster_id,
source_app=run.source_app,
)
actions = plugin.run(**run.plugin_arguments) or []
return {"actions": [action.to_spec().to_dict() for action in actions]}
Expand Down
4 changes: 4 additions & 0 deletions src/lightning/app/runners/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def cloudspace_dispatch(
cloudspace_id: str,
name: str,
cluster_id: str,
source_app: Optional[str] = None,
) -> str:
"""Slim dispatch for creating runs from a cloudspace. This dispatch avoids resolution of some properties
such as the project and cluster IDs that are instead passed directly.
Expand Down Expand Up @@ -260,6 +261,7 @@ def cloudspace_dispatch(
V1LightningappInstanceState.RUNNING,
queue_server_type,
env_vars,
source_app=source_app,
)

return self._get_app_url(project, run_instance, "logs" if run.is_headless else "web-ui")
Expand Down Expand Up @@ -978,6 +980,7 @@ def _api_create_run_instance(
queue_server_type: Optional[V1QueueServerType] = None,
env_vars: Optional[List[V1EnvVar]] = None,
auth: Optional[V1LightningAuth] = None,
source_app: Optional[str] = None,
) -> Externalv1LightningappInstance:
"""Create a new instance of the given run with the given specification."""
return self.backend.client.cloud_space_service_create_lightning_run_instance(
Expand All @@ -991,6 +994,7 @@ def _api_create_run_instance(
queue_server_type=queue_server_type,
env=env_vars,
auth=auth,
source_app=source_app,
),
)

Expand Down
6 changes: 6 additions & 0 deletions tests/tests_app/plugin/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def run(self):
cloudspace_id="any",
cluster_id="any",
plugin_arguments={},
source_app="any",
),
"Error downloading plugin source:",
None,
Expand All @@ -97,6 +98,7 @@ def run(self):
cloudspace_id="any",
cluster_id="any",
plugin_arguments={},
source_app="any",
),
"Error extracting plugin source:",
None,
Expand All @@ -110,6 +112,7 @@ def run(self):
cloudspace_id="any",
cluster_id="any",
plugin_arguments={},
source_app="any",
),
"Error loading plugin:",
"plugin.py",
Expand All @@ -123,6 +126,7 @@ def run(self):
cloudspace_id="any",
cluster_id="any",
plugin_arguments={},
source_app="any",
),
"Error running plugin:",
"plugin.py",
Expand Down Expand Up @@ -203,6 +207,7 @@ def test_run_job(mock_requests, mock_cloud_runtime, mock_plugin_server, plugin_s
cloudspace_id="test_cloudspace_id",
cluster_id="test_cluster_id",
plugin_arguments={"name": "test_name", "entrypoint": "test_entrypoint"},
source_app="test_source_app",
)

mock_app = mock.MagicMock()
Expand Down Expand Up @@ -230,6 +235,7 @@ def test_run_job(mock_requests, mock_cloud_runtime, mock_plugin_server, plugin_s
cloudspace_id=body.cloudspace_id,
name="test_name",
cluster_id=body.cluster_id,
source_app=body.source_app,
)


Expand Down

0 comments on commit 60f2e3a

Please sign in to comment.