Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an api endpoint for getting the current leader #741

Merged
merged 2 commits into from
Nov 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ All examples in this section assume that you've found a running leader at `chron
When you have multiple Chronos nodes running, only one of them will be elected as the leader.
The leader is the only node that responds to API requests, but if you attempt to talk to a non-leader your request will automatically be redirected to a leader.

To get the current leader you can hit the following endpoint.

* Endpoint: __/leader__
* Method: __GET__
* Example: `curl -L chronos-node:8080/leader`
* Response: A JSON dict containing a single `leader` key.

## Listing Jobs

* Endpoint: __/scheduler/jobs__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ChronosRestModule extends ServletModule {
bind(classOf[MetricsServlet]).in(Scopes.SINGLETON)
bind(classOf[LogConfigServlet]).in(Scopes.SINGLETON)
bind(classOf[ConstraintViolationExceptionMapper]).in(Scopes.SINGLETON)
bind(classOf[LeaderResource]).in(Scopes.SINGLETON)

serve(pingUrl).`with`(classOf[PingServlet])
serve(metricsUrl).`with`(classOf[MetricsServlet])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.apache.mesos.chronos.scheduler.api

import org.apache.mesos.chronos.scheduler.jobs.JobScheduler
import javax.ws.rs.core.{MediaType, Response}
import javax.ws.rs.{GET, Path, Produces}
import com.google.inject.Inject


@Path(PathConstants.getLeaderPattern)
@Produces(Array(MediaType.APPLICATION_JSON))
class LeaderResource @Inject()(
val jobScheduler: JobScheduler
) {
@GET
def getLeader(): Response = {
Response.ok(Map("leader" -> jobScheduler.getLeader)).build
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ object PathConstants {
final val jobGraphDotPath = "dot"
final val jobGraphCsvPath = "csv"
final val killTaskPattern = "kill/{jobName}"
final val getLeaderPattern = "/leader"

final val isMasterPath = "isMaster"
final val taskBasePath = "/task"
Expand Down