Skip to content

Commit c3cce47

Browse files
authored
Merge pull request #4 from kssrao87/main
Add Kafka quotas Java SDK
2 parents 504ed36 + 11d2b51 commit c3cce47

21 files changed

+2259
-7
lines changed

README.md

Lines changed: 250 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Build Status](https://travis-ci.com/IBM/eventstreams-java-sdk.svg?&branch=main)](https://travis-ci.com/IBM/eventstreams-java-sdk)
22
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
33

4-
# IBM Cloud Eventstreams Java SDK Version 1.1.0
4+
# IBM Cloud Eventstreams Java SDK Version 1.2.0
55

66
## Introduction
77

@@ -60,7 +60,7 @@ Service Name | Artifact Coordinates
6060
* Java 8 or above.
6161

6262
## Installation
63-
The current version of this SDK is: 1.1.0
63+
The current version of this SDK is: 1.2.0
6464

6565
Each service's artifact coordinates are listed in the table above.
6666

@@ -78,13 +78,13 @@ artifact coordinates (group id, artifact id and version) for the service, like t
7878
<dependency>
7979
<groupId>com.ibm.cloud</groupId>
8080
<artifactId>eventstreams_sdk</artifactId>
81-
<version>1.1.0</version>
81+
<version>1.2.0</version>
8282
</dependency>
8383
```
8484

8585
##### Gradle
8686
```gradle
87-
'com.ibm.cloud:eventstreams_sdk:1.1.0'
87+
'com.ibm.cloud:eventstreams_sdk:1.2.0'
8888
```
8989

9090
## Using the SDK
@@ -128,6 +128,11 @@ operations:
128128
- [List which topics are mirrored](#list-current-mirroring-topic-selection)
129129
- [Replace selection of topics which are mirrored](#replace-selection-of-topics-which-are-mirrored)
130130
- [List active mirroring topics](#list-active-mirroring-topics)
131+
- [Create a Kafka quota](#creating-a-kafka-quota)
132+
- [List Kafka quotas](#listing-kafka-quotas)
133+
- [Get a Kafka quota](#getting-a-kafka-quota)
134+
- [Delete a Kafka quota](#deleting-a-kafka-quota)
135+
- [Update a Kafka quota information](#updating-kafka-quotas-information)
131136

132137
The Admin REST API is also [documented using swagger](./admin-rest-api.yaml).
133138

@@ -234,8 +239,9 @@ import com.ibm.cloud.sdk.core.http.HttpStatus;
234239
public class AdminrestExample {
235240

236241

237-
private AdminrestExample() {
238-
}
242+
private AdminrestExample() {
243+
}
244+
}
239245
// End Code Setup
240246
```
241247

@@ -721,3 +727,241 @@ Expected status codes
721727
}
722728
}
723729
```
730+
731+
### Creating a Kafka quota
732+
---
733+
To create a Kafka quota the admin REST SDK issues a POST request to the /admin/quotas/ENTITYNAME path (where `ENTITYNAME` is the name of the entity that you want to create. The entity name of the quota can be `default` or an IAM Service ID that starts with an `iam-ServiceId` prefix).
734+
The body of the request contains a JSON document, for example:
735+
```json
736+
{
737+
"producer_byte_rate": 1024,
738+
"consumer_byte_rate": 1024
739+
}
740+
```
741+
742+
Create Quota would create either 1 or 2 quotas depending on what data is passed in.
743+
744+
Expected HTTP status codes:
745+
746+
- 201: Quota creation request was created.
747+
- 400: Invalid request JSON.
748+
- 403: Not authorized to create quota.
749+
- 422: Semantically invalid request.
750+
751+
If the request to create a Kafka quota succeeds then HTTP status code 201 (Created) is returned. If the operation fails then a HTTP status code of 422 (Un-processable Entity) is returned, and a JSON object containing additional information about the failure is returned as the body of the response.
752+
753+
754+
755+
756+
#### Example
757+
758+
```java
759+
private static void createQuota(Adminrest service, String entityName) {
760+
System.out.println("Create Quota");
761+
762+
// Construct an instance of the CreateQuotaOptions.
763+
CreateQuotaOptions createQuotaOptions = new CreateQuotaOptions.Builder()
764+
.entityName(entityName)
765+
.producerByteRate(1024)
766+
.consumerByteRate(1024)
767+
.build();
768+
769+
// Invoke operation with valid options.
770+
Response<Void> response = service.createQuota(createQuotaOptions).execute();
771+
772+
// Print the results.
773+
if (response.getStatusCode() == HttpStatus.CREATED) {
774+
System.out.println("\tQuota created for the entity: " + entityName);
775+
} else {
776+
System.out.println("\tError creating quota for the entity: " + entityName);
777+
}
778+
}
779+
```
780+
781+
782+
### Deleting a Kafka quota
783+
---
784+
To delete a Kafka quota, the admin REST SDK issues a DELETE request to the `/admin/quotas/ENTITYNAME`
785+
path (where `ENTITYNAME` is the name of the entity that you want to delete. The entity name of the quota can be `default` or an IAM Service ID that starts with an `iam-ServiceId` prefix).
786+
787+
Expected return codes:
788+
- 202: Quota deletion request was accepted.
789+
- 403: Not authorized to delete quota.
790+
- 404: Entity Quota does not exist.
791+
- 422: Semantically invalid request.
792+
793+
A 202 (Accepted) status code is returned if the REST API accepts the delete
794+
request or status code 422 (Un-processable Entity) if the delete request is
795+
rejected. If a delete request is rejected then the body of the HTTP response
796+
will contain a JSON object which provides additional information about why
797+
the request was rejected.
798+
799+
#### Example
800+
801+
```java
802+
private static void deleteQuota(Adminrest service, String entityName) {
803+
System.out.println("Delete Quota");
804+
805+
// Construct an instance of the DeleteQuotaOptions.
806+
DeleteQuotaOptions deleteQuotaOptions = new DeleteQuotaOptions.Builder()
807+
.entityName(entityName)
808+
.build();
809+
810+
// Invoke operation with valid options.
811+
Response<Void> response = service.deleteQuota(deleteQuotaOptions).execute();
812+
813+
// Print the results.
814+
if (response.getStatusCode() == HttpStatus.ACCEPTED) {
815+
System.out.println("\tQuota deleted for the entity: " + entityName);
816+
} else {
817+
System.out.println("\tError deleting quota for the entity: " + entityName);
818+
}
819+
}
820+
```
821+
822+
### Listing Kafka quotas
823+
---
824+
You can list all of your Kafka quotas by issuing a GET request to the
825+
`/admin/quotas` path.
826+
827+
Expected status codes:
828+
- 200: quotas list is returned as JSON in the following format:
829+
```json
830+
{
831+
"data": [
832+
{
833+
"entity_name": "default",
834+
"producer_byte_rate": 1024,
835+
"consumer_byte_rate": 1024
836+
},
837+
{
838+
"entity_name": "iam-ServiceId-38288dac-1f80-46dd-b135-a56153296bcd",
839+
"producer_byte_rate": 1024
840+
},
841+
{
842+
"entity_name": "iam-ServiceId-38288dac-1f80-46dd-b135-e56153296fgh",
843+
"consumer_byte_rate": 2048
844+
},
845+
{
846+
"entity_name": "iam-ServiceId-38288dac-1f80-46dd-b135-f56153296bfa",
847+
"producer_byte_rate": 2048,
848+
"consumer_byte_rate": 1024
849+
}
850+
]
851+
}
852+
```
853+
854+
A successful response will have HTTP status code 200 (OK) and contain an
855+
array of JSON objects, where each object represents a Kafka quota and has the
856+
following properties:
857+
858+
| Property name | Description |
859+
|-------------------|---------------------------------------------------------|
860+
| entity_name | The entity name of the quota can be `default` or an IAM Service ID that starts with an `iam-ServiceId` prefix. |
861+
| producer_byte_rate| The producer byte rate quota value. |
862+
| consumer_byte_rate| The consumer byte rate quota value. |
863+
864+
#### Example
865+
866+
```java
867+
private static void listQuotas(Adminrest service) {
868+
System.out.println("List Quotas");
869+
870+
// Invoke operation
871+
Response<EntityQuotasList> response = service.listQuotas().execute();
872+
873+
// Print the results.
874+
if (response.getStatusCode() == HttpStatus.OK) {
875+
for (EntityQuotaDetail entityQuota : response.getResult().getData()) {
876+
System.out.println("\tentity_name: " + entityQuota.getEntityName() + "\t producer_byte_rate: " + entityQuota.getProducerByteRate() + "\tconsumer_byte_rate: " + entityQuota.getConsumerByteRate());
877+
}
878+
} else {
879+
System.out.println("\tError listing quotas");
880+
}
881+
}
882+
```
883+
884+
### Getting a Kafka quota
885+
---
886+
To get a Kafka quota detail information, issue a GET request to the `/admin/quotas/ENTITYNAME`
887+
path (where `ENTITYNAME` is the name of the entity that you want to get. The entity name of the quota can be `default` or an IAM Service ID that starts with an `iam-ServiceId` prefix).
888+
889+
Expected status codes
890+
- 200: Retrieve quota details successfully in following format:
891+
```json
892+
{
893+
"producer_byte_rate": 1024,
894+
"consumer_byte_rate": 1024
895+
}
896+
```
897+
- 403: Not authorized.
898+
899+
#### Example
900+
901+
```java
902+
private static void getQuota(Adminrest service, String entityName) {
903+
904+
System.out.println("Get Entity Quota Details");
905+
906+
// Construct an instance of the GetQuotaOptions.
907+
GetQuotaOptions getQuotaOptions = new GetQuotaOptions.Builder()
908+
.entityName(entityName)
909+
.build();
910+
911+
// Invoke operation with valid options.
912+
Response<QuotaDetail> response = service.getQuota(getQuotaOptions).execute();
913+
914+
// Print the results.
915+
if (response.getStatusCode() == HttpStatus.OK) {
916+
QuotaDetail entityQuotaDetail = response.getResult();
917+
System.out.println("\tproducer_byte_rate: " + entityQuotaDetail.getProducerByteRate() + "\tconsumer_byte_rate: " + entityQuotaDetail.getConsumerByteRate());
918+
} else {
919+
System.out.println("\tError getting quota details for the entity: " + entityName);
920+
}
921+
}
922+
```
923+
924+
### Updating Kafka quota's information
925+
---
926+
To Update an entity's quota, issue a
927+
`PATCH` request to `/admin/quotas/ENTITYNAME` with the following body:
928+
(where `ENTITYNAME` is the name of the entity that you want to update. The entity name of the quota can be `default` or an IAM Service ID that starts with an `iam-ServiceId` prefix).
929+
```json
930+
{
931+
"producer_byte_rate": 2048,
932+
"consumer_byte_rate": 2048
933+
}
934+
```
935+
936+
Expected status codes
937+
- 202: Update quota request was accepted.
938+
- 400: Invalid request JSON.
939+
- 404: Entity quota specified does not exist.
940+
- 422: Semantically invalid request.
941+
942+
#### Example
943+
944+
```java
945+
private static void updateQuota(Adminrest service, String entityName) {
946+
947+
System.out.println("Update Quota");
948+
949+
// Construct an instance of the UpdateQuotaOptions.
950+
UpdateQuotaOptions updateQuotaOptions = new UpdateQuotaOptions.Builder()
951+
.entityName(entityName)
952+
.producerByteRate(2048)
953+
.consumerByteRate(2048)
954+
.build();
955+
956+
// Invoke operation with valid options.
957+
Response<Void> response = service.updateQuota(updateQuotaOptions).execute();
958+
959+
// Print the results.
960+
if (response.getStatusCode() == HttpStatus.ACCEPTED) {
961+
System.out.println("\tQuota updated for the entity: " + entityName);
962+
} else {
963+
System.out.println("\tError updating quota for the entity: " + entityName);
964+
}
965+
}
966+
```
967+

0 commit comments

Comments
 (0)