Skip to content

Commit

Permalink
🐛 Make domain match with new api classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lysoun committed Mar 19, 2024
1 parent 8784bd7 commit 7d0ca25
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class Executor(private val context: Context,
fun execute(scripts: List<ScriptWithContent>, executionId: ExecutionId?): Report {
if (!context.config.logs.porcelain) { logger.info { "Executes scripts.." } }
try {
for (script in scripts) {
for ((index, script) in scripts.withIndex()) {
if (reportSender != null && executionId != null) {
reportSender.startScriptExecution(executionId, script)
reportSender.startScriptExecution(executionId, script, index)
}

val executedScript = when (executorConfig.executionMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package datamaintain.domain.report

import datamaintain.domain.script.ExecutedScript
import datamaintain.domain.script.ScriptWithContent
import java.util.*

typealias ExecutionId = Int
typealias ExecutionId = UUID

interface IExecutionWorkflowMessagesSender {
fun startExecution(): ExecutionId?
fun sendReport(executionId: ExecutionId, report: Report)
fun startScriptExecution(executionId: ExecutionId, script: ScriptWithContent)
fun startScriptExecution(executionId: ExecutionId, script: ScriptWithContent, orderIndex: Int)
fun stopScriptExecution(executionId: ExecutionId, executedScript: ExecutedScript)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ class Http4KExecutionWorkflowMessagesSender(baseUrl: String, private val clock:
httpClient(Request(Method.PUT, "$executionApiBaseUrl/stop/$executionId").body(report.toMonitoringReport()))
}

override fun startScriptExecution(executionId: ExecutionId, script: ScriptWithContent) {
override fun startScriptExecution(executionId: ExecutionId, script: ScriptWithContent, orderIndex: Int) {
httpClient(
Request(Method.PUT, "$executionApiBaseUrl/$executionId/script/start")
.body(script.toScriptExecutionStart(clock.instant()))
.body(script.toScriptExecutionStart(clock.instant(), orderIndex))
)
}

override fun stopScriptExecution(executionId: ExecutionId, executedScript: ExecutedScript) {
httpClient(
Request(Method.PUT, "$executionApiBaseUrl/$executionId/script/stop")
.body(executedScript.toScriptExecutionStop())
.body(executedScript.toScriptExecutionStop(clock.instant()))
)
}

Expand All @@ -53,11 +53,10 @@ class Http4KExecutionWorkflowMessagesSender(baseUrl: String, private val clock:
}
}

private fun ExecutedScript.toScriptExecutionStop(): ScriptExecutionStop = ScriptExecutionStop(
checksum = checksum,
executionDurationInMillis = executionDurationInMillis,
private fun ExecutedScript.toScriptExecutionStop(endDate: Instant): ScriptExecutionStop = ScriptExecutionStop(
executionStatus = executionStatus.toMonitoringExecutionStatus(),
executionOutput = executionOutput
executionOutput = executionOutput,
executionEndDate = endDate
)

private fun ExecutionStatus.toMonitoringExecutionStatus(): datamaintain.monitoring.api.execution.report.api.ExecutionStatus =
Expand All @@ -70,13 +69,13 @@ private fun ExecutionStatus.toMonitoringExecutionStatus(): datamaintain.monitori
fun Report.toMonitoringReport() =
MonitoringReport(this.executedScripts.size)

fun ScriptWithContent.toScriptExecutionStart(startDate: Instant) =
fun ScriptWithContent.toScriptExecutionStart(startDate: Instant, orderIndex: Int) =
ScriptExecutionStart(
name = this.name,
checksum = this.checksum,
content = this.content,
startDate = startDate,
tags = this.tags.map { it.name }
tags = this.tags.map { it.name },
executionOrderIndex = orderIndex
)

fun <T : Any> Request.body(payload: T) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import java.nio.file.Paths
import java.time.Clock
import java.time.Instant
import java.time.ZoneId
import java.util.*

/**
* When monitoring configuration is given an url for monitoring, Executor should send information about
Expand Down Expand Up @@ -51,7 +52,7 @@ class MonitoringSendHttp4KIT : AbstractMonitoringSendWithHttpTest() {
@Test
internal fun should_send_script_execution_start_with_execution_id() {
// When
val executionId = 12
val executionId = UUID.randomUUID()
setupMockStartAnswer(executionId)
buildDatamaintainWithMonitoringConfiguration("src/test/resources/integration/ok").updateDatabase()

Expand Down Expand Up @@ -85,7 +86,7 @@ class MonitoringSendHttp4KIT : AbstractMonitoringSendWithHttpTest() {
}

private fun checkStartMessageBodyContains(subStringExpectedInBody: String) {
val executionId = 12
val executionId = UUID.randomUUID()
setupMockStartAnswer(executionId)
buildDatamaintainWithMonitoringConfiguration(
scriptsPath = "src/test/resources/integration/ok",
Expand All @@ -105,7 +106,7 @@ class MonitoringSendHttp4KIT : AbstractMonitoringSendWithHttpTest() {
@Test
internal fun should_send_script_execution_stop_with_execution_id() {
// When
val executionId = 12
val executionId = UUID.randomUUID()
setupMockStartAnswer(executionId)
buildDatamaintainWithMonitoringConfiguration("src/test/resources/integration/ok").updateDatabase()

Expand All @@ -121,7 +122,7 @@ class MonitoringSendHttp4KIT : AbstractMonitoringSendWithHttpTest() {
@Test
internal fun should_send_script_execution_duration_in_millis_in_body() {
// When
val executionId = 12
val executionId = UUID.randomUUID()
setupMockStartAnswer(executionId)
val report = buildDatamaintainWithMonitoringConfiguration(
scriptsPath = "src/test/resources/integration/ok"
Expand All @@ -145,7 +146,7 @@ class MonitoringSendHttp4KIT : AbstractMonitoringSendWithHttpTest() {
}

private fun checkStopMessageBodyContains(subStringExpectedInBody: String) {
val executionId = 12
val executionId = UUID.randomUUID()
setupMockStartAnswer(executionId)
buildDatamaintainWithMonitoringConfiguration(
scriptsPath = "src/test/resources/integration/ok"
Expand All @@ -163,7 +164,7 @@ class MonitoringSendHttp4KIT : AbstractMonitoringSendWithHttpTest() {
@Test
internal fun should_send_script_execution_stop_with_execution_id() {
// When
val executionId = 12
val executionId = UUID.randomUUID()
setupMockStartAnswer(executionId)
buildDatamaintainWithMonitoringConfiguration("src/test/resources/integration/ok").updateDatabase()

Expand All @@ -177,7 +178,7 @@ class MonitoringSendHttp4KIT : AbstractMonitoringSendWithHttpTest() {
}

private fun checkExecutionStopMessageBodyContains(subStringExpectedInBody: String) {
val executionId = 12
val executionId = UUID.randomUUID()
setupMockStartAnswer(executionId)
buildDatamaintainWithMonitoringConfiguration(
scriptsPath = "src/test/resources/integration/ok"
Expand All @@ -191,7 +192,7 @@ class MonitoringSendHttp4KIT : AbstractMonitoringSendWithHttpTest() {
}
}

private fun setupMockStartAnswer(executionId: ExecutionId = 42) {
private fun setupMockStartAnswer(executionId: ExecutionId = UUID.randomUUID()) {
mockServerClient.`when`(
request()
.withMethod("POST")
Expand Down

0 comments on commit 7d0ca25

Please sign in to comment.