Skip to content

Commit

Permalink
M7l5 gremlin (#32)
Browse files Browse the repository at this point in the history
* m7l5 Gremlin/ArcadeDB

* m7l5 ArcadeDB tiny fix

(cherry picked from commit cdc05c32e1017ad016151030076da3722c7230a5)
  • Loading branch information
svok committed Jul 5, 2024
1 parent 70b8567 commit ad3a6de
Show file tree
Hide file tree
Showing 30 changed files with 723 additions and 28 deletions.
16 changes: 16 additions & 0 deletions deploy/docker-compose-arcadedb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3.3"
services:
arcadedb:
image: "arcadedata/arcadedb:24.4.1"
ports:
- "2480:2480"
- "2424:2424"
- "8182:8182"
# volumes:
# - ./volumes/arcadedb:/home/arcadedb/databases
# Здесь можно добавить доступные через gremlin графы и псевдонимы
# - ./volumes/arcadedb:/home/arcadedb/config/gremlin-server.groovy
environment:
JAVA_OPTS: >
-Darcadedb.server.rootPassword=root_root
-Darcadedb.server.plugins=GremlinServer:com.arcadedb.server.gremlin.GremlinServerPlugin
8 changes: 8 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ spring-boot = "3.2.0"
liquibase = "4.27.0"
exposed = "0.50.0"
cassandra = "4.17.0"
arcadedb = "24.4.1"
gremlin = "3.7.2"

# Docker
testcontainers = "1.19.7"
Expand Down Expand Up @@ -98,6 +100,12 @@ db-cassandra-qbuilder = { module = "com.datastax.oss:java-driver-query-builder",
db-cassandra-kapt = { module = "com.datastax.oss:java-driver-mapper-processor", version.ref = "cassandra" }
db-cassandra-mapper = { module = "com.datastax.oss:java-driver-mapper-runtime", version.ref = "cassandra" }

# Gremlin
gdb-gremlin-driver = { module = "org.apache.tinkerpop:gremlin-driver", version.ref = "gremlin" }
gdb-arcade-engine = { module = "com.arcadedb:arcadedb-engine", version.ref = "arcadedb" }
gdb-arcade-network = { module = "com.arcadedb:arcadedb-network", version.ref = "arcadedb" }
gdb-arcade-gremlin = { module = "com.arcadedb:arcadedb-gremlin", version.ref = "arcadedb" }

# Liquidbase
liquibase-core = { module = "org.liquibase:liquibase-core", version.ref = "liquibase" }
liquibase-picocli = "info.picocli:picocli:4.7.5"
Expand Down
2 changes: 2 additions & 0 deletions ok-marketplace-be/ok-marketplace-app-ktor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ kotlin {
implementation(project(":ok-marketplace-api-v1-mappers"))

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

implementation("ru.otus.otuskotlin.marketplace.libs:ok-marketplace-lib-logging-logback")
implementation(libs.testcontainers.cassandra)
implementation(libs.testcontainers.core)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,25 @@ marketplace:
repository:
test: "inmemory"
prod: "$DB_TYPE_PROD:inmemory"

psql:
schema: public
database: "$MKPLADS_DB:marketplace-ads"
host: "$MKPLADS_HOST:localhost"
port: "$MKPLADS_PORT:5432"
user: "$MKPLADS_USER:postgres"
password: "$MKPLADS_PASS:marketplace-pass"

cassandra:
hosts: localhost
keyspace: test_keyspace
pass: cassandra
port: 9042
user: cassandra

gremlin:
host: "$DB_GREMLIN_HOST:localhost"
user: "$DB_GREMLIN_HOST:root"
password: "$DB_GREMLIN_HOST:root_root"
port: "$DB_GREMLIN_PORT:8182"
enableSsl: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ru.otus.otuskotlin.marketplace.app.ktor.configs

import io.ktor.server.config.*

data class GremlinConfig(
val host: String = "localhost",
val port: Int = 8182,
val user: String = "root",
val pass: String,
val enableSsl: Boolean = false,
) {
constructor(config: ApplicationConfig): this(
host = config.property("$PATH.host").getString(),
user = config.property("$PATH.user").getString(),
pass = config.property("$PATH.password").getString(),
enableSsl = config.property("$PATH.enableSsl").getString().toBoolean(),
)

companion object {
const val PATH = "${ConfigPaths.repository}.gremlin"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package ru.otus.otuskotlin.marketplace.app.ktor.plugins
import io.ktor.server.application.*
import ru.otus.otuskotlin.marketplace.app.ktor.configs.CassandraConfig
import ru.otus.otuskotlin.marketplace.app.ktor.configs.ConfigPaths
import ru.otus.otuskotlin.marketplace.app.ktor.configs.GremlinConfig
import ru.otus.otuskotlin.marketplace.backend.repo.cassandra.RepoAdCassandra
import ru.otus.otuskotlin.marketplace.backend.repository.gremlin.AdRepoGremlin
import ru.otus.otuskotlin.marketplace.common.repo.IRepoAd

actual fun Application.getDatabaseConf(type: AdDbType): IRepoAd {
Expand All @@ -13,6 +15,7 @@ actual fun Application.getDatabaseConf(type: AdDbType): IRepoAd {
"in-memory", "inmemory", "memory", "mem" -> initInMemory()
"postgres", "postgresql", "pg", "sql", "psql" -> initPostgres()
"cassandra", "nosql", "cass" -> initCassandra()
"arcade", "arcadedb", "graphdb", "gremlin", "g", "a" -> initGremliln()
else -> throw IllegalArgumentException(
"$dbSettingPath must be set in application.yml to one of: " +
"'inmemory', 'postgres', 'cassandra', 'gremlin'"
Expand All @@ -31,3 +34,13 @@ private fun Application.initCassandra(): IRepoAd {
)
}

private fun Application.initGremliln(): IRepoAd {
val config = GremlinConfig(environment.config)
return AdRepoGremlin(
hosts = config.host,
port = config.port,
user = config.user,
pass = config.pass,
enableSsl = config.enableSsl,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,30 @@ ktor:
# queue: mkpl-ads-v1-queue
# consumerTag: "mkpl-ads-v1-consumer"
# exchangeType: direct

marketplace:
repository:
test: "inmemory"
prod: "$DB_TYPE_PROD:inmemory"

psql:
schema: public
database: "$MKPLADS_DB:marketplace-ads"
host: "$MKPLADS_HOST:localhost"
port: "$MKPLADS_PORT:5432"
user: "$MKPLADS_USER:postgres"
password: "$MKPLADS_PASS:marketplace-pass"

cassandra:
hosts: localhost
keyspace: test_keyspace
pass: cassandra
port: 9042
user: cassandra

gremlin:
host: "$DB_GREMLIN_HOST:localhost"
user: "$DB_GREMLIN_HOST:root"
password: "$DB_GREMLIN_HOST:root_root"
port: "$DB_GREMLIN_PORT:8182"
enableSsl: false
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fun errorEmptyLock(id: MkplAdId) = DbAdResponseErr(

fun errorDb(e: RepoException) = DbAdResponseErr(
errorSystem(
violationCode = "dbLockEmpty",
violationCode = "db-error",
e = e
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package ru.otus.otuskotlin.marketplace.common.repo.exceptions

class UnknownDbException(mes: String): RepoException(mes)
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,38 @@ import com.benasher44.uuid.uuid4
import org.testcontainers.containers.CassandraContainer
import ru.otus.otuskotlin.marketplace.backend.repo.tests.*
import ru.otus.otuskotlin.marketplace.repo.common.AdRepoInitialized
import ru.otus.otuskotlin.marketplace.repo.common.IRepoAdInitializable
import java.time.Duration

class RepoAdCassandraCreateTest : RepoAdCreateTest() {
override val repo: IRepoAdInitializable = AdRepoInitialized(
override val repo = AdRepoInitialized(
initObjects = initObjects,
repo = TestCompanion.repository("ks_create", uuidNew.asString())
repo = TestCompanion.repository("ks_create", lockNew.asString())
)
}

class RepoAdCassandraReadTest : RepoAdReadTest() {
override val repo: IRepoAdInitializable = AdRepoInitialized(
override val repo = AdRepoInitialized(
initObjects = initObjects,
repo = TestCompanion.repository("ks_read")
)
}

class RepoAdCassandraUpdateTest : RepoAdUpdateTest() {
override val repo: IRepoAdInitializable = AdRepoInitialized(
override val repo = AdRepoInitialized(
initObjects = initObjects,
repo = TestCompanion.repository("ks_update", lockNew.asString())
)
}

class RepoAdCassandraDeleteTest : RepoAdDeleteTest() {
override val repo: IRepoAdInitializable = AdRepoInitialized(
override val repo = AdRepoInitialized(
initObjects = initObjects,
repo = TestCompanion.repository("ks_delete")
)
}

class RepoAdCassandraSearchTest : RepoAdSearchTest() {
override val repo: IRepoAdInitializable = AdRepoInitialized(
override val repo = AdRepoInitialized(
initObjects = initObjects,
repo = TestCompanion.repository("ks_search")
)
Expand Down
1 change: 1 addition & 0 deletions ok-marketplace-be/ok-marketplace-repo-gremlin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/log/
7 changes: 7 additions & 0 deletions ok-marketplace-be/ok-marketplace-repo-gremlin/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Модуль `ok-marketplace-repo-gremlin`


Модуль реализует интерфейс репозитория ArcadeDb с вариантом Apache TinkerPop Gremlin.

Поддерживается только JVM платформа.

47 changes: 47 additions & 0 deletions ok-marketplace-be/ok-marketplace-repo-gremlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated

plugins {
id("build-jvm")
}

val generatedPath = layout.buildDirectory.dir("generated/main/kotlin").get()
sourceSets {
main {
java.srcDir(generatedPath)
}
}

dependencies {
implementation(projects.okMarketplaceCommon)
implementation(projects.okMarketplaceRepoCommon)

implementation(libs.coroutines.core)
implementation(libs.uuid)

implementation(libs.gdb.gremlin.driver)
implementation(libs.gdb.arcade.engine)
implementation(libs.gdb.arcade.network)
implementation(libs.gdb.arcade.gremlin)

testImplementation(kotlin("test-junit"))
testImplementation(libs.testcontainers.core)
testImplementation(projects.okMarketplaceRepoTests)
}

val arcadeDbVersion: String by project

tasks {
val gradleConstants by creating {
file("$generatedPath/GradleConstants.kt").apply {
ensureParentDirsCreated()
writeText(
"""
package ru.otus.otuskotlin.marketplace.backend.repository.gremlin
const val ARCADEDB_VERSION = "${libs.versions.arcadedb.get()}"
""".trimIndent()
)
}
}
compileKotlin.get().dependsOn(gradleConstants)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ru.otus.otuskotlin.marketplace.backend.repository.gremlin

object AdGremlinConst {
const val RESULT_SUCCESS = "success"
const val RESULT_LOCK_FAILURE = "lock-failure"

const val FIELD_ID = "#id"
const val FIELD_TITLE = "title"
const val FIELD_DESCRIPTION = "description"
const val FIELD_AD_TYPE = "adType"
const val FIELD_OWNER_ID = "ownerId"
const val FIELD_VISIBILITY = "visibility"
const val FIELD_PRODUCT_ID = "productId"
const val FIELD_LOCK = "lock"
const val FIELD_TMP_RESULT = "_result"
}
Loading

0 comments on commit ad3a6de

Please sign in to comment.