Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.idea
out
target
kafkatools.iml
.classpath
.project
.settings/
.vscode/
exports.sh
env.env
prd.sh
qa.sh
stg.sh


testtopic
kafka_client_jaas.config
local.sh
oldway
eclipse-formatter.xml
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Adding source, compile and package into a fat jar
ADD src /code/src
RUN ["mvn", "package"]

EXPOSE 3800
CMD ["/usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-jar", "target/oct-kafka-api-jar-with-dependencies.jar"]
ADD create.sql create.sql

Check failure on line 17 in Dockerfile

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Dockerfile#L17

Use COPY instead of ADD for files and folders

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy found a critical ErrorProne issue: Use COPY instead of ADD for files and folders

The issue identified by Hadolint regarding the use of ADD instead of COPY is based on best practices in Dockerfile optimization. The ADD instruction is more powerful than COPY because it can handle remote URLs and automatically extract tar files. However, when you are simply copying files or directories from the build context to the image, it is recommended to use COPY instead of ADD. This makes your intentions clearer and can lead to smaller images, as COPY does not have the additional overhead of the extra features provided by ADD.

To fix the issue, you should replace the ADD instruction with COPY for the create.sql file. Here’s the single line change:

Suggested change
ADD create.sql create.sql
COPY create.sql create.sql

This comment was generated by an experimental AI tool.

EXPOSE 9000
CMD ["/usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-jar", "target/kafka-api-jar-with-dependencies.jar"]

93 changes: 88 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,99 @@

## Synopis

Runs a REST API to offer management of Kafka topics.
Runs a REST API to offer management of Kafka topics, consumergroups, users, and ACLs

## Details

* GET ... (todo)
```
get /v1/kafka/cluster/:cluster/consumergroups
get /v1/kafka/cluster/:cluster/credentials/:username
get /v1/kafka/cluster/:cluster/topic/:topic
get /v1/kafka/cluster/:cluster/topic/:topic/consumergroups
get /v1/kafka/cluster/:cluster/topics
post /v1/kafka/cluster/:cluster/topic
post /v1/kafka/cluster/:cluster/user
post /v1/kafka/cluster/:cluster/user/:username/topic/:topic/consumergroup/rotate
put /v1/kafka/cluster/:cluster/acl/user/:user/topic/:topic/role/:role
put /v1/kafka/cluster/:cluster/topic/:topic/retentionms/:retentionms
delete /v1/kafka/cluster/:cluster/topic/:topic

## Runtime Environment Variables

* PORT
JSON payload exmample for creation of a topic is

{
"topic": {
"name": "tt9",
"description":"User.Friendly.Name",
"organization":"testorg",
"config": {
"cleanup.policy": "delete",
"partitions": 8,
"retention.ms":8888
}
}
}


```


## Runtime Environment Variables
```
SANDBOX_KAFKA_PORT
SANDBOX_DEFAULT_PARTITIONS
SANDBOX_DEFAULT_REPLICAS
SANDBOX_DEFAULT_RETENTION
SANDBOX_KAFKA_ADMIN_USERNAME
SANDBOX_KAFKA_ADMIN_PASSWORD
SANDBOX_KAFKA_LOCATION
SANDBOX_KAFKA_HOSTNAME
SANDBOX_ZK
SANDBOX_KAFKA_AVRO_REGISTRY_LOCATION
SANDBOX_KAFKA_AVRO_REGISTRY_HOSTNAME
SANDBOX_KAFKA_AVRO_REGISTRY_PORT
DEV_KAFKA_PORT
DEV_DEFAULT_PARTITIONS
DEV_DEFAULT_REPLICAS
DEV_DEFAULT_RETENTION
DEV_KAFKA_ADMIN_USERNAME
DEV_KAFKA_ADMIN_PASSWORD
DEV_KAFKA_LOCATION
DEV_KAFKA_HOSTNAME
DEV_ZK
DEV_KAFKA_AVRO_REGISTRY_LOCATION
DEV_KAFKA_AVRO_REGISTRY_HOSTNAME
DEV_KAFKA_AVRO_REGISTRY_PORT
PRODUCTION_KAFKA_POST
PRODUCTION_DEFAULT_PARTITIONS
PRODUCTION_DEFAULT_REPLICAS
PRODUCTION_DEFAULT_RETENTION
PRODUCTION_KAFKA_ADMIN_USERNAME
PRODUCTION_KAFKA_ADMIN_PASSWORD
PRODUCTION_KAFKA_LOCATION
PRODUCTION_KAFKA_HOSTNAME
PRODUCTION_ZK
PRODUCTION_KAFKA_AVRO_REGISTRY_LOCATION
PRODUCTION_KAFKA_AVRO_REGISTRY_HOSTNAME
PRODUCTION_KAFKA_AVRO_REGISTRY_PORT
BROKERDB
BROKERDBUSER
BROKERDBPASS
PORT
```
## Build

* mvn deploy
```
mvn dependency:resolve
mvn verify
mvn package
```

## Run

```
java -jar target/kafka-api-jar-with-dependencies.jar
```



131 changes: 131 additions & 0 deletions create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
-- DDL generated by Postico 1.4.2
-- Not all database features are supported. Do not use for backup.

-- Table Definition ----------------------------------------------

CREATE TABLE IF NOT EXISTS provision_user (
userid text DEFAULT uuid_generate_v4() PRIMARY KEY,
password text,
username text UNIQUE,
created_timestamp timestamp without time zone DEFAULT now(),
claimed boolean,
claimed_timestamp timestamp without time zone,
cluster text
);

-- Indices -------------------------------------------------------

CREATE UNIQUE INDEX IF NOT EXISTS username_uniqu ON provision_user(username text_ops);
CREATE UNIQUE INDEX IF NOT EXISTS provision_user_pkey ON provision_user(userid text_ops);


-- DDL generated by Postico 1.4.2
-- Not all database features are supported. Do not use for backup.

-- Table Definition ----------------------------------------------

CREATE TABLE IF NOT EXISTS provision_topic (
topicid text DEFAULT uuid_generate_v4() PRIMARY KEY,
topic text UNIQUE,
partitions integer,
replicas integer,
retentionms integer,
cleanuppolicy text,
created_timestamp timestamp without time zone DEFAULT now(),
cluster text,
organization text,
updated_timestamp timestamp without time zone,
description text
);

-- Indices -------------------------------------------------------

CREATE UNIQUE INDEX IF NOT EXISTS topic_unique ON provision_topic(topic text_ops);
CREATE UNIQUE INDEX IF NOT EXISTS provision_topic_pkey ON provision_topic(topicid text_ops);


-- DDL generated by Postico 1.4.2
-- Not all database features are supported. Do not use for backup.

-- Table Definition ----------------------------------------------

CREATE TABLE IF NOT EXISTS provision_consumergroup (
consumergroupid text DEFAULT uuid_generate_v4(),
userid text,
topicid text,
consumergroupname text,
active boolean,
created_timestamp timestamp without time zone DEFAULT now(),
updated_timestamp timestamp without time zone,
cluster text
);



-- DDL generated by Postico 1.4.2
-- Not all database features are supported. Do not use for backup.

-- Table Definition ----------------------------------------------

CREATE TABLE IF NOT EXISTS provision_acl (
aclid text DEFAULT uuid_generate_v4() PRIMARY KEY,
userid text,
topicid text,
role text,
created_timestamp timestamp without time zone DEFAULT now(),
cluster text,
CONSTRAINT acl_unique UNIQUE (userid, topicid, role)
);

-- Indices -------------------------------------------------------

CREATE UNIQUE INDEX IF NOT EXISTS provision_acl_pkey ON provision_acl(aclid text_ops);
CREATE UNIQUE INDEX IF NOT EXISTS acl_unique ON provision_acl(userid text_ops,topicid text_ops,role text_ops);


-- DDL generated by Postico 1.4.2
-- Not all database features are supported. Do not use for backup.

-- Table Definition ----------------------------------------------

CREATE OR REPLACE VIEW credentials AS SELECT provision_user.username,
provision_user.password,
provision_topic.topic,
provision_acl.role,
provision_consumergroup.consumergroupname,
provision_user.cluster
FROM provision_consumergroup,
provision_acl,
provision_user,
provision_topic
WHERE provision_consumergroup.topicid = provision_acl.topicid AND provision_acl.userid = provision_user.userid AND provision_acl.topicid = provision_topic.topicid AND provision_acl.role = 'consumer'::text AND provision_user.cluster = provision_topic.cluster AND provision_topic.cluster = provision_acl.cluster AND provision_acl.cluster = provision_consumergroup.cluster AND provision_consumergroup.active = true
UNION ALL
SELECT provision_user.username,
provision_user.password,
provision_topic.topic,
provision_acl.role,
''::text AS consumergroupname,
provision_user.cluster
FROM provision_acl,
provision_user,
provision_topic
WHERE provision_acl.userid = provision_user.userid AND provision_acl.topicid = provision_topic.topicid AND provision_user.cluster = provision_topic.cluster AND provision_topic.cluster = provision_acl.cluster AND provision_acl.role = 'producer'::text;



-- DDL generated by Postico 1.4.2
-- Not all database features are supported. Do not use for backup.

-- Table Definition ----------------------------------------------

CREATE OR REPLACE VIEW consumergroups AS SELECT provision_user.username,
provision_topic.topic,
provision_consumergroup.consumergroupname,
provision_consumergroup.cluster
FROM provision_consumergroup,
provision_topic,
provision_user
WHERE provision_consumergroup.userid = provision_user.userid AND provision_consumergroup.topicid = provision_topic.topicid AND provision_consumergroup.active = true;



Loading