Skip to content

Commit 36233e1

Browse files
committed
Merge branch '19-kafka-websocket-user-driven-gateway' into kafka-streams-module
2 parents aae30d1 + 32e1a7f commit 36233e1

File tree

92 files changed

+4395
-337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+4395
-337
lines changed

README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,44 @@
1-
"# kafka-web-gateway"
1+
# kafka-web-gateway
2+
3+
**Enter project directory**
4+
5+
```
6+
cd ./code/kafka-web-gateway/
7+
```
8+
9+
**Generate uberJar with gradle task extractUberJar**
10+
11+
```
12+
./gradlew task extractUberJar
13+
```
14+
15+
**Start docker containers**
16+
17+
* PostgreSQL Database
18+
* 2 Gateway's
19+
* 3 Apache Kafka Servers/Nodes
20+
* 3 ZooKeeper's Servers
21+
* Nginx
22+
23+
```
24+
./gradlew task composeUp
25+
```
26+
27+
* If preferred, use docker compose
28+
29+
```
30+
docker compose up --build --force-recreate
31+
```
32+
33+
**Utils**
34+
35+
* Start shell on postgres container
36+
37+
```
38+
docker exec -ti db-g06-tests bash
39+
```
40+
41+
* Start `psql` inside postgres container
42+
43+
```
44+
psql -U gateway_user -d gateway_db

code/kafka-web-gateway/.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
HELP.md
2+
.gradle
3+
build/
4+
!gradle/wrapper/gradle-wrapper.jar
5+
!**/src/main/**/build/
6+
!**/src/test/**/build/
7+
8+
### STS ###
9+
.apt_generated
10+
.classpath
11+
.factorypath
12+
.project
13+
.settings
14+
.springBeans
15+
.sts4-cache
16+
bin/
17+
!**/src/main/**/bin/
18+
!**/src/test/**/bin/
19+
20+
### IntelliJ IDEA ###
21+
.idea
22+
*.iws
23+
*.iml
24+
*.ipr
25+
out/
26+
!**/src/main/**/out/
27+
!**/src/test/**/out/
28+
29+
### NetBeans ###
30+
/nbproject/private/
31+
/nbbuild/
32+
/dist/
33+
/nbdist/
34+
/.nb-gradle/
35+
36+
### VS Code ###
37+
.vscode/

code/kafka-web-gateway/build.gradle

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
3+
plugins {
4+
id("org.springframework.boot") version "2.7.12"
5+
id("io.spring.dependency-management") version "1.1.0"
6+
kotlin("jvm") version "1.7.22"
7+
kotlin("plugin.spring") version "1.7.22"
8+
}
9+
10+
group = "com.isel.ps"
11+
version = "0.0.1-SNAPSHOT"
12+
java.sourceCompatibility = JavaVersion.VERSION_17
13+
14+
repositories {
15+
mavenCentral()
16+
}
17+
18+
dependencies {
19+
implementation("org.springframework.boot:spring-boot-starter-web")
20+
implementation("org.springframework.boot:spring-boot-starter-websocket")
21+
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
22+
implementation("org.jetbrains.kotlin:kotlin-reflect")
23+
implementation("org.springframework.kafka:spring-kafka")
24+
implementation("org.springframework.security:spring-security-core")
25+
26+
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
27+
implementation("org.springframework.boot:spring-boot-starter-jdbc")
28+
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
29+
runtimeOnly("org.postgresql:postgresql")
30+
31+
implementation("org.springdoc:springdoc-openapi-ui:1.6.15")
32+
runtimeOnly("org.springdoc:springdoc-openapi-kotlin:1.6.15")
33+
34+
testImplementation("org.springframework.boot:spring-boot-starter-test")
35+
testImplementation("org.springframework.kafka:spring-kafka-test")
36+
}
37+
38+
tasks.withType<KotlinCompile> {
39+
kotlinOptions {
40+
freeCompilerArgs = listOf("-Xjsr305=strict")
41+
jvmTarget = "17"
42+
}
43+
}
44+
45+
tasks.withType<Test> {
46+
enabled = false
47+
useJUnitPlatform()
48+
}
49+
50+
task<Copy>("extractUberJar") {
51+
dependsOn("assemble")
52+
// opens the JAR containing everything...
53+
from(zipTree("$buildDir/libs/${rootProject.name}-$version.jar"))
54+
// ... into the 'build/dependency' folder
55+
into("build/dependency")
56+
}
57+
58+
task<Exec>("composeUp") {
59+
commandLine("docker-compose", "up", "--build", "--force-recreate")
60+
dependsOn("extractUberJar")
61+
}
62+
63+
tasks.named("build") {
64+
dependsOn("assemble", "extractUberJar")
65+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
create table if not exists client
2+
(
3+
client_id bigint primary key
4+
);
5+
6+
create table if not exists gateway
7+
(
8+
gateway_id bigint primary key,
9+
topic_clients varchar(255) not null,
10+
topic_commands varchar(255) not null,
11+
active boolean not null,
12+
updated_at timestamp not null
13+
);
14+
15+
create table if not exists session
16+
(
17+
session_id bigint primary key,
18+
client_id bigint references client (client_id) on delete cascade on update cascade,
19+
gateway_id bigint references gateway (gateway_id) on delete cascade on update cascade,
20+
created_at timestamp default now(),
21+
updated_at timestamp not null,
22+
active boolean not null
23+
);
24+
25+
create table if not exists subscription
26+
(
27+
subscription_id int generated always as identity primary key,
28+
session_id bigint not null references session (session_id) on delete cascade on update cascade,
29+
topic varchar(255) not null,
30+
key varchar(255),
31+
unique (session_id, topic, key)
32+
);
33+
34+
create table if not exists role
35+
(
36+
role_id int generated always as identity primary key,
37+
name varchar(36) unique not null,
38+
description varchar(255)
39+
);
40+
41+
create table if not exists client_role
42+
(
43+
client_id bigint references client (client_id) on delete cascade on update cascade,
44+
role_id int references role (role_id) on delete cascade on update cascade,
45+
primary key (client_id, role_id)
46+
);
47+
48+
create table if not exists permission
49+
(
50+
permission_id int generated always as identity primary key,
51+
topic varchar(255) not null,
52+
key varchar(255),
53+
read boolean NOT NULL,
54+
write boolean NOT NULL,
55+
unique (topic, key, read, write)
56+
);
57+
58+
create table if not exists role_permission
59+
(
60+
role_id int references role (role_id) on delete cascade on update cascade,
61+
permission_id int references permission (permission_id) on delete cascade on update cascade,
62+
primary key (role_id, permission_id)
63+
);
64+
65+
create table if not exists client_permission
66+
(
67+
client_id bigint references client (client_id) on delete cascade on update cascade,
68+
permission_id int references permission (permission_id) on delete cascade on update cascade,
69+
primary key (client_id, permission_id)
70+
);
71+
72+
create table if not exists admin
73+
(
74+
admin_id int generated always as identity primary key,
75+
name varchar(64) not null,
76+
description varchar(255),
77+
owner boolean not null,
78+
administrative boolean not null,
79+
permission boolean not null
80+
);
81+
82+
create table if not exists admin_token
83+
(
84+
token_validation varchar(255) primary key,
85+
admin_id int not null references admin (admin_id) on delete cascade on update cascade,
86+
created_at timestamp not null default now(),
87+
last_used_at timestamp not null
88+
);
89+
90+
create table if not exists setting
91+
(
92+
name varchar(64) primary key,
93+
value varchar(255) not null,
94+
description varchar(255),
95+
updated_at timestamp not null
96+
);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
delete from client_permission;
2+
delete from client_role;
3+
delete from role_permission;
4+
delete from role;
5+
delete from subscription;
6+
delete from session;
7+
delete from gateway;
8+
delete from admin_token;
9+
delete from setting;
10+
delete from admin;
11+
delete from client;
12+
delete from permission;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
drop table if exists client_permission;
2+
drop table if exists client_role;
3+
drop table if exists role_permission;
4+
drop table if exists role;
5+
drop table if exists subscription;
6+
drop table if exists session;
7+
drop table if exists gateway;
8+
drop table if exists admin_token;
9+
drop table if exists setting;
10+
drop table if exists admin;
11+
drop table if exists client;
12+
drop table if exists permission;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
INSERT INTO client (client_id)
2+
VALUES (1);
3+
4+
INSERT INTO gateway (gateway_id, topic_clients, topic_commands, active, updated_at)
5+
VALUES (1, 'topic1', 'command1', true, current_timestamp);
6+
7+
INSERT INTO session (session_id, client_id, gateway_id, updated_at, active)
8+
VALUES (1, 1, 1, current_timestamp, true);
9+
10+
INSERT INTO subscription (session_id, topic, key)
11+
VALUES (1, 'topic1', 'key1');
12+
13+
INSERT INTO role (name, description)
14+
VALUES ('role1', 'Role 1 Description');
15+
16+
INSERT INTO client_role (client_id, role_id)
17+
VALUES (1, 1);
18+
19+
INSERT INTO permission (topic, key, read, write)
20+
VALUES ('topic1', 'key1', true, true);
21+
22+
INSERT INTO role_permission (role_id, permission_id)
23+
VALUES (1, 1);
24+
25+
INSERT INTO client_permission (client_id, permission_id)
26+
VALUES (1, 1);
27+
28+
INSERT INTO admin (name, description, owner, administrative, permission)
29+
VALUES ('admin1', 'Admin 1 Description', true, true, true);
30+
31+
INSERT INTO admin_token (token_validation, admin_id, created_at, last_used_at)
32+
VALUES ('token1', 1, current_timestamp, current_timestamp);
33+
34+
INSERT INTO setting (name, value, description, updated_at)
35+
VALUES ('setting1', 'value1', 'Setting 1 Description', current_timestamp);

0 commit comments

Comments
 (0)