Skip to content

Commit

Permalink
Add subtype property to the APIs
Browse files Browse the repository at this point in the history
Add subtype property to the APIs to identify AIAPI subtype
Fix db connection not closing issue
Fix type mismatch issue in internal REST APIs related to TokenBaseThrottlingCountHolder
  • Loading branch information
SavinduDimal committed Sep 22, 2024
1 parent 9179ecb commit c6c103a
Show file tree
Hide file tree
Showing 32 changed files with 272 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class API implements Serializable {
private String graphQLSchema;
private String asyncApiDefinition;
private String type;
private String subtype;
private String context;
private String contextTemplate;
private String thumbnailUrl;
Expand Down Expand Up @@ -1193,6 +1194,18 @@ public void setType(String type) {
}
}

public String getSubtype() {
return subtype;
}

public void setSubtype(String subtype) {
if (StringUtils.isEmpty(subtype) || NULL_VALUE.equalsIgnoreCase(StringUtils.trim(subtype))) {
this.subtype = "DEFAULT";
} else {
this.subtype = StringUtils.trim(subtype).toUpperCase();
}
}

public String getCreatedTime() {
return createdTime;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class APIInfo {
private String contextTemplate;
private String apiTier;
private String apiType;
private String apiSubtype;
private String createdTime;
private String createdBy;
private String updatedTime;
Expand Down Expand Up @@ -128,6 +129,16 @@ public void setApiType(String apiType) {
this.apiType = apiType;
}

public String getApiSubtype() {

return apiSubtype;
}

public void setApiSubtype(String apiSubtype) {

this.apiSubtype = apiSubtype;
}

public String getCreatedTime() {

return createdTime;
Expand Down Expand Up @@ -226,6 +237,7 @@ public static class Builder {
private String contextTemplate;
private String apiTier;
private String apiType;
private String apiSubtype;
private String createdTime;
private String createdBy;
private String updatedTime;
Expand Down Expand Up @@ -284,6 +296,12 @@ public Builder apiType(String apiType) {
return this;
}

public Builder apiSubtype(String apiSubtype) {

this.apiSubtype = apiSubtype;
return this;
}

public Builder createdTime(String createdTime) {

this.createdTime = createdTime;
Expand Down Expand Up @@ -337,6 +355,7 @@ public APIInfo build() {
apiInfo.contextTemplate = contextTemplate;
apiInfo.apiTier = apiTier;
apiInfo.apiType = apiType;
apiInfo.apiSubtype = apiSubtype;
apiInfo.createdTime = createdTime;
apiInfo.createdBy = createdBy;
apiInfo.updatedTime = updatedTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,8 @@ public enum RegistryResourceTypesForUI {
public static final String[] API_SUPPORTED_TYPE_LIST = {"HTTP", "WS", "SOAPTOREST", "GRAPHQL", "SOAP", "WEBSUB",
"SSE", "ASYN" +
"C"};
public static final String API_SUBTYPE_DEFAULT = "DEFAULT";
public static final String API_SUBTYPE_AI_API = "AIAPI";
public static final String API_PRODUCT_REVISION = "Current";
public static class AdvancedThrottleConstants {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3860,6 +3860,7 @@ public Map<String, Object> searchPaginatedAPIs(String searchQuery, String organi
mappedAPI.setAvailableTiers(availableTiers);
populateGatewayVendor(mappedAPI);
populateEgressStatus(mappedAPI);
populateAPISubtype(mappedAPI);
apiList.add(mappedAPI);
} catch (APIManagementException e) {
log.warn("Retrieving API details from DB failed for API: " + mappedAPI.getUuid() + " " + e);
Expand Down Expand Up @@ -3908,6 +3909,7 @@ public ApiTypeWrapper getAPIorAPIProductByUUID(String uuid, String organization)
populateAPIStatus(api);
populateGatewayVendor(api);
populateEgressStatus(api);
populateAPISubtype(api);
api = addTiersToAPI(api, organization);
return new ApiTypeWrapper(api);
}
Expand Down Expand Up @@ -4094,6 +4096,7 @@ private ApiTypeWrapper getAPIorAPIProductByUUIDWithoutPermissionCheck(String uui
API api = APIMapper.INSTANCE.toApi(devPortalApi);
populateDevPortalAPIInformation(uuid, organization, api);
populateDefaultVersion(api);
populateAPISubtype(api);
api = addTiersToAPI(api, organization);
return new ApiTypeWrapper(api);
}
Expand Down Expand Up @@ -4691,4 +4694,17 @@ private void populateEgressStatus(APIProduct apiProduct) throws APIManagementExc
apiProduct.setEgress(apiMgtDAO.checkForEgressAPIWithUUID(apiProduct.getUuid()));
}
}

/**
* This method populates the subType in the API.
* @param api API that needs to be populated with the subtype
* @throws APIManagementException
*/
private void populateAPISubtype(API api) throws APIManagementException {
if (api.isRevision()) {
api.setSubtype(apiMgtDAO.retrieveAPISubtypeWithUUID(api.getRevisionedApiId()));
} else {
api.setSubtype(apiMgtDAO.retrieveAPISubtypeWithUUID(api.getUuid()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5311,7 +5311,10 @@ public API getAPIbyUUID(String uuid, String organization) throws APIManagementEx
populateRevisionInformation(api, uuid);
populateAPIInformation(uuid, organization, api);
populateAPILevelPolicies(api);
populateAiConfiguration(api);
populateAPISubtype(api);
if (APIConstants.API_SUBTYPE_AI_API.equals(api.getSubtype())) {
populateAiConfiguration(api);
}
if (APIUtil.isSequenceDefined(api.getInSequence()) || APIUtil.isSequenceDefined(api.getOutSequence())
|| APIUtil.isSequenceDefined(api.getFaultSequence())) {
if (migrationEnabled == null) {
Expand Down Expand Up @@ -5419,6 +5422,7 @@ public APISearchResult searchPaginatedAPIsByFQDN(String endpoint, String tenantD
populateDefaultVersion(mappedAPI);
populateGatewayVendor(mappedAPI);
populateEgressStatus(mappedAPI);
populateAPISubtype(mappedAPI);
apiList.add(mappedAPI);
}
result.setApis(apiList);
Expand Down Expand Up @@ -5490,6 +5494,19 @@ private void populateEgressStatus(APIProduct apiProduct) throws APIManagementExc
}
}

/**
* This method populates the subtype in the API.
* @param api API that needs to be populated with the subtype
* @throws APIManagementException
*/
private void populateAPISubtype(API api) throws APIManagementException {
if (api.isRevision()) {
api.setSubtype(apiMgtDAO.retrieveAPISubtypeWithUUID(api.getRevisionedApiId()));
} else {
api.setSubtype(apiMgtDAO.retrieveAPISubtypeWithUUID(api.getUuid()));
}
}

public APIProduct getAPIProductbyUUID(String uuid, String organization) throws APIManagementException {
try {
Organization org = new Organization(organization);
Expand Down Expand Up @@ -5548,6 +5565,7 @@ public Map<String, Object> searchPaginatedAPIs(String searchQuery, String organi
populateDefaultVersion(mappedAPI);
populateGatewayVendor(mappedAPI);
populateEgressStatus(mappedAPI);
populateAPISubtype(mappedAPI);
apiList.add(mappedAPI);
}
apiSet.addAll(apiList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5592,6 +5592,7 @@ public int addAPI(API api, int tenantId, String organization) throws APIManageme
prepStmt.setString(13, api.getGatewayVendor());
prepStmt.setString(14, api.getVersionTimestamp());
prepStmt.setInt(15, api.isEgress());
prepStmt.setString(16, api.getSubtype());
prepStmt.execute();

rs = prepStmt.getGeneratedKeys();
Expand Down Expand Up @@ -10009,6 +10010,10 @@ public APIInfo getAPIInfoByUUID(String apiId) throws APIManagementException {
String contextTemplate = resultSet.getString("CONTEXT_TEMPLATE");
String context = resultSet.getString("CONTEXT");
String apiType = resultSet.getString("API_TYPE");
String apiSubtype = resultSet.getString("API_SUBTYPE");
if (StringUtils.isEmpty(apiSubtype)) {
apiSubtype = APIConstants.API_SUBTYPE_DEFAULT;
}
String version = resultSet.getString("API_VERSION");
if (APIConstants.API_PRODUCT.equalsIgnoreCase(apiType)
&& APIConstants.API_PRODUCT_VERSION_1_0_0.equals(version)
Expand All @@ -10024,6 +10029,7 @@ public APIInfo getAPIInfoByUUID(String apiId) throws APIManagementException {
.contextTemplate(contextTemplate)
.status(APIUtil.getApiStatus(resultSet.getString("STATUS")))
.apiType(apiType)
.apiSubtype(apiSubtype)
.createdBy(resultSet.getString("CREATED_BY"))
.createdTime(resultSet.getString("CREATED_TIME"))
.updatedBy(resultSet.getString("UPDATED_BY"))
Expand Down Expand Up @@ -14747,9 +14753,9 @@ public LLMProvider getLLMProvider(String organization, String llmProviderId) thr
public LLMProvider getLLMProvider(String organization, String name, String apiVersion) throws APIManagementException {

String errorMessage = "Failed to get LLM Provider in tenant domain: " + organization;
try {
Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(SQLConstants.GET_LLM_PROVIDER_BY_NAME_AND_VERSION_SQL);
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(
SQLConstants.GET_LLM_PROVIDER_BY_NAME_AND_VERSION_SQL)) {
preparedStatement.setString(1, organization);
preparedStatement.setString(2, name);
preparedStatement.setString(3, apiVersion);
Expand Down Expand Up @@ -22429,4 +22435,30 @@ public int checkForEgressAPIWithUUID(String uuid) throws APIManagementException
}
return 0;
}

/**
* This retrieves the API subtype for the given API UUID.
*
* @param uuid API UUID
* @return API subtype
* @throws APIManagementException
*/
public String retrieveAPISubtypeWithUUID(String uuid) throws APIManagementException {

try (Connection connection = APIMgtDBUtil.getConnection()) {
try (PreparedStatement preparedStatement = connection.prepareStatement(
SQLConstants.RETRIEVE_API_SUBTYPE_WITH_UUID)) {
preparedStatement.setString(1, uuid);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
if (resultSet.next()) {
return resultSet.getString("API_SUBTYPE");
}
}
}
} catch (SQLException e) {
throw new APIManagementException("Error while retrieving apimgt connection", e,
ExceptionCodes.INTERNAL_ERROR);
}
return APIConstants.API_SUBTYPE_DEFAULT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1471,8 +1471,8 @@ public class SQLConstants {
public static final String ADD_API_SQL =
" INSERT INTO AM_API (API_PROVIDER,API_NAME,API_VERSION,CONTEXT,CONTEXT_TEMPLATE,CREATED_BY," +
"CREATED_TIME,API_TIER,API_TYPE,API_UUID,STATUS,ORGANIZATION,GATEWAY_VENDOR,VERSION_COMPARABLE," +
"IS_EGRESS)" +
" VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
"IS_EGRESS, API_SUBTYPE)" +
" VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

public static final String GET_GATEWAY_TYPE_SQL_BY_UUID =
"SELECT API.GATEWAY_TYPE FROM AM_API API WHERE API.API_UUID = ?";
Expand Down Expand Up @@ -3108,9 +3108,10 @@ public class SQLConstants {
public static final String UPDATE_API_STATUS = "UPDATE AM_API SET STATUS = ? WHERE API_ID = ?";
public static final String RETRIEVE_API_STATUS_FROM_UUID = "SELECT STATUS FROM AM_API WHERE API_UUID = ?";
public static final String CHECK_API_EGRESS_WITH_UUID = "SELECT IS_EGRESS FROM AM_API WHERE API_UUID = ?";
public static final String RETRIEVE_API_SUBTYPE_WITH_UUID = "SELECT API_SUBTYPE FROM AM_API WHERE API_UUID = ?";
public static final String RETRIEVE_API_INFO_FROM_UUID = "SELECT API_UUID, API_PROVIDER, API_NAME, API_VERSION, " +
"CONTEXT, CONTEXT_TEMPLATE, API_TIER, API_TYPE, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME, " +
" ORGANIZATION, REVISIONS_CREATED, STATUS, IS_EGRESS FROM AM_API WHERE API_UUID = ?";
" ORGANIZATION, REVISIONS_CREATED, STATUS, IS_EGRESS, API_SUBTYPE FROM AM_API WHERE API_UUID = ?";
public static final String RETRIEVE_DEFAULT_VERSION = "SELECT DEFAULT_API_VERSION,PUBLISHED_DEFAULT_API_VERSION " +
"FROM AM_API_DEFAULT_VERSION WHERE API_NAME = ? AND API_PROVIDER =?";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3984,6 +3984,12 @@ components:
description: Whether the API is Egress or not
default: false
example: true
subtype:
type: string
description: Subtype of the API.
default: DEFAULT
example: AIAPI
readOnly: true
APIInfoList:
title: API Info List
type: object
Expand Down Expand Up @@ -4265,6 +4271,12 @@ components:
description: Whether the API is egress or not
default: false
example: true
subtype:
type: string
description: Subtype of the API.
default: DEFAULT
example: AIAPI
readOnly: true
APIMonetizationInfo:
title: API monetization object
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9505,6 +9505,12 @@ components:
type:
type: string
example: HTTP
subtype:
type: string
description: Subtype of the API.
default: DEFAULT
example: AIAPI
readOnly: true
audience:
type: string
description: The audience of the API. Accepted values are PUBLIC, SINGLE
Expand Down Expand Up @@ -9835,6 +9841,12 @@ components:
- SSE
- WEBHOOK
- ASYNC
subtype:
type: string
description: Subtype of the API.
default: DEFAULT
example: AIAPI
readOnly: true
audience:
type: string
description: The audience of the API. Accepted values are PUBLIC, SINGLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public static TypeEnum fromValue(String v) {
}
}
private TypeEnum type = TypeEnum.HTTP;
private String subtype = "DEFAULT";

@XmlType(name="AudienceEnum")
@XmlEnum(String.class)
Expand Down Expand Up @@ -656,6 +657,24 @@ public void setType(TypeEnum type) {
this.type = type;
}

/**
* Subtype of the API.
**/
public APIDTO subtype(String subtype) {
this.subtype = subtype;
return this;
}


@ApiModelProperty(example = "AIAPI", value = "Subtype of the API.")
@JsonProperty("subtype")
public String getSubtype() {
return subtype;
}
public void setSubtype(String subtype) {
this.subtype = subtype;
}

/**
* The audience of the API. Accepted values are PUBLIC, SINGLE
**/
Expand Down Expand Up @@ -1452,6 +1471,7 @@ public boolean equals(java.lang.Object o) {
Objects.equals(enableSchemaValidation, API.enableSchemaValidation) &&
Objects.equals(enableSubscriberVerification, API.enableSubscriberVerification) &&
Objects.equals(type, API.type) &&
Objects.equals(subtype, API.subtype) &&
Objects.equals(audience, API.audience) &&
Objects.equals(audiences, API.audiences) &&
Objects.equals(transport, API.transport) &&
Expand Down Expand Up @@ -1499,7 +1519,7 @@ public boolean equals(java.lang.Object o) {

@Override
public int hashCode() {
return Objects.hash(id, name, description, context, version, provider, lifeCycleStatus, wsdlInfo, wsdlUrl, responseCachingEnabled, cacheTimeout, hasThumbnail, isDefaultVersion, isRevision, revisionedApiId, revisionId, enableSchemaValidation, enableSubscriberVerification, type, audience, audiences, transport, tags, policies, apiThrottlingPolicy, authorizationHeader, apiKeyHeader, securityScheme, maxTps, visibility, visibleRoles, visibleTenants, mediationPolicies, apiPolicies, subscriptionAvailability, subscriptionAvailableTenants, additionalProperties, additionalPropertiesMap, monetization, accessControl, accessControlRoles, businessInformation, corsConfiguration, websubSubscriptionConfiguration, workflowStatus, createdTime, lastUpdatedTimestamp, lastUpdatedTime, endpointConfig, endpointImplementationType, aiConfiguration, scopes, operations, threatProtectionPolicies, categories, keyManagers, serviceInfo, advertiseInfo, gatewayVendor, gatewayType, asyncTransportProtocols, egress);
return Objects.hash(id, name, description, context, version, provider, lifeCycleStatus, wsdlInfo, wsdlUrl, responseCachingEnabled, cacheTimeout, hasThumbnail, isDefaultVersion, isRevision, revisionedApiId, revisionId, enableSchemaValidation, enableSubscriberVerification, type, subtype, audience, audiences, transport, tags, policies, apiThrottlingPolicy, authorizationHeader, apiKeyHeader, securityScheme, maxTps, visibility, visibleRoles, visibleTenants, mediationPolicies, apiPolicies, subscriptionAvailability, subscriptionAvailableTenants, additionalProperties, additionalPropertiesMap, monetization, accessControl, accessControlRoles, businessInformation, corsConfiguration, websubSubscriptionConfiguration, workflowStatus, createdTime, lastUpdatedTimestamp, lastUpdatedTime, endpointConfig, endpointImplementationType, aiConfiguration, scopes, operations, threatProtectionPolicies, categories, keyManagers, serviceInfo, advertiseInfo, gatewayVendor, gatewayType, asyncTransportProtocols, egress);
}

@Override
Expand All @@ -1526,6 +1546,7 @@ public String toString() {
sb.append(" enableSchemaValidation: ").append(toIndentedString(enableSchemaValidation)).append("\n");
sb.append(" enableSubscriberVerification: ").append(toIndentedString(enableSubscriberVerification)).append("\n");
sb.append(" type: ").append(toIndentedString(type)).append("\n");
sb.append(" subtype: ").append(toIndentedString(subtype)).append("\n");
sb.append(" audience: ").append(toIndentedString(audience)).append("\n");
sb.append(" audiences: ").append(toIndentedString(audiences)).append("\n");
sb.append(" transport: ").append(toIndentedString(transport)).append("\n");
Expand Down
Loading

0 comments on commit c6c103a

Please sign in to comment.