Skip to content
Open
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

from typing import Any, Dict, Iterable, Optional, cast

from azure.ai.ml._scope_dependent_operations import OperationScope, OperationConfig, _ScopeDependentOperations
from azure.ai.ml._scope_dependent_operations import OperationConfig, OperationScope, _ScopeDependentOperations
from azure.ai.ml._telemetry import ActivityType, monitor_with_telemetry_mixin
from azure.ai.ml._utils._experimental import experimental
from azure.ai.ml._utils._logger_utils import OpsLogger
from azure.ai.ml.entities import DeploymentTemplate
from azure.core.tracing.decorator import distributed_trace
from azure.core.exceptions import ResourceNotFoundError
from azure.core.tracing.decorator import distributed_trace

ops_logger = OpsLogger(__name__)
module_logger = ops_logger.module_logger
Expand Down Expand Up @@ -51,10 +51,10 @@ def _get_registry_endpoint(self) -> str:
"""
try:
# Import here to avoid circular dependencies
from azure.ai.ml.operations import RegistryOperations
from azure.ai.ml._restclient.v2022_10_01_preview import (
AzureMachineLearningWorkspaces as ServiceClient102022,
)
from azure.ai.ml.operations import RegistryOperations

# Try to get credential from service client or operation config
credential = None
Expand Down Expand Up @@ -91,7 +91,7 @@ def _get_registry_endpoint(self) -> str:
return f"https://{region}.api.azureml.ms"

except Exception as e:
module_logger.warning("Could not determine registry region dynamically: %s. Using default.", e)
module_logger.debug("Could not determine registry region dynamically: %s. Using default.", e)

# Fallback to default region if unable to determine dynamically
return f"https://int.experiments.azureml-test.net"
Expand Down Expand Up @@ -337,7 +337,7 @@ def get(self, name: str, version: Optional[str] = None, **kwargs: Any) -> Deploy
)
return DeploymentTemplate._from_rest_object(result)
except Exception as e:
module_logger.warning("DeploymentTemplate get operation failed: %s", e)
module_logger.debug("DeploymentTemplate get operation failed: %s", e)
raise ResourceNotFoundError(f"DeploymentTemplate {name}:{version} not found") from e

@distributed_trace
Expand All @@ -351,31 +351,27 @@ def create_or_update(self, deployment_template: DeploymentTemplate, **kwargs: An
:return: DeploymentTemplate object representing the created or updated resource.
:rtype: ~azure.ai.ml.entities.DeploymentTemplate
"""
try:
# Ensure we have a DeploymentTemplate object
if not isinstance(deployment_template, DeploymentTemplate):
raise ValueError("deployment_template must be a DeploymentTemplate object")
# Ensure we have a DeploymentTemplate object
if not isinstance(deployment_template, DeploymentTemplate):
raise ValueError("deployment_template must be a DeploymentTemplate object")

if hasattr(self._service_client, "deployment_templates"):
endpoint = self._get_registry_endpoint()
if hasattr(self._service_client, "deployment_templates"):
endpoint = self._get_registry_endpoint()

rest_object = deployment_template._to_rest_object()
self._service_client.deployment_templates.begin_create(
endpoint=endpoint,
subscription_id=self._operation_scope.subscription_id,
resource_group_name=self._operation_scope.resource_group_name,
registry_name=self._operation_scope.registry_name,
name=deployment_template.name,
version=deployment_template.version,
body=rest_object,
**kwargs,
)
return deployment_template
else:
raise RuntimeError("DeploymentTemplate service not available")
except Exception as e:
module_logger.error("DeploymentTemplate create_or_update operation failed: %s", e)
raise
rest_object = deployment_template._to_rest_object()
self._service_client.deployment_templates.begin_create(
endpoint=endpoint,
subscription_id=self._operation_scope.subscription_id,
resource_group_name=self._operation_scope.resource_group_name,
registry_name=self._operation_scope.registry_name,
name=deployment_template.name,
version=deployment_template.version,
body=rest_object,
**kwargs,
)
return deployment_template
else:
raise RuntimeError("DeploymentTemplate service not available")

@distributed_trace
@monitor_with_telemetry_mixin(ops_logger, "DeploymentTemplate.Delete", ActivityType.PUBLICAPI)
Expand Down Expand Up @@ -407,7 +403,7 @@ def delete(self, name: str, version: Optional[str] = None, **kwargs: Any) -> Non
except ResourceNotFoundError:
raise
except Exception as e:
module_logger.error("DeploymentTemplate delete operation failed: %s", e)
module_logger.debug("DeploymentTemplate delete operation failed: %s", e)
raise

@distributed_trace
Expand All @@ -423,18 +419,14 @@ def archive(self, name: str, version: Optional[str] = None, **kwargs: Any) -> De
:rtype: ~azure.ai.ml.entities.DeploymentTemplate
:raises: ~azure.core.exceptions.ResourceNotFoundError if deployment template not found.
"""
try:
# Get the existing template
template = self.get(name=name, version=version, **kwargs)
# Get the existing template
template = self.get(name=name, version=version, **kwargs)

# Set stage to Archived
template.stage = "Archived"
# Set stage to Archived
template.stage = "Archived"

# Update the template using create_or_update
return self.create_or_update(template, **kwargs)
except Exception as e:
module_logger.error("DeploymentTemplate archive operation failed: %s", e)
raise
# Update the template using create_or_update
return self.create_or_update(template, **kwargs)

@distributed_trace
@monitor_with_telemetry_mixin(ops_logger, "DeploymentTemplate.Restore", ActivityType.PUBLICAPI)
Expand All @@ -449,15 +441,11 @@ def restore(self, name: str, version: Optional[str] = None, **kwargs: Any) -> De
:rtype: ~azure.ai.ml.entities.DeploymentTemplate
:raises: ~azure.core.exceptions.ResourceNotFoundError if deployment template not found.
"""
try:
# Get the existing template
template = self.get(name=name, version=version, **kwargs)
# Get the existing template
template = self.get(name=name, version=version, **kwargs)

# Set stage to Development
template.stage = "Development"
# Set stage to Development
template.stage = "Development"

# Update the template using create_or_update
return self.create_or_update(template, **kwargs)
except Exception as e:
module_logger.error("DeploymentTemplate restore operation failed: %s", e)
raise
# Update the template using create_or_update
return self.create_or_update(template, **kwargs)
Loading