Skip to content

Commit

Permalink
Merge pull request wso2#12579 from AnuGayan/master-AI-API-temp
Browse files Browse the repository at this point in the history
Add Backend and Subscription based throttling for AI APIs
  • Loading branch information
AnuGayan authored Sep 24, 2024
2 parents d4770e9 + 30fc272 commit a310bd2
Show file tree
Hide file tree
Showing 151 changed files with 4,089 additions and 394 deletions.
2 changes: 1 addition & 1 deletion components/apimgt/org.wso2.carbon.apimgt.api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>apimgt</artifactId>
<version>9.29.200-SNAPSHOT</version>
<version>9.29.205-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,15 @@ Map<String, Object> searchPaginatedAPIProducts(String searchQuery, String tenant
*/
String getSecuritySchemeOfAPI(String uuid, String organization) throws APIManagementException;

/**
* Returns whether subscription validation is disabled for an API
*
* @param uuid UUID of the API
* @return whether subscription validation is disabled
* @throws APIManagementException if failed get API from APIIdentifier
*/
boolean isSubscriptionValidationDisabled(String uuid) throws APIManagementException;

/**
* Returns details of an API
* @param uuid UUID of the API's registry artifact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,111 @@ public enum ExceptionCodes implements ErrorHandler {
ENDPOINT_SECURITY_TYPE_NOT_DEFINED(903214, "Endpoint security type not defined", 400,
"Endpoint security type not defined for the %s endpoint", false),

ADDITIONAL_PROPERTIES_CANNOT_BE_NULL(903215, "'additionalProperties' is required and should " +
"not be null", 400,
"The field 'additionalProperties' is required and should not be null"),

ADDITIONAL_PROPERTIES_PARSE_ERROR(903216, "Error while parsing 'additionalProperties'", 400,
"Error while parsing 'additionalProperties'", true),

ENDPOINT_SECURITY_CRYPTO_EXCEPTION(903217, "Error while encrypting the secret key of API", 500,
"%s"),

OPENAPI_RETRIEVAL_ERROR(903218, "Error while retrieving the OAS definition", 500,
"Error while retrieving the OAS definition for API with UUID %s"),

ASYNCAPI_RETRIEVAL_ERROR(903219, "Error while retrieving the Async API definition", 500,
"Error while retrieving the Async API definition for API with UUID %s"),

ERROR_RETRIEVING_API(903220, "Failed to get API", 500, "Failed to get API with UUID %s"),

ERROR_CHANGING_REGISTRY_LIFECYCLE_STATE(903221, "Error changing registry lifecycle state", 500,
"Error changing registry lifecycle state for API/API Product with UUID %s"),

UN_AUTHORIZED_TO_VIEW_MODIFY_API(903222, "User is not authorized to view or modify the api",
403, "User %s is not authorized to view or modify the api"),

FAILED_PUBLISHING_API_NO_ENDPOINT_SELECTED(903223, "Failed to publish service to API store. No endpoint selected",
400, "Failed to publish service to API store. No endpoint selected for API with UUID %s"),

FAILED_PUBLISHING_API_NO_TIERS_SELECTED(903224, "Failed to publish service to API store. No Tiers selected",
400, "Failed to publish service to API store. No Tiers selected for API with UUID %s"),

THIRD_PARTY_API_REVISION_CREATION_UNSUPPORTED(903225, "Creating API Revisions is not supported " +
"for third party APIs", 400,"Creating API Revisions is not supported for third party APIs: %s"),

THIRD_PARTY_API_REVISION_DEPLOYMENT_UNSUPPORTED(903226, "Deploying API Revisions is not supported " +
"for third party APIs", 400,"Deploying API Revisions is not supported for third party APIs: %s"),

RETIRED_API_REVISION_DEPLOYMENT_UNSUPPORTED(903227, "Deploying API Revisions is not supported for retired APIs",
400, "Deploying API Revisions is not supported for retired APIs. ApiId: %s"),

REVISION_NOT_FOUND_FOR_REVISION_NUMBER(903228, "No revision found", 404,
"No revision found for revision number %s"),

ERROR_PROCESSING_DIRECTORY_TO_IMPORT(903229, "Error extracting and processing the directory", 500,
"Error extracting and processing the directory to be imported", true),

IMPORT_ERROR_INVALID_GRAPHQL_SCHEMA(903230, "Error occurred while importing the API. Invalid " +
"GraphQL schema definition found", 400, "Invalid GraphQL schema definition " +
"found. %s"),

IMPORT_ERROR_INVALID_ASYNC_API_SCHEMA(903231, "Error occurred while importing the API. " +
"Invalid AsyncAPI definition found.", 400, "Invalid AsyncAPI definition found. %s"),

NO_VHOSTS_DEFINED_FOR_ENVIRONMENT(903232, "No VHosts defined for the environment", 400,
"No VHosts defined for the environment: %s"),

PROVIDED_GATEWAY_ENVIRONMENT_NOT_FOUND(903233, "Gateway environment not found", 400,
"Provided gateway environment %s is not found"),

UNSUPPORTED_AND_ALLOWED_LIFECYCLE_ACTIONS(903234, "Unsupported state change action", 400,
"Lifecycle state change action %s is not allowed for this API. Allowed actions are %s"),

NO_CORRESPONDING_RESOURCE_FOUND_IN_API(903235, "No corresponding resource found in API", 400,
"API with id %s does not have a resource %s with http method %s"),

ERROR_PARSING_MONETIZATION_PROPERTIES(903237, "Error when parsing monetization properties",
400, "Error when parsing monetization properties"),

API_NAME_CANNOT_BE_NULL(903238, "API name is required", 400,
"API name is required and cannot be null"),

API_NAME_ILLEGAL_CHARACTERS(903239, "API name contains illegal characters", 400,
"API name %s contains one or more illegal characters from (%s)"),

API_VERSION_CANNOT_BE_NULL(903240, "API version is required", 400,
"API version is required and cannot be null"),

API_VERSION_ILLEGAL_CHARACTERS(903241, "API version contains illegal characters", 400,
"API version %s contains one or more illegal characters from (%s)"),

UNSUPPORTED_CONTEXT(903242, "Unsupported context", 400,
"Unsupported context %s"),

ERROR_PARSING_ENDPOINT_CONFIG(903243, "Error when parsing endpoint configuration",
400, "Error when parsing endpoint configuration"),

NOT_IN_OPEN_API_FORMAT(903244, "Not in Open API format",
400, "The API definition is not in Open API format"),

PARAMETER_NOT_PROVIDED_FOR_DOCUMENTATION(903245, "Parameter value missing", 400,
"Some of the mandatory parameter values were missing. %s"),

INVALID_API_RESOURCES_FOR_API_PRODUCT(903246, "Cannot find API resources for some API Product " +
"resources.", 404, "Some of the resources in the API Product are not found as API resources. %s"),

INVALID_ADDITIONAL_PROPERTIES_WITH_ERROR(903247, "Invalid additional properties", 400,
"Invalid additional properties for API: %s:%s Error: %s"),

TIER_NAME_INVALID_WITH_TIER_INFO(903248, "The tier name is invalid.", 400,
"The tier name(s) %s are invalid"),

LENGTH_EXCEEDS_ERROR(903249, "Character length exceeds the allowable limit", 400, "%s"),

ROLE_OF_SCOPE_DOES_NOT_EXIST(903250, "Role does not exist", 404,
"Role %s does not exist"),

OPERATION_OR_RESOURCE_TYPE_OR_METHOD_NOT_DEFINED(902031,
"Operation type/http method is not specified for the operation/resource", 400,
"Operation type/http method is not specified for the operation/resource: %s", false),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.apimgt.api.model;

/**
* This model is used to represent the API defintion content search results.
*/
public class APIDefinitionContentSearchResult {

private String id;
private String name;
private String apiUuid;
private String apiName;
private String apiContext;
private String apiVersion;
private String apiProvider;
private String apiType;
private String associatedType;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getApiUuid() {
return apiUuid;
}

public void setApiUuid(String apiUuid) {
this.apiUuid = apiUuid;
}

public String getApiName() {
return apiName;
}

public void setApiName(String apiName) {
this.apiName = apiName;
}

public String getApiVersion() {
return apiVersion;
}

public void setApiVersion(String apiVersion) {
this.apiVersion = apiVersion;
}

public String getApiProvider() {
return apiProvider;
}

public void setApiProvider(String apiProvider) {
this.apiProvider = apiProvider;
}

public String getApiType() {
return apiType;
}

public void setApiType(String apiType) {
this.apiType = apiType;
}

public String getAssociatedType() {
return associatedType;
}

public void setAssociatedType(String associatedType) {
this.associatedType = associatedType;
}

public String getApiContext() {
return apiContext;
}

public void setApiContext(String apiContext) {
this.apiContext = apiContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class API implements CacheableEntity<String> {
private String revision;
private String organization;
private Set<OperationPolicy> apiPolicies = new HashSet<>();
private boolean isSubscriptionValidationDisabled = false;
private AIConfiguration aiConfiguration;

public String getRevision() {
Expand Down Expand Up @@ -216,6 +217,14 @@ public Set<OperationPolicy> getApiPolicies() {
return apiPolicies;
}

public boolean isSubscriptionValidationDisabled() {
return isSubscriptionValidationDisabled;
}

public void setSubscriptionValidationDisabled(boolean subscriptionValidationDisabled) {
isSubscriptionValidationDisabled = subscriptionValidationDisabled;
}

public AIConfiguration getAiConfiguration() {
return aiConfiguration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>apimgt</artifactId>
<groupId>org.wso2.carbon.apimgt</groupId>
<version>9.29.200-SNAPSHOT</version>
<version>9.29.205-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<artifactId>apimgt</artifactId>
<groupId>org.wso2.carbon.apimgt</groupId>
<version>9.29.200-SNAPSHOT</version>
<version>9.29.205-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>apimgt</artifactId>
<version>9.29.200-SNAPSHOT</version>
<version>9.29.205-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>apimgt</artifactId>
<version>9.29.200-SNAPSHOT</version>
<version>9.29.205-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>apimgt</artifactId>
<version>9.29.200-SNAPSHOT</version>
<version>9.29.205-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>apimgt</artifactId>
<version>9.29.200-SNAPSHOT</version>
<version>9.29.205-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion components/apimgt/org.wso2.carbon.apimgt.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>apimgt</artifactId>
<version>9.29.200-SNAPSHOT</version>
<version>9.29.205-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>apimgt</artifactId>
<version>9.29.200-SNAPSHOT</version>
<version>9.29.205-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>apimgt</artifactId>
<groupId>org.wso2.carbon.apimgt</groupId>
<version>9.29.200-SNAPSHOT</version>
<version>9.29.205-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion components/apimgt/org.wso2.carbon.apimgt.eventing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>apimgt</artifactId>
<groupId>org.wso2.carbon.apimgt</groupId>
<version>9.29.200-SNAPSHOT</version>
<version>9.29.205-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion components/apimgt/org.wso2.carbon.apimgt.gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>apimgt</artifactId>
<version>9.29.200-SNAPSHOT</version>
<version>9.29.205-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,19 @@ public class APIThrottleConstants {
public static final String API_THROTTLE_OUT_HANDLER = "_throttle_out_handler_";
public static final String HARD_THROTTLING_CONFIGURATION = "hard_throttling_limits";
public static final String PRODUCTION_HARD_LIMIT = "PRODUCTION_HARD_LIMIT";
public static final String PRODUCTION_HARD_LIMIT_TOTAL_TOKEN = "PRODUCTION_HARD_LIMIT_TOTAL_TOKEN";
public static final String PRODUCTION_HARD_LIMIT_COMPLETION_TOKEN = "PRODUCTION_HARD_LIMIT_COMPLETION_TOKEN";
public static final String PRODUCTION_HARD_LIMIT_PROMPT_TOKEN = "PRODUCTION_HARD_LIMIT_PROMPT_TOKEN";
public static final String SUBSCRIPTION_BURST_LIMIT = "SUBSCRIPTION_BURST_LIMIT";
public static final String APPLICATION_BURST_LIMIT = "APPLICATION_BURST_LIMIT";
public static final String APPLICATION_BURST_LIMIT_EXCEEDED = "APPLICATION_BURST_LIMIT_EXCEED";
public static final String SANDBOX_HARD_LIMIT = "SANDBOX_HARD_LIMIT";
public static final String SANDBOX_HARD_LIMIT_TOTAL_TOKEN = "SANDBOX_HARD_LIMIT_TOTAL_TOKEN";
public static final String SANDBOX_HARD_LIMIT_PROMPT_TOKEN = "SANDBOX_HARD_LIMIT_PROMPT_TOKEN";
public static final String SANDBOX_HARD_LIMIT_COMPLETION_TOKEN = "SANDBOX_HARD_LIMIT_COMPLETION_TOKEN";
public static final String TOTAL_TOKENS = "TOTAL_TOKENS";
public static final String PROMPT_TOKENS = "PROMPT_TOKENS";
public static final String COMPLETION_TOKENS = "COMPLETION_TOKENS";
public static final String THROTTLED_OUT_REASON = APIConstants.THROTTLE_OUT_REASON_KEY;
public static final String THROTTLED_NEXT_ACCESS_TIMESTAMP = "NEXT_ACCESS_TIME";
public static final String THROTTLED_NEXT_ACCESS_TIME = "NEXT_ACCESS_UTC_TIME";
Expand Down
Loading

0 comments on commit a310bd2

Please sign in to comment.