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

Add instance count for scg&api portal in service creation #42

Merged
merged 1 commit into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 9 additions & 7 deletions src/spring-cloud/azext_spring_cloud/_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ def spring_cloud_create(cmd, client, resource_group, name, location=None,
app_insights_key=None, app_insights=None, sampling_rate=None,
disable_app_insights=None, enable_java_agent=None,
enable_application_configuration_service=None, enable_service_registry=None,
enable_gateway=None, enable_api_portal=None,
enable_gateway=None, gateway_instance_count=None,
enable_api_portal=None, api_portal_instance_count=None,
sku=None, tags=None, build_pool_size=None, no_wait=False):
resource = _create_service(cmd, client, resource_group, name,
poller = _create_service(cmd, client, resource_group, name,
location=location,
service_runtime_subnet=service_runtime_subnet,
app_subnet=app_subnet,
Expand All @@ -54,19 +55,20 @@ def spring_cloud_create(cmd, client, resource_group, name, location=None,
app_network_resource_group=app_network_resource_group,
sku=sku,
tags=tags)

service = client.services.get(resource_group, name)
pollers = [
_update_default_build_agent_pool(cmd, client, resource_group, name, build_pool_size),
create_application_configuration_service(cmd, client, resource_group, name, enable_application_configuration_service),
create_service_registry(cmd, client, resource_group, name, enable_service_registry),
create_gateway(cmd, client, resource_group, name, enable_gateway),
create_api_portal(cmd, client, resource_group, name, enable_api_portal),
create_gateway(cmd, client, resource_group, name, enable_gateway, gateway_instance_count, service.sku),
create_api_portal(cmd, client, resource_group, name, enable_api_portal, api_portal_instance_count, service.sku),
create_default_buildpack_binding_for_application_insights(cmd, client, resource_group, name, location, app_insights_key,
app_insights, sampling_rate, disable_app_insights)
]
app_insights, sampling_rate, disable_app_insights)]
pollers = [x for x in pollers if x]
if not no_wait:
_wait_till_end(cmd, *pollers)
return resource
return poller


def app_create_enterprise(cmd, client, resource_group, service, name,
Expand Down
16 changes: 15 additions & 1 deletion src/spring-cloud/azext_spring_cloud/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
validate_buildpack_binding_not_exist, validate_buildpack_binding_exist,
validate_git_uri, validate_acs_patterns, validate_routes, validate_builder,
validate_build_pool_size, validate_builder_resource, validate_builder_create,
validate_builder_update)
validate_builder_update, validate_gateway_instance_count, validate_api_portal_instance_count)
from ._app_validator import (fulfill_deployment_param, active_deployment_exist, active_deployment_exist_under_app, ensure_not_active_deployment)
from ._utils import ApiType

Expand Down Expand Up @@ -97,15 +97,29 @@ def load_arguments(self, _):
is_preview=True,
help='Only support in enterprise tier now. Enable Service Registry.')
c.argument('enable_gateway',
arg_group="Spring Cloud Gateway",
arg_type=get_three_state_flag(),
default=False,
is_preview=True,
help='Only support in enterprise tier now. Enable Spring Cloud Gateway.')
c.argument('gateway_instance_count',
arg_group="Spring Cloud Gateway",
type=int,
validator=validate_gateway_instance_count,
is_preview=True,
help='Only support in enterprise tier now. Number of Spring Cloud Gateway instances.')
c.argument('enable_api_portal',
arg_group="API portal",
arg_type=get_three_state_flag(),
default=False,
is_preview=True,
help='Only support in enterprise tier now. Enable API portal.')
c.argument('api_portal_instance_count',
arg_group="API portal",
type=int,
validator=validate_api_portal_instance_count,
is_preview=True,
help='Only support in enterprise tier now. Number of API portal instances.')

with self.argument_context('spring-cloud update') as c:
c.argument('sku', arg_type=get_enum_type(['Basic', 'Standard', 'Enterprise']), validator=validate_sku, help='Name of SKU.')
Expand Down
12 changes: 9 additions & 3 deletions src/spring-cloud/azext_spring_cloud/_tanzu_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
DEFAULT_NAME = "default"
logger = get_logger(__name__)

def create_application_configuration_service(cmd, client, resource_group, service, enable_application_configuration_service=None):
def create_application_configuration_service(cmd, client, resource_group, service, enable_application_configuration_service):
if enable_application_configuration_service:
logger.warning(" - Creating Application Configuration Service ..")
acs_resource = models.ConfigurationServiceResource()
Expand All @@ -27,14 +27,17 @@ def create_service_registry(cmd, client, resource_group, service, enable_service
return client.service_registries.begin_create_or_update(resource_group, service, DEFAULT_NAME)


def create_gateway(cmd, client, resource_group, service, enable_gateway):
def create_gateway(cmd, client, resource_group, service, enable_gateway, gateway_instance_count, sku):
if enable_gateway:
logger.warning(" - Creating Spring Cloud Gateway ..")
gateway_resource = models.GatewayResource()
if gateway_instance_count and sku:
gateway_resource.sku = models.Sku(name=sku.name, tier=sku.tier,
capacity=gateway_instance_count)
return client.gateways.begin_create_or_update(resource_group, service, DEFAULT_NAME, gateway_resource)


def create_api_portal(cmd, client, resource_group, service, enable_api_portal):
def create_api_portal(cmd, client, resource_group, service, enable_api_portal, api_portal_instance_count, sku):
if enable_api_portal:
logger.warning(" - Creating API portal ..")
gateway_id = resource_id(
Expand All @@ -52,4 +55,7 @@ def create_api_portal(cmd, client, resource_group, service, enable_api_portal):
gateway_ids=[gateway_id]
)
)
if api_portal_instance_count and sku:
api_portal_resource.sku = models.Sku(name=sku.name, tier=sku.tier,
capacity=api_portal_instance_count)
return client.api_portals.begin_create_or_update(resource_group, service, DEFAULT_NAME, api_portal_resource)
12 changes: 12 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_validators_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,15 @@ def validate_builder_resource(namespace):
def validate_build_pool_size(namespace):
if _parse_sku_name(namespace.sku) != 'enterprise':
namespace.build_pool_size = None


def validate_gateway_instance_count(namespace):
if namespace.gateway_instance_count is not None:
if namespace.gateway_instance_count < 1:
raise CLIError("--gateway-instance-count must be greater than 0")


def validate_api_portal_instance_count(namespace):
if namespace.api_portal_instance_count is not None:
if namespace.api_portal_instance_count < 1:
raise CLIError("--api-portal-instance-count must be greater than 0")
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def spring_cloud_create(cmd, client, resource_group, name,
enable_application_configuration_service=None,
enable_service_registry=None,
enable_gateway=None,
gateway_instance_count=None,
enable_api_portal=None,
api_portal_instance_count=None,
sku=None,
tags=None,
build_pool_size=None,
Expand All @@ -51,7 +53,9 @@ def spring_cloud_create(cmd, client, resource_group, name,
enable_application_configuration_service=enable_application_configuration_service,
enable_service_registry=enable_service_registry,
enable_gateway=enable_gateway,
gateway_instance_count=gateway_instance_count,
enable_api_portal=enable_api_portal,
api_portal_instance_count=api_portal_instance_count,
sku=sku,
tags=tags,
build_pool_size=build_pool_size,
Expand Down