From 8392ce646e027cf550c562270c8ab0c462ca5999 Mon Sep 17 00:00:00 2001 From: pasant9 Date: Wed, 26 Feb 2025 18:22:33 +0530 Subject: [PATCH] Refactor AI API policy gateway implementation --- .../src/main/resources/conf/default.json | 5 +- .../ai_api_endpoints_seq_template.xml | 2 +- .../api_templates/endpoint_template.xml | 28 +-- .../src/main/resources/conf/default.json | 5 +- .../ai_api_endpoints_seq_template.xml | 2 +- .../api_templates/endpoint_template.xml | 28 +-- .../ai_api_endpoints_seq_template.xml | 87 -------- .../api_templates/ai_api_template.xml | 209 ------------------ 8 files changed, 40 insertions(+), 326 deletions(-) delete mode 100644 gateway/modules/distribution/resources/api_templates/ai_api_endpoints_seq_template.xml delete mode 100644 gateway/modules/distribution/resources/api_templates/ai_api_template.xml diff --git a/all-in-one-apim/modules/distribution/product/src/main/resources/conf/default.json b/all-in-one-apim/modules/distribution/product/src/main/resources/conf/default.json index 65c2ec2cd2..64d8e36a45 100644 --- a/all-in-one-apim/modules/distribution/product/src/main/resources/conf/default.json +++ b/all-in-one-apim/modules/distribution/product/src/main/resources/conf/default.json @@ -555,5 +555,8 @@ "apim.governance.scheduler.thread_pool_size": "20", "apim.governance.scheduler.queue_size": "20", "apim.governance.scheduler.task_check_interval_minutes": "2", - "apim.governance.scheduler.task_cleanup_interval_minutes": "30" + "apim.governance.scheduler.task_cleanup_interval_minutes": "30", + "apim.ai.default_request_timeout": "30", + "apim.ai.failover_configurations.failover_endpoints_limit": "10", + "apim.ai.failover_configurations.default_request_timeout": "30" } diff --git a/all-in-one-apim/modules/distribution/resources/api_templates/ai_api_endpoints_seq_template.xml b/all-in-one-apim/modules/distribution/resources/api_templates/ai_api_endpoints_seq_template.xml index 435b2f1961..af01613b98 100644 --- a/all-in-one-apim/modules/distribution/resources/api_templates/ai_api_endpoints_seq_template.xml +++ b/all-in-one-apim/modules/distribution/resources/api_templates/ai_api_endpoints_seq_template.xml @@ -53,7 +53,7 @@ #if( $defaultEndpoint ) - + #fail_scenario diff --git a/all-in-one-apim/modules/distribution/resources/api_templates/endpoint_template.xml b/all-in-one-apim/modules/distribution/resources/api_templates/endpoint_template.xml index 908f3bca30..cf859d6505 100644 --- a/all-in-one-apim/modules/distribution/resources/api_templates/endpoint_template.xml +++ b/all-in-one-apim/modules/distribution/resources/api_templates/endpoint_template.xml @@ -45,7 +45,7 @@ #end - #macro ( timeout $config) + #macro ( timeout $config $dynamicTimeout) #if( $config.get("actionSelect") == "neverTimeout" ) ## print nothing. #elseif($config.get("actionDuration")|| $config.get("actionSelect")) @@ -56,6 +56,9 @@ #elseif( $endpointClass != "ws" ) ##add default timeout config for non WS endpoints + #if( $dynamicTimeout ) + {get-property('REQUEST_TIMEOUT')} + #end fault #end @@ -86,10 +89,10 @@ #end ##macro for http_endpoints in failover and load balance types - #macro ( http_endpoint $name $ep ) + #macro ( http_endpoint $name $ep $dynamicTimeout) -#timeout( $ep.get('config') ) +#timeout( $ep.get('config') $dynamicTimeout) #if($enableRetryCallWithNewOauthToken) #set( $endpointSecurity = $endpoint_security.get($type) ) #if($endpointSecurity.type == "oauth" || $endpointSecurity.type == "OAUTH") @@ -157,7 +160,7 @@ -#timeout( $ep.get('config') ) +#timeout( $ep.get('config') false) @@ -175,7 +178,7 @@ format="$advance_ep.get("format")" optimize="$advance_ep.get("optimize")" #end > -#timeout( $ep.get('config') ) +#timeout( $ep.get('config') false) @@ -204,10 +207,9 @@ optimize="$advance_ep.get("optimize")" #if($endpointUuid && "$endpointUuid" != "") #set( $ep_key = "${endpointKey}_API_LLMEndpoint_${endpointUuid}" ) - #end - - #if( $endpointClass == "http" ) - #http_endpoint( $ep_key $endpoints ) + #http_endpoint( $ep_key $endpoints true) + #elseif( $endpointClass == "http" ) + #http_endpoint( $ep_key $endpoints false) #elseif( $endpointClass == "ws" ) #websocket_endpoint( $ep_key ) #elseif( $endpointClass == "address" ) @@ -219,14 +221,14 @@ optimize="$advance_ep.get("optimize")" #if($endpoints.get("endpoint_type") == "address") #address_endpoint("${ep_key}_0" $endpoints) #else - #http_endpoint("${ep_key}_0" $endpoints) + #http_endpoint("${ep_key}_0" $endpoints false) #end #set( $i = 1) #foreach($endpoint in $failover_endpoints) #if($endpoint.get("endpoint_type") == "address") #address_endpoint("${ep_key}_$i" $endpoint) #else - #http_endpoint("${ep_key}_$i" $endpoint) + #http_endpoint("${ep_key}_$i" $endpoint false) #end #set( $i = $i + 1) #end @@ -250,7 +252,7 @@ optimize="$advance_ep.get("optimize")" #if($endpoint.get("endpoint_type") == "address") #address_endpoint("${ep_key}_$i" $endpoint) #else - #http_endpoint("${ep_key}_$i" $endpoint) + #http_endpoint("${ep_key}_$i" $endpoint false) #end #set( $i = $i + 1) #end @@ -259,7 +261,7 @@ optimize="$advance_ep.get("optimize")" #elseif ($endpointClass == "default") - #timeout( $endpoints.get('config') ) + #timeout( $endpoints.get('config') false) #end diff --git a/api-control-plane/modules/distribution/product/src/main/resources/conf/default.json b/api-control-plane/modules/distribution/product/src/main/resources/conf/default.json index 65c2ec2cd2..64d8e36a45 100644 --- a/api-control-plane/modules/distribution/product/src/main/resources/conf/default.json +++ b/api-control-plane/modules/distribution/product/src/main/resources/conf/default.json @@ -555,5 +555,8 @@ "apim.governance.scheduler.thread_pool_size": "20", "apim.governance.scheduler.queue_size": "20", "apim.governance.scheduler.task_check_interval_minutes": "2", - "apim.governance.scheduler.task_cleanup_interval_minutes": "30" + "apim.governance.scheduler.task_cleanup_interval_minutes": "30", + "apim.ai.default_request_timeout": "30", + "apim.ai.failover_configurations.failover_endpoints_limit": "10", + "apim.ai.failover_configurations.default_request_timeout": "30" } diff --git a/api-control-plane/modules/distribution/resources/api_templates/ai_api_endpoints_seq_template.xml b/api-control-plane/modules/distribution/resources/api_templates/ai_api_endpoints_seq_template.xml index aba25c979c..4ddc3d6b6e 100644 --- a/api-control-plane/modules/distribution/resources/api_templates/ai_api_endpoints_seq_template.xml +++ b/api-control-plane/modules/distribution/resources/api_templates/ai_api_endpoints_seq_template.xml @@ -53,7 +53,7 @@ #if( $defaultEndpoint ) - + #fail_scenario diff --git a/api-control-plane/modules/distribution/resources/api_templates/endpoint_template.xml b/api-control-plane/modules/distribution/resources/api_templates/endpoint_template.xml index 908f3bca30..5fba82ee7f 100644 --- a/api-control-plane/modules/distribution/resources/api_templates/endpoint_template.xml +++ b/api-control-plane/modules/distribution/resources/api_templates/endpoint_template.xml @@ -45,7 +45,7 @@ #end - #macro ( timeout $config) + #macro ( timeout $config $dynamicTimeout) #if( $config.get("actionSelect") == "neverTimeout" ) ## print nothing. #elseif($config.get("actionDuration")|| $config.get("actionSelect")) @@ -56,6 +56,9 @@ #elseif( $endpointClass != "ws" ) ##add default timeout config for non WS endpoints + #if( $dynamicTimeout ) + {get-property('REQUEST_TIMEOUT')} + #end fault #end @@ -86,10 +89,10 @@ #end ##macro for http_endpoints in failover and load balance types - #macro ( http_endpoint $name $ep ) + #macro ( http_endpoint $name $ep $dynamicTimeout ) -#timeout( $ep.get('config') ) +#timeout( $ep.get('config') $dynamicTimeout) #if($enableRetryCallWithNewOauthToken) #set( $endpointSecurity = $endpoint_security.get($type) ) #if($endpointSecurity.type == "oauth" || $endpointSecurity.type == "OAUTH") @@ -157,7 +160,7 @@ -#timeout( $ep.get('config') ) +#timeout( $ep.get('config') false) @@ -175,7 +178,7 @@ format="$advance_ep.get("format")" optimize="$advance_ep.get("optimize")" #end > -#timeout( $ep.get('config') ) +#timeout( $ep.get('config') false) @@ -204,10 +207,9 @@ optimize="$advance_ep.get("optimize")" #if($endpointUuid && "$endpointUuid" != "") #set( $ep_key = "${endpointKey}_API_LLMEndpoint_${endpointUuid}" ) - #end - - #if( $endpointClass == "http" ) - #http_endpoint( $ep_key $endpoints ) + #http_endpoint( $ep_key $endpoints true) + #elseif( $endpointClass == "http" ) + #http_endpoint( $ep_key $endpoints false) #elseif( $endpointClass == "ws" ) #websocket_endpoint( $ep_key ) #elseif( $endpointClass == "address" ) @@ -219,14 +221,14 @@ optimize="$advance_ep.get("optimize")" #if($endpoints.get("endpoint_type") == "address") #address_endpoint("${ep_key}_0" $endpoints) #else - #http_endpoint("${ep_key}_0" $endpoints) + #http_endpoint("${ep_key}_0" $endpoints false) #end #set( $i = 1) #foreach($endpoint in $failover_endpoints) #if($endpoint.get("endpoint_type") == "address") #address_endpoint("${ep_key}_$i" $endpoint) #else - #http_endpoint("${ep_key}_$i" $endpoint) + #http_endpoint("${ep_key}_$i" $endpoint false) #end #set( $i = $i + 1) #end @@ -250,7 +252,7 @@ optimize="$advance_ep.get("optimize")" #if($endpoint.get("endpoint_type") == "address") #address_endpoint("${ep_key}_$i" $endpoint) #else - #http_endpoint("${ep_key}_$i" $endpoint) + #http_endpoint("${ep_key}_$i" $endpoint false) #end #set( $i = $i + 1) #end @@ -259,7 +261,7 @@ optimize="$advance_ep.get("optimize")" #elseif ($endpointClass == "default") - #timeout( $endpoints.get('config') ) + #timeout( $endpoints.get('config') false) #end diff --git a/gateway/modules/distribution/resources/api_templates/ai_api_endpoints_seq_template.xml b/gateway/modules/distribution/resources/api_templates/ai_api_endpoints_seq_template.xml deleted file mode 100644 index aba25c979c..0000000000 --- a/gateway/modules/distribution/resources/api_templates/ai_api_endpoints_seq_template.xml +++ /dev/null @@ -1,87 +0,0 @@ - - ##################### Define the macros ###################### - - #macro ( print_string_if_exist $field $default) - #if($field && "$field" !="") - "$field" - #else - "$default" - #end - #end - - #macro ( draw_endpoint $type $endpoint ) - #if($endpoint.endpointSecurityEnabled) - - - - - - #end - - #if( $endpoint && $endpoint.endpointUuid ) - #set( $ep_key = "${endpointKey}_API_LLMEndpoint_${endpoint.endpointUuid}" ) - #else - #set( $ep_key = "${endpointKey}_API${deploymentStage}Endpoint") - #end - - - - #end - - #macro ( fail_scenario ) - - - - - #end - - -#if( $defaultEndpoint ) - - - #fail_scenario - - - - - #foreach( $endpoint in $!endpoints ) - - #draw_endpoint($type, $endpoint) - - #end - - #draw_endpoint($type, $defaultEndpoint) - - - #fail_scenario - - - - - - - - - - - - - -#end - \ No newline at end of file diff --git a/gateway/modules/distribution/resources/api_templates/ai_api_template.xml b/gateway/modules/distribution/resources/api_templates/ai_api_template.xml deleted file mode 100644 index 3224dc642b..0000000000 --- a/gateway/modules/distribution/resources/api_templates/ai_api_template.xml +++ /dev/null @@ -1,209 +0,0 @@ - - - ##################### Define the macros ###################### - - #macro ( print_string_if_exist $field $default) - #if($field && "$field" !="") - "$field" - #else - "$default" - #end - #end - - ######################## End of Macros ###################################### - - - - #set( $originalEndPointConfig = $endpoint_config ) - #if( $apiIsBlocked ) - ## if API is blocked send the API Block message - - - - - - 700700 - API blocked - This API has been blocked temporarily. Please try again later or contact the system administrators. - - - - - - -
- - - - #else - ## api not blocked - #set ( $resourceNo = 0 ) - #foreach( $resource in $resources ) - #set( $isGQLWSResource = false ) - #set( $endpoint_config = $originalEndPointConfig ) - - - -
- - - - - - - -############## define the filter based on environment type production only, sandbox only , hybrid ############ - -#if( ($environmentType == 'sandbox') || ($environmentType =='hybrid' -&& !$endpoint_config.get("production_endpoints")) ) -#set( $filterRegex = "SANDBOX" ) -#else -#set( $filterRegex = "PRODUCTION" ) -#end -#if( $endpoint_config.get("endpoint_type") == 'sequence_backend' ) -#if( $endpoint_config.get("sandbox")) -#set( $sequenceKey = $endpoint_config.get("sandbox") ) - - - - - - - -#end -#if( $endpoint_config.get("production")) -#set( $sequenceKey = $endpoint_config.get("production") ) - - - - - - - -#end -#else - - - #if( ($environmentType == 'sandbox') || ($environmentType == 'hybrid' && !$defaultProductionEndpoint)) ) - #if( $defaultSandboxEndpoint ) - - #end - #else - #if( $defaultProductionEndpoint ) - - #end - #end - - - #if( $environmentType !='hybrid' ) - #if( $resource.getAuthType() == 'None' && $environmentType == 'sandbox' && $defaultSandboxEndpoint)) ) - #if( $defaultSandboxEndpoint ) - - #end - #else - - - - #if( $environmentType == 'production' ) - Sandbox Key Provided for Production Gateway - #elseif( $environmentType == 'sandbox' ) - Production Key Provided for Sandbox Gateway - #end - - - - - -
- - - - #end - #else - #if( $defaultSandboxEndpoint && $defaultProductionEndpoint ) - - #elseif( $defaultProductionEndpoint ) - - #elseif( $defaultSandboxEndpoint ) - #if( $resource.getAuthType() == 'None' ) - - #else - - #end - #end - #end - - -#end - - - - - - #set ($resourceNo = $resourceNo + 1 ) - #end ## end of resource iterator - ## print the handlers - #if( $handlers.size() > 0 ) - -#foreach( $handler in $handlers ) - - #if($handler.hasProperties()) - #set ($map = $handler.getProperties() ) - #foreach($property in $map.entrySet()) - - #end - #end - -#end -## check and set enable schema validation -#if($enableSchemaValidation) - -#end - - #end - #end - ## end of apiIsBlocked check - - - - - - \ No newline at end of file