-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Search API Microservice and manual testing facilities
- Loading branch information
Showing
11 changed files
with
207 additions
and
5 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
modules/redis-client/src/test/scala/io/renku/redis/client/util/TestSearchRedisServer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2024 Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.renku.redis.client.util | ||
|
||
import cats.effect.{ExitCode, IO, IOApp} | ||
import io.renku.servers.RedisServer | ||
|
||
/** This is a utility to start a Redis server for manual testing */ | ||
object TestSearchRedisServer extends IOApp: | ||
|
||
override def run(args: List[String]): IO[ExitCode] = | ||
(IO(RedisServer.start()) >> IO.never[ExitCode]).as(ExitCode.Success) |
44 changes: 44 additions & 0 deletions
44
modules/search-api/src/main/scala/io/renku/search/api/HttpApplication.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2024 Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.renku.search.api | ||
|
||
import cats.Monad | ||
import cats.effect.{Async, Resource} | ||
import fs2.io.net.Network | ||
import io.renku.solr.client.SolrConfig | ||
import org.http4s.dsl.Http4sDsl | ||
import org.http4s.server.Router | ||
import org.http4s.{HttpApp, HttpRoutes, Request, Response} | ||
import scribe.Scribe | ||
|
||
object HttpApplication: | ||
def apply[F[_]: Async: Network: Scribe]( | ||
solrConfig: SolrConfig | ||
): Resource[F, HttpApp[F]] = | ||
SearchApi[F](solrConfig).map(new HttpApplication[F](_).router) | ||
|
||
class HttpApplication[F[_]: Monad](searchApi: SearchApi[F]) extends Http4sDsl[F]: | ||
|
||
lazy val router: HttpApp[F] = | ||
Router[F]("/" -> routes).orNotFound | ||
|
||
private lazy val routes: HttpRoutes[F] = HttpRoutes.of[F] { | ||
case GET -> Root / "api" / phrase => searchApi.find(phrase) | ||
case GET -> Root / "ping" => Ok("pong") | ||
} |
38 changes: 38 additions & 0 deletions
38
modules/search-api/src/main/scala/io/renku/search/api/HttpServer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2024 Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.renku.search.api | ||
|
||
import cats.effect.{Async, Resource} | ||
import com.comcast.ip4s.{Port, ipv4, port} | ||
import fs2.io.net.Network | ||
import org.http4s.HttpApp | ||
import org.http4s.ember.server.EmberServerBuilder | ||
import org.http4s.server.Server | ||
|
||
object HttpServer: | ||
|
||
val port: Port = port"8080" | ||
|
||
def build[F[_]: Async: Network](app: HttpApp[F]): Resource[F, Server] = | ||
EmberServerBuilder | ||
.default[F] | ||
.withHost(ipv4"0.0.0.0") | ||
.withPort(port) | ||
.withHttpApp(app) | ||
.build |
43 changes: 43 additions & 0 deletions
43
modules/search-api/src/main/scala/io/renku/search/api/Microservice.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2024 Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.renku.search.api | ||
|
||
import cats.effect.{ExitCode, IO, IOApp} | ||
import cats.syntax.all.* | ||
import io.renku.solr.client.SolrConfig | ||
import org.http4s.implicits.* | ||
import scribe.Scribe | ||
|
||
import scala.concurrent.duration.Duration | ||
|
||
object Microservice extends IOApp: | ||
|
||
private given Scribe[IO] = scribe.cats[IO] | ||
|
||
private val solrConfig = SolrConfig( | ||
baseUrl = uri"http://localhost:8983" / "solr", | ||
core = "search-core-test", | ||
commitWithin = Some(Duration.Zero), | ||
logMessageBodies = true | ||
) | ||
|
||
override def run(args: List[String]): IO[ExitCode] = | ||
(createHttpApp >>= HttpServer.build).use(_ => IO.never).as(ExitCode.Success) | ||
|
||
private def createHttpApp = HttpApplication[IO](solrConfig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
.../search-solr-client/src/test/scala/io/renku/search/solr/client/TestSearchSolrServer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2024 Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.renku.search.solr.client | ||
|
||
import cats.effect.{ExitCode, IO, IOApp} | ||
import io.renku.servers.SolrServer | ||
|
||
/** This is a utility to start a Solr server for manual testing */ | ||
object TestSearchSolrServer extends IOApp: | ||
|
||
override def run(args: List[String]): IO[ExitCode] = | ||
(IO(SolrServer.start()) >> IO.never[ExitCode]).as(ExitCode.Success) |