Skip to content

Commit 9665292

Browse files
committed
Migration to elastic4s 6.3.0
1 parent d277fce commit 9665292

14 files changed

+52
-51
lines changed

src/main/scala/de/upb/cs/swt/delphi/crawler/Crawler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package de.upb.cs.swt.delphi.crawler
1818

1919
import akka.actor.ActorSystem
2020
import akka.stream.ActorMaterializer
21-
import com.sksamuel.elastic4s.http.{HttpClient}
21+
import com.sksamuel.elastic4s.http.ElasticClient
2222
import de.upb.cs.swt.delphi.crawler.control.Server
2323
import de.upb.cs.swt.delphi.crawler.discovery.maven.MavenCrawlActor
2424
import de.upb.cs.swt.delphi.crawler.discovery.maven.MavenCrawlActor.Start
@@ -65,7 +65,7 @@ object Crawler extends App with AppLogging {
6565

6666
new Server(configuration.controlServerPort).start()
6767

68-
val elasticActor = system.actorOf(ElasticActor.props(HttpClient(configuration.elasticsearchClientUri)))
68+
val elasticActor = system.actorOf(ElasticActor.props(ElasticClient(configuration.elasticsearchClientUri)))
6969
val hermesActor = system.actorOf(HermesActor.props(elasticActor))
7070
val processingDispatchActor = system.actorOf(ProcessingDispatchActor.props(hermesActor))
7171
val preprocessingDispatchActor = system.actorOf(PreprocessingDispatchActor.props(configuration, processingDispatchActor, elasticActor))

src/main/scala/de/upb/cs/swt/delphi/crawler/Playground.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package de.upb.cs.swt.delphi.crawler
1818

1919
import akka.actor.{ActorRef, ActorSystem}
2020
import com.sksamuel.elastic4s.ElasticsearchClientUri
21-
import com.sksamuel.elastic4s.http.HttpClient
21+
import com.sksamuel.elastic4s.http.ElasticClient
2222
import de.upb.cs.swt.delphi.crawler.storage.ElasticActor
2323

2424
/**
@@ -29,7 +29,7 @@ object Playground extends App {
2929
val system : ActorSystem = ActorSystem("trial")
3030

3131
val clientUri = ElasticsearchClientUri("localhost", 9200)
32-
val elastic : ActorRef = system.actorOf(ElasticActor.props(HttpClient(clientUri)), "elastic")
32+
val elastic : ActorRef = system.actorOf(ElasticActor.props(ElasticClient(clientUri)), "elastic")
3333

3434
//val maven : ActorRef = system.actorOf(MavenCrawlActor.props(Uri("http://repo1.maven.org/maven2/de/tu-darmstadt/"), elastic), "maven")
3535

src/main/scala/de/upb/cs/swt/delphi/crawler/discovery/maven/MavenCrawlActor.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package de.upb.cs.swt.delphi.crawler.discovery.maven
1818

1919
import akka.actor.{Actor, ActorLogging, ActorRef, Props}
2020
import akka.stream.ActorMaterializer
21-
import com.sksamuel.elastic4s.http.HttpClient
21+
import com.sksamuel.elastic4s.http.ElasticClient
2222
import de.upb.cs.swt.delphi.crawler.Configuration
2323
import de.upb.cs.swt.delphi.crawler.discovery.maven.MavenCrawlActor.Start
2424
import de.upb.cs.swt.delphi.crawler.storage.ArtifactExistsQuery
@@ -37,7 +37,7 @@ class MavenCrawlActor(configuration: Configuration, nextStep : ActorRef)
3737
log.info("Starting Maven discovery process...")
3838

3939
implicit val materializer = ActorMaterializer()
40-
implicit val client = HttpClient(configuration.elasticsearchClientUri)
40+
implicit val client = ElasticClient(configuration.elasticsearchClientUri)
4141
implicit val logger = log
4242

4343
createSource(configuration.mavenRepoBase)

src/main/scala/de/upb/cs/swt/delphi/crawler/preprocessing/PreprocessingDispatchActor.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717
package de.upb.cs.swt.delphi.crawler.preprocessing
1818

1919
import akka.actor.{Actor, ActorLogging, ActorRef, Props}
20-
import com.sksamuel.elastic4s.http.HttpClient
21-
import akka.util.Timeout
2220
import akka.pattern.ask
21+
import akka.routing.{BalancingPool, RoundRobinPool}
22+
import akka.util.Timeout
23+
import com.sksamuel.elastic4s.http.ElasticClient
2324
import de.upb.cs.swt.delphi.crawler.Configuration
2425
import de.upb.cs.swt.delphi.crawler.discovery.maven.MavenIdentifier
25-
import de.upb.cs.swt.delphi.crawler.storage.ElasticActor
26-
import akka.routing.{BalancingPool, RoundRobinPool}
2726
import de.upb.cs.swt.delphi.crawler.processing.CallGraphStream
27+
import de.upb.cs.swt.delphi.crawler.storage.ElasticActor
2828

2929
import scala.concurrent.duration._
30-
import scala.util.{Success, Try}
30+
import scala.util.Success
3131

3232
class PreprocessingDispatchActor(configuration : Configuration, nextStep : ActorRef, elasticActor : ActorRef) extends Actor with ActorLogging {
3333

3434
val elasticPool = context.actorOf(RoundRobinPool(configuration.elasticActorPoolSize)
35-
.props(ElasticActor.props(HttpClient(configuration.elasticsearchClientUri))))
35+
.props(ElasticActor.props(ElasticClient(configuration.elasticsearchClientUri))))
3636
val callGraphPool = context.actorOf(BalancingPool(configuration.callGraphStreamPoolSize)
3737
.props(CallGraphStream.props(configuration)))
3838

src/main/scala/de/upb/cs/swt/delphi/crawler/processing/CallGraphStream.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import akka.stream.scaladsl.GraphDSL.Implicits._
1010
import akka.stream.scaladsl.{Flow, GraphDSL, Keep, RunnableGraph, Sink, Source}
1111
import akka.util.Timeout
1212
import akka.{Done, NotUsed}
13-
import com.sksamuel.elastic4s.http.HttpClient
13+
import com.sksamuel.elastic4s.http.ElasticClient
1414
import de.upb.cs.swt.delphi.crawler.Configuration
1515
import de.upb.cs.swt.delphi.crawler.discovery.maven.MavenIdentifier
1616
import de.upb.cs.swt.delphi.crawler.preprocessing.{JarFile, MavenDownloader, PomFile}
@@ -50,7 +50,7 @@ class CallGraphStream(configuration: Configuration) extends Actor with ActorLogg
5050
implicit val parallelism = 1
5151
implicit val ec = ExecutionContext.global
5252

53-
val esClient = HttpClient(configuration.elasticsearchClientUri)
53+
val esClient = ElasticClient(configuration.elasticsearchClientUri)
5454

5555
val mavenDependencyActor = context.actorOf(MavenDependencyActor.props(configuration))
5656
val opalActor: ActorRef = context.actorOf(OpalActor.props(configuration))

src/main/scala/de/upb/cs/swt/delphi/crawler/processing/ElasticEdgeSearchActor.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package de.upb.cs.swt.delphi.crawler.processing
22

33
import akka.actor.{Actor, ActorLogging, Props}
4+
import com.sksamuel.elastic4s.http.{ElasticClient, Response}
45
import com.sksamuel.elastic4s.http.ElasticDsl._
5-
import com.sksamuel.elastic4s.http.HttpClient
6+
import com.sksamuel.elastic4s.http.search.MultiSearchResponse
67
import de.upb.cs.swt.delphi.crawler.discovery.maven.MavenIdentifier
78
import de.upb.cs.swt.delphi.crawler.processing.CallGraphStream.{MappedEdge, unresMCtoStr}
89
import org.opalj.ai.analyses.cg.UnresolvedMethodCall
@@ -14,7 +15,7 @@ import org.opalj.ai.analyses.cg.UnresolvedMethodCall
1415
* method is marked as belonging to that dependency.
1516
*/
1617

17-
class ElasticEdgeSearchActor(client: HttpClient) extends Actor with ActorLogging{
18+
class ElasticEdgeSearchActor(client: ElasticClient) extends Actor with ActorLogging{
1819

1920
val maxBatchSize = 150
2021

@@ -61,13 +62,13 @@ class ElasticEdgeSearchActor(client: HttpClient) extends Actor with ActorLogging
6162
}
6263

6364
def searchEsDb(calls: List[UnresolvedMethodCall], id: MavenIdentifier): (UnresolvedMethodCall) => Boolean = {
64-
val resp = client.execute{
65+
val resp: Response[MultiSearchResponse] = client.execute{
6566
multi(
6667
for(call <- calls) yield genSearchDef(call, id)
6768
)
6869
}.await
6970

70-
val result = resp.right.get.result.items
71+
val result = resp.result.items
7172
val hitIndices = result.filter(_.response.isRight).filter(_.response.right.get.totalHits > 0).map(_.index)
7273
val hits = for (i <- hitIndices) yield calls(i)
7374

@@ -90,5 +91,5 @@ class ElasticEdgeSearchActor(client: HttpClient) extends Actor with ActorLogging
9091
}
9192

9293
object ElasticEdgeSearchActor {
93-
def props(client: HttpClient) = Props(new ElasticEdgeSearchActor(client))
94+
def props(client: ElasticClient) = Props(new ElasticEdgeSearchActor(client))
9495
}

src/main/scala/de/upb/cs/swt/delphi/crawler/storage/ArtifactExistsQuery.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package de.upb.cs.swt.delphi.crawler.storage
1818

1919
import com.sksamuel.elastic4s.http.ElasticDsl._
2020
import com.sksamuel.elastic4s.http.search.SearchResponse
21-
import com.sksamuel.elastic4s.http.{HttpClient, RequestSuccess}
21+
import com.sksamuel.elastic4s.http.{ElasticClient, RequestSuccess}
2222
import de.upb.cs.swt.delphi.crawler.discovery.maven.MavenIdentifier
2323

2424
/**
@@ -32,12 +32,12 @@ trait ArtifactExistsQuery {
3232
* @param client
3333
* @return
3434
*/
35-
def exists(identifier : MavenIdentifier)(implicit client : HttpClient) : Boolean = {
35+
def exists(identifier : MavenIdentifier)(implicit client : ElasticClient) : Boolean = {
3636
client.execute {
3737
searchWithType(delphiProjectType) query must (
3838
matchQuery("name", identifier.toUniqueString)
3939
)
40-
}.await.merge match {
40+
}.await match {
4141
case RequestSuccess(_,_,_,SearchResponse(_, false, false, _, _, _, _, hits)) => (hits.total > 0)
4242
case _ => false
4343
}

src/main/scala/de/upb/cs/swt/delphi/crawler/storage/ArtifactIdentityQuery.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616

1717
package de.upb.cs.swt.delphi.crawler.storage
1818

19-
import com.sksamuel.elastic4s.http.{HttpClient, RequestSuccess}
2019
import com.sksamuel.elastic4s.http.ElasticDsl._
2120
import com.sksamuel.elastic4s.http.search.SearchResponse
21+
import com.sksamuel.elastic4s.http.{ElasticClient, RequestSuccess}
2222
import de.upb.cs.swt.delphi.crawler.discovery.maven.MavenIdentifier
2323

2424
trait ArtifactIdentityQuery {
25-
def elasticId(identifier : MavenIdentifier)(implicit client : HttpClient) : Option[String] = {
25+
def elasticId(identifier : MavenIdentifier)(implicit client : ElasticClient) : Option[String] = {
2626
client.execute {
2727
searchWithType(delphiProjectType) query must (
2828
matchQuery("name", identifier.toUniqueString)
2929
)
30-
}.await.merge match {
30+
}.await match {
3131
case RequestSuccess(_,_,_,SearchResponse(_, false, false, _, _, _, _, hits)) => hits.hits.headOption.map { case hit => hit.id }
3232
case x => None
3333
}

src/main/scala/de/upb/cs/swt/delphi/crawler/storage/ElasticActor.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
package de.upb.cs.swt.delphi.crawler.storage
1818

1919
import akka.actor.{Actor, ActorLogging, Props}
20-
2120
import akka.event.LoggingAdapter
22-
import com.sksamuel.elastic4s.http.HttpClient
21+
import com.sksamuel.elastic4s.http.ElasticClient
2322
import de.upb.cs.swt.delphi.crawler.Identifier
2423
import de.upb.cs.swt.delphi.crawler.discovery.git.GitIdentifier
2524
import de.upb.cs.swt.delphi.crawler.discovery.maven.MavenIdentifier
@@ -30,8 +29,8 @@ import de.upb.cs.swt.delphi.crawler.processing.HermesResults
3029
* @param client The currently active elasticsearch client
3130
* @author Ben Hermann
3231
*/
33-
class ElasticActor(client: HttpClient) extends Actor with ActorLogging with ArtifactIdentityQuery with ElasticStoreQueries {
34-
private implicit val c : HttpClient = client
32+
class ElasticActor(client: ElasticClient) extends Actor with ActorLogging with ArtifactIdentityQuery with ElasticStoreQueries {
33+
private implicit val c : ElasticClient = client
3534
private implicit val l : LoggingAdapter = log
3635

3736
override def receive: PartialFunction[Any, Unit] = {
@@ -44,7 +43,7 @@ class ElasticActor(client: HttpClient) extends Actor with ActorLogging with Arti
4443
}
4544

4645
object ElasticActor {
47-
def props(client: HttpClient): Props = Props(new ElasticActor(client))
46+
def props(client: ElasticClient): Props = Props(new ElasticActor(client))
4847

4948
case class Push(identity: Identifier)
5049

src/main/scala/de/upb/cs/swt/delphi/crawler/storage/ElasticCallGraphActor.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package de.upb.cs.swt.delphi.crawler.storage
22

33
import akka.actor.{Actor, ActorLogging, Props}
4+
import com.sksamuel.elastic4s.http.ElasticClient
45
import com.sksamuel.elastic4s.http.ElasticDsl._
5-
import com.sksamuel.elastic4s.http.HttpClient
66
import de.upb.cs.swt.delphi.crawler.discovery.maven.MavenIdentifier
77
import de.upb.cs.swt.delphi.crawler.processing.CallGraphStream.MappedEdge
88

@@ -13,7 +13,7 @@ import de.upb.cs.swt.delphi.crawler.processing.CallGraphStream.MappedEdge
1313
* into a single map (defined in createLibraryMap), then adds these maps to a preexisting document.
1414
*/
1515

16-
class ElasticCallGraphActor(client: HttpClient) extends Actor with ActorLogging {
16+
class ElasticCallGraphActor(client: ElasticClient) extends Actor with ActorLogging {
1717
override def receive: Receive = {
1818
case (i: MavenIdentifier, ex: Set[MappedEdge]) => {
1919
try {
@@ -48,8 +48,9 @@ class ElasticCallGraphActor(client: HttpClient) extends Actor with ActorLogging
4848
)
4949
}.sourceInclude("_id")
5050
}.await
51-
if (resp.isRight) {
52-
val hits = resp.right.get.result.hits
51+
52+
if (resp.isSuccess) {
53+
val hits = resp.result.hits
5354
if (hits.total > 0) {
5455
hits.hits.head.id
5556
} else {
@@ -62,7 +63,7 @@ class ElasticCallGraphActor(client: HttpClient) extends Actor with ActorLogging
6263
"artifactId" -> id.artifactId,
6364
"version" -> id.version))
6465
}.await
65-
resp.right.get.result.id
66+
resp.result.id
6667
}
6768
} else {
6869
throw new Exception("Elasticsearch server cannot be reached - call graph for " + id.toString +" lost.")
@@ -91,5 +92,5 @@ class ElasticCallGraphActor(client: HttpClient) extends Actor with ActorLogging
9192
}
9293

9394
object ElasticCallGraphActor{
94-
def props(client: HttpClient) = Props(new ElasticCallGraphActor(client))
95+
def props(client: ElasticClient) = Props(new ElasticCallGraphActor(client))
9596
}

0 commit comments

Comments
 (0)