Skip to content

Commit

Permalink
Check service existence before creation (Azure#5141)
Browse files Browse the repository at this point in the history
  • Loading branch information
qingc authored Jul 28, 2022
1 parent 6a6badc commit 67aaaaa
Show file tree
Hide file tree
Showing 11 changed files with 11,407 additions and 4,948 deletions.
4 changes: 4 additions & 0 deletions src/spring/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Release History
===============
1.1.5
---
* Add service instance existance check before service creation

1.1.4
---
* Add warning that `az spring app-insights` don't support Enterprise tier.
Expand Down
7 changes: 7 additions & 0 deletions src/spring/azext_spring/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ def validate_instance_count(namespace):
raise InvalidArgumentValueError("--instance-count must be greater than 0")


def validate_instance_not_existed(client, resource_group, name, location):
availability_parameters = models.NameAvailabilityParameters(type="Microsoft.AppPlatform/Spring", name=name)
name_availability = client.services.check_name_availability(location, availability_parameters)
if not name_availability.name_available and name_availability.reason == "AlreadyExists":
raise InvalidArgumentValueError("Service instance '{}' under resource group '{}' is already existed in region '{}', cannot be created again.".format(name, resource_group, location))


def validate_name(namespace):
namespace.name = namespace.name.lower()
matchObj = match(r'^[a-z][a-z0-9-]{2,30}[a-z0-9]$', namespace.name)
Expand Down
11 changes: 9 additions & 2 deletions src/spring/azext_spring/spring_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
create_api_portal)


from ._validators import (_parse_sku_name)
from ._validators import (_parse_sku_name, validate_instance_not_existed)
from knack.log import get_logger

logger = get_logger(__name__)
Expand All @@ -38,6 +38,10 @@ def create(self, **kwargs):

def before_create(self, **kwargs):
_warn_enable_java_agent(**kwargs)
validate_instance_not_existed(self.client,
self.resource_group,
self.name,
self.location)

def after_create(self, **kwargs):
_update_application_insights_asc_create(self.cmd,
Expand Down Expand Up @@ -95,7 +99,10 @@ def create_service(self,

class EnterpriseSpringCloud(DefaultSpringCloud):
def before_create(self, **_):
pass
validate_instance_not_existed(self.client,
self.resource_group,
self.name,
self.location)

def after_create(self, no_wait=None, **kwargs):
pollers = [
Expand Down

Large diffs are not rendered by default.

496 changes: 274 additions & 222 deletions src/spring/azext_spring/tests/latest/recordings/test_az_asc_create.yaml

Large diffs are not rendered by default.

8,566 changes: 7,496 additions & 1,070 deletions src/spring/azext_spring/tests/latest/recordings/test_create_asc_heavy_cases.yaml

Large diffs are not rendered by default.

Loading

0 comments on commit 67aaaaa

Please sign in to comment.