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

Dev/0.1.0 #1

Merged
merged 12 commits into from
Mar 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
dbUrl method
  • Loading branch information
alhuelamo committed Mar 19, 2022
commit 8ff28acca0c2abd24be77b078c4573bc9e3d0901
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object DatabricksApi {

def getActiveJobRuns(jobId: Long, ws: DatabricksWorkspace): List[Long] = {
val response = requests.get(
url = s"${ws.host}/api/2.1/jobs/runs/list",
url = dbUrl("jobs/runs/list", ws),
headers = defaultHeaders(ws),
params = Map(
"active_only" -> "true",
Expand Down Expand Up @@ -38,7 +38,7 @@ object DatabricksApi {

def cancelJobRun(runId: Long, ws: DatabricksWorkspace): Unit = {
val response = requests.post(
url = s"${ws.host}/api/2.1/jobs/runs/cancel",
url = dbUrl("jobs/runs/cancel", ws),
headers = defaultHeaders(ws),
data = ujson.Obj("run_id" -> runId.toString),
check = false
Expand All @@ -51,7 +51,7 @@ object DatabricksApi {

def triggerJobRun(jobId: Long, ws: DatabricksWorkspace): Unit = {
val response = requests.post(
url = s"${ws.host}/api/2.1/jobs/run-now",
url = dbUrl("jobs/run-now", ws),
headers = defaultHeaders(ws),
data = ujson.Obj("job_id" -> jobId.toString),
check = false
Expand All @@ -69,4 +69,7 @@ object DatabricksApi {
"Content-Type" -> "application/json"
)

private[jobmanager] def dbUrl(endpoint: String, ws: DatabricksWorkspace) =
s"https://${ws.host}/api/2.1/$endpoint"

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.alhuelamo.databricks.jobmanager

import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import com.alhuelamo.databricks.jobmanager.conf.DatabricksWorkspace

class DatabricksApiSpec extends AnyWordSpec with Matchers {

Expand Down Expand Up @@ -133,4 +134,16 @@ class DatabricksApiSpec extends AnyWordSpec with Matchers {
}
}

"dbUrl method" should {
"generate valid Databricks urls out of valid configuration" in {
val ws = DatabricksWorkspace(host = "myhost", token = "mytoken")

val actual = DatabricksApi.dbUrl("jobs/list", ws)

val expected = "https://myhost/api/2.1/jobs/list"

actual shouldBe expected
}
}

}