Skip to content
This repository has been archived by the owner on Feb 26, 2018. It is now read-only.

First stab at using a cachedHostConnectionPool in a High level akka http DSL. Closes cromwell#2130 #3

Merged
merged 1 commit into from
May 5, 2017

Conversation

jsotobroad
Copy link
Contributor

Wanted to try using a cachedHostConnectionPool while still making use of the high level dsl Route request parsing. Everything functionally works but there are still things that need to be made better or just changed completely.

Copy link
Contributor

@cjllanwarne cjllanwarne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly notes for myself!

implicit val materializer = ActorMaterializer()

val config = ConfigFactory.load()
// we shoudl be able to control this pool with lots of different configs talked about here. We use `Unit` here because
// there isnt a context we need to pass around to make sure resquests get the correct response because we only call the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnt -> isn't
resquests -> requests

implicit val materializer = ActorMaterializer()

val config = ConfigFactory.load()
// we shoudl be able to control this pool with lots of different configs talked about here. We use `Unit` here because
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we -> We
shoudl -> should

// we shoudl be able to control this pool with lots of different configs talked about here. We use `Unit` here because
// there isnt a context we need to pass around to make sure resquests get the correct response because we only call the
// pool using Source.single but its something we could use in the future if need be
val cromwellPool = Http().cachedHostConnectionPool[Unit](host = config.getString("cromwell.interface"), port = config.getInt("cromwell.port"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values are used a few times. Let's validate once and reuse the results

val config: Config
val cromwellPool: Flow[(HttpRequest, Unit), (Try[HttpResponse], Unit), HostConnectionPool]

// Header that akka http DSL api adds to a request when we recieve, We get an warning in logs if we dont strip it out before sending the request to cromwell
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recieve -> receive

}

// left in here for now in case we decide to not use akka streams to send requests in the future, can probably remove soon
def forwardToCromwellNoStreaming(httpRequest: HttpRequest) : Future[HttpResponse] = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree about removing this ASAP if it won't be used

}

def forwardToCromwellStreaming(httpRequest: HttpRequest) = {
Source.single((cromIamRequestToCromwellRequest(httpRequest), ())).via(cromwellPool).runWith(Sink.head).map(cromwellResponseHandler)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to use Http.singleRequest. It's faster and less complicated. Using the streaming pool interface makes only sense if you really supply it with a stream of requests. Otherwise, it's functionally equivalent to use Http.singleRequest.

@cjllanwarne cjllanwarne changed the title First stab at using a cachedHostConnectionPool in a High level akka http DSL First stab at using a cachedHostConnectionPool in a High level akka http DSL. Closes broadinstitute/cromwell#2130 May 2, 2017
@cjllanwarne cjllanwarne changed the title First stab at using a cachedHostConnectionPool in a High level akka http DSL. Closes broadinstitute/cromwell#2130 First stab at using a cachedHostConnectionPool in a High level akka http DSL. Closes cromwell#2130 May 2, 2017
returnInternalServerError("engine stats")
extractRequest { req =>
complete {
forwardToCromwell(req)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to forward any stats requests to Cromwell, we should return some kind of "no you cant do that" response directly from CromIam - broadinstitute/cromwell#2137.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and ignore the typo from that geoffjentry fellow

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I did wonder why that one was left unchanged!


// Header that Akka HTTP adds to every request on receive.
// We get an warning in logs if we don't strip it out before sending the request to cromwell
// HTTP header ‘Timeout-Access: <function1>’ is not allowed in requests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add this link as further justification: "https://github.com/akka/akka-http/issues/64"

extractRequest { req =>
complete {
forwardToCromwell(req)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to DRY this out? It seems very repetitive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought about that... I'm gonna hold off on that until after we get the extra validation steps in, in case we end up with a premature abstraction that we just end up unpicking.

val logger = NoLogging

"Stats endpoint" should "respond with internal server error" in {
override def cromwellInterface: String = ???
override def cromwellPort: Int = ???
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??? is really meant as a WIP placeholder, these should probably be changed to throw NotImplementedErrors

@mcovarr
Copy link
Contributor

mcovarr commented May 4, 2017

👍

@mcovarr
Copy link
Contributor

mcovarr commented May 4, 2017

Should there be pullapprove on this project?

@Horneth
Copy link

Horneth commented May 5, 2017

From a CromIAM client perspective, the responses look like they come from Cromwell directly it seems. Is this the desired behavior ? Or will it be changed in a later PR ?
👍

…).singlerequest that talks to a local cromwell

and responds to the user with that request
@cjllanwarne cjllanwarne merged commit a94b66f into develop May 5, 2017
@cjllanwarne cjllanwarne deleted the js_akka_streams branch May 5, 2017 17:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants