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

[Spring-Cloud] add Build Service related command for enterprise tier #4295

Merged
merged 49 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
76cf97c
[Spring-Cloud] Add Build service for enterprise tier
smile37773 Jan 4, 2022
b0ed715
fix
smile37773 Jan 4, 2022
f4478f7
fix
smile37773 Jan 5, 2022
2838ffa
Update src/spring-cloud/azext_spring_cloud/_params.py
smile37773 Jan 5, 2022
30ded6d
Update src/spring-cloud/azext_spring_cloud/_params.py
smile37773 Jan 5, 2022
36c3e01
fix
smile37773 Jan 5, 2022
7da7b61
fix
smile37773 Jan 5, 2022
19e60b7
fix
smile37773 Jan 5, 2022
ac0ffaf
fix
smile37773 Jan 5, 2022
2a35037
Merge remote-tracking branch 'origin' into qingyliu/build-service
smile37773 Jan 5, 2022
b1d10d5
fix
smile37773 Jan 5, 2022
5e47e35
Update src/spring-cloud/azext_spring_cloud/_buildservices.py
smile37773 Jan 5, 2022
c5d1c8b
Update src/spring-cloud/azext_spring_cloud/_buildservices.py
smile37773 Jan 5, 2022
00f31d9
fix
smile37773 Jan 5, 2022
3da1853
fix
smile37773 Jan 6, 2022
6deaa1d
fix
smile37773 Jan 6, 2022
a03dca4
Merge remote-tracking branch 'origin' into qingyliu/build-service
smile37773 Jan 6, 2022
19b4f47
fix
smile37773 Jan 6, 2022
668a5bf
fix
smile37773 Jan 6, 2022
46238c9
fix
smile37773 Jan 6, 2022
dbc9cec
fix
smile37773 Jan 6, 2022
8888047
fix
smile37773 Jan 6, 2022
194b817
fix
smile37773 Jan 6, 2022
7877b79
fix
smile37773 Jan 6, 2022
bfbf842
fix
smile37773 Jan 7, 2022
8e60c93
fix
smile37773 Jan 7, 2022
d0223da
fix
smile37773 Jan 7, 2022
d03285e
fix
smile37773 Jan 7, 2022
43830f1
fix
smile37773 Jan 7, 2022
f4a573c
fix
smile37773 Jan 7, 2022
bc5db5c
fix
smile37773 Jan 7, 2022
a2c5bd3
fix
smile37773 Jan 7, 2022
ecca582
Update src/spring-cloud/azext_spring_cloud/_params.py
smile37773 Jan 10, 2022
5748fe5
Update src/spring-cloud/azext_spring_cloud/_params.py
smile37773 Jan 10, 2022
9d2e35f
fix
smile37773 Jan 10, 2022
71c532b
add delete test
smile37773 Jan 11, 2022
a7dd44f
fix
smile37773 Jan 11, 2022
690cd05
Merge branch 'main' into qingyliu/build-service
smile37773 Jan 11, 2022
821ac97
Update spring_cloud_instance.py
smile37773 Jan 11, 2022
5bc8787
Update commands.py
smile37773 Jan 12, 2022
b861619
Merge branch 'main' into qingyliu/build-service
smile37773 Jan 12, 2022
0de9300
Merge branch 'main' into qingyliu/build-service
smile37773 Jan 12, 2022
fd2538a
fix
smile37773 Jan 12, 2022
8f50489
fix
smile37773 Jan 12, 2022
5b2899c
Update _params.py
smile37773 Jan 12, 2022
ec7fb1d
fix
smile37773 Jan 12, 2022
3ba8b36
fix test
smile37773 Jan 13, 2022
a38102d
fix test
smile37773 Jan 13, 2022
431305e
fix test
smile37773 Jan 13, 2022
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
51 changes: 51 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_buildservices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=too-few-public-methods, unused-argument, redefined-builtin

import json
from .vendored_sdks.appplatform.v2022_01_01_preview import models as models_20220101preview
smile37773 marked this conversation as resolved.
Show resolved Hide resolved

DEFAULT_BUILD_SERVICE_NAME = "default"
DEFAULT_BUILD_AGENT_POOL_NAME = "default"


def _update_default_build_agent_pool(cmd, client, resource_group, name, build_pool_size=None):
if build_pool_size is not None:
build_properties = models_20220101preview.BuildServiceAgentPoolProperties(
pool_size=models_20220101preview.BuildServiceAgentPoolSizeProperties(
name=build_pool_size))
agent_pool_resource = models_20220101preview.BuildServiceAgentPoolResource(
properties=build_properties)
client.build_service_agent_pool.begin_update_put(
smile37773 marked this conversation as resolved.
Show resolved Hide resolved
resource_group, name, DEFAULT_BUILD_SERVICE_NAME, DEFAULT_BUILD_AGENT_POOL_NAME, agent_pool_resource)


def create_or_update_builder(cmd, client, resource_group, service, name, builder_json=None, builder_file=None, no_wait=False):
builder = _update_builder(builder_file, builder_json)
builder_resource = models_20220101preview.BuilderResource(
properties=builder
)
return client.build_service_builder.begin_create_or_update(resource_group, service, DEFAULT_BUILD_SERVICE_NAME,
name, builder_resource, no_wait)
smile37773 marked this conversation as resolved.
Show resolved Hide resolved


def builder_show(cmd, client, resource_group, service, name):
return client.build_service_builder.get(resource_group, service, DEFAULT_BUILD_SERVICE_NAME, name)


def builder_delete(cmd, client, resource_group, service, name, no_wait=False):
return client.build_service_builder.begin_delete(resource_group, service, DEFAULT_BUILD_SERVICE_NAME, name, no_wait)
smile37773 marked this conversation as resolved.
Show resolved Hide resolved


def _update_builder(builder_file, builder_json):
if builder_file is not None:
with open(builder_file, 'r') as json_file:
builder = json.load(json_file)

if builder_json is not None:
builder = json.loads(builder_json)

return builder
6 changes: 5 additions & 1 deletion src/spring-cloud/azext_spring_cloud/_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from knack.log import get_logger
from .custom import (_create_service)
from ._buildservices import _update_default_build_agent_pool


logger = get_logger(__name__)
Expand All @@ -17,7 +18,7 @@ def spring_cloud_create(cmd, client, resource_group, name, location=None,
service_runtime_network_resource_group=None, app_network_resource_group=None,
app_insights_key=None, app_insights=None, sampling_rate=None,
disable_app_insights=None, enable_java_agent=None,
sku=None, tags=None, zone_redundant=False, no_wait=False):
sku=None, tags=None, zone_redundant=False, build_pool_size=None, no_wait=False):
"""
This method creates Azure Spring Cloud enterprise tier instance, it also creates sub-component under the instance if
user enable these component.
Expand All @@ -32,4 +33,7 @@ def spring_cloud_create(cmd, client, resource_group, name, location=None,
zone_redundant=zone_redundant,
sku=sku,
tags=tags)

_update_default_build_agent_pool(
cmd, client, resource_group, name, build_pool_size)
return poller
37 changes: 37 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,3 +607,40 @@
- name: Unbind an app from Service Registry.
text: az spring-cloud service-registry unbind --app MyApp -s MyService -g MyResourceGroup
"""

helps['spring-cloud build-service builder'] = """
type: group
short-summary: (Enterprise Tier Only) Commands to manage Builder Resource
"""

helps['spring-cloud build-service builder create'] = """
type: command
short-summary: Create a builder.
examples:
- name: Create a builder using JSON file.
text: az spring-cloud build-service builder create --name my-builder --builder-json MyJson.json
"""

helps['spring-cloud build-service builder update'] = """
type: command
short-summary: Update a builder.
examples:
- name: Update a builder using JSON file.
text: az spring-cloud build-service builder update --name my-builder --builder-json MyJson.json
"""

helps['spring-cloud build-service builder show'] = """
type: command
short-summary: Show a builder.
examples:
- name: Show a builder.
text: az spring-cloud build-service builder show --name my-builder
"""

helps['spring-cloud build-service builder delete'] = """
type: command
short-summary: Delete a builder.
examples:
- name: Delete a builder.
text: az spring-cloud build-service builder delete --name my-builder
"""
30 changes: 29 additions & 1 deletion src/spring-cloud/azext_spring_cloud/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
validate_tracing_parameters_asc_create, validate_tracing_parameters_asc_update,
validate_app_insights_parameters, validate_instance_count, validate_java_agent_parameters,
validate_jar)
from ._validators_enterprise import only_support_enterprise
from ._validators_enterprise import (only_support_enterprise, validate_builder_resource, validate_builder_create,
validate_builder_update, validate_build_pool_size)
from ._app_validator import (fulfill_deployment_param, active_deployment_exist, active_deployment_exist_under_app,
ensure_not_active_deployment, validate_deloy_path, validate_deloyment_create_path,
validate_cpu, validate_memory)
Expand Down Expand Up @@ -85,6 +86,12 @@ def load_arguments(self, _):
help="Create your Azure Spring Cloud service in an Azure availability zone or not, "
"this could only be supported in several regions at the moment ",
default=False, is_preview=True)
c.argument('build_pool_size',
arg_type=get_enum_type(['S1', 'S2', 'S3', 'S4', 'S5']),
smile37773 marked this conversation as resolved.
Show resolved Hide resolved
validator=validate_build_pool_size,
default='S1',
is_preview=True,
help='(Enterprise Tier Only) Size of build agent pool. See Azure Spring Cloud Doc for size info.')
smile37773 marked this conversation as resolved.
Show resolved Hide resolved

with self.argument_context('spring-cloud update') as c:
c.argument('sku', arg_type=sku_type)
Expand All @@ -111,6 +118,10 @@ def load_arguments(self, _):
deprecate_info=c.deprecate(target='az spring-cloud update --disable-app-insights',
redirect='az spring-cloud app-insights update --disable',
hide=True))
c.argument('build_pool_size',
arg_type=get_enum_type(['S1', 'S2', 'S3', 'S4', 'S5']),
is_preview=True,
help='(Enterprise Tier Only) Size of build agent pool. See Azure Spring Cloud Doc for size info.')
smile37773 marked this conversation as resolved.
Show resolved Hide resolved

for scope in ['spring-cloud create', 'spring-cloud update']:
with self.argument_context(scope) as c:
Expand Down Expand Up @@ -421,3 +432,20 @@ def prepare_logs_argument(c):

with self.argument_context('spring-cloud service-registry unbind') as c:
c.argument('app', app_name_type, help='Name of app.', validator=validate_app_name)

for scope in ['spring-cloud build-service builder create',
'spring-cloud build-service builder update']:
with self.argument_context(scope) as c:
smile37773 marked this conversation as resolved.
Show resolved Hide resolved
c.argument('builder_json', type=str, help="The JSON array of builder.", validator=validate_builder_resource)
c.argument('builder_file', type=str, help="The file path of JSON array of builder.", validator=validate_builder_resource)

with self.argument_context('spring-cloud build-service builder create') as c:
c.argument('name', type=str, help="The builder name.", validator=validate_builder_create)

with self.argument_context('spring-cloud build-service builder update') as c:
c.argument('name', type=str, help="The builder name.", validator=validate_builder_update)

for scope in ['spring-cloud build-service builder show',
'spring-cloud build-service builder delete']:
with self.argument_context(scope) as c:
smile37773 marked this conversation as resolved.
Show resolved Hide resolved
c.argument('name', type=str, help="The builder name.")
43 changes: 42 additions & 1 deletion src/spring-cloud/azext_spring_cloud/_validators_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@

# pylint: disable=too-few-public-methods, unused-argument, redefined-builtin

from azure.cli.core.util import CLIError
from azure.cli.core.azclierror import ClientRequestError
from ._util_enterprise import is_enterprise_tier
from azure.core.exceptions import ResourceNotFoundError
from ._util_enterprise import (
is_enterprise_tier, get_client
)
from .vendored_sdks.appplatform.v2022_01_01_preview.models import _app_platform_management_client_enums as AppPlatformEnums
from ._validators import _parse_sku_name
from ._buildservices import DEFAULT_BUILD_SERVICE_NAME


def only_support_enterprise(cmd, namespace):
Expand All @@ -17,3 +24,37 @@ def only_support_enterprise(cmd, namespace):
def not_support_enterprise(cmd, namespace):
if namespace.resource_group and namespace.service and is_enterprise_tier(cmd, namespace.resource_group, namespace.service):
raise ClientRequestError("'{}' doesn't support for Enterprise tier Spring instance.".format(namespace.command))


def validate_builder_create(cmd, namespace):
client = get_client(cmd)
try:
builder = client.build_service_builder.get(namespace.resource_group,
namespace.service,
DEFAULT_BUILD_SERVICE_NAME,
namespace.name)
if builder is not None:
raise CLIError('Builder {} already exists.'.format(namespace.name))
smile37773 marked this conversation as resolved.
Show resolved Hide resolved
except ResourceNotFoundError:
pass


def validate_builder_update(cmd, namespace):
client = get_client(cmd)
try:
client.build_service_builder.get(namespace.resource_group,
namespace.service,
DEFAULT_BUILD_SERVICE_NAME,
namespace.name)
except ResourceNotFoundError:
raise CLIError('Builder {} does not exist.'.format(namespace.name))
smile37773 marked this conversation as resolved.
Show resolved Hide resolved


def validate_builder_resource(namespace):
if namespace.builder_json is not None and namespace.builder_file is not None:
raise CLIError("You can only specify either --builder-json or --builder-file.")
smile37773 marked this conversation as resolved.
Show resolved Hide resolved


def validate_build_pool_size(namespace):
if _parse_sku_name(namespace.sku) != 'enterprise':
namespace.build_pool_size = None
13 changes: 13 additions & 0 deletions src/spring-cloud/azext_spring_cloud/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def load_command_table(self, _):
client_factory=cf_spring_cloud_20220101preview
)

builder_cmd_group = CliCommandType(
operations_tmpl="azext_spring_cloud._build_service#{}",
client_factory=cf_spring_cloud_20220101preview
)

with self.command_group('spring-cloud', custom_command_type=spring_cloud_routing_util,
exception_handler=handle_asc_exception) as g:
g.custom_command('create', 'spring_cloud_create', supports_no_wait=True)
Expand Down Expand Up @@ -174,3 +179,11 @@ def load_command_table(self, _):

with self.command_group('spring-cloud', exception_handler=handle_asc_exception):
pass

with self.command_group('spring-cloud build-service builder',
custom_command_type=builder_cmd_group,
exception_handler=handle_asc_exception, is_preview=True) as g:
g.custom_command('create', 'create_or_update_builder', supports_no_wait=True)
g.custom_command('update', 'create_or_update_builder', supports_no_wait=True)
g.custom_command('show', 'builder_show')
g.custom_command('delete', 'builder_delete', supports_no_wait=True)
smile37773 marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 5 additions & 1 deletion src/spring-cloud/azext_spring_cloud/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import base64
from collections import defaultdict
from ._log_stream import LogStream
from ._buildservices import _update_default_build_agent_pool

logger = get_logger(__name__)
DEFAULT_DEPLOYMENT_NAME = "default"
Expand Down Expand Up @@ -146,7 +147,7 @@ def _update_application_insights_asc_create(cmd, resource_group, name, location,


def spring_cloud_update(cmd, client, resource_group, name, app_insights_key=None, app_insights=None,
disable_app_insights=None, sku=None, tags=None, no_wait=False):
disable_app_insights=None, sku=None, tags=None, build_pool_size=None, no_wait=False):
"""
TODO (jiec) app_insights_key, app_insights and disable_app_insights are marked as deprecated.
Will be decommissioned in future releases.
Expand All @@ -168,6 +169,9 @@ def spring_cloud_update(cmd, client, resource_group, name, app_insights_key=None
_update_application_insights_asc_update(cmd, resource_group, name, location,
app_insights_key, app_insights, disable_app_insights, no_wait)

_update_default_build_agent_pool(
cmd, client, resource_group, name, build_pool_size)

# update service tags
if tags is not None:
updated_resource.tags = tags
Expand Down