Skip to content

Commit

Permalink
Remove postgres integration.
Browse files Browse the repository at this point in the history
We are moving away from this vendor-release API, favouring postgres over
mongodb. Postgres persistence is now handled by the sdkman-state application.
We should perform all persistence via this API instead.
  • Loading branch information
marc0der committed Jan 14, 2024
1 parent 1e315c2 commit 5f5db71
Show file tree
Hide file tree
Showing 26 changed files with 54 additions and 473 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ jobs:
image: mongo:3.2
ports:
- 27017:27017
postgres:
image: postgres:14
ports:
- 5432:5432
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: sdkman
steps:
- name: Checkout source code
uses: actions/checkout@v2
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ jobs:
image: mongo:3.2
ports:
- 27017:27017
postgres:
image: postgres:14
ports:
- 5432:5432
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: sdkman
steps:
- uses: actions/checkout@v2
with:
Expand Down
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,4 @@ Used by vendors for releasing new candidate versions on SDKMAN!
### Run locally

$ docker run --rm -d -p="27017:27017" --name=mongo mongo:3.2
$ docker run \
--name postgres \
-p 5432:5432 \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=sdkman \
-d postgres
$ sbt run

6 changes: 1 addition & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % "1.1.8",
"io.spray" %% "spray-json" % "1.3.2",
"com.github.sdkman" % "sdkman-mongodb-persistence" % "2.1",
"com.github.sdkman" % "sdkman-url-validator" % "0.2.4",
"com.typesafe.slick" %% "slick" % "3.4.1",
"com.typesafe.slick" %% "slick-hikaricp" % "3.4.1",
"org.flywaydb" % "flyway-core" % "9.16.0",
"org.postgresql" % "postgresql" % "42.5.4"
"com.github.sdkman" % "sdkman-url-validator" % "0.2.4"
) ++ testDependencies

lazy val `vendor-release` = (project in file("."))
Expand Down
18 changes: 0 additions & 18 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,3 @@ mongo {
password = ""
password = ${?MONGO_PASSWORD}
}

jdbc {
connectionPool = "HikariCP"
dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
properties = {
driver = "org.postgresql.Driver"

url = "jdbc:postgresql://localhost:5432/sdkman"
url = ${?DATABASE_URL}

user = "postgres"
user = ${?DATABASE_USER}

password = "postgres"
password = ${?DATABASE_PASSWORD}
}
numThreads = 10
}
10 changes: 0 additions & 10 deletions src/main/resources/db/migration/V1__create_version_table.sql

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions src/main/scala/io/sdkman/vendor/release/Configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,4 @@ trait Configuration {
lazy val serviceToken: String = config.getString("service.token")

lazy val serviceAdminConsumer: String = config.getString("service.adminConsumer")

lazy val jdbcUrl: String = config.getString("jdbc.properties.url")

lazy val jdbcUser: String = config.getString("jdbc.properties.user")

lazy val jdbcPassword: String = config.getString("jdbc.properties.password")
}
16 changes: 2 additions & 14 deletions src/main/scala/io/sdkman/vendor/release/HttpServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Route
import io.sdkman.vendor.release.routes.{
CandidateReleaseRoutes,
CandidateDefaultRoutes,
CandidateReleaseRoutes,
HealthRoutes,
VersionReleaseRoutes
}
import org.flywaydb.core.Flyway
import org.flywaydb.core.api.output.MigrateResult

import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
Expand All @@ -41,23 +39,13 @@ class HttpServer

val routes: Route = healthRoutes ~ versionReleaseRoutes ~ candidateDefaultRoutes ~ candidateReleaseRoutes

private val flyway = Flyway
.configure()
.dataSource(jdbcUrl, jdbcUser, jdbcPassword)
.load()

def migrate(): MigrateResult = flyway.migrate()

def start(): Future[Http.ServerBinding] =
Http().newServerAt(serviceHost, servicePort).bindFlow(routes)

def shutdown(): Unit = {
Await.ready(actorSystem.terminate(), 5.seconds)
}
def shutdown(): Unit = Await.ready(actorSystem.terminate(), 5.seconds)
}

object HttpServer extends App {
val server = new HttpServer
server.migrate()
server.start()
}
22 changes: 0 additions & 22 deletions src/main/scala/io/sdkman/vendor/release/PostgresConnectivity.scala

This file was deleted.

This file was deleted.

63 changes: 0 additions & 63 deletions src/main/scala/io/sdkman/vendor/release/repos/PgVersionRepo.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ package io.sdkman.vendor.release.routes
import akka.http.scaladsl.server.{Directives, Route}
import io.sdkman.db.{MongoConfiguration, MongoConnectivity}
import io.sdkman.repos.{CandidatesRepo, VersionsRepo}
import io.sdkman.vendor.release.repos.PgCandidateRepo
import io.sdkman.vendor.release.{Configuration, HttpResponses, PostgresConnectivity}
import io.sdkman.vendor.release.{Configuration, HttpResponses}

import scala.concurrent.ExecutionContext.Implicits.global

Expand All @@ -30,8 +29,6 @@ trait CandidateDefaultRoutes
with MongoConnectivity
with Configuration
with MongoConfiguration
with PostgresConnectivity
with PgCandidateRepo
with JsonSupport
with HttpResponses
with Authorisation {
Expand All @@ -50,10 +47,8 @@ trait CandidateDefaultRoutes
candidateO.fold(badRequestResponseF(s"Invalid candidate: ${req.candidate}")) { _ =>
versions.headOption
.map { v =>
for {
_ <- updateDefaultVersion(v.candidate, v.version)
_ <- updateDefaultVersionPostgres(v.candidate, v.version)
} yield acceptedResponse(s"Defaulted: ${v.candidate} ${v.version}")
updateDefaultVersion(v.candidate, v.version)
.map(_ => acceptedResponse(s"Defaulted: ${v.candidate} ${v.version}"))
}
.getOrElse(
badRequestResponseF(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import com.typesafe.scalalogging.LazyLogging
import io.sdkman.db.{MongoConfiguration, MongoConnectivity}
import io.sdkman.model._
import io.sdkman.repos.CandidatesRepo
import io.sdkman.vendor.release.{Configuration, HttpResponses, PostgresConnectivity}
import io.sdkman.vendor.release.repos.PgCandidateRepo
import io.sdkman.vendor.release.{Configuration, HttpResponses}
import org.mongodb.scala.Completed
import org.mongodb.scala.model.Filters.equal

Expand All @@ -16,10 +15,8 @@ import scala.concurrent.Future
trait CandidateReleaseRoutes
extends Directives
with Configuration
with PostgresConnectivity
with MongoConfiguration
with MongoConnectivity
with PgCandidateRepo
with CandidatesRepo
with LazyLogging
with JsonSupport
Expand All @@ -32,33 +29,26 @@ trait CandidateReleaseRoutes
authorised(req.id) {
complete {
for {
_ <- insertCandidatePostgres(
req.id,
req.name,
req.description,
req.websiteUrl,
req.distribution
_ <- upsertCandidate(
Candidate(
candidate = req.id,
name = req.name,
description = req.description,
websiteUrl = req.websiteUrl,
distribution = req.distribution,
default = None
)
)
candidate = Candidate(
candidate = req.id,
name = req.name,
description = req.description,
websiteUrl = req.websiteUrl,
distribution = req.distribution,
default = None
)
_ <- upsertCandidate(candidate)
} yield acceptedResponse(s"Create or update candidate: ${req.id}")
}
}
}
}
}

private def upsertCandidate(candidate: Candidate): Future[Completed] = {
private def upsertCandidate(candidate: Candidate): Future[Completed] =
for {
_ <- candidatesCollection.deleteOne(equal("candidate", candidate.candidate)).toFuture()
result <- insertCandidate(candidate)
} yield result
}
}
Loading

0 comments on commit 5f5db71

Please sign in to comment.