Skip to content

Commit

Permalink
[ACS JobRouter] Review feedback items (Azure#31083)
Browse files Browse the repository at this point in the history
* Update with new swagger

* changes for job matching modes

* remove generated models
- all models have been handcoded

* fix lint errors #1

* fix lint errors 2

* update swagger to point to main specs repo
  • Loading branch information
sarkar-rajarshi authored Jul 12, 2023
1 parent cf31b2f commit 9904083
Show file tree
Hide file tree
Showing 110 changed files with 29,809 additions and 19,321 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
from ._version import VERSION
from ._router_client import JobRouterClient
from ._router_administration_client import JobRouterAdministrationClient
from ._generated.models import (
from ._enums import (
ScoringRuleParameterSelector,
RouterWorkerStateSelector,
RouterWorkerState,
RouterWorkerSelectorStatus,
RouterJobStatusSelector,
RouterJobStatus,
LabelOperator,
JobMatchModeType,
ExpressionRouterRuleLanguage
)

from ._models import (
ClassificationPolicy,
ClassificationPolicyItem,
RouterQueue,
RouterQueueItem,
LabelOperator,
RouterQueueSelector,
StaticQueueSelectorAttachment,
ConditionalQueueSelectorAttachment,
Expand All @@ -21,11 +32,11 @@
PassThroughWorkerSelectorAttachment,
WorkerWeightedAllocation,
WeightedAllocationWorkerSelectorAttachment,
StaticRule,
DirectMapRule,
ExpressionRule,
FunctionRule,
FunctionRuleCredential,
StaticRouterRule,
DirectMapRouterRule,
ExpressionRouterRule,
FunctionRouterRule,
FunctionRouterRuleCredential,
DistributionPolicy,
DistributionPolicyItem,
DistributionMode,
Expand All @@ -42,111 +53,88 @@
CancelExceptionAction,
RouterQueueStatistics,
ChannelConfiguration,
RouterWorkerStateSelector,
RouterWorkerState,
RouterJobStatus,
RouterJobAssignment,
AcceptJobOfferResult,
DeclineJobOfferRequest,
UnassignJobResult,
RouterJobPositionDetails,
RouterJobStatusSelector,
RouterWorkerAssignment,
RouterJobOffer,
ScoringRuleOptions,
ScoringRuleParameterSelector,
RouterWorker,
RouterWorkerItem,
QueueAssignment,
DeclineJobOfferResult,
ReclassifyJobResult,
CancelJobResult,
CompleteJobResult,
CloseJobResult,
RouterJob,
RouterJobItem,
JobMatchingMode,
JobMatchModeType,
ScheduleAndSuspendMode,
)


__all__ = [
# Clients
'JobRouterClient',
'JobRouterAdministrationClient',

# Generated models
'AcceptJobOfferResult',
'BestWorkerMode',
'CancelExceptionAction',
'ChannelConfiguration',
'ClassificationPolicy',
'ClassificationPolicyItem',
'RouterQueue',
'RouterQueueItem',
'LabelOperator',
'RouterQueueSelector',
'StaticQueueSelectorAttachment',
'ConditionalQueueSelectorAttachment',
'RuleEngineQueueSelectorAttachment',
'PassThroughQueueSelectorAttachment',
'QueueWeightedAllocation',
'WeightedAllocationQueueSelectorAttachment',
'RouterWorkerSelector',
'StaticWorkerSelectorAttachment',
'ConditionalWorkerSelectorAttachment',
'RuleEngineWorkerSelectorAttachment',
'PassThroughWorkerSelectorAttachment',
'WorkerWeightedAllocation',
'WeightedAllocationWorkerSelectorAttachment',
'StaticRule',
'DirectMapRule',
'ExpressionRule',
'FunctionRule',
'FunctionRuleCredential',
'DeclineJobOfferRequest',
'DirectMapRouterRule',
'DistributionMode',
'DistributionPolicy',
'DistributionPolicyItem',
'DistributionMode',
'BestWorkerMode',
'LongestIdleMode',
'RoundRobinMode',
'ExceptionPolicy',
'ExceptionPolicyItem',
'ExceptionRule',
'ExpressionRouterRule',
'ExpressionRouterRuleLanguage',
'FunctionRouterRule',
'FunctionRouterRuleCredential',
'JobMatchModeType',
'JobMatchingMode',
'JobRouterAdministrationClient',
'JobRouterClient',
'LabelOperator',
'LongestIdleMode',
'ManualReclassifyExceptionAction',
'PassThroughQueueSelectorAttachment',
'PassThroughWorkerSelectorAttachment',
'QueueLengthExceptionTrigger',
'WaitTimeExceptionTrigger',
'QueueWeightedAllocation',
'ReclassifyExceptionAction',
'ManualReclassifyExceptionAction',
'CancelExceptionAction',
'RoundRobinMode',
'RouterJob',
'RouterQueueStatistics',
'ChannelConfiguration',
'RouterWorkerStateSelector',
'RouterWorkerState',
'RouterJobStatus',
'RouterJobAssignment',
'AcceptJobOfferResult',
'DeclineJobOfferRequest',
'UnassignJobResult',
'RouterJobItem',
'RouterJobOffer',
'RouterJobPositionDetails',
'RouterJobStatus',
'RouterJobStatusSelector',
'RouterWorkerAssignment',
'RouterJobOffer',
'ScoringRuleOptions',
'ScoringRuleParameterSelector',
'RouterQueue',
'RouterQueueItem',
'RouterQueueSelector',
'RouterQueueStatistics',
'RouterWorker',
'RouterWorkerAssignment',
'RouterWorkerItem',
'JobMatchingMode',
'JobMatchModeType',
'RouterWorkerSelector',
'RouterWorkerSelectorStatus',
'RouterWorkerState',
'RouterWorkerStateSelector',
'RuleEngineQueueSelectorAttachment',
'RuleEngineWorkerSelectorAttachment',
'ScheduleAndSuspendMode',

# Created models

'RouterJob',
'RouterJobItem',
'QueueAssignment',
'DeclineJobOfferResult',
'ReclassifyJobResult',
'CancelJobResult',
'CompleteJobResult',
'CloseJobResult',
'ScoringRuleOptions',
'ScoringRuleParameterSelector',
'StaticQueueSelectorAttachment',
'StaticRouterRule',
'StaticWorkerSelectorAttachment',
'UnassignJobResult',
'WaitTimeExceptionTrigger',
'WeightedAllocationQueueSelectorAttachment',
'WeightedAllocationWorkerSelectorAttachment',
'WorkerWeightedAllocation'
]

__version__ = VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------


from datetime import datetime, timezone
from dateutil.parser import parse

# cSpell:ignore tzinfos
def _convert_str_to_datetime(datetime_as_str: str) -> datetime:
dt = parse(datetime_as_str, tzinfos=[timezone.utc])
return dt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from azure.core import CaseInsensitiveEnumMeta


class ExpressionLanguage(str, Enum, metaclass=CaseInsensitiveEnumMeta):
class ExpressionRouterRuleLanguage(str, Enum, metaclass=CaseInsensitiveEnumMeta):
"""The expression language to compile to and execute."""

POWER_FX = "powerFx"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from azure.core import PipelineClient
from azure.core.rest import HttpRequest, HttpResponse

from . import models as _models
from ._configuration import AzureCommunicationJobRouterServiceConfiguration
from ._serialization import Deserializer, Serializer
from .operations import JobRouterAdministrationOperations, JobRouterOperations
Expand Down Expand Up @@ -40,10 +39,8 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
self._config = AzureCommunicationJobRouterServiceConfiguration(endpoint=endpoint, **kwargs)
self._client: PipelineClient = PipelineClient(base_url=_endpoint, config=self._config, **kwargs)

client_models = {k: v for k, v in _models._models.__dict__.items() if isinstance(v, type)}
client_models.update({k: v for k, v in _models.__dict__.items() if isinstance(v, type)})
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)
self._serialize = Serializer()
self._deserialize = Deserializer()
self._serialize.client_side_validation = False
self.job_router_administration = JobRouterAdministrationOperations(
self._client, self._config, self._serialize, self._deserialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,70 @@
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
"""
from typing import List
from azure.core.exceptions import DeserializationError, SerializationError, raise_with_traceback

__all__: List[str] = [] # Add all objects you want publicly available to users at this package level
from ._serialization import basestring, unicode_str, _FLATTEN, _decode_attribute_map_key
from ._serialization import Deserializer as DeserializerGenerated


class Deserializer(DeserializerGenerated):
@staticmethod
def _flatten_subtype(cls, key, objects):
if "_subtype_map" not in cls.__dict__:
return {}
result = dict(cls._subtype_map[key])
for valuetype in cls._subtype_map[key].values():
result.update(Deserializer._flatten_subtype(objects[valuetype], key, objects))
return result

@staticmethod
def _get_rest_key_parts(cls, attr_key):
"""Get the RestAPI key of this attr, split it and decode part
:param str attr_key: Attribute key must be in attribute_map.
:returns: A list of RestAPI part
:rtype: list
"""
rest_split_key = _FLATTEN.split(cls._attribute_map[attr_key]["key"])
return [_decode_attribute_map_key(key_part) for key_part in rest_split_key]

def _classify_target(self, target, data):
"""Overload for _classify_target to accommodate for handwritten models
Check to see whether the deserialization target object can
be classified into a subclass.
Once classification has been determined, initialize object.
:param str target: The target object type to deserialize to.
:param str/dict data: The response data to deserialize.
"""

if target is None:
return None, None

if isinstance(target, basestring):
try:
target = self.dependencies[target]
except KeyError:
return target, target

# Target is not a Model, perform a manual search
subtype_keys = target.__dict__.get("_subtype_map", {}).keys()
for subtype_key in subtype_keys:
rest_api_response_key = Deserializer._get_rest_key_parts(target, subtype_key)[-1]
subtype_value = data.pop(rest_api_response_key, None) or data.pop(subtype_key, None)

if subtype_value:
if target.__name__ == subtype_value:
target = target
flatten_mapping_type = Deserializer._flatten_subtype(target, subtype_key, self.dependencies)
try:
target = self.dependencies[flatten_mapping_type[subtype_value]]
except KeyError:
raise_with_traceback(DeserializationError, "Failed to deserialize: " + target.__class__.__name__)

return target, target.__class__.__name__ # type: ignore


__all__: List[str] = ["Deserializer"] # Add all objects you want publicly available to users at this package level


def patch_sdk():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,9 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
_serialized.update(_new_attr) # type: ignore
_new_attr = _new_attr[k] # type: ignore
_serialized = _serialized[k]
except ValueError:
continue
except ValueError as err:
if isinstance(err, SerializationError):
raise

except (AttributeError, KeyError, TypeError) as err:
msg = "Attribute {} in object {} cannot be serialized.\n{}".format(attr_name, class_name, str(target_obj))
Expand Down Expand Up @@ -903,7 +904,9 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs):
for d in data:
try:
serialized.append(self.serialize_data(d, iter_type, **kwargs))
except ValueError:
except ValueError as err:
if isinstance(err, SerializationError):
raise
serialized.append(None)

if div:
Expand Down Expand Up @@ -950,7 +953,9 @@ def serialize_dict(self, attr, dict_type, **kwargs):
for key, value in attr.items():
try:
serialized[self.serialize_unicode(key)] = self.serialize_data(value, dict_type, **kwargs)
except ValueError:
except ValueError as err:
if isinstance(err, SerializationError):
raise
serialized[self.serialize_unicode(key)] = None

if "xml" in serialization_ctxt:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from azure.core import AsyncPipelineClient
from azure.core.rest import AsyncHttpResponse, HttpRequest

from .. import models as _models
from .._serialization import Deserializer, Serializer
from ._configuration import AzureCommunicationJobRouterServiceConfiguration
from .operations import JobRouterAdministrationOperations, JobRouterOperations
Expand Down Expand Up @@ -40,10 +39,8 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
self._config = AzureCommunicationJobRouterServiceConfiguration(endpoint=endpoint, **kwargs)
self._client: AsyncPipelineClient = AsyncPipelineClient(base_url=_endpoint, config=self._config, **kwargs)

client_models = {k: v for k, v in _models._models.__dict__.items() if isinstance(v, type)}
client_models.update({k: v for k, v in _models.__dict__.items() if isinstance(v, type)})
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)
self._serialize = Serializer()
self._deserialize = Deserializer()
self._serialize.client_side_validation = False
self.job_router_administration = JobRouterAdministrationOperations(
self._client, self._config, self._serialize, self._deserialize
Expand Down
Loading

0 comments on commit 9904083

Please sign in to comment.