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

Check service existence before creation #5141

Merged
merged 10 commits into from
Jul 28, 2022
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
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