Skip to content

Commit

Permalink
M8l2 state machine
Browse files Browse the repository at this point in the history
  • Loading branch information
svok committed Oct 12, 2024
1 parent 9a115fc commit 59acf67
Show file tree
Hide file tree
Showing 62 changed files with 975 additions and 24 deletions.
1 change: 0 additions & 1 deletion build-plugin/src/main/kotlin/BuildPluginMultiplatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ internal class BuildPluginMultiplatform : Plugin<Project> {
configureTargets(this@with)
sourceSets.configureEach {
languageSettings.apply {
languageVersion = "1.9"
progressiveMode = true
optIn("kotlin.time.ExperimentalTime")
}
Expand Down
7 changes: 6 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ subprojects {
}

tasks {
create("clean") {
group = "build"
gradle.includedBuilds.forEach {
dependsOn(it.task(":clean"))
}
}
val buildImages: Task by creating {
dependsOn(gradle.includedBuild("ok-marketplace-be").task(":buildImages"))
}
Expand All @@ -29,7 +35,6 @@ tasks {

create("check") {
group = "verification"
// dependsOn(gradle.includedBuild("ok-marketplace-be").task(":check"))
dependsOn(buildImages)
dependsOn(e2eTests)
}
Expand Down
4 changes: 2 additions & 2 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ services:
nofile:
soft: 65536
hard: 65536
volumes:
- opensearch-data:/usr/share/opensearch/data
# volumes:
# - opensearch-data:/usr/share/opensearch/data

dashboards:
image: opensearchproject/opensearch-dashboards:latest
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kotlin.code.style=official
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1024m -Dfile.encoding=UTF-8
kotlin.mpp.enableCInteropCommonization=true
kotlin.native.ignoreDisabledTargets=true
#kotlin.native.cacheKind.linuxX64=none
Expand Down
10 changes: 10 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[versions]
kotlin = "2.0.0"
mkpl = "0.0.1"

kotlinx-datetime = "0.5.0"
kotlinx-serialization = "1.6.3"
Expand Down Expand Up @@ -123,6 +124,15 @@ testcontainers-rabbitmq = { module = "org.testcontainers:rabbitmq", version.ref
testcontainers-postgres = { module = "org.testcontainers:postgresql", version.ref = "testcontainers" }
testcontainers-cassandra = { module = "org.testcontainers:cassandra", version.ref = "testcontainers" }

mkpl-logs-common = { module = "ru.otus.otuskotlin.marketplace.libs:ok-marketplace-lib-logging-common", version.ref = "mkpl" }
mkpl-logs-kermit = { module = "ru.otus.otuskotlin.marketplace.libs:ok-marketplace-lib-logging-kermit", version.ref = "mkpl" }
mkpl-logs-logback = { module = "ru.otus.otuskotlin.marketplace.libs:ok-marketplace-lib-logging-logback", version.ref = "mkpl" }
mkpl-logs-socket = { module = "ru.otus.otuskotlin.marketplace.libs:ok-marketplace-lib-logging-socket", version.ref = "mkpl" }
mkpl-cor = { module = "ru.otus.otuskotlin.marketplace.libs:ok-marketplace-lib-cor", version.ref = "mkpl" }
mkpl-state-common = { module = "ru.otus.otuskotlin.marketplace.state:ok-marketplace-states-common", version.ref = "mkpl" }
mkpl-state-biz = { module = "ru.otus.otuskotlin.marketplace.state:ok-marketplace-states-biz", version.ref = "mkpl" }


[bundles]
kotest = ["kotest-junit5", "kotest-core", "kotest-datatest", "kotest-property"]
exposed = ["db-exposed-core", "db-exposed-dao", "db-exposed-jdbc"]
Expand Down
2 changes: 1 addition & 1 deletion ok-marketplace-be/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kotlin.code.style=official
kotlin.native.ignoreDisabledTargets=true
kotlin.native.cacheKind.linuxX64=none
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8


Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies {
implementation(libs.coroutines.core)
implementation(libs.kotlinx.atomicfu)

implementation("ru.otus.otuskotlin.marketplace.libs:ok-marketplace-lib-logging-logback")
implementation(libs.mkpl.logs.logback)

implementation(project(":ok-marketplace-app-common"))

Expand Down
17 changes: 11 additions & 6 deletions ok-marketplace-be/ok-marketplace-app-ktor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ kotlin {
implementation(projects.okMarketplaceRepoInmemory)
implementation(projects.okMarketplaceRepoPostgres)

// States
implementation(libs.mkpl.state.common)
implementation(libs.mkpl.state.biz)

// logging
implementation(project(":ok-marketplace-api-log1"))
implementation("ru.otus.otuskotlin.marketplace.libs:ok-marketplace-lib-logging-common")
implementation("ru.otus.otuskotlin.marketplace.libs:ok-marketplace-lib-logging-kermit")
implementation("ru.otus.otuskotlin.marketplace.libs:ok-marketplace-lib-logging-socket")
implementation(libs.mkpl.logs.common)
implementation(libs.mkpl.logs.kermit)
implementation(libs.mkpl.logs.socket)
}
}

Expand Down Expand Up @@ -115,13 +119,14 @@ kotlin {
implementation(libs.logback)

// transport models
implementation(project(":ok-marketplace-api-v1-jackson"))
implementation(project(":ok-marketplace-api-v1-mappers"))
implementation(projects.okMarketplaceApiV1Jackson)
implementation(projects.okMarketplaceApiV1Mappers)
implementation(projects.okMarketplaceApiV2Kmp)

implementation(projects.okMarketplaceRepoCassandra)
implementation(projects.okMarketplaceRepoGremlin)

implementation("ru.otus.otuskotlin.marketplace.libs:ok-marketplace-lib-logging-logback")
implementation(libs.mkpl.logs.logback)
implementation(libs.testcontainers.cassandra)
implementation(libs.testcontainers.core)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ import ru.otus.otuskotlin.marketplace.app.ktor.MkplAppSettings
import ru.otus.otuskotlin.marketplace.app.ktor.base.KtorWsSessionRepo
import ru.otus.otuskotlin.marketplace.backend.repository.inmemory.AdRepoStub
import ru.otus.otuskotlin.marketplace.biz.MkplAdProcessor
import ru.otus.otuskotlin.marketplace.biz.statemachine.resolver.SMAdStateResolverDefault
import ru.otus.otuskotlin.marketplace.common.MkplCorSettings
import ru.otus.otuskotlin.marketplace.states.common.MkplStatesCorSettings

fun Application.initAppSettings(): MkplAppSettings {
val loggerProvider = getLoggerProviderConf()
val corSettings = MkplCorSettings(
loggerProvider = getLoggerProviderConf(),
loggerProvider = loggerProvider,
wsSessions = KtorWsSessionRepo(),
repoTest = getDatabaseConf(AdDbType.TEST),
repoProd = getDatabaseConf(AdDbType.PROD),
repoStub = AdRepoStub(),
stateSettings = MkplStatesCorSettings(
loggerProvider = loggerProvider,
stateMachine = SMAdStateResolverDefault(),
),
)
return MkplAppSettings(
appUrls = environment.config.propertyOrNull("ktor.urls")?.getList() ?: emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {

implementation(project(":ok-marketplace-common"))
implementation(project(":ok-marketplace-app-common"))
implementation("ru.otus.otuskotlin.marketplace.libs:ok-marketplace-lib-logging-logback")
implementation(libs.mkpl.logs.logback)

// v1 api
implementation(project(":ok-marketplace-api-v1-jackson"))
Expand Down
6 changes: 5 additions & 1 deletion ok-marketplace-be/ok-marketplace-app-spring/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {
// Внутренние модели
implementation(project(":ok-marketplace-common"))
implementation(project(":ok-marketplace-app-common"))
implementation("ru.otus.otuskotlin.marketplace.libs:ok-marketplace-lib-logging-logback")
implementation(libs.mkpl.logs.logback)

// v1 api
implementation(project(":ok-marketplace-api-v1-jackson"))
Expand All @@ -42,6 +42,10 @@ dependencies {
testImplementation(projects.okMarketplaceRepoCommon)
testImplementation(projects.okMarketplaceStubs)

// State
implementation(libs.mkpl.state.common)
implementation(libs.mkpl.state.biz)

// tests
testImplementation(kotlin("test-junit5"))
testImplementation(libs.spring.test)
Expand Down
3 changes: 2 additions & 1 deletion ok-marketplace-be/ok-marketplace-biz/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ kotlin {
dependencies {
implementation(kotlin("stdlib-common"))

implementation(libs.cor)
implementation(libs.mkpl.cor)
implementation(libs.mkpl.state.common)

implementation(project(":ok-marketplace-common"))
implementation(project(":ok-marketplace-stubs"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ru.otus.otuskotlin.marketplace.biz

import ru.otus.otuskotlin.marketplace.biz.general.getAdState
import ru.otus.otuskotlin.marketplace.biz.general.getAdStates
import ru.otus.otuskotlin.marketplace.biz.general.initStatus
import ru.otus.otuskotlin.marketplace.biz.general.operation
import ru.otus.otuskotlin.marketplace.biz.repo.*
Expand Down Expand Up @@ -49,6 +51,7 @@ class MkplAdProcessor(
repoPrepareCreate("Подготовка объекта для сохранения")
repoCreate("Создание объявления в БД")
}
getAdState("Вычисление состояния объявления")
prepareResult("Подготовка ответа")
}
operation("Получить объявление", MkplCommand.READ) {
Expand All @@ -75,6 +78,7 @@ class MkplAdProcessor(
handle { adRepoDone = adRepoRead }
}
}
getAdState("Вычисление состояния объявления")
prepareResult("Подготовка ответа")
}
operation("Изменить объявление", MkplCommand.UPDATE) {
Expand Down Expand Up @@ -110,6 +114,7 @@ class MkplAdProcessor(
repoPrepareUpdate("Подготовка объекта для обновления")
repoUpdate("Обновление объявления в БД")
}
getAdState("Вычисление состояния объявления")
prepareResult("Подготовка ответа")
}
operation("Удалить объявление", MkplCommand.DELETE) {
Expand Down Expand Up @@ -138,6 +143,7 @@ class MkplAdProcessor(
repoPrepareDelete("Подготовка объекта для удаления")
repoDelete("Удаление объявления из БД")
}
getAdState("Вычисление состояния объявления")
prepareResult("Подготовка ответа")
}
operation("Поиск объявлений", MkplCommand.SEARCH) {
Expand All @@ -154,6 +160,7 @@ class MkplAdProcessor(
finishAdFilterValidation("Успешное завершение процедуры валидации")
}
repoSearch("Поиск объявления в БД по фильтру")
getAdStates("Вычисление состояния объявления")
prepareResult("Подготовка ответа")
}
operation("Поиск подходящих предложений для объявления", MkplCommand.OFFERS) {
Expand All @@ -177,8 +184,8 @@ class MkplAdProcessor(
repoPrepareOffers("Подготовка данных для поиска предложений")
repoOffers("Поиск предложений для объявления в БД")
}
getAdStates("Вычисление состояния объявления")
prepareResult("Подготовка ответа")
}
}.build()
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ru.otus.otuskotlin.marketplace.biz.general

import ru.otus.otuskotlin.marketplace.common.MkplContext
import ru.otus.otuskotlin.marketplace.common.models.MkplState
import ru.otus.otuskotlin.marketplace.cor.ICorChainDsl
import ru.otus.otuskotlin.marketplace.cor.worker

fun ICorChainDsl<MkplContext>.getAdState(title: String) = worker {
this.title = title
this.description = """
Получаем состояние из сервиса состояний
""".trimIndent()
on { state == MkplState.RUNNING }
handle {
corSettings.stateSettings.stateMachine
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ru.otus.otuskotlin.marketplace.biz.general

import ru.otus.otuskotlin.marketplace.common.MkplContext
import ru.otus.otuskotlin.marketplace.common.models.MkplState
import ru.otus.otuskotlin.marketplace.cor.ICorChainDsl
import ru.otus.otuskotlin.marketplace.cor.worker

fun ICorChainDsl<MkplContext>.getAdStates(title: String) = worker {
this.title = title
this.description = """
Получаем состояние из сервиса состояний
""".trimIndent()
on { state == MkplState.RUNNING }
handle {
corSettings.stateSettings.stateMachine
}
}
2 changes: 1 addition & 1 deletion ok-marketplace-be/ok-marketplace-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ kotlin {

api(libs.kotlinx.datetime)
implementation(libs.coroutines.core)
api("ru.otus.otuskotlin.marketplace.libs:ok-marketplace-lib-logging-common")
api(libs.mkpl.state.common)
}
}
val commonTest by getting {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ru.otus.otuskotlin.marketplace.common.models.*
import ru.otus.otuskotlin.marketplace.common.repo.IRepoAd
import ru.otus.otuskotlin.marketplace.common.stubs.MkplStubs
import ru.otus.otuskotlin.marketplace.common.ws.IMkplWsSession
import ru.otus.otuskotlin.marketplace.states.common.models.MkplStateRq

data class MkplContext(
var command: MkplCommand = MkplCommand.NONE,
Expand Down Expand Up @@ -33,6 +34,9 @@ data class MkplContext(
var adRepoDone: MkplAd = MkplAd(), // Результат, полученный из БД
var adsRepoDone: MutableList<MkplAd> = mutableListOf(),

// Запрашиваем статус из модуля статистики
var adState: MkplStateRq = MkplStateRq(),

var adResponse: MkplAd = MkplAd(),
var adsResponse: MutableList<MkplAd> = mutableListOf(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package ru.otus.otuskotlin.marketplace.common
import ru.otus.otuskotlin.marketplace.common.repo.IRepoAd
import ru.otus.otuskotlin.marketplace.common.ws.IMkplWsSessionRepo
import ru.otus.otuskotlin.marketplace.logging.common.MpLoggerProvider
import ru.otus.otuskotlin.marketplace.states.common.MkplStatesCorSettings

data class MkplCorSettings(
val loggerProvider: MpLoggerProvider = MpLoggerProvider(),
val wsSessions: IMkplWsSessionRepo = IMkplWsSessionRepo.NONE,
val repoStub: IRepoAd = IRepoAd.NONE,
val repoTest: IRepoAd = IRepoAd.NONE,
val repoProd: IRepoAd = IRepoAd.NONE,
val stateSettings: MkplStatesCorSettings = MkplStatesCorSettings(),
) {
companion object {
val NONE = MkplCorSettings()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ru.otus.otuskotlin.marketplace.common.models

import ru.otus.otuskotlin.marketplace.states.common.statemachine.SMAdStates

data class MkplAd(
var id: MkplAdId = MkplAdId.NONE,
var title: String = "",
Expand All @@ -9,7 +11,9 @@ data class MkplAd(
var visibility: MkplVisibility = MkplVisibility.NONE,
var productId: MkplProductId = MkplProductId.NONE,
var lock: MkplAdLock = MkplAdLock.NONE,
val permissionsClient: MutableSet<MkplAdPermissionClient> = mutableSetOf()
val permissionsClient: MutableSet<MkplAdPermissionClient> = mutableSetOf(),

var adState: SMAdStates = SMAdStates.NONE,
) {
fun deepCopy(): MkplAd = copy(
permissionsClient = permissionsClient.toMutableSet(),
Expand Down
8 changes: 8 additions & 0 deletions ok-marketplace-states/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

/.idea/
/kotlin-js-store/
37 changes: 37 additions & 0 deletions ok-marketplace-states/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
plugins {
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlin.kapt) apply false
alias(libs.plugins.muschko.remote) apply false
alias(libs.plugins.muschko.java) apply false
}

group = "ru.otus.otuskotlin.marketplace.state"
version = "0.0.1"

allprojects {
repositories {
mavenCentral()
}
}

subprojects {
group = rootProject.group
version = rootProject.version
}

ext {
val specDir = layout.projectDirectory.dir("../specs")
set("spec-v1", specDir.file("specs-ad-v1.yaml").toString())
set("spec-v2", specDir.file("specs-ad-v2.yaml").toString())
set("spec-log1", specDir.file("specs-ad-log1.yaml").toString())
}

tasks {
arrayOf("build", "clean", "check").forEach {tsk ->
create(tsk) {
group = "build"
dependsOn(subprojects.map { it.getTasksByName(tsk,false)})
}
}
}
6 changes: 6 additions & 0 deletions ok-marketplace-states/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kotlin.code.style=official
kotlin.native.ignoreDisabledTargets=true
kotlin.native.cacheKind.linuxX64=none
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1024m -Dfile.encoding=UTF-8


Loading

0 comments on commit 59acf67

Please sign in to comment.