Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
theodolite
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sören Henning
theodolite
Commits
fdf759d5
Commit
fdf759d5
authored
3 years ago
by
Sören Henning
Browse files
Options
Downloads
Patches
Plain Diff
Apply minor style fixes
parent
ce33558e
No related branches found
No related tags found
3 merge requests
!159
Re-implementation of Theodolite with Kotlin/Quarkus
,
!157
Update Graal Image in CI pipeline
,
!83
WIP: Re-implementation of Theodolite with Kotlin/Quarkus
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt
+12
-12
12 additions, 12 deletions
...te-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt
with
12 additions
and
12 deletions
theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt
+
12
−
12
View file @
fdf759d5
...
...
@@ -4,6 +4,7 @@ import mu.KotlinLogging
import
org.apache.kafka.clients.admin.AdminClient
import
org.apache.kafka.clients.admin.CreateTopicsResult
import
org.apache.kafka.clients.admin.NewTopic
import
org.apache.kafka.common.errors.TopicExistsException
import
java.lang.Thread.sleep
private
val
logger
=
KotlinLogging
.
logger
{}
...
...
@@ -29,13 +30,12 @@ class TopicManager(private val kafkaConfig: Map<String, Any>) {
try
{
result
=
kafkaAdmin
.
createTopics
(
newTopics
)
result
.
all
().
get
()
// wait for the future to be completed
}
catch
(
e
:
Exception
)
{
}
catch
(
e
:
Exception
)
{
// TopicExistsException
logger
.
warn
(
e
)
{
"Error during topic creation."
}
logger
.
debug
{
e
}
// TODO remove?
logger
.
debug
{
e
}
// TODO remove
due to attached exception to warn log
?
logger
.
info
{
"Remove existing topics."
}
delete
(
newTopics
.
map
{
topic
->
topic
.
name
()
},
kafkaAdmin
)
logger
.
info
{
"Will retry the topic creation in $RETRY_TIME seconds."
}
logger
.
info
{
"Will retry the topic creation in $
{
RETRY_TIME
/1000}
seconds."
}
sleep
(
RETRY_TIME
)
retryCreation
=
true
}
...
...
@@ -43,7 +43,9 @@ class TopicManager(private val kafkaConfig: Map<String, Any>) {
logger
.
info
{
"Topics creation finished with result: ${
result
.
values
().
map
{
it
->
it
.
key
+
": "
+
it
.
value
.
isDone
}
result
.
values
()
.
map
{
it
->
it
.
key
+
": "
+
it
.
value
.
isDone
}
.
joinToString
(
separator
=
","
)
}
"
}
...
...
@@ -57,7 +59,7 @@ class TopicManager(private val kafkaConfig: Map<String, Any>) {
fun
removeTopics
(
topics
:
List
<
String
>)
{
val
kafkaAdmin
:
AdminClient
=
AdminClient
.
create
(
this
.
kafkaConfig
)
val
currentTopics
=
kafkaAdmin
.
listTopics
().
names
().
get
()
delete
(
currentTopics
.
filter
{
matchRegex
(
it
,
topics
)},
kafkaAdmin
)
delete
(
currentTopics
.
filter
{
matchRegex
(
it
,
topics
)
},
kafkaAdmin
)
kafkaAdmin
.
close
()
}
...
...
@@ -70,7 +72,7 @@ class TopicManager(private val kafkaConfig: Map<String, Any>) {
*/
private
fun
matchRegex
(
existingTopic
:
String
,
topics
:
List
<
String
>):
Boolean
{
for
(
t
in
topics
)
{
val
regex
=
t
.
toRegex
()
val
regex
=
t
.
toRegex
()
if
(
regex
.
matches
(
existingTopic
))
{
return
true
}
...
...
@@ -93,17 +95,15 @@ class TopicManager(private val kafkaConfig: Map<String, Any>) {
}
}
catch
(
e
:
Exception
)
{
logger
.
error
(
e
)
{
"Error while removing topics: $e"
}
logger
.
info
{
"Existing topics are: ${kafkaAdmin.listTopics()}."
}
logger
.
info
{
"Existing topics are: ${kafkaAdmin.listTopics()
.names().get()
}."
}
}
val
toDelete
=
topics
.
filter
{
topic
->
kafkaAdmin
.
listTopics
().
names
().
get
().
contains
(
topic
)
}
val
toDelete
=
topics
.
filter
{
kafkaAdmin
.
listTopics
().
names
().
get
().
contains
(
it
)
}
if
(
toDelete
.
isNullOrEmpty
())
{
deleted
=
true
}
else
{
logger
.
info
{
"Deletion of
k
afka topics failed, will retry in $RETRY_TIME seconds."
}
logger
.
info
{
"Deletion of
K
afka topics failed, will retry in $
{
RETRY_TIME
/1000}
seconds."
}
sleep
(
RETRY_TIME
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment