Skip to content

Commit

Permalink
Support scale property on java component (#7911)
Browse files Browse the repository at this point in the history
  • Loading branch information
Caoxuyang authored Aug 29, 2024
1 parent ab4e4e1 commit c93c410
Show file tree
Hide file tree
Showing 16 changed files with 38,490 additions and 44,338 deletions.
2 changes: 2 additions & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Release History
upcoming
++++++

* 'az containerapp env java-component`: Support --min-replicas and --max-replicas for Java components'

0.3.55
++++++
* 'az containerapp create': Support --registry-identity to use Environment identity for ACR authentication.
Expand Down
3 changes: 2 additions & 1 deletion src/containerapp/azext_containerapp/_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
logger = get_logger(__name__)

PREVIEW_API_VERSION = "2024-02-02-preview"
AUG_PREVIEW_API_VERSION = "2024-08-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 @@ -886,7 +887,7 @@ def list_auth_token(cls, cmd, builder_name, build_name, resource_group_name, loc


class JavaComponentPreviewClient():
api_version = PREVIEW_API_VERSION
api_version = AUG_PREVIEW_API_VERSION

@classmethod
def create(cls, cmd, resource_group_name, environment_name, name, java_component_envelope, no_wait=False):
Expand Down
12 changes: 12 additions & 0 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,12 @@
-n MyJavaComponentName \\
--environment MyEnvironment \\
--configuration PropertyName1=Value1 PropertyName2=Value2
- name: Create a Config Server for Spring with multiple replicas.
text: |
az containerapp env java-component config-server-for-spring create -g MyResourceGroup \\
-n MyJavaComponentName \\
--environment MyEnvironment \\
--min-replicas 2 --max-replicas 2
"""

helps['containerapp env java-component config-server-for-spring delete'] = """
Expand Down Expand Up @@ -1503,6 +1509,12 @@
-n MyJavaComponentName \\
--environment MyEnvironment \\
--configuration PropertyName1=Value1 PropertyName2=Value2
- name: Create an Admin for Spring with multiple replicas.
text: |
az containerapp env java-component admin-for-spring create -g MyResourceGroup \\
-n MyJavaComponentName \\
--environment MyEnvironment \\
--min-replicas 2 --max-replicas 2
"""

helps['containerapp env java-component admin-for-spring delete'] = """
Expand Down
18 changes: 10 additions & 8 deletions src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def load_arguments(self, _):
c.argument('service_principal_tenant_id', help='The service principal tenant ID. Used by GitHub Actions to authenticate with Azure.', options_list=["--service-principal-tenant-id", "--sp-tid"])

# Runtime
with self.argument_context('containerapp create', arg_group='Runtime', is_preview=True) as c:
c.argument('runtime', arg_type=get_enum_type(['generic', 'java']), help='The runtime of the container app.', is_preview=True)
c.argument('enable_java_metrics', arg_type=get_three_state_flag(), help='Boolean indicating whether to enable Java metrics for the app. Only applicable for Java runtime.', is_preview=True)
c.argument('enable_java_agent', arg_type=get_three_state_flag(), help='Boolean indicating whether to enable Java agent for the app. Only applicable for Java runtime.', is_preview=True)
with self.argument_context('containerapp create', arg_group='Runtime') as c:
c.argument('runtime', arg_type=get_enum_type(['generic', 'java']), help='The runtime of the container app.')
c.argument('enable_java_metrics', arg_type=get_three_state_flag(), help='Boolean indicating whether to enable Java metrics for the app. Only applicable for Java runtime.')
c.argument('enable_java_agent', arg_type=get_three_state_flag(), help='Boolean indicating whether to enable Java agent for the app. Only applicable for Java runtime.')

# Source and Artifact
with self.argument_context('containerapp update') as c:
Expand All @@ -71,10 +71,10 @@ def load_arguments(self, _):
c.argument('unbind_service_bindings', nargs='*', options_list=['--unbind'], help="Space separated list of services, bindings or Java components to be removed from this app. e.g. BIND_NAME1...")

# Runtime
with self.argument_context('containerapp update', arg_group='Runtime', is_preview=True) as c:
c.argument('runtime', arg_type=get_enum_type(['generic', 'java']), help='The runtime of the container app.', is_preview=True)
c.argument('enable_java_metrics', arg_type=get_three_state_flag(), help='Boolean indicating whether to enable Java metrics for the app. Only applicable for Java runtime.', is_preview=True)
c.argument('enable_java_agent', arg_type=get_three_state_flag(), help='Boolean indicating whether to enable Java agent for the app. Only applicable for Java runtime.', is_preview=True)
with self.argument_context('containerapp update', arg_group='Runtime') as c:
c.argument('runtime', arg_type=get_enum_type(['generic', 'java']), help='The runtime of the container app.')
c.argument('enable_java_metrics', arg_type=get_three_state_flag(), help='Boolean indicating whether to enable Java metrics for the app. Only applicable for Java runtime.')
c.argument('enable_java_agent', arg_type=get_three_state_flag(), help='Boolean indicating whether to enable Java agent for the app. Only applicable for Java runtime.')

with self.argument_context('containerapp env', arg_group='Virtual Network') as c:
c.argument('infrastructure_resource_group', options_list=['--infrastructure-resource-group', '-i'], help='Name for resource group that will contain infrastructure resources. If not provided, a resource group name will be generated.', is_preview=True)
Expand Down Expand Up @@ -362,6 +362,8 @@ def load_arguments(self, _):
c.argument('service_bindings', nargs='*', options_list=['--bind'], help="Space separated list of services, bindings or other Java components to be connected to this Java Component. e.g. SVC_NAME1[:BIND_NAME1] SVC_NAME2[:BIND_NAME2]...")
c.argument('unbind_service_bindings', nargs='*', options_list=['--unbind'], help="Space separated list of services, bindings or Java components to be removed from this Java Component. e.g. BIND_NAME1...")
c.argument('configuration', nargs="*", help="Java component configuration. Configuration must be in format \"<propertyName>=<value>\" \"<propertyName>=<value>\"...")
c.argument('min_replicas', type=int, help="Minimum number of replicas to run for the Java component.")
c.argument('max_replicas', type=int, help="Maximum number of replicas to run for the Java component.")

with self.argument_context('containerapp job logs show') as c:
c.argument('follow', help="Print logs in real time if present.", arg_type=get_three_state_flag())
Expand Down
4 changes: 2 additions & 2 deletions src/containerapp/azext_containerapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def load_command_table(self, args):
g.custom_command('set', 'connected_env_create_or_update_storage', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('remove', 'connected_env_remove_storage', supports_no_wait=True, confirmation=True, exception_handler=ex_handler_factory())

with self.command_group('containerapp env java-component', is_preview=True) as g:
with self.command_group('containerapp env java-component') as g:
g.custom_command('list', 'list_java_components')

with self.command_group('containerapp env java-component spring-cloud-config',
Expand Down Expand Up @@ -252,7 +252,7 @@ def load_command_table(self, args):
g.custom_show_command('list-files', 'list_files_session_code_interpreter')
g.custom_command('delete-file', 'delete_file_session_code_interpreter', confirmation=True, supports_no_wait=True)

with self.command_group('containerapp java logger', is_preview=True) as g:
with self.command_group('containerapp java logger') as g:
g.custom_command('set', 'create_or_update_java_logger', supports_no_wait=True)
g.custom_command('delete', 'delete_java_logger', supports_no_wait=True)
g.custom_show_command('show', 'show_java_logger')
36 changes: 18 additions & 18 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2309,7 +2309,7 @@ def delete_java_component(cmd, java_component_name, environment_name, resource_g
return java_component_decorator.delete()


def create_java_component(cmd, java_component_name, environment_name, resource_group_name, target_java_component_type, configuration, service_bindings, unbind_service_bindings, no_wait):
def create_java_component(cmd, java_component_name, environment_name, resource_group_name, target_java_component_type, configuration, service_bindings, unbind_service_bindings, min_replicas, max_replicas, no_wait):
raw_parameters = locals()
java_component_decorator = JavaComponentDecorator(
cmd=cmd,
Expand All @@ -2321,7 +2321,7 @@ def create_java_component(cmd, java_component_name, environment_name, resource_g
return java_component_decorator.create()


def update_java_component(cmd, java_component_name, environment_name, resource_group_name, target_java_component_type, configuration, service_bindings, unbind_service_bindings, no_wait):
def update_java_component(cmd, java_component_name, environment_name, resource_group_name, target_java_component_type, configuration, service_bindings, unbind_service_bindings, min_replicas, max_replicas, no_wait):
raw_parameters = locals()
java_component_decorator = JavaComponentDecorator(
cmd=cmd,
Expand All @@ -2333,12 +2333,12 @@ def update_java_component(cmd, java_component_name, environment_name, resource_g
return java_component_decorator.update()


def create_config_server_for_spring(cmd, java_component_name, environment_name, resource_group_name, configuration=None, unbind_service_bindings=None, service_bindings=None, no_wait=False):
return create_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_CONFIG, configuration, service_bindings, unbind_service_bindings, no_wait)
def create_config_server_for_spring(cmd, java_component_name, environment_name, resource_group_name, configuration=None, unbind_service_bindings=None, service_bindings=None, min_replicas=1, max_replicas=1, no_wait=False):
return create_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_CONFIG, configuration, service_bindings, unbind_service_bindings, min_replicas, max_replicas, no_wait)


def update_config_server_for_spring(cmd, java_component_name, environment_name, resource_group_name, configuration=None, unbind_service_bindings=None, service_bindings=None, no_wait=False):
return update_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_CONFIG, configuration, service_bindings, unbind_service_bindings, no_wait)
def update_config_server_for_spring(cmd, java_component_name, environment_name, resource_group_name, configuration=None, unbind_service_bindings=None, service_bindings=None, min_replicas=None, max_replicas=None, no_wait=False):
return update_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_CONFIG, configuration, service_bindings, unbind_service_bindings, min_replicas, max_replicas, no_wait)


def show_config_server_for_spring(cmd, java_component_name, environment_name, resource_group_name):
Expand All @@ -2349,12 +2349,12 @@ def delete_config_server_for_spring(cmd, java_component_name, environment_name,
return delete_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_CONFIG, no_wait)


def create_eureka_server_for_spring(cmd, java_component_name, environment_name, resource_group_name, configuration=None, unbind_service_bindings=None, service_bindings=None, no_wait=False):
return create_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_EUREKA, configuration, service_bindings, unbind_service_bindings, no_wait)
def create_eureka_server_for_spring(cmd, java_component_name, environment_name, resource_group_name, configuration=None, unbind_service_bindings=None, service_bindings=None, min_replicas=1, max_replicas=1, no_wait=False):
return create_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_EUREKA, configuration, service_bindings, unbind_service_bindings, min_replicas, max_replicas, no_wait)


def update_eureka_server_for_spring(cmd, java_component_name, environment_name, resource_group_name, configuration=None, unbind_service_bindings=None, service_bindings=None, no_wait=False):
return update_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_EUREKA, configuration, service_bindings, unbind_service_bindings, no_wait)
def update_eureka_server_for_spring(cmd, java_component_name, environment_name, resource_group_name, configuration=None, unbind_service_bindings=None, service_bindings=None, min_replicas=None, max_replicas=None, no_wait=False):
return update_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_EUREKA, configuration, service_bindings, unbind_service_bindings, min_replicas, max_replicas, no_wait)


def show_eureka_server_for_spring(cmd, java_component_name, environment_name, resource_group_name):
Expand All @@ -2365,12 +2365,12 @@ def delete_eureka_server_for_spring(cmd, java_component_name, environment_name,
return delete_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_EUREKA, no_wait)


def create_nacos(cmd, java_component_name, environment_name, resource_group_name, configuration=None, service_bindings=None, unbind_service_bindings=None, no_wait=False):
return create_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_NACOS, configuration, service_bindings, unbind_service_bindings, no_wait)
def create_nacos(cmd, java_component_name, environment_name, resource_group_name, configuration=None, service_bindings=None, unbind_service_bindings=None, min_replicas=1, max_replicas=1, no_wait=False):
return create_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_NACOS, configuration, service_bindings, unbind_service_bindings, min_replicas, max_replicas, no_wait)


def update_nacos(cmd, java_component_name, environment_name, resource_group_name, configuration=None, service_bindings=None, unbind_service_bindings=None, no_wait=False):
return update_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_NACOS, configuration, service_bindings, unbind_service_bindings, no_wait)
def update_nacos(cmd, java_component_name, environment_name, resource_group_name, configuration=None, service_bindings=None, unbind_service_bindings=None, min_replicas=None, max_replicas=None, no_wait=False):
return update_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_NACOS, configuration, service_bindings, unbind_service_bindings, min_replicas, max_replicas, no_wait)


def show_nacos(cmd, java_component_name, environment_name, resource_group_name):
Expand All @@ -2381,12 +2381,12 @@ def delete_nacos(cmd, java_component_name, environment_name, resource_group_name
return delete_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_NACOS, no_wait)


def create_admin_for_spring(cmd, java_component_name, environment_name, resource_group_name, configuration=None, service_bindings=None, unbind_service_bindings=None, no_wait=False):
return create_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_ADMIN, configuration, service_bindings, unbind_service_bindings, no_wait)
def create_admin_for_spring(cmd, java_component_name, environment_name, resource_group_name, configuration=None, service_bindings=None, unbind_service_bindings=None, min_replicas=1, max_replicas=1, no_wait=False):
return create_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_ADMIN, configuration, service_bindings, unbind_service_bindings, min_replicas, max_replicas, no_wait)


def update_admin_for_spring(cmd, java_component_name, environment_name, resource_group_name, configuration=None, service_bindings=None, unbind_service_bindings=None, no_wait=False):
return update_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_ADMIN, configuration, service_bindings, unbind_service_bindings, no_wait)
def update_admin_for_spring(cmd, java_component_name, environment_name, resource_group_name, configuration=None, service_bindings=None, unbind_service_bindings=None, min_replicas=None, max_replicas=None, no_wait=False):
return update_java_component(cmd, java_component_name, environment_name, resource_group_name, JAVA_COMPONENT_ADMIN, configuration, service_bindings, unbind_service_bindings, min_replicas, max_replicas, no_wait)


def show_admin_for_spring(cmd, java_component_name, environment_name, resource_group_name):
Expand Down
14 changes: 13 additions & 1 deletion src/containerapp/azext_containerapp/java_component_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long, broad-except, logging-format-interpolation, too-many-public-methods, too-many-boolean-expressions

from copy import deepcopy
from knack.log import get_logger
from msrestazure.tools import resource_id
from typing import Any, Dict
Expand All @@ -25,7 +26,7 @@
class JavaComponentDecorator(BaseResource):
def __init__(self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str):
super().__init__(cmd, client, raw_parameters, models)
self.java_component_def = JavaComponentModel
self.java_component_def = deepcopy(JavaComponentModel)

def get_argument_configuration(self):
return self.get_param("configuration")
Expand Down Expand Up @@ -54,10 +55,21 @@ def get_argument_service_bindings(self):
def get_argument_unbind_service_bindings(self):
return self.get_param("unbind_service_bindings")

def get_argument_min_replicas(self):
return self.get_param("min_replicas")

def get_argument_max_replicas(self):
return self.get_param("max_replicas")

def construct_payload(self):
self.java_component_def["properties"]["componentType"] = self.get_argument_target_java_component_type()
self.set_up_service_bindings()
self.set_up_unbind_service_bindings()
if self.get_argument_min_replicas() is not None and self.get_argument_max_replicas() is not None:
self.java_component_def["properties"]["scale"] = {
"minReplicas": self.get_argument_min_replicas(),
"maxReplicas": self.get_argument_max_replicas()
}

if self.get_argument_configuration() is not None:
configuration_list = []
Expand Down
Loading

0 comments on commit c93c410

Please sign in to comment.