Skip to content

Commit

Permalink
add CQRS detection to the detection workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jooaodanieel committed May 19, 2022
1 parent de98dc4 commit bb2e040
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ data class PatternsInSystemPayload(
detections.databasePerServices,
detections.singleServicePerHosts,
detections.apiCompostions,
detections.asyncMessages
detections.asyncMessages,
detections.cqrs
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.sortinghat.pattern_detector.api

import com.sortinghat.pattern_detector.domain.model.patterns.APIComposition
import com.sortinghat.pattern_detector.domain.model.patterns.AsyncMessage
import com.sortinghat.pattern_detector.domain.model.patterns.DatabasePerService
import com.sortinghat.pattern_detector.domain.model.patterns.SingleServicePerHost
import com.sortinghat.pattern_detector.domain.model.patterns.*
import kotlinx.serialization.Serializable

@Serializable
data class PatternsPresent(
val databasePerService: Set<DatabasePerService>,
val singleServicePerHost: Set<SingleServicePerHost>,
val apiCompositions: Set<APIComposition>,
val asyncMessages: Set<AsyncMessage>
val asyncMessages: Set<AsyncMessage>,
val cqrs: Set<CQRS>
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.sortinghat.pattern_detector.domain.model.patterns

import com.sortinghat.pattern_detector.domain.behaviors.Pattern
import com.sortinghat.pattern_detector.domain.model.Service
import kotlinx.serialization.Serializable

fun extractName(service: Service) = service.name

@Serializable
data class CQRS(
val queryService: String,
val commandServices: Set<String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ data class Detections(
val databasePerServices: Set<DatabasePerService>,
val singleServicePerHosts: Set<SingleServicePerHost>,
val apiCompostions: Set<APIComposition>,
val asyncMessages: Set<AsyncMessage>
val asyncMessages: Set<AsyncMessage>,
val cqrs: Set<CQRS>
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,42 @@ import com.sortinghat.pattern_detector.domain.model.patterns.Detections
fun detectionWorkflow(systemSlug: String, serviceRepository: ServiceRepository, thresholds: Map<String, Int>): Detections {
val services = serviceRepository.findAllOfSystem(systemSlug)

val visitors = mapOf(
"metrics" to MetricCollector(),
"dbps" to DatabasePerServiceDetector(
maxOperationsPerService = thresholds["maxOperationsPerService"]!!
),
"ssph" to SingleServicePerHostDetector(
maxOperationsPerService = thresholds["maxOperationsPerService"]!!
),
"apic" to APICompositionDetector(
maxOperationsPerService = thresholds["maxOperationsPerService"]!!,
minComposedServices = thresholds["minComposedServices"]!!
),
"amsg" to AsyncMessageDetector()
val metricCollector = MetricCollector()
services.forEach { it.accept(metricCollector) }

val dbps = DatabasePerServiceDetector(
maxOperationsPerService = thresholds["maxOperationsPerService"]!!
)
services.forEach { it.accept(dbps) }

val ssph = SingleServicePerHostDetector(
maxOperationsPerService = thresholds["maxOperationsPerService"]!!
)
services.forEach { it.accept(ssph) }

val apic = APICompositionDetector(
maxOperationsPerService = thresholds["maxOperationsPerService"]!!,
minComposedServices = thresholds["minComposedServices"]!!
)
services.forEach { it.accept(apic) }

val amsg = AsyncMessageDetector()
services.forEach { it.accept(amsg) }

val amsgOccurrences = amsg.getResults()

val cqrs = CQRSDetector(
asyncMessageOccurrences = amsgOccurrences,
maxOperationsPerService = thresholds["maxOperationsPerService"]!!
)
services.forEach { it.accept(cqrs) }

visitors.values.forEach { visitor ->
services.forEach { it.accept(visitor) }
}

return Detections(
databasePerServices = (visitors["dbps"] as DatabasePerServiceDetector).getResults(),
singleServicePerHosts = (visitors["ssph"] as SingleServicePerHostDetector).getResults(),
apiCompostions = (visitors["apic"] as APICompositionDetector).getResults(),
asyncMessages = (visitors["amsg"] as AsyncMessageDetector).getResults()
databasePerServices = dbps.getResults(),
singleServicePerHosts = ssph.getResults(),
apiCompostions = apic.getResults(),
asyncMessages = amsgOccurrences,
cqrs = cqrs.getResults()
)
}

0 comments on commit bb2e040

Please sign in to comment.