in src/containerapp/azext_containerapp/daprcomponent_resiliency_decorator.py [0:0]
def construct_payload(self):
if self.get_argument_yaml():
self.component_resiliency_update_def = self.set_up_component_resiliency_yaml(file_name=self.get_argument_yaml())
return
component_resiliency_def = None
try:
component_resiliency_def = DaprComponentResiliencyPreviewClient.show(cmd=self.cmd, resource_group_name=self.get_argument_resource_group_name(),
name=self.get_argument_name(), dapr_component_name=self.get_argument_dapr_component_name(),
environment_name=self.get_argument_environment())
except: # pylint: disable=bare-except
pass
if not component_resiliency_def:
raise ResourceNotFoundError("The dapr component resiliency policy '{}' does not exist".format(self.get_argument_name()))
if self.get_argument_in_http_retry_delay_in_milliseconds() is not None or self.get_argument_in_http_retry_interval_in_milliseconds() is not None or self.get_argument_in_http_retry_max() is not None:
# First, fetch the value from the flag if it exists, else fetch it from the existing component resiliency policy, else set it to default
if self.get_argument_in_http_retry_max() is not None:
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "httpRetryPolicy", "maxRetries", value=self.get_argument_in_http_retry_max())
elif safe_get(component_resiliency_def, "properties", "inboundPolicy", "httpRetryPolicy", "maxRetries"):
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "httpRetryPolicy", "maxRetries", value=safe_get(component_resiliency_def, "properties", "inboundPolicy", "httpRetryPolicy", "maxRetries"))
else:
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "httpRetryPolicy", "maxRetries", value=DEFAULT_COMPONENT_HTTP_RETRY_MAX)
if self.get_argument_in_http_retry_delay_in_milliseconds() is not None:
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "httpRetryPolicy", "retryBackOff", "initialDelayInMilliseconds", value=self.get_argument_in_http_retry_delay_in_milliseconds())
elif safe_get(component_resiliency_def, "properties", "inboundPolicy", "httpRetryPolicy", "retryBackOff", "initialDelayInMilliseconds"):
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "httpRetryPolicy", "retryBackOff", "initialDelayInMilliseconds", value=safe_get(component_resiliency_def, "properties", "inboundPolicy", "httpRetryPolicy", "retryBackOff", "initialDelayInMilliseconds"))
else:
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "httpRetryPolicy", "retryBackOff", "initialDelayInMilliseconds", value=DEFAULT_COMPONENT_HTTP_RETRY_BACKOFF_INITIAL_DELAY)
if self.get_argument_in_http_retry_interval_in_milliseconds() is not None:
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "httpRetryPolicy", "retryBackOff", "maxIntervalInMilliseconds", value=self.get_argument_in_http_retry_interval_in_milliseconds())
elif safe_get(component_resiliency_def, "properties", "inboundPolicy", "httpRetryPolicy", "retryBackOff", "maxIntervalInMilliseconds"):
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "httpRetryPolicy", "retryBackOff", "maxIntervalInMilliseconds", value=safe_get(component_resiliency_def, "properties", "inboundPolicy", "httpRetryPolicy", "retryBackOff", "maxIntervalInMilliseconds"))
else:
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "httpRetryPolicy", "retryBackOff", "maxIntervalInMilliseconds", value=DEFAULT_COMPONENT_HTTP_RETRY_BACKOFF_MAX_DELAY)
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "timeoutPolicy", "responseTimeoutInSeconds", value=(self.get_argument_in_timeout_response_in_seconds() or safe_get(component_resiliency_def, "properties", "inboundPolicy", "timeoutPolicy", "responseTimeoutInSeconds")))
if self.get_argument_in_circuit_breaker_consecutive_errors() is not None or self.get_argument_in_circuit_breaker_interval() is not None or self.get_argument_in_circuit_breaker_timeout() is not None:
# First, fetch the value from the flag if it exists, else fetch it from the existing component resiliency policy
if self.get_argument_out_circuit_breaker_consecutive_errors() is not None:
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "circuitBreakerPolicy", "consecutiveErrors", value=self.get_argument_in_circuit_breaker_consecutive_errors())
elif safe_get(component_resiliency_def, "properties", "inboundPolicy", "circuitBreakerPolicy", "consecutiveErrors"):
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "circuitBreakerPolicy", "consecutiveErrors", value=safe_get(component_resiliency_def, "properties", "inboundPolicy", "circuitBreakerPolicy", "consecutiveErrors"))
if self.get_argument_in_circuit_breaker_interval() is not None:
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "circuitBreakerPolicy", "intervalInSeconds", value=self.get_argument_in_circuit_breaker_interval())
elif safe_get(component_resiliency_def, "properties", "inboundPolicy", "circuitBreakerPolicy", "intervalInSeconds"):
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "circuitBreakerPolicy", "intervalInSeconds", value=safe_get(component_resiliency_def, "properties", "inboundPolicy", "circuitBreakerPolicy", "intervalInSeconds"))
if self.get_argument_in_circuit_breaker_timeout() is not None:
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "circuitBreakerPolicy", "timeoutInSeconds", value=self.get_argument_in_circuit_breaker_timeout())
elif safe_get(component_resiliency_def, "properties", "inboundPolicy", "circuitBreakerPolicy", "timeoutInSeconds"):
safe_set(self.component_resiliency_patch_def, "properties", "inboundPolicy", "circuitBreakerPolicy", "timeoutInSeconds", value=safe_get(component_resiliency_def, "properties", "inboundPolicy", "circuitBreakerPolicy", "timeoutInSeconds"))
if self.get_argument_out_http_retry_delay_in_milliseconds() is not None or self.get_argument_out_http_retry_interval_in_milliseconds() is not None or self.get_argument_out_http_retry_max() is not None:
if self.get_argument_out_http_retry_max() is not None:
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "httpRetryPolicy", "maxRetries", value=self.get_argument_out_http_retry_max())
elif safe_get(component_resiliency_def, "properties", "outboundPolicy", "httpRetryPolicy", "maxRetries"):
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "httpRetryPolicy", "maxRetries", value=safe_get(component_resiliency_def, "properties", "outboundPolicy", "httpRetryPolicy", "maxRetries"))
else:
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "httpRetryPolicy", "maxRetries", value=DEFAULT_COMPONENT_HTTP_RETRY_MAX)
if self.get_argument_out_http_retry_delay_in_milliseconds() is not None:
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "httpRetryPolicy", "retryBackOff", "initialDelayInMilliseconds", value=self.get_argument_out_http_retry_delay_in_milliseconds())
elif safe_get(component_resiliency_def, "properties", "outboundPolicy", "httpRetryPolicy", "retryBackOff", "initialDelayInMilliseconds"):
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "httpRetryPolicy", "retryBackOff", "initialDelayInMilliseconds", value=safe_get(component_resiliency_def, "properties", "outboundPolicy", "httpRetryPolicy", "retryBackOff", "initialDelayInMilliseconds"))
else:
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "httpRetryPolicy", "retryBackOff", "initialDelayInMilliseconds", value=DEFAULT_COMPONENT_HTTP_RETRY_BACKOFF_INITIAL_DELAY)
if self.get_argument_out_http_retry_interval_in_milliseconds() is not None:
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "httpRetryPolicy", "retryBackOff", "maxIntervalInMilliseconds", value=self.get_argument_out_http_retry_interval_in_milliseconds())
elif safe_get(component_resiliency_def, "properties", "outboundPolicy", "httpRetryPolicy", "retryBackOff", "maxIntervalInMilliseconds"):
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "httpRetryPolicy", "retryBackOff", "maxIntervalInMilliseconds", value=safe_get(component_resiliency_def, "properties", "outboundPolicy", "httpRetryPolicy", "retryBackOff", "maxIntervalInMilliseconds"))
else:
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "httpRetryPolicy", "retryBackOff", "maxIntervalInMilliseconds", value=DEFAULT_COMPONENT_HTTP_RETRY_BACKOFF_MAX_DELAY)
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "timeoutPolicy", "responseTimeoutInSeconds", value=(self.get_argument_out_timeout_response_in_seconds() or safe_get(component_resiliency_def, "properties", "outboundPolicy", "timeoutPolicy", "responseTimeoutInSeconds")))
if self.get_argument_out_circuit_breaker_consecutive_errors() is not None or self.get_argument_out_circuit_breaker_interval() is not None or self.get_argument_out_circuit_breaker_timeout() is not None:
if self.get_argument_out_circuit_breaker_consecutive_errors() is not None:
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "circuitBreakerPolicy", "consecutiveErrors", value=self.get_argument_out_circuit_breaker_consecutive_errors())
elif safe_get(component_resiliency_def, "properties", "outboundPolicy", "circuitBreakerPolicy", "consecutiveErrors"):
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "circuitBreakerPolicy", "consecutiveErrors", value=safe_get(component_resiliency_def, "properties", "outboundPolicy", "circuitBreakerPolicy", "consecutiveErrors"))
if self.get_argument_out_circuit_breaker_interval() is not None:
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "circuitBreakerPolicy", "intervalInSeconds", value=self.get_argument_out_circuit_breaker_interval())
elif safe_get(component_resiliency_def, "properties", "outboundPolicy", "circuitBreakerPolicy", "intervalInSeconds"):
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "circuitBreakerPolicy", "intervalInSeconds", value=safe_get(component_resiliency_def, "properties", "outboundPolicy", "circuitBreakerPolicy", "intervalInSeconds"))
if self.get_argument_out_circuit_breaker_timeout() is not None:
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "circuitBreakerPolicy", "timeoutInSeconds", value=self.get_argument_out_circuit_breaker_timeout())
elif safe_get(component_resiliency_def, "properties", "outboundPolicy", "circuitBreakerPolicy", "timeoutInSeconds"):
safe_set(self.component_resiliency_patch_def, "properties", "outboundPolicy", "circuitBreakerPolicy", "timeoutInSeconds", value=safe_get(component_resiliency_def, "properties", "outboundPolicy", "circuitBreakerPolicy", "timeoutInSeconds"))
if safe_get(self.component_resiliency_patch_def, "properties", "inboundPolicy", "httpRetryPolicy", "maxRetries") or safe_get(self.component_resiliency_patch_def, "properties", "inboundPolicy", "httpRetryPolicy", "retryBackOff", "initialDelayInMilliseconds") or safe_get(self.component_resiliency_patch_def, "properties", "inboundPolicy", "httpRetryPolicy", "retryBackOff", "maxIntervalInMilliseconds"):
safe_set(component_resiliency_def, "properties", "inboundPolicy", "httpRetryPolicy", value=safe_get(self.component_resiliency_patch_def, "properties", "inboundPolicy", "httpRetryPolicy"))
if safe_get(self.component_resiliency_patch_def, "properties", "inboundPolicy", "timeoutPolicy", "responseTimeoutInSeconds"):
safe_set(component_resiliency_def, "properties", "inboundPolicy", "timeoutPolicy", value=safe_get(self.component_resiliency_patch_def, "properties", "inboundPolicy", "timeoutPolicy"))
if safe_get(self.component_resiliency_patch_def, "properties", "inboundPolicy", "circuitBreakerPolicy", "consecutiveErrors") or safe_get(self.component_resiliency_patch_def, "properties", "inboundPolicy", "circuitBreakerPolicy", "intervalInSeconds") or safe_get(self.component_resiliency_patch_def, "properties", "inboundPolicy", "circuitBreakerPolicy", "timeoutInSeconds"):
safe_set(component_resiliency_def, "properties", "inboundPolicy", "circuitBreakerPolicy", value=safe_get(self.component_resiliency_patch_def, "properties", "inboundPolicy", "circuitBreakerPolicy"))
if safe_get(self.component_resiliency_patch_def, "properties", "outboundPolicy", "httpRetryPolicy", "maxRetries") or safe_get(self.component_resiliency_patch_def, "properties", "outboundPolicy", "httpRetryPolicy", "retryBackOff", "initialDelayInMilliseconds") or safe_get(self.component_resiliency_patch_def, "properties", "outboundPolicy", "httpRetryPolicy", "retryBackOff", "maxIntervalInMilliseconds"):
safe_set(component_resiliency_def, "properties", "outboundPolicy", "httpRetryPolicy", value=safe_get(self.component_resiliency_patch_def, "properties", "outboundPolicy", "httpRetryPolicy"))
if safe_get(self.component_resiliency_patch_def, "properties", "outboundPolicy", "timeoutPolicy", "responseTimeoutInSeconds"):
safe_set(component_resiliency_def, "properties", "outboundPolicy", "timeoutPolicy", value=safe_get(self.component_resiliency_patch_def, "properties", "outboundPolicy", "timeoutPolicy"))
if safe_get(self.component_resiliency_patch_def, "properties", "outboundPolicy", "circuitBreakerPolicy", "consecutiveErrors") or safe_get(self.component_resiliency_patch_def, "properties", "outboundPolicy", "circuitBreakerPolicy", "intervalInSeconds") or safe_get(self.component_resiliency_patch_def, "properties", "outboundPolicy", "circuitBreakerPolicy", "timeoutInSeconds"):
safe_set(component_resiliency_def, "properties", "outboundPolicy", "circuitBreakerPolicy", value=safe_get(self.component_resiliency_patch_def, "properties", "outboundPolicy", "circuitBreakerPolicy"))
component_resiliency_def = clean_null_values(component_resiliency_def)
self.component_resiliency_update_def = component_resiliency_def