-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into improve_allocatable_resource
- Loading branch information
Showing
37 changed files
with
959 additions
and
356 deletions.
There are no files selected for viewing
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,25 @@ | ||
FROM ubuntu:24.04 | ||
|
||
ARG SCALA_VERSION=2.13.15 | ||
ARG SBT_VERSION=1.10.7 | ||
|
||
LABEL org.opencontainers.image.authors="G-Research Open-Source Software" | ||
LABEL org.opencontainers.image.licenses="Apache-2.0" | ||
LABEL org.opencontainers.image.ref.name="Ubuntu Scala Image" | ||
LABEL org.opencontainers.image.version="" | ||
|
||
RUN set -ex && \ | ||
apt update && \ | ||
apt install -y apt-utils && \ | ||
apt install -y bash curl && \ | ||
curl -s -O https://downloads.lightbend.com/scala/${SCALA_VERSION}/scala-${SCALA_VERSION}.deb && \ | ||
apt install -y ./scala-${SCALA_VERSION}.deb && \ | ||
curl -s -L -O https://github.com/sbt/sbt/releases/download/v${SBT_VERSION}/sbt-${SBT_VERSION}.tgz && \ | ||
tar -C / -xzvf ./sbt-${SBT_VERSION}.tgz && \ | ||
apt-get clean && \ | ||
rm -rf scala-${SCALA_VERSION}.deb sbt-${SBT_VERSION}.tgz /var/lib/apt/lists/* | ||
|
||
COPY scripts/build-scala-client.sh / | ||
RUN chmod +x /build-scala-client.sh | ||
|
||
ENTRYPOINT [ "/build-scala-client.sh" ] |
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,36 @@ | ||
# macOS | ||
.DS_Store | ||
|
||
# sbt specific | ||
dist/* | ||
# During development of this client, you may want to | ||
# comment out the next three lines, so IDEs/LSPs can | ||
# find and use the protoc-generated scala code. | ||
target/ | ||
lib_managed/ | ||
src_managed/ | ||
|
||
project/boot/ | ||
project/plugins/project/ | ||
project/local-plugins.sbt | ||
.history | ||
.ensime | ||
.ensime_cache/ | ||
.sbt-scripted/ | ||
local.sbt | ||
|
||
# Bloop | ||
.bsp | ||
|
||
# VS Code | ||
.vscode/ | ||
|
||
# Metals | ||
.bloop/ | ||
.metals/ | ||
metals.sbt | ||
|
||
# IDEA | ||
.idea | ||
.idea_modules | ||
/.worksheet/ |
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,11 @@ | ||
To build the example Armada client programs, build the Scala Armada client first: | ||
``` | ||
cd client/scala/scala-armada-client/ | ||
sbt publishLocal | ||
``` | ||
|
||
Then compile the examples project: | ||
``` | ||
cd client/scala/examples/ | ||
sbt compile | ||
``` |
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,26 @@ | ||
val scala2Version = "2.13.15" | ||
|
||
lazy val root = project | ||
.in(file(".")) | ||
.settings( | ||
name := "Scala Armada Client", | ||
version := "0.1.0-SNAPSHOT", | ||
|
||
scalaVersion := scala2Version, | ||
|
||
libraryDependencies += "io.armadaproject.armada" %% "scala-armada-client" % "0.1.0-SNAPSHOT", | ||
libraryDependencies += "org.scalameta" %% "munit" % "1.0.0" % Test | ||
) | ||
|
||
Compile / PB.targets := Seq( | ||
scalapb.gen() -> (Compile / sourceManaged).value | ||
) | ||
|
||
// Additional directories to search for imports: | ||
Compile / PB.protoSources ++= Seq(file("./proto")) | ||
|
||
libraryDependencies ++= Seq( | ||
"com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion | ||
) | ||
|
||
resolvers += Resolver.mavenLocal |
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 @@ | ||
sbt.version=1.10.7 |
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,7 @@ | ||
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.7") | ||
|
||
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.13" | ||
|
||
libraryDependencies ++= Seq( | ||
"com.google.protobuf" % "protobuf-java" % "3.13.0" % "protobuf" | ||
) |
12 changes: 12 additions & 0 deletions
12
client/scala/examples/src/main/scala/io/armadaproject/armada/Health.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,12 @@ | ||
import io.armadaproject.armada.ArmadaClient | ||
|
||
object Main { | ||
def main(args: Array[String]): Unit = { | ||
val host = "localhost" | ||
val port = 30002 | ||
|
||
val ac = ArmadaClient(host, port) | ||
val status = ac.eventHealth() | ||
println(status) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
client/scala/examples/src/main/scala/io/armadaproject/armada/Job.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,54 @@ | ||
package io.armadaproject.armada | ||
|
||
import k8s.io.api.core.v1.generated.{Container, PodSpec, ResourceRequirements} | ||
import k8s.io.apimachinery.pkg.api.resource.generated.Quantity | ||
|
||
object Main { | ||
val host = "localhost" | ||
val port = 30002 | ||
|
||
def main(args: Array[String]): Unit = { | ||
val sleepContainer = Container() | ||
.withName("ls") | ||
.withImagePullPolicy("IfNotPresent") | ||
.withImage("alpine:3.10") | ||
.withCommand(Seq("ls")) | ||
.withArgs( | ||
Seq( | ||
"-c", | ||
"ls -l; sleep 30; date; echo '========'; ls -l; sleep 10; date" | ||
) | ||
) | ||
.withResources( | ||
ResourceRequirements( | ||
limits = Map( | ||
"memory" -> Quantity(Option("10Mi")), | ||
"cpu" -> Quantity(Option("100m")) | ||
), | ||
requests = Map( | ||
"memory" -> Quantity(Option("10Mi")), | ||
"cpu" -> Quantity(Option("100m")) | ||
) | ||
) | ||
) | ||
|
||
val podSpec = PodSpec() | ||
.withTerminationGracePeriodSeconds(0) | ||
.withRestartPolicy("Never") | ||
.withContainers(Seq(sleepContainer)) | ||
|
||
val testJob = api.submit | ||
.JobSubmitRequestItem() | ||
.withPriority(0) | ||
.withNamespace("personal-anonymous") | ||
.withPodSpec(podSpec) | ||
|
||
val ac = ArmadaClient("localhost", 30002) | ||
val response = ac.submitJobs("testQueue", "testJobSetId", List(testJob)) | ||
|
||
println(s"Job Submit Response") | ||
for (respItem <- response.jobResponseItems) { | ||
println(s"JobID: ${respItem.jobId} Error: ${respItem.error} ") | ||
} | ||
} | ||
} |
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,36 @@ | ||
# macOS | ||
.DS_Store | ||
|
||
# sbt specific | ||
dist/* | ||
# During development of this client, you may want to | ||
# comment out the next three lines, so IDEs/LSPs can | ||
# find and use the protoc-generated scala code. | ||
target/ | ||
lib_managed/ | ||
src_managed/ | ||
|
||
project/boot/ | ||
project/plugins/project/ | ||
project/local-plugins.sbt | ||
.history | ||
.ensime | ||
.ensime_cache/ | ||
.sbt-scripted/ | ||
local.sbt | ||
|
||
# Bloop | ||
.bsp | ||
|
||
# VS Code | ||
.vscode/ | ||
|
||
# Metals | ||
.bloop/ | ||
.metals/ | ||
metals.sbt | ||
|
||
# IDEA | ||
.idea | ||
.idea_modules | ||
/.worksheet/ |
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,3 @@ | ||
version = 3.8.3 | ||
|
||
runner.dialect = scala213 |
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,5 @@ | ||
## sbt project compiled with Scala 2 | ||
|
||
### Usage | ||
|
||
You can build the Scala Armada client with `sbt package`. The jar can be found in `target/scala-2.13/`. |
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,25 @@ | ||
val scala2Version = "2.13.15" | ||
|
||
lazy val root = project | ||
.in(file(".")) | ||
.settings( | ||
organization := "io.armadaproject.armada", | ||
name := "Scala-Armada-Client", | ||
version := "0.1.0-SNAPSHOT", | ||
|
||
scalaVersion := scala2Version, | ||
|
||
libraryDependencies += "org.scalameta" %% "munit" % "1.0.0" % Test | ||
) | ||
|
||
Compile / PB.targets := Seq( | ||
scalapb.gen() -> (Compile / sourceManaged).value | ||
) | ||
|
||
// Additional directories to search for imports: | ||
Compile / PB.protoSources ++= Seq(file("./proto")) | ||
|
||
libraryDependencies ++= Seq( | ||
"io.grpc" % "grpc-netty" % scalapb.compiler.Version.grpcJavaVersion, | ||
"com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion | ||
) |
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 @@ | ||
sbt.version=1.10.7 |
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,7 @@ | ||
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.7") | ||
|
||
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.13" | ||
|
||
libraryDependencies ++= Seq( | ||
"com.google.protobuf" % "protobuf-java" % "3.13.0" % "protobuf" | ||
) |
64 changes: 64 additions & 0 deletions
64
client/scala/scala-armada-client/src/main/scala/io/armadaproject/armada/ArmadaClient.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,64 @@ | ||
package io.armadaproject.armada | ||
|
||
import api.job.{JobStatusRequest, JobStatusResponse, JobsGrpc} | ||
import api.event.EventGrpc | ||
import api.submit.{SubmitGrpc, JobSubmitRequest, JobSubmitResponse, JobSubmitRequestItem, | ||
Queue, QueueDeleteRequest, QueueGetRequest} | ||
import api.health.HealthCheckResponse | ||
import api.submit.Job | ||
import k8s.io.api.core.v1.generated.{Container, PodSpec, ResourceRequirements} | ||
import k8s.io.apimachinery.pkg.api.resource.generated.Quantity | ||
import com.google.protobuf.empty.Empty | ||
import io.grpc.{ManagedChannelBuilder, ManagedChannel} | ||
|
||
class ArmadaClient(channel: ManagedChannel) { | ||
def submitJobs(queue: String, jobSetId: String, jobRequestItems: Seq[JobSubmitRequestItem]): JobSubmitResponse = { | ||
val blockingStub = SubmitGrpc.blockingStub(channel) | ||
blockingStub.submitJobs(JobSubmitRequest(queue, jobSetId, jobRequestItems)) | ||
} | ||
|
||
def getJobStatus(jobId: String): JobStatusResponse = { | ||
val blockingStub = JobsGrpc.blockingStub(channel) | ||
blockingStub.getJobStatus(JobStatusRequest(jobIds = Seq(jobId))) | ||
} | ||
|
||
def eventHealth(): HealthCheckResponse.ServingStatus = { | ||
val blockingStub = EventGrpc.blockingStub(channel) | ||
blockingStub.health(Empty()).status | ||
} | ||
|
||
def submitHealth(): HealthCheckResponse.ServingStatus = { | ||
val blockingStub = SubmitGrpc.blockingStub(channel) | ||
blockingStub.health(Empty()).status | ||
} | ||
|
||
def createQueue(name: String): Unit = { | ||
val blockingStub = SubmitGrpc.blockingStub(channel) | ||
val q = api.submit.Queue().withName(name).withPriorityFactor(1) | ||
blockingStub.createQueue(q) | ||
} | ||
|
||
def deleteQueue(name: String): Unit = { | ||
val qReq = QueueDeleteRequest(name) | ||
val blockingStub = SubmitGrpc.blockingStub(channel) | ||
blockingStub.deleteQueue(qReq) | ||
} | ||
|
||
def getQueue(name: String): Queue = { | ||
val qReq = QueueGetRequest(name) | ||
val blockingStub = SubmitGrpc.blockingStub(channel) | ||
blockingStub.getQueue(qReq) | ||
} | ||
} | ||
|
||
object ArmadaClient { | ||
// TODO: SSL | ||
def apply(channel: ManagedChannel): ArmadaClient = { | ||
new ArmadaClient(channel) | ||
} | ||
|
||
def apply(host: String, port: Int): ArmadaClient = { | ||
val channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext().build | ||
ArmadaClient(channel) | ||
} | ||
} |
Oops, something went wrong.