Skip to content

Commit

Permalink
Merge pull request #56 from MarshallWace/migration-prep
Browse files Browse the repository at this point in the history
topology changes for migrating from legacy
  • Loading branch information
mw-lb authored Oct 7, 2024
2 parents 50da533 + ff7b538 commit a64e0b4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ node_modules/
local.properties
buildSrcTmp/
distTmp/
outTmp/
outTmp
/test.output
/kotlin-native/dist
kotlin-ide/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.mwam.kafkakewl.domain

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/** Base interface for the different kind of matchers that can match a fully qualified topic or application id. */
@Serializable
sealed interface Matcher
object Matchers {
/** It matches any topic or application id */
@Serializable
@SerialName("any")
object Any: Matcher

/** It matches exactly the specified topic or application id */
@Serializable
@SerialName("exact")
data class Exact(val value: String): Matcher

/** It matches exactly the specified topic or application id */
@Serializable
@SerialName("regex")
data class Regex(val value: String): Matcher

/** It matches the topic or application ids in the specified namespace */
@Serializable
@SerialName("namespace")
data class Namespace(val value: String): Matcher
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,31 @@ import kotlinx.serialization.Serializable
@Serializable
value class TopicId(override val value: String) : StringValue

@JvmInline
@Serializable
value class TopicConfigDefaultsId(override val value: String) : StringValue

@JvmInline
@Serializable
value class TopicConfigKey(override val value: String) : StringValue

@JvmInline
@Serializable
value class TopicConfigValue(override val value: String) : StringValue

@Serializable
data class Topic(
val name: String, val partitions: Int = 1, val config: Map<TopicConfigKey, TopicConfigValue> = emptyMap()
val name: String,
val partitions: Int = 1,
val replicationFactor: Short? = null,
val configDefaults: TopicConfigDefaultsId? = null,
val config: Map<TopicConfigKey, TopicConfigValue> = emptyMap(),
val unManaged: Boolean = false,
val description: String? = null,
val allowConsumeFor: List<Matcher> = emptyList(),
val allowProduceFor: List<Matcher> = emptyList(),
val tags: List<String> = emptyList(), // only for migrating existing topologies
val labels: Map<String, String> = emptyMap() // only for migrating existing topologies
) {

/** The topic's fully qualified id is the same as the name. */
Expand All @@ -37,6 +52,7 @@ value class ApplicationLocalId(override val value: String) : StringValue
@JvmInline
@Serializable
value class UserId(override val value: String) : StringValue

@Serializable
data class Application(
val id: ApplicationLocalId, val user: UserId
Expand All @@ -49,6 +65,7 @@ data class Application(
@JvmInline
@Serializable
value class TopicAliasLocalId(override val value: String) : StringValue

@Serializable
data class TopicAlias(
val id: TopicAliasLocalId,
Expand All @@ -62,6 +79,7 @@ data class TopicAlias(
@JvmInline
@Serializable
value class ApplicationAliasLocalId(override val value: String) : StringValue

@Serializable
data class ApplicationAlias(
val id: ApplicationAliasLocalId,
Expand All @@ -71,7 +89,8 @@ data class ApplicationAlias(

@Serializable
data class Aliases(
val topics: List<TopicAlias> = emptyList(), val applications: List<ApplicationAlias> = emptyList()
val topics: List<TopicAlias> = emptyList(),
val applications: List<ApplicationAlias> = emptyList()
)

/** ApplicationFlexId can be an application alias or application id, local or fully qualified.
Expand All @@ -85,10 +104,13 @@ value class ApplicationFlexId(override val value: String) : StringValue
@JvmInline
@Serializable
value class TopicFlexId(override val value: String) : StringValue

@Serializable
data class ProducedTopic(val topic: TopicFlexId)

@Serializable
data class ConsumedTopic(val topic: TopicFlexId)

@Serializable
data class Relationship(
val application: ApplicationFlexId,
Expand All @@ -99,21 +121,34 @@ data class Relationship(
@JvmInline
@Serializable
value class TopologyId(override val value: String) : StringValue

@JvmInline
@Serializable
value class Namespace(override val value: String) : StringValue

@JvmInline
@Serializable
value class Developer(override val value: String) : StringValue

@Serializable
enum class DevelopersAccess {
Full,
TopicReadOnly
}

@Serializable
data class Topology(
val id: TopologyId,
val namespace: Namespace,
val description: String? = null,
val developers: List<Developer> = emptyList(),
val developersAccess: DevelopersAccess = DevelopersAccess.TopicReadOnly,
val topics: List<Topic> = emptyList(),
val applications: List<Application> = emptyList(),
val aliases: Aliases = Aliases(),
val relationships: List<Relationship> = emptyList()
val relationships: List<Relationship> = emptyList(),
val tags: List<String> = emptyList(), // only for migrating existing topologies
val labels: Map<String, String> = emptyMap() // only for migrating existing topologies
)

typealias Topologies = Map<TopologyId, Topology>

0 comments on commit a64e0b4

Please sign in to comment.