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

Anfranci/add job operations #5956

Merged
merged 48 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
f57bc77
Merge remote-tracking branch 'origin/main' into anfranci/addJobOperat…
anandanthony Mar 3, 2023
5693d15
adding job operations for az cli
anandanthony Mar 8, 2023
8879deb
Merge remote-tracking branch 'origin/main' into anfranci/addJobOperat…
anandanthony Mar 8, 2023
14a7121
adding job operations for az cli
anandanthony Mar 8, 2023
801f748
adding job operations for az cli
anandanthony Mar 8, 2023
26bf2fc
Merge remote-tracking branch 'origin/main' into anfranci/addJobOperat…
anandanthony Mar 8, 2023
2250771
adding job operations for az cli | fix pylint issues
anandanthony Mar 8, 2023
fd493ed
adding job operations for az cli | fix pylint issues
anandanthony Mar 8, 2023
f503fc4
adding job operations for az cli
anandanthony Mar 10, 2023
1e038b4
Merge remote-tracking branch 'origin/main' into anfranci/addJobOperat…
anandanthony Mar 30, 2023
eabe9b9
add cli change for jobs
anandanthony Apr 4, 2023
2357314
Merge remote-tracking branch 'origin/main' into anfranci/addJobOperat…
anandanthony Apr 10, 2023
3fbb988
add Job Operations to Az Cli
anandanthony Apr 14, 2023
fe70aeb
Merge remote-tracking branch 'origin/main' into anfranci/addJobOperat…
anandanthony Apr 14, 2023
c6c007c
Merge remote-tracking branch 'origin/main' into anfranci/addJobOperat…
anandanthony Apr 20, 2023
690d648
add container app job operations
anandanthony Apr 25, 2023
0aee6e1
add job operations to Cli
anandanthony Apr 26, 2023
767a24a
add job operations to Cli | merge main
anandanthony Apr 26, 2023
96d510e
add job operations to Cli | merge main
anandanthony Apr 26, 2023
c2cb727
add job operations to Cli | merge main
anandanthony Apr 26, 2023
a3c3ccc
add job operations to Cli | merge main
anandanthony Apr 26, 2023
bc7fdb0
add job operations to Cli | merge main
anandanthony Apr 26, 2023
25d8fe3
add containerapp job to azcli
anandanthony May 6, 2023
4fbaea3
add containerapp job to azcli | merge main
anandanthony May 6, 2023
38cc3f7
add containerapp job to azcli
anandanthony May 9, 2023
746f477
add containerapp job to azcli | merge main
anandanthony May 9, 2023
661f965
add containerapp job to azcli
anandanthony May 9, 2023
ca2b8d4
add containerapp job to azcli
anandanthony May 9, 2023
e049d2b
add containerapp job to azcli
anandanthony May 9, 2023
5f42538
add containerapp job to azcli
anandanthony May 9, 2023
f8290f8
add containerapp job to azcli
anandanthony May 9, 2023
8ee9950
add containerapp job to azcli
anandanthony May 9, 2023
8119600
add containerapp job to azcli
anandanthony May 9, 2023
14d582c
add containerapp job to azcli
anandanthony May 12, 2023
f523e8d
add containerapp job to azcli
anandanthony May 16, 2023
76a9407
add containerapp job to azcli
anandanthony May 16, 2023
098a165
add containerapp job to azcli
anandanthony May 16, 2023
78ad306
add containerapp job to azcli
anandanthony May 17, 2023
ba7a3b2
add containerapp job to azcli | merge main
anandanthony May 17, 2023
fb782dc
add containerapp job to azcli | address comments
anandanthony May 17, 2023
d65f1ea
add containerapp job to azcli
anandanthony May 17, 2023
ab90b6e
add containerapp job to azcli
anandanthony May 18, 2023
380a3e7
add containerapp job to azcli
anandanthony May 18, 2023
39a462f
Merge remote-tracking branch 'origin/main' into anfranci/addJobOperat…
anandanthony May 18, 2023
943b73e
add containerapp job to azcli
anandanthony May 18, 2023
49f53b5
add containerapp job to azcli
anandanthony May 18, 2023
1efb609
add containerapp job to azcli | merge main
anandanthony May 18, 2023
2692885
add containerapp job to azcli | merge main
anandanthony May 18, 2023
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
3 changes: 3 additions & 0 deletions src/containerapp/azext_containerapp/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def handle_raw_exception(e):
if "Unknown properties Name in Microsoft.ContainerApps.WebApi.Views.Version20221101Preview.WorkloadProfile are not supported" in stringErr:
raise CLIInternalError("Bad Request: Workload profile name is not yet supported in this region.")

if "Error starting job" in stringErr:
raise CLIInternalError("There was an error starting the job execution. Please check input parameters and try again.")

if "{" in stringErr and "}" in stringErr:
jsonError = stringErr[stringErr.index("{"):stringErr.rindex("}") + 1]
jsonError = json.loads(jsonError)
Expand Down
248 changes: 248 additions & 0 deletions src/containerapp/azext_containerapp/_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,254 @@ def list(cls, cmd, resource_group_name, env_name):
return r.json().get("value")


class ContainerAppsJobClient():
@classmethod
def create_or_update(cls, cmd, resource_group_name, name, containerapp_job_envelope, no_wait=False):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
api_version = CURRENT_API_VERSION
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/jobs/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
api_version)

r = send_raw_request(cmd.cli_ctx, "PUT", request_url, body=json.dumps(containerapp_job_envelope))

if no_wait:
return r.json()
elif r.status_code == 201:
anandanthony marked this conversation as resolved.
Show resolved Hide resolved
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/jobs/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
api_version)
return poll(cmd, request_url, "inprogress")

return r.json()

@classmethod
def update(cls, cmd, resource_group_name, name, containerapp_job_envelope, no_wait=False):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager

api_version = CURRENT_API_VERSION

sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/jobs/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
api_version)

r = send_raw_request(cmd.cli_ctx, "PATCH", request_url, body=json.dumps(containerapp_job_envelope))

if no_wait:
return r.json()
elif r.status_code == 202:
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/jobs/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
api_version)
return poll(cmd, request_url, "inprogress")
anandanthony marked this conversation as resolved.
Show resolved Hide resolved

return r.json()

@classmethod
def show(cls, cmd, resource_group_name, name):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
api_version = CURRENT_API_VERSION
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/jobs/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
api_version)

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

@classmethod
def list_by_subscription(cls, cmd, formatter=lambda x: x):
app_list = []

management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
api_version = CURRENT_API_VERSION
sub_id = get_subscription_id(cmd.cli_ctx)
request_url = "{}/subscriptions/{}/providers/Microsoft.App/jobs?api-version={}".format(
management_hostname.strip('/'),
sub_id,
api_version)

r = send_raw_request(cmd.cli_ctx, "GET", request_url)
j = r.json()
for app in j["value"]:
formatted = formatter(app)
app_list.append(formatted)

while j.get("nextLink") is not None:
request_url = j["nextLink"]
r = send_raw_request(cmd.cli_ctx, "GET", request_url)
j = r.json()
for app in j["value"]:
formatted = formatter(app)
app_list.append(formatted)

return app_list

@classmethod
def list_by_resource_group(cls, cmd, resource_group_name, formatter=lambda x: x):
app_list = []

management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
api_version = CURRENT_API_VERSION
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/jobs?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
api_version)

r = send_raw_request(cmd.cli_ctx, "GET", request_url)
j = r.json()
for app in j["value"]:
formatted = formatter(app)
app_list.append(formatted)

while j.get("nextLink") is not None:
request_url = j["nextLink"]
r = send_raw_request(cmd.cli_ctx, "GET", request_url)
j = r.json()
for app in j["value"]:
formatted = formatter(app)
app_list.append(formatted)
anandanthony marked this conversation as resolved.
Show resolved Hide resolved

return app_list

@classmethod
def delete(cls, cmd, resource_group_name, name, no_wait=False):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
api_version = CURRENT_API_VERSION
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/jobs/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
api_version)

r = send_raw_request(cmd.cli_ctx, "DELETE", request_url)

if no_wait:
return # API doesn't return JSON (it returns no content)
elif r.status_code in [200, 201, 202, 204]:
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/jobs/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
api_version)

if r.status_code == 202:
from azure.cli.core.azclierror import ResourceNotFoundError
try:
poll(cmd, request_url, "cancelled")
except ResourceNotFoundError:
pass
logger.warning('Containerapps job successfully deleted')
anandanthony marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def start_job(cls, cmd, resource_group_name, name, containerapp_job_start_envelope):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
api_version = CURRENT_API_VERSION
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/jobs/{}/start?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
api_version)
if containerapp_job_start_envelope is None:
r = send_raw_request(cmd.cli_ctx, "POST", request_url)
else:
r = send_raw_request(cmd.cli_ctx, "POST", request_url, body=json.dumps(containerapp_job_start_envelope))

return r.json()

@classmethod
def stop_job(cls, cmd, resource_group_name, name, job_execution_name, job_execution_names=None):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
api_version = CURRENT_API_VERSION
sub_id = get_subscription_id(cmd.cli_ctx)

if not job_execution_name:
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/jobs/{}/stop?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
api_version)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/jobs/{}/stop/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
job_execution_name,
api_version)

r = send_raw_request(cmd.cli_ctx, "POST", request_url, body=json.dumps(job_execution_names))
return r.json()

@classmethod
def get_executions(cls, cmd, resource_group_name, name):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
api_version = CURRENT_API_VERSION
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/jobs/{}/executions?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
api_version)

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

@classmethod
def get_single_execution(cls, cmd, resource_group_name, name, job_execution_name):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
api_version = CURRENT_API_VERSION
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/jobs/{}/executions/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
job_execution_name,
api_version)

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


class GitHubActionClient():
@classmethod
def create_or_update(cls, cmd, resource_group_name, name, github_action_envelope, headers, no_wait=False):
Expand Down
4 changes: 2 additions & 2 deletions src/containerapp/azext_containerapp/_dev_service_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ._constants import (
CONTAINER_APPS_RP
)
from ._utils import register_provider_if_needed, validate_container_app_name
from ._utils import register_provider_if_needed, validate_container_app_name, AppType


class DevServiceUtils:
Expand All @@ -19,7 +19,7 @@ def create_service(cmd, service_name, environment_name, resource_group_name, no_
from .custom import create_containerapp

register_provider_if_needed(cmd, CONTAINER_APPS_RP)
validate_container_app_name(service_name)
validate_container_app_name(service_name, AppType.ContainerApp.name)

env_info = None

Expand Down
Loading