Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Container Apps session execute new api-version #8249

Merged
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ upcoming
* 'az containerapp create': Fix Role assignment error when the default Azure Container Registry could not be found
* Upgrade api-version to 2024-10-02-preview
* 'az containerapp create/update': `--yaml` support property pollingInterval and cooldownPeriod
* 'az containerapp session code-interpreter upload-file/list-files/show-file-content/show-file-metadata/delete-file': Support `--path` to specify the path of code interpreter session file resource
* 'az containerapp session code-interpreter': Update response payload format for api-version 2024-10-02-preview
* 'az containerapp env maintenance-config add/update/list/remove': Support environment maintenance config management
* 'az containerapp sessionpool create': Support managed identity when create session pool with --mi-system-assigned --mi-user-assigned

Expand Down
38 changes: 27 additions & 11 deletions src/containerapp/azext_containerapp/_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
logger = get_logger(__name__)

PREVIEW_API_VERSION = "2024-10-02-preview"
SESSION_API_VERSION = "2024-02-02-preview"
POLLING_TIMEOUT = 1500 # how many seconds before exiting
POLLING_SECONDS = 2 # how many seconds between requests
POLLING_TIMEOUT_FOR_MANAGED_CERTIFICATE = 1500 # how many seconds before exiting
Expand Down Expand Up @@ -1158,11 +1157,11 @@ def list_by_subscription(cls, cmd, formatter=lambda x: x):


class SessionCodeInterpreterPreviewClient():
api_version = SESSION_API_VERSION
api_version = PREVIEW_API_VERSION

@classmethod
def execute(cls, cmd, identifier, code_interpreter_envelope, session_pool_endpoint, no_wait=False):
url_fmt = "{}/code/execute?identifier={}&api-version={}"
url_fmt = "{}/executions?identifier={}&api-version={}"
request_url = url_fmt.format(
session_pool_endpoint,
identifier,
Expand All @@ -1181,10 +1180,11 @@ def execute(cls, cmd, identifier, code_interpreter_envelope, session_pool_endpoi
return r.json()

@classmethod
def upload(cls, cmd, identifier, filepath, session_pool_endpoint, no_wait=False):
url_fmt = "{}/files/upload?identifier={}&api-version={}"
def upload(cls, cmd, identifier, filepath, path, session_pool_endpoint, no_wait=False):
url_fmt = "{}/files?{}identifier={}&api-version={}"
request_url = url_fmt.format(
session_pool_endpoint,
f"path={path}&" if path is not None else "",
identifier,
cls.api_version)

Expand Down Expand Up @@ -1221,11 +1221,13 @@ def upload(cls, cmd, identifier, filepath, session_pool_endpoint, no_wait=False)
return r.json()

@classmethod
def show_file_content(cls, cmd, identifier, filename, session_pool_endpoint):
url_fmt = "{}/files/content/{}?identifier={}&api-version={}"
def show_file_content(cls, cmd, identifier, filename, path, session_pool_endpoint):
path, filename = cls.extract_path_from_filename(path, filename)
url_fmt = "{}/files/{}/content?{}identifier={}&api-version={}"

This comment was marked as resolved.

This comment was marked as resolved.

request_url = url_fmt.format(
session_pool_endpoint,
filename,
f"path={path}&" if path is not None else "",
identifier,
cls.api_version)

Expand All @@ -1236,11 +1238,13 @@ def show_file_content(cls, cmd, identifier, filename, session_pool_endpoint):
return json.dumps(r.content.decode())

@classmethod
def show_file_metadata(cls, cmd, identifier, filename, session_pool_endpoint):
url_fmt = "{}/files/{}?identifier={}&api-version={}"
def show_file_metadata(cls, cmd, identifier, filename, path, session_pool_endpoint):
path, filename = cls.extract_path_from_filename(path, filename)
url_fmt = "{}/files/{}?{}identifier={}&api-version={}"
request_url = url_fmt.format(
session_pool_endpoint,
filename,
f"path={path}&" if path is not None else "",
identifier,
cls.api_version)
logger.warning(request_url)
Expand All @@ -1249,11 +1253,13 @@ def show_file_metadata(cls, cmd, identifier, filename, session_pool_endpoint):
return r.json()

@classmethod
def delete_file(cls, cmd, identifier, filename, session_pool_endpoint, no_wait=False):
url_fmt = "{}/files/{}?identifier={}&api-version={}"
def delete_file(cls, cmd, identifier, filename, path, session_pool_endpoint, no_wait=False):
path, filename = cls.extract_path_from_filename(path, filename)
url_fmt = "{}/files/{}?{}identifier={}&api-version={}"
request_url = url_fmt.format(
session_pool_endpoint,
filename,
f"path={path}&" if path is not None else "",
identifier,
cls.api_version)

Expand Down Expand Up @@ -1281,6 +1287,16 @@ def list_files(cls, cmd, identifier, path, session_pool_endpoint):

r = send_raw_request(cmd.cli_ctx, "GET", request_url, resource=SESSION_RESOURCE)
return r.json()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI style failed
src/containerapp/azext_containerapp/_clients.py:1290:0: C0303: Trailing whitespace (trailing-whitespace)

remove the whitespece

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed

@staticmethod
def extract_path_from_filename(path, filename):
if '/' not in filename:
return path, filename
path_in_filename, filename = filename.rsplit('/', 1)
if path is None:
return path_in_filename, filename
else:
return path.rstrip("/") + "/" + path_in_filename.lstrip('/'), filename


class DotNetComponentPreviewClient():
Expand Down
10 changes: 5 additions & 5 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@
- name: Upload a file to a session.
text: |
az containerapp session code-interpreter upload-file -n MySessionPool -g MyResourceGroup --identifier MySession \\
--filepath example.txt
--filepath example.txt --path /
"""

helps['containerapp session code-interpreter show-file-content'] = """
Expand All @@ -1993,7 +1993,7 @@
examples:
- name: Show content of file.
text: az containerapp session code-interpreter show-file-content -n MySessionPool -g MyResourceGroup --identifier MySession \\
--filename example.txt
--filename example.txt --path /
"""

helps['containerapp session code-interpreter show-file-metadata'] = """
Expand All @@ -2002,7 +2002,7 @@
examples:
- name: Show the meta-data details of a file uploaded to a session.
text: az containerapp session code-interpreter show-file-metadata -n MySessionPool -g MyResourceGroup --identifier MySession \\
--filename example.txt
--filename example.txt --path /
"""

helps['containerapp session code-interpreter delete-file'] = """
Expand All @@ -2011,7 +2011,7 @@
examples:
- name: Delete a file .
text: az containerapp session code-interpreter delete-file -n MySessionPool -g MyResourceGroup --identifier MySession \\
--filename example.txt
--filename example.txt --path /
"""

helps['containerapp session code-interpreter list-files'] = """
Expand All @@ -2020,7 +2020,7 @@
examples:
- name: List files uploaded in a code-interpreter session.
text: |
az containerapp session code-interpreter list-files -n MySessionPool -g MyResourceGroup --identifier MySession
az containerapp session code-interpreter list-files -n MySessionPool -g MyResourceGroup --identifier MySession --path /
"""

helps['containerapp java'] = """
Expand Down
11 changes: 4 additions & 7 deletions src/containerapp/azext_containerapp/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,10 @@
}

SessionCodeInterpreterExecution = {
"properties": {
"identifier": None,
"codeInputType": None,
"executionType": None,
"code": None,
"timeoutInSeconds": None
}
"codeInputType": None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with one property identifier removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backend Api is switched to use 2024-10-02-preview in this PR, in which the identifier property is removed in the payload, but still exists in the query parameter.

"executionType": None,
"code": None,
"timeoutInSeconds": None
}

DaprComponentResiliency = {
Expand Down
2 changes: 1 addition & 1 deletion src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def load_arguments(self, _):
with self.argument_context('containerapp session code-interpreter', arg_group='file') as c:
c.argument('filename', help="The file to delete or show from the session")
c.argument('filepath', help="The local path to the file to upload to the session")
c.argument('path', help="The path to list files from the session")
c.argument('path', help="The path of files in the session")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend to add an example for --path in the _help.py

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


with self.argument_context('containerapp session code-interpreter', arg_group='execute') as c:
c.argument('code', help="The code to execute in the code interpreter session")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,10 @@ def validate_arguments(self):
"sessionPools")

def construct_payload(self):
self.session_code_interpreter_def["properties"]["identifier"] = self.get_argument_identifier()

self.session_code_interpreter_def["properties"]["codeInputType"] = "inline"
self.session_code_interpreter_def["properties"]["executionType"] = "synchronous"

if self.get_argument_timeout_in_seconds() is not None:
self.session_code_interpreter_def["properties"]["timeoutInSeconds"] = self.get_argument_timeout_in_seconds()
else:
self.session_code_interpreter_def["properties"]["timeoutInSeconds"] = 60
self.session_code_interpreter_def["properties"]["code"] = self.get_argument_code()
self.session_code_interpreter_def["codeInputType"] = "inline"
self.session_code_interpreter_def["executionType"] = "synchronous"
self.session_code_interpreter_def["timeoutInSeconds"] = self.get_argument_timeout_in_seconds()
self.session_code_interpreter_def["code"] = self.get_argument_code()

def execute(self):
try:
Expand All @@ -111,6 +105,7 @@ def upload(self):
cmd=self.cmd,
identifier=self.get_argument_identifier(),
filepath=self.get_argument_filepath(),
path=self.get_argument_path(),
session_pool_endpoint=self.get_sessionpool_endpoint(),
no_wait=self.get_argument_no_wait())
except Exception as e:
Expand All @@ -122,6 +117,7 @@ def show_file_content(self):
cmd=self.cmd,
identifier=self.get_argument_identifier(),
filename=self.get_argument_filename(),
path=self.get_argument_path(),
session_pool_endpoint=self.get_sessionpool_endpoint())
except Exception as e:
handle_raw_exception(e)
Expand All @@ -132,6 +128,7 @@ def show_file_metadata(self):
cmd=self.cmd,
identifier=self.get_argument_identifier(),
filename=self.get_argument_filename(),
path=self.get_argument_path(),
session_pool_endpoint=self.get_sessionpool_endpoint())
except Exception as e:
handle_raw_exception(e)
Expand All @@ -152,6 +149,7 @@ def delete_file(self):
cmd=self.cmd,
identifier=self.get_argument_identifier(),
filename=self.get_argument_filename(),
path=self.get_argument_path(),
session_pool_endpoint=self.get_sessionpool_endpoint(),
no_wait=self.get_argument_no_wait())
except Exception as e:
Expand Down
4 changes: 4 additions & 0 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2994,6 +2994,7 @@ def upload_session_code_interpreter(cmd,
resource_group_name,
identifier,
filepath,
path=None,
session_pool_location=None):
raw_parameters = locals()
session_code_interpreter_decorator = SessionCodeInterpreterCommandsPreviewDecorator(
Expand All @@ -3014,6 +3015,7 @@ def show_file_content_session_code_interpreter(cmd,
resource_group_name,
identifier,
filename,
path=None,
session_pool_location=None):
raw_parameters = locals()
session_code_interpreter_decorator = SessionCodeInterpreterCommandsPreviewDecorator(
Expand All @@ -3034,6 +3036,7 @@ def show_file_metadata_session_code_interpreter(cmd,
resource_group_name,
identifier,
filename,
path=None,
session_pool_location=None):
raw_parameters = locals()
session_code_interpreter_decorator = SessionCodeInterpreterCommandsPreviewDecorator(
Expand Down Expand Up @@ -3074,6 +3077,7 @@ def delete_file_session_code_interpreter(cmd,
resource_group_name,
identifier,
filename,
path=None,
session_pool_location=None):
raw_parameters = locals()
session_code_interpreter_decorator = SessionCodeInterpreterCommandsPreviewDecorator(
Expand Down
Loading
Loading