Skip to content

Commit

Permalink
M8l1 state machine
Browse files Browse the repository at this point in the history
  • Loading branch information
svok committed Jul 16, 2024
1 parent a1a4382 commit cfe177c
Show file tree
Hide file tree
Showing 65 changed files with 1,007 additions and 31 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ jobs:
submodules: recursive
token: ${{ secrets.PAT_TOKEN }}

- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'

- name: Validate Gradle wrapper
Expand All @@ -50,5 +50,5 @@ jobs:
- name: Run Tests
uses: gradle/gradle-build-action@v2
with:
gradle-version: 8.6
gradle-version: 8.7
arguments: check -i
25 changes: 24 additions & 1 deletion build-plugin/src/main/kotlin/BuildPluginJvm.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
package ru.otus.otuskotlin.marketplace.plugin

import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.the
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension

@Suppress("unused")
internal class BuildPluginJvm : Plugin<Project> {

override fun apply(project: Project) = with(project) {
pluginManager.apply("org.jetbrains.kotlin.jvm")
// pluginManager.apply(KotlinPlatformJvmPlugin::class.java)
plugins.withId("org.jetbrains.kotlin.jvm") {
extensions.configure<KotlinJvmProjectExtension> {
val libs = project.the<LibrariesForLibs>()
sourceSets.configureEach {
languageSettings.apply {
languageVersion = libs.versions.kotlin.language.get()
progressiveMode = true
optIn("kotlin.time.ExperimentalTime")
}
}
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(libs.versions.jvm.language.get()))
}
compilerOptions {
jvmTarget.set(JvmTarget.valueOf("JVM_${libs.versions.jvm.compiler.get()}"))
}
}
}
group = rootProject.group
version = rootProject.version
}
Expand Down
3 changes: 2 additions & 1 deletion build-plugin/src/main/kotlin/BuildPluginMultiplatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ internal class BuildPluginMultiplatform : Plugin<Project> {

plugins.withId("org.jetbrains.kotlin.multiplatform") {
extensions.configure<KotlinMultiplatformExtension> {
val libs = project.the<LibrariesForLibs>()
configureTargets(this@with)
sourceSets.configureEach {
languageSettings.apply {
languageVersion = "1.9"
languageVersion = libs.versions.kotlin.language.get()
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
14 changes: 12 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[versions]
mkpl = "0.0.1"
kotlin = "1.9.23"

kotlinx-datetime = "0.5.0"
Expand Down Expand Up @@ -29,7 +30,8 @@ testcontainers = "1.19.7"
muschko = "9.4.0"

# BASE
jvm-compiler = "17"
kotlin-language = "1.9"
jvm-compiler = "21"
jvm-language = "21"

[libraries]
Expand All @@ -44,7 +46,6 @@ coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", ve
coroutines-reactor = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-reactor", version.ref = "coroutines" }
coroutines-reactive = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-reactive", version.ref = "coroutines" }
coroutines-jdk9 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-jdk9", version.ref = "coroutines" }
cor = { module = "ru.otus.otuskotlin.marketplace.libs:ok-marketplace-lib-cor" }
uuid = "com.benasher44:uuid:0.8.4"

jackson-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" }
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(),
)
Loading

0 comments on commit cfe177c

Please sign in to comment.