Skip to content

Commit

Permalink
Merge branch 'master' into improve_allocatable_resource
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesMurkin authored Feb 10, 2025
2 parents 77c47ba + eb1324c commit fc707b8
Show file tree
Hide file tree
Showing 37 changed files with 959 additions and 356 deletions.
25 changes: 25 additions & 0 deletions build/scala-client/Dockerfile
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" ]
36 changes: 36 additions & 0 deletions client/scala/examples/.gitignore
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/
11 changes: 11 additions & 0 deletions client/scala/examples/README.md
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
```
26 changes: 26 additions & 0 deletions client/scala/examples/build.sbt
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
1 change: 1 addition & 0 deletions client/scala/examples/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.10.7
7 changes: 7 additions & 0 deletions client/scala/examples/project/plugins.sbt
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"
)
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)
}
}
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} ")
}
}
}
36 changes: 36 additions & 0 deletions client/scala/scala-armada-client/.gitignore
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/
3 changes: 3 additions & 0 deletions client/scala/scala-armada-client/.scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version = 3.8.3

runner.dialect = scala213
5 changes: 5 additions & 0 deletions client/scala/scala-armada-client/README.md
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/`.
25 changes: 25 additions & 0 deletions client/scala/scala-armada-client/build.sbt
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
)
1 change: 1 addition & 0 deletions client/scala/scala-armada-client/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.10.7
7 changes: 7 additions & 0 deletions client/scala/scala-armada-client/project/plugins.sbt
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"
)
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)
}
}
Loading

0 comments on commit fc707b8

Please sign in to comment.