From 8282615e252dd4f4777d6264be212e5cb7f5c748 Mon Sep 17 00:00:00 2001 From: Ashan Rathnaweera Date: Mon, 9 Sep 2024 09:56:18 +0530 Subject: [PATCH 1/2] Add transaction counting capability --- .../apimgt/impl/dao/TransactionCountDAO.java | 87 +++++++++ .../impl/dao/constants/SQLConstants.java | 8 + .../apimgt/impl/dto/TransactionCountDTO.java | 72 +++++++ .../service/TransactionRecordsApi.java | 51 +++++ .../service/TransactionRecordsApiService.java | 25 +++ .../service/dto/TransactionRecordDTO.java | 180 ++++++++++++++++++ .../TransactionRecordsApiServiceImpl.java | 53 ++++++ .../src/main/resources/api.yaml | 48 +++++ .../src/main/webapp/WEB-INF/beans.xml | 1 + .../src/main/webapp/WEB-INF/web.xml | 1 + .../swagger.json | 57 ++++++ .../api/admin/v1/TransactionCountApi.java | 54 ++++++ .../admin/v1/TransactionCountApiService.java | 25 +++ .../api/admin/v1/dto/TransactionCountDTO.java | 81 ++++++++ .../impl/TransactionCountApiServiceImpl.java | 53 ++++++ .../src/main/resources/admin-api.yaml | 44 +++++ .../src/main/webapp/WEB-INF/beans.xml | 1 + .../src/main/webapp/WEB-INF/web.xml | 3 +- .../src/main/resources/admin-api.yaml | 44 +++++ .../src/main/resources/sql/db2.sql | 11 +- .../src/main/resources/sql/h2.sql | 11 +- .../src/main/resources/sql/mssql.sql | 12 ++ .../src/main/resources/sql/mysql.sql | 10 + .../src/main/resources/sql/mysql_cluster.sql | 10 +- .../src/main/resources/sql/oracle.sql | 11 +- .../src/main/resources/sql/oracle_rac.sql | 10 + .../src/main/resources/sql/postgresql.sql | 10 + 27 files changed, 967 insertions(+), 6 deletions(-) create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/TransactionCountDAO.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/TransactionCountDTO.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApi.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApiService.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/TransactionRecordDTO.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/impl/TransactionRecordsApiServiceImpl.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApi.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApiService.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/TransactionCountDTO.java create mode 100644 components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/TransactionCountApiServiceImpl.java diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/TransactionCountDAO.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/TransactionCountDAO.java new file mode 100644 index 000000000000..578b95f29406 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/TransactionCountDAO.java @@ -0,0 +1,87 @@ +package org.wso2.carbon.apimgt.impl.dao; + +import org.wso2.carbon.apimgt.api.APIManagementException; +import org.wso2.carbon.apimgt.api.ExceptionCodes; +import org.wso2.carbon.apimgt.impl.dao.constants.SQLConstants; +import org.wso2.carbon.apimgt.impl.dto.TransactionCountDTO; +import org.wso2.carbon.apimgt.impl.utils.APIMgtDBUtil; + +import java.sql.*; + +/** + * This class represent the TransactionCountDAO. + */ +public class TransactionCountDAO { + + private static final TransactionCountDAO transactionCountDAO = new TransactionCountDAO(); + + private TransactionCountDAO() { + } + + public static TransactionCountDAO getInstance() { + return transactionCountDAO; + } + + public boolean insertTransactionRecords(TransactionCountDTO[] dto) throws APIManagementException { + try (Connection connection = APIMgtDBUtil.getConnection()) { + connection.setAutoCommit(false); + + try (PreparedStatement insertTransactionRecordsStatement = connection.prepareStatement( + SQLConstants.TransactionCountConstants.INSERT_TRANSACTION_COUNT)) { + for (TransactionCountDTO record : dto) { + insertTransactionRecordsStatement.setString(1, record.getId()); + insertTransactionRecordsStatement.setString(2, record.getHost()); + insertTransactionRecordsStatement.setString(3, record.getServerID()); + insertTransactionRecordsStatement.setString(4, record.getServerType()); + insertTransactionRecordsStatement.setInt(5, record.getCount()); + + Timestamp recordedTimestamp = Timestamp.valueOf(record.getRecordedTime()); + insertTransactionRecordsStatement.setTimestamp(6, recordedTimestamp); + + insertTransactionRecordsStatement.addBatch(); + } + insertTransactionRecordsStatement.executeBatch(); + connection.commit(); + return true; + } catch (SQLException e) { + connection.rollback(); + throw new APIManagementException("Error while inserting transaction records", e, + ExceptionCodes.INTERNAL_ERROR); + } + } catch (SQLException e) { + throw new APIManagementException("Error while retrieving database connection", e, + ExceptionCodes.INTERNAL_ERROR); + } + } + + public TransactionCountDTO getTransactionCount(String startTime, String endTime) throws APIManagementException { + StringBuilder query = new StringBuilder(SQLConstants.TransactionCountConstants.GET_TRANSACTION_COUNT); + + try (Connection connection = APIMgtDBUtil.getConnection()) { + PreparedStatement getTransactionCountStatement = connection.prepareStatement(query.toString()); + + Timestamp startTimestamp = Timestamp.valueOf(startTime); + getTransactionCountStatement.setTimestamp(1, startTimestamp); + + Timestamp endTimestamp = Timestamp.valueOf(endTime); + getTransactionCountStatement.setTimestamp(2, endTimestamp); + + try (ResultSet resultSet = getTransactionCountStatement.executeQuery()) { + if (resultSet.next()) { + int count = resultSet.getInt(1); + TransactionCountDTO dto = new TransactionCountDTO(); + dto.setCount(count); + return dto; + } else { + return new TransactionCountDTO(); + } + } catch (SQLException e) { + throw new APIManagementException("Error while fetching transaction count", e, + ExceptionCodes.INTERNAL_ERROR); + } + } catch (SQLException e) { + throw new APIManagementException("Error while retrieving database connection", e, + ExceptionCodes.INTERNAL_ERROR); + } + } +} \ No newline at end of file diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java index db8b176b0e01..01b51ca62357 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java @@ -4408,4 +4408,12 @@ public static class SystemConfigsConstants { + "SET CONFIGURATION = ? WHERE ORGANIZATION = ? AND CONFIG_TYPE = ?"; } + /** + * Static class to hold database queries related to AM_TRANSACTION_RECORDS table + */ + public static class TransactionCountConstants { + public static final String INSERT_TRANSACTION_COUNT = "INSERT INTO AM_TRANSACTION_RECORDS " + "(ID, HOST, SERVER_ID, SERVER_TYPE, COUNT, RECORDED_TIME) " + "VALUES (?,?,?,?,?,?)"; + public static final String GET_TRANSACTION_COUNT = "SELECT SUM(COUNT) FROM AM_TRANSACTION_RECORDS " + "WHERE RECORDED_TIME >= ? AND RECORDED_TIME <= ?"; + } + } diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/TransactionCountDTO.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/TransactionCountDTO.java new file mode 100644 index 000000000000..a8c1cb4192f1 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/TransactionCountDTO.java @@ -0,0 +1,72 @@ +package org.wso2.carbon.apimgt.impl.dto; + +public class TransactionCountDTO { + private String id; + private String host; + private String serverID; + private String serverType; + private int count; + private String recordedTime; + + public TransactionCountDTO(String id, String host, String serverId, String serverType, int count, + String recordedTime) { + this.id = id; + this.host = host; + this.serverID = serverId; + this.serverType = serverType; + this.count = count; + this.recordedTime = recordedTime; + } + + public TransactionCountDTO() { + + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public String getServerID() { + return serverID; + } + + public void setServerID(String serverID) { + this.serverID = serverID; + } + + public String getServerType() { + return serverType; + } + + public void setServerType(String serverType) { + this.serverType = serverType; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public String getRecordedTime() { + return recordedTime; + } + + public void setRecordedTime(String recordedTime) { + this.recordedTime = recordedTime; + } +} diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApi.java b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApi.java new file mode 100644 index 000000000000..4b82d461ccaa --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApi.java @@ -0,0 +1,51 @@ +package org.wso2.carbon.apimgt.internal.service; + +import java.util.List; +import org.wso2.carbon.apimgt.internal.service.dto.TransactionRecordDTO; +import org.wso2.carbon.apimgt.internal.service.TransactionRecordsApiService; +import org.wso2.carbon.apimgt.internal.service.impl.TransactionRecordsApiServiceImpl; +import org.wso2.carbon.apimgt.api.APIManagementException; + +import javax.ws.rs.*; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; +import javax.inject.Inject; + +import io.swagger.annotations.*; +import java.io.InputStream; + +import org.apache.cxf.jaxrs.ext.MessageContext; +import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.apache.cxf.jaxrs.ext.multipart.Multipart; + +import java.util.Map; +import java.util.List; +import javax.validation.constraints.*; +@Path("/transaction-records") + +@Api(description = "the transaction-records API") + +@Produces({ "application/json" }) + + +public class TransactionRecordsApi { + + @Context MessageContext securityContext; + +TransactionRecordsApiService delegate = new TransactionRecordsApiServiceImpl(); + + + @POST + + + @Produces({ "application/json" }) + @ApiOperation(value = "Insert Transaction Records", notes = "Inserts a list of transaction records into the database.", response = Boolean.class, tags={ }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successfully inserted transaction records", response = Boolean.class), + @ApiResponse(code = 400, message = "Bad request. Invalid input data.", response = Void.class), + @ApiResponse(code = 500, message = "Internal server error. Failed to insert transaction records.", response = Void.class) }) + public Response insertTransactionRecords(@ApiParam(value = "A list of transaction records to be inserted" ,required=true) List body) throws APIManagementException{ + return delegate.insertTransactionRecords(body, securityContext); + } +} diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApiService.java b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApiService.java new file mode 100644 index 000000000000..ba0cdc2deacc --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApiService.java @@ -0,0 +1,25 @@ +package org.wso2.carbon.apimgt.internal.service; + +import org.wso2.carbon.apimgt.internal.service.*; +import org.wso2.carbon.apimgt.internal.service.dto.*; + +import org.apache.cxf.jaxrs.ext.MessageContext; +import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.apache.cxf.jaxrs.ext.multipart.Multipart; + +import org.wso2.carbon.apimgt.api.APIManagementException; + +import java.util.List; +import org.wso2.carbon.apimgt.internal.service.dto.TransactionRecordDTO; + +import java.util.List; + +import java.io.InputStream; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; + + +public interface TransactionRecordsApiService { + public Response insertTransactionRecords(List body, MessageContext messageContext) throws APIManagementException; +} diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/TransactionRecordDTO.java b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/TransactionRecordDTO.java new file mode 100644 index 000000000000..01985ea5250b --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/TransactionRecordDTO.java @@ -0,0 +1,180 @@ +package org.wso2.carbon.apimgt.internal.service.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; + +import javax.xml.bind.annotation.*; +import org.wso2.carbon.apimgt.rest.api.common.annotations.Scope; +import com.fasterxml.jackson.annotation.JsonCreator; + + + +public class TransactionRecordDTO { + + private String id = null; + private String serverID = null; + private String serverType = null; + private String host = null; + private Integer count = null; + private String recordedTime = null; + + /** + **/ + public TransactionRecordDTO id(String id) { + this.id = id; + return this; + } + + + @ApiModelProperty(required = true, value = "") + @JsonProperty("id") + @NotNull + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + /** + **/ + public TransactionRecordDTO serverID(String serverID) { + this.serverID = serverID; + return this; + } + + + @ApiModelProperty(value = "") + @JsonProperty("serverID") + public String getServerID() { + return serverID; + } + public void setServerID(String serverID) { + this.serverID = serverID; + } + + /** + **/ + public TransactionRecordDTO serverType(String serverType) { + this.serverType = serverType; + return this; + } + + + @ApiModelProperty(value = "") + @JsonProperty("serverType") + public String getServerType() { + return serverType; + } + public void setServerType(String serverType) { + this.serverType = serverType; + } + + /** + **/ + public TransactionRecordDTO host(String host) { + this.host = host; + return this; + } + + + @ApiModelProperty(value = "") + @JsonProperty("host") + public String getHost() { + return host; + } + public void setHost(String host) { + this.host = host; + } + + /** + **/ + public TransactionRecordDTO count(Integer count) { + this.count = count; + return this; + } + + + @ApiModelProperty(required = true, value = "") + @JsonProperty("count") + @NotNull + public Integer getCount() { + return count; + } + public void setCount(Integer count) { + this.count = count; + } + + /** + **/ + public TransactionRecordDTO recordedTime(String recordedTime) { + this.recordedTime = recordedTime; + return this; + } + + + @ApiModelProperty(required = true, value = "") + @JsonProperty("recordedTime") + @NotNull + public String getRecordedTime() { + return recordedTime; + } + public void setRecordedTime(String recordedTime) { + this.recordedTime = recordedTime; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + TransactionRecordDTO transactionRecord = (TransactionRecordDTO) o; + return Objects.equals(id, transactionRecord.id) && + Objects.equals(serverID, transactionRecord.serverID) && + Objects.equals(serverType, transactionRecord.serverType) && + Objects.equals(host, transactionRecord.host) && + Objects.equals(count, transactionRecord.count) && + Objects.equals(recordedTime, transactionRecord.recordedTime); + } + + @Override + public int hashCode() { + return Objects.hash(id, serverID, serverType, host, count, recordedTime); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class TransactionRecordDTO {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" serverID: ").append(toIndentedString(serverID)).append("\n"); + sb.append(" serverType: ").append(toIndentedString(serverType)).append("\n"); + sb.append(" host: ").append(toIndentedString(host)).append("\n"); + sb.append(" count: ").append(toIndentedString(count)).append("\n"); + sb.append(" recordedTime: ").append(toIndentedString(recordedTime)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/impl/TransactionRecordsApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/impl/TransactionRecordsApiServiceImpl.java new file mode 100644 index 000000000000..00fc7eb16e0a --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/impl/TransactionRecordsApiServiceImpl.java @@ -0,0 +1,53 @@ +package org.wso2.carbon.apimgt.internal.service.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.apimgt.api.APIManagementException; +import org.wso2.carbon.apimgt.impl.dao.TransactionCountDAO; +import org.wso2.carbon.apimgt.impl.dto.TransactionCountDTO; +import org.wso2.carbon.apimgt.internal.service.*; +import org.wso2.carbon.apimgt.internal.service.dto.*; + +import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.apache.cxf.jaxrs.ext.MessageContext; + +import java.util.List; + +import org.wso2.carbon.apimgt.internal.service.dto.TransactionRecordDTO; +import org.wso2.carbon.apimgt.rest.api.util.utils.RestApiUtil; + +import java.util.List; + +import java.io.InputStream; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; + +public class TransactionRecordsApiServiceImpl implements TransactionRecordsApiService { + + private static final Log log = LogFactory.getLog(TransactionRecordsApiServiceImpl.class); + + public Response insertTransactionRecords(List body, MessageContext messageContext) { + TransactionCountDAO transactionCountDAO = TransactionCountDAO.getInstance(); + + try { + TransactionCountDTO[] transactionCountDTOArray = body.stream().map(recordDTO -> { + TransactionCountDTO transactionCountDTO = new TransactionCountDTO(); + transactionCountDTO.setId(recordDTO.getId()); + transactionCountDTO.setHost(recordDTO.getHost()); + transactionCountDTO.setServerID(recordDTO.getServerID()); + transactionCountDTO.setServerType(recordDTO.getServerType()); + transactionCountDTO.setCount(recordDTO.getCount()); + transactionCountDTO.setRecordedTime(recordDTO.getRecordedTime()); + return transactionCountDTO; + }).toArray(TransactionCountDTO[]::new); + + Boolean result = transactionCountDAO.insertTransactionRecords(transactionCountDTOArray); + return Response.ok().entity(result).build(); + } catch (APIManagementException e) { + String errorMessage = "Error while inserting transaction records."; + RestApiUtil.handleInternalServerError(errorMessage, e, log); + } + return null; + } +} diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/resources/api.yaml b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/resources/api.yaml index 810642f41497..f83c4887a113 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/resources/api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/resources/api.yaml @@ -693,6 +693,32 @@ paths: description: Unexpected error schema: $ref: '#/definitions/Error' + #-------------------------------------------- + # Transaction count related resources + #-------------------------------------------- + /transaction-records: + post: + summary: Insert Transaction Records + description: Inserts a list of transaction records into the database. + operationId: insertTransactionRecords + parameters: + - in: body + name: body + description: A list of transaction records to be inserted + required: true + schema: + type: array + items: + $ref: '#/definitions/TransactionRecord' + responses: + '200': + description: Successfully inserted transaction records + schema: + type: boolean + '400': + description: Bad request. Invalid input data. + '500': + description: Internal server error. Failed to insert transaction records. ###################################################### # Parameters - required by some of the APIs above @@ -1717,3 +1743,25 @@ definitions: items: type: string example: "MessageDeliveryTaskPool" + #----------------------------------------------------- + # The Transaction Count resource + #----------------------------------------------------- + TransactionRecord: + type: object + properties: + id: + type: string + serverID: + type: string + serverType: + type: string + host: + type: string + count: + type: integer + recordedTime: + type: string + required: + - id + - count + - recordedTime diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/webapp/WEB-INF/beans.xml b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/webapp/WEB-INF/beans.xml index 4a4d7a8057e1..10de134b04d5 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/webapp/WEB-INF/beans.xml +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/webapp/WEB-INF/beans.xml @@ -36,6 +36,7 @@ + diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/webapp/WEB-INF/web.xml b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/webapp/WEB-INF/web.xml index 1616a5c52e27..234e45aeb387 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/webapp/WEB-INF/web.xml +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/webapp/WEB-INF/web.xml @@ -57,6 +57,7 @@ org.wso2.carbon.apimgt.internal.service.ApiLoggingConfigsApi, org.wso2.carbon.apimgt.internal.service.CorrelationConfigsApi, org.wso2.carbon.apimgt.internal.service.GatewayPolicyArtifactsApi, + org.wso2.carbon.apimgt.internal.service.TransactionRecordsApi, org.wso2.carbon.apimgt.internal.service.SubscribeInternalApi diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/swagger.json b/components/apimgt/org.wso2.carbon.apimgt.internal.service/swagger.json index 5d4bae5a7656..4a0864b5ff7c 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/swagger.json +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/swagger.json @@ -917,6 +917,39 @@ } } } + }, + "/transaction-records" : { + "post" : { + "summary" : "Insert Transaction Records", + "description" : "Inserts a list of transaction records into the database.", + "operationId" : "insertTransactionRecords", + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "A list of transaction records to be inserted", + "required" : true, + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/TransactionRecord" + } + } + } ], + "responses" : { + "200" : { + "description" : "Successfully inserted transaction records", + "schema" : { + "type" : "boolean" + } + }, + "400" : { + "description" : "Bad request. Invalid input data." + }, + "500" : { + "description" : "Internal server error. Failed to insert transaction records." + } + } + } } }, "definitions" : { @@ -2127,6 +2160,30 @@ } }, "title" : "Properties for correlation components" + }, + "TransactionRecord" : { + "type" : "object", + "required" : [ "count", "id", "recordedTime" ], + "properties" : { + "id" : { + "type" : "string" + }, + "serverID" : { + "type" : "string" + }, + "serverType" : { + "type" : "string" + }, + "host" : { + "type" : "string" + }, + "count" : { + "type" : "integer" + }, + "recordedTime" : { + "type" : "string" + } + } } }, "parameters" : { diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApi.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApi.java new file mode 100644 index 000000000000..a3a3b6178073 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApi.java @@ -0,0 +1,54 @@ +package org.wso2.carbon.apimgt.rest.api.admin.v1; + +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ErrorDTO; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.TransactionCountDTO; +import org.wso2.carbon.apimgt.rest.api.admin.v1.TransactionCountApiService; +import org.wso2.carbon.apimgt.rest.api.admin.v1.impl.TransactionCountApiServiceImpl; +import org.wso2.carbon.apimgt.api.APIManagementException; + +import javax.ws.rs.*; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; +import javax.inject.Inject; + +import io.swagger.annotations.*; +import java.io.InputStream; + +import org.apache.cxf.jaxrs.ext.MessageContext; +import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.apache.cxf.jaxrs.ext.multipart.Multipart; + +import java.util.Map; +import java.util.List; +import javax.validation.constraints.*; +@Path("/transaction-count") + +@Api(description = "the transaction-count API") + + + + +public class TransactionCountApi { + + @Context MessageContext securityContext; + +TransactionCountApiService delegate = new TransactionCountApiServiceImpl(); + + + @GET + + + @Produces({ "application/json" }) + @ApiOperation(value = "Get transaction count", notes = "This endpoint retrieves the transaction count based on various filter parameters.", response = TransactionCountDTO.class, authorizations = { + @Authorization(value = "OAuth2Security", scopes = { + @AuthorizationScope(scope = "apim:admin", description = "Manage all admin operations") + }) + }, tags={ "Transaction Records" }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Transaction count retrieved successfully", response = TransactionCountDTO.class), + @ApiResponse(code = 200, message = "Unexpected error", response = ErrorDTO.class) }) + public Response transactionCountGet( @NotNull @ApiParam(value = "Start time for the transaction count retrieval",required=true) @QueryParam("startTime") String startTime, @NotNull @ApiParam(value = "End time for the transaction count retrieval",required=true) @QueryParam("endTime") String endTime) throws APIManagementException{ + return delegate.transactionCountGet(startTime, endTime, securityContext); + } +} diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApiService.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApiService.java new file mode 100644 index 000000000000..09a797a43e76 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApiService.java @@ -0,0 +1,25 @@ +package org.wso2.carbon.apimgt.rest.api.admin.v1; + +import org.wso2.carbon.apimgt.rest.api.admin.v1.*; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.*; + +import org.apache.cxf.jaxrs.ext.MessageContext; +import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.apache.cxf.jaxrs.ext.multipart.Multipart; + +import org.wso2.carbon.apimgt.api.APIManagementException; + +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ErrorDTO; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.TransactionCountDTO; + +import java.util.List; + +import java.io.InputStream; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; + + +public interface TransactionCountApiService { + public Response transactionCountGet(String startTime, String endTime, MessageContext messageContext) throws APIManagementException; +} diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/TransactionCountDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/TransactionCountDTO.java new file mode 100644 index 000000000000..bf459c259ff2 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/TransactionCountDTO.java @@ -0,0 +1,81 @@ +package org.wso2.carbon.apimgt.rest.api.admin.v1.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.*; + + +import io.swagger.annotations.*; +import java.util.Objects; + +import javax.xml.bind.annotation.*; +import org.wso2.carbon.apimgt.rest.api.common.annotations.Scope; +import com.fasterxml.jackson.annotation.JsonCreator; + +import javax.validation.Valid; + + + +public class TransactionCountDTO { + + private Integer count = null; + + /** + **/ + public TransactionCountDTO count(Integer count) { + this.count = count; + return this; + } + + + @ApiModelProperty(example = "120", value = "") + @JsonProperty("count") + public Integer getCount() { + return count; + } + public void setCount(Integer count) { + this.count = count; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + TransactionCountDTO transactionCount = (TransactionCountDTO) o; + return Objects.equals(count, transactionCount.count); + } + + @Override + public int hashCode() { + return Objects.hash(count); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class TransactionCountDTO {\n"); + + sb.append(" count: ").append(toIndentedString(count)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/TransactionCountApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/TransactionCountApiServiceImpl.java new file mode 100644 index 000000000000..27290d095c59 --- /dev/null +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/TransactionCountApiServiceImpl.java @@ -0,0 +1,53 @@ +package org.wso2.carbon.apimgt.rest.api.admin.v1.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.apimgt.api.APIManagementException; +import org.wso2.carbon.apimgt.impl.dao.TransactionCountDAO; +import org.wso2.carbon.apimgt.impl.dto.TransactionCountDTO; +import org.wso2.carbon.apimgt.rest.api.admin.v1.*; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.*; + +import org.apache.cxf.jaxrs.ext.multipart.Attachment; +import org.apache.cxf.jaxrs.ext.MessageContext; + +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ErrorDTO; +import org.wso2.carbon.apimgt.rest.api.util.utils.RestApiUtil; + +import java.sql.Timestamp; +import java.time.Instant; +import java.time.LocalTime; +import java.time.ZoneId; +import java.util.List; + +import java.io.InputStream; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; + +public class TransactionCountApiServiceImpl implements TransactionCountApiService { + + private static final Log log = LogFactory.getLog(TransactionCountApiServiceImpl.class); + + public Response transactionCountGet(String startTime, String endTime, MessageContext messageContext) { + try { + ZoneId zoneId = ZoneId.systemDefault(); + // Convert start and end times to the start and end of the respective days + String startTimeTimestamp = Timestamp.from( + Instant.ofEpochSecond(Long.parseLong(startTime)).atZone(zoneId).toLocalDate().atStartOfDay(zoneId) + .toInstant()).toString(); + String endTimeTimestamp = Timestamp.from( + Instant.ofEpochSecond(Long.parseLong(endTime)).atZone(zoneId).toLocalDate().atTime(LocalTime.MAX) + .atZone(zoneId).toInstant()).toString(); + TransactionCountDAO transactionCountDAO = TransactionCountDAO.getInstance(); + TransactionCountDTO transactionCountDTO = transactionCountDAO.getTransactionCount(startTimeTimestamp, + endTimeTimestamp); + + return Response.ok().entity(transactionCountDTO).build(); + } catch (APIManagementException e) { + String errorMessage = "Error while retrieving transaction count."; + RestApiUtil.handleInternalServerError(errorMessage, e, log); + } + return null; + } +} diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml index 8dff2ebf0c29..c03e23a75a4b 100755 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml @@ -3592,6 +3592,44 @@ paths: - lang: Curl source: 'curl -k -X PUT -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" -H "Content-Type: application/json" "https://127.0.0.1:9443/api/am/admin/v4/provider/admin/apis/33662a62-8db1-4d75-af08-afd63c6bd0b4/change-provider?provider=user1"' + ###################################################### + # The "Transaction Count" resource API + ###################################################### + /transaction-count: + get: + tags: + - "Transaction Records" + summary: "Get transaction count" + description: "This endpoint retrieves the transaction count based on various filter parameters." + parameters: + - name: "startTime" + in: "query" + description: "Start time for the transaction count retrieval" + required: true + schema: + type: "string" + - name: "endTime" + in: "query" + description: "End time for the transaction count retrieval" + required: true + schema: + type: "string" + responses: + 200: + description: "Transaction count retrieved successfully" + content: + application/json: + schema: + $ref: "#/components/schemas/TransactionCount" + default: + description: "Unexpected error" + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + security: + - OAuth2Security: + - apim:admin components: schemas: Error: @@ -5494,6 +5532,12 @@ components: type: string id: type: string + TransactionCount: + type: object + properties: + count: + type: integer + example: 120 responses: BadRequest: description: Bad Request. Invalid request or validation error. diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/webapp/WEB-INF/beans.xml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/webapp/WEB-INF/beans.xml index a036f2021804..d391cca6363b 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/webapp/WEB-INF/beans.xml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/webapp/WEB-INF/beans.xml @@ -51,6 +51,7 @@ + diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/webapp/WEB-INF/web.xml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/webapp/WEB-INF/web.xml index f2475dc7c01b..78b877901f25 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/webapp/WEB-INF/web.xml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/webapp/WEB-INF/web.xml @@ -54,7 +54,8 @@ org.wso2.carbon.apimgt.rest.api.admin.v1.TenantConfigApi, org.wso2.carbon.apimgt.rest.api.admin.v1.TenantConfigSchemaApi, org.wso2.carbon.apimgt.rest.api.admin.v1.GlobalKeyManagersApi, - org.wso2.carbon.apimgt.rest.api.admin.v1.ApisApi + org.wso2.carbon.apimgt.rest.api.admin.v1.ApisApi, + org.wso2.carbon.apimgt.rest.api.admin.v1.TransactionCountApi diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/admin-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/admin-api.yaml index 8dff2ebf0c29..c03e23a75a4b 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/admin-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/admin-api.yaml @@ -3592,6 +3592,44 @@ paths: - lang: Curl source: 'curl -k -X PUT -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" -H "Content-Type: application/json" "https://127.0.0.1:9443/api/am/admin/v4/provider/admin/apis/33662a62-8db1-4d75-af08-afd63c6bd0b4/change-provider?provider=user1"' + ###################################################### + # The "Transaction Count" resource API + ###################################################### + /transaction-count: + get: + tags: + - "Transaction Records" + summary: "Get transaction count" + description: "This endpoint retrieves the transaction count based on various filter parameters." + parameters: + - name: "startTime" + in: "query" + description: "Start time for the transaction count retrieval" + required: true + schema: + type: "string" + - name: "endTime" + in: "query" + description: "End time for the transaction count retrieval" + required: true + schema: + type: "string" + responses: + 200: + description: "Transaction count retrieved successfully" + content: + application/json: + schema: + $ref: "#/components/schemas/TransactionCount" + default: + description: "Unexpected error" + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + security: + - OAuth2Security: + - apim:admin components: schemas: Error: @@ -5494,6 +5532,12 @@ components: type: string id: type: string + TransactionCount: + type: object + properties: + count: + type: integer + example: 120 responses: BadRequest: description: Bad Request. Invalid request or validation error. diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sql index c82f3d40a43f..044f258f3ed1 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/db2.sql @@ -3257,7 +3257,16 @@ CREATE TABLE AM_SUBJECT_ENTITY_REVOKED_EVENT ) / - +CREATE TABLE AM_TRANSACTION_RECORDS ( + ID VARCHAR(255) NOT NULL, + HOST VARCHAR(255), + SERVER_ID VARCHAR(255), + SERVER_TYPE VARCHAR(20), + COUNT INTEGER NOT NULL, + RECORDED_TIME TIMESTAMP NOT NULL, + PRIMARY KEY (ID) +); +/ diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/h2.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/h2.sql index 5aaaae6a7cbc..4a7f3de63ae8 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/h2.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/h2.sql @@ -2451,7 +2451,15 @@ CREATE TABLE IF NOT EXISTS AM_SUBJECT_ENTITY_REVOKED_EVENT ( PRIMARY KEY (ENTITY_ID, ENTITY_TYPE, ORGANIZATION) ); - +CREATE TABLE AM_TRANSACTION_RECORDS ( + ID VARCHAR(255) NOT NULL, + HOST VARCHAR(255), + SERVER_ID VARCHAR(255), + SERVER_TYPE VARCHAR(20), + COUNT INT NOT NULL, + RECORDED_TIME TIMESTAMP NOT NULL, + PRIMARY KEY (ID) +); @@ -2471,4 +2479,3 @@ CREATE UNIQUE INDEX POLICY_HARD_NAME_TENANT ON AM_POLICY_HARD_THROTTLING(NAME, T CREATE UNIQUE INDEX API_NAME_TENANT ON AM_API_THROTTLE_POLICY(NAME, TENANT_ID); -- - diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mssql.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mssql.sql index aa85570d2d62..888bdea803af 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mssql.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mssql.sql @@ -2397,6 +2397,18 @@ CREATE TABLE AM_TENANT_THEMES ( THEME VARBINARY(MAX) NOT NULL, PRIMARY KEY (TENANT_ID) ); + +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_TRANSACTION_RECORDS]') AND TYPE IN (N'U')) +CREATE TABLE AM_TRANSACTION_RECORDS ( + ID VARCHAR(255) NOT NULL, + HOST VARCHAR(255), + SERVER_ID VARCHAR(255), + SERVER_TYPE VARCHAR(20), + COUNT INT NOT NULL, + RECORDED_TIME DATETIME NOT NULL, + PRIMARY KEY (ID) +); + -- End of API-MGT Tables -- IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_SCOPE]') AND TYPE IN (N'U')) diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql.sql index d4bd6b84b854..aa7a46b742fb 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql.sql @@ -2053,6 +2053,16 @@ CREATE TABLE IF NOT EXISTS AM_TENANT_THEMES ( THEME MEDIUMBLOB NOT NULL, PRIMARY KEY (TENANT_ID) ) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS AM_TRANSACTION_RECORDS ( + ID VARCHAR(255) NOT NULL, + HOST VARCHAR(255), + SERVER_ID VARCHAR(255), + SERVER_TYPE VARCHAR(20), + COUNT INT NOT NULL, + RECORDED_TIME TIMESTAMP NOT NULL, + PRIMARY KEY (ID) +) ENGINE=INNODB; -- End of API-MGT Tables -- -- UMA tables -- diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql_cluster.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql_cluster.sql index 50829b45755e..747055429ef4 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql_cluster.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/mysql_cluster.sql @@ -2648,7 +2648,15 @@ CREATE TABLE IF NOT EXISTS AM_SUBJECT_ENTITY_REVOKED_EVENT ( PRIMARY KEY (ENTITY_ID, ENTITY_TYPE, ORGANIZATION) )ENGINE=NDB; - +CREATE TABLE IF NOT EXISTS AM_TRANSACTION_RECORDS ( + ID VARCHAR(255) NOT NULL, + HOST VARCHAR(255), + SERVER_ID VARCHAR(255), + SERVER_TYPE VARCHAR(20), + COUNT INT NOT NULL, + RECORDED_TIME TIMESTAMP NOT NULL, + PRIMARY KEY (ID) +) ENGINE=NDB; -- End of API-MGT Tables -- diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle.sql index 15b59fa2e94e..c970b47d3b48 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle.sql @@ -3837,7 +3837,16 @@ CREATE TABLE AM_SUBJECT_ENTITY_REVOKED_EVENT ) / - +CREATE TABLE AM_TRANSACTION_RECORDS ( + ID VARCHAR(255) NOT NULL, + HOST VARCHAR2(255), + SERVER_ID VARCHAR2(255), + SERVER_TYPE VARCHAR2(20), + COUNT NUMBER NOT NULL, + RECORDED_TIME TIMESTAMP NOT NULL, + PRIMARY KEY (ID) +); +/ -- End of API-MGT Tables -- diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_rac.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_rac.sql index f0c3a17b5bac..505d819b2f77 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_rac.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/oracle_rac.sql @@ -3808,6 +3808,16 @@ CREATE TABLE AM_SUBJECT_ENTITY_REVOKED_EVENT ) / +CREATE TABLE AM_TRANSACTION_RECORDS ( + ID VARCHAR(255) NOT NULL, + HOST VARCHAR(255), + SERVER_ID VARCHAR(255), + SERVER_TYPE VARCHAR(20), + COUNT NUMBER NOT NULL, + RECORDED_TIME TIMESTAMP NOT NULL, + PRIMARY KEY (ID) +); +/ -- End of API-MGT Tables -- diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/postgresql.sql b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/postgresql.sql index f5b355130299..e91ef68f5f97 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/postgresql.sql +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/sql/postgresql.sql @@ -2824,6 +2824,16 @@ CREATE TABLE IF NOT EXISTS AM_SUBJECT_ENTITY_REVOKED_EVENT ( PRIMARY KEY (ENTITY_ID, ENTITY_TYPE, ORGANIZATION) ); +DROP TABLE IF EXISTS AM_TRANSACTION_RECORDS; +CREATE TABLE IF NOT EXISTS AM_TRANSACTION_RECORDS ( + ID VARCHAR(255) NOT NULL, + HOST VARCHAR(255), + SERVER_ID VARCHAR(255), + SERVER_TYPE VARCHAR(20), + COUNT INT NOT NULL, + RECORDED_TIME TIMESTAMP NOT NULL, + PRIMARY KEY (ID) +); -- End of API-MGT Tables -- From adfef467f438d43d5b4531f3aa1e7fea8d658f9e Mon Sep 17 00:00:00 2001 From: Ashan Rathnaweera Date: Mon, 9 Sep 2024 12:08:24 +0530 Subject: [PATCH 2/2] Add license text to new files --- .../apimgt/impl/dao/TransactionCountDAO.java | 20 ++++++++++++++++++- .../apimgt/impl/dto/TransactionCountDTO.java | 18 +++++++++++++++++ .../service/TransactionRecordsApi.java | 18 +++++++++++++++++ .../service/TransactionRecordsApiService.java | 18 +++++++++++++++++ .../service/dto/TransactionRecordDTO.java | 19 +++++++++++++++++- .../TransactionRecordsApiServiceImpl.java | 18 +++++++++++++++++ .../api/admin/v1/TransactionCountApi.java | 18 +++++++++++++++++ .../admin/v1/TransactionCountApiService.java | 18 +++++++++++++++++ .../impl/TransactionCountApiServiceImpl.java | 18 +++++++++++++++++ 9 files changed, 163 insertions(+), 2 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/TransactionCountDAO.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/TransactionCountDAO.java index 578b95f29406..2cef69a84cda 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/TransactionCountDAO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/TransactionCountDAO.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * 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.impl.dao; import org.wso2.carbon.apimgt.api.APIManagementException; @@ -84,4 +102,4 @@ public TransactionCountDTO getTransactionCount(String startTime, String endTime) ExceptionCodes.INTERNAL_ERROR); } } -} \ No newline at end of file +} diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/TransactionCountDTO.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/TransactionCountDTO.java index a8c1cb4192f1..ba99d7db4ea2 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/TransactionCountDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/TransactionCountDTO.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * 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.impl.dto; public class TransactionCountDTO { diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApi.java b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApi.java index 4b82d461ccaa..4976284731ad 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApi.java +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApi.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * 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.internal.service; import java.util.List; diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApiService.java b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApiService.java index ba0cdc2deacc..41bc68597742 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApiService.java +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/TransactionRecordsApiService.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * 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.internal.service; import org.wso2.carbon.apimgt.internal.service.*; diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/TransactionRecordDTO.java b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/TransactionRecordDTO.java index 01985ea5250b..b8e4a43f3b8f 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/TransactionRecordDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/TransactionRecordDTO.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * 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.internal.service.dto; import com.fasterxml.jackson.annotation.JsonProperty; @@ -177,4 +195,3 @@ private String toIndentedString(java.lang.Object o) { return o.toString().replace("\n", "\n "); } } - diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/impl/TransactionRecordsApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/impl/TransactionRecordsApiServiceImpl.java index 00fc7eb16e0a..384fccb6a3d7 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/impl/TransactionRecordsApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/impl/TransactionRecordsApiServiceImpl.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * 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.internal.service.impl; import org.apache.commons.logging.Log; diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApi.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApi.java index a3a3b6178073..34f888ad44b7 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApi.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApi.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * 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.rest.api.admin.v1; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ErrorDTO; diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApiService.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApiService.java index 09a797a43e76..6d4eead4a0ae 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApiService.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/TransactionCountApiService.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * 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.rest.api.admin.v1; import org.wso2.carbon.apimgt.rest.api.admin.v1.*; diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/TransactionCountApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/TransactionCountApiServiceImpl.java index 27290d095c59..bcb83c642db1 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/TransactionCountApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/TransactionCountApiServiceImpl.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * 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.rest.api.admin.v1.impl; import org.apache.commons.logging.Log;