Skip to content

Commit

Permalink
Add container attributes as possible extension point of Titus Agent L…
Browse files Browse the repository at this point in the history
…auncher

Titus allows certain special key value pairs to be added as container level attributes. This wasn't exposed and some of them are needed.

Examples of these are the ability to have bursty network or cpu that exceed the defined resource limits for limited period of time.
  • Loading branch information
tgianos committed Feb 23, 2021
1 parent 4cf8d28 commit 33a9369
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
5 changes: 5 additions & 0 deletions genie-docs/src/docs/asciidoc/_properties.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-featu
|default
|yes

|genie.agent.launcher.titus.container-attributes
|Map attributes to send to Titus specific to the container
|empty
|yes

|genie.agent.launcher.titus.enabled
|Whether the Titus agent launcher is active or not
|false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,19 @@ private TitusBatchJobRequest createJobRequest(final ResolvedJob resolvedJob) {
)
),
entryPoint,
// Environment Variables
this.binder
.bind(
TitusAgentLauncherProperties.ADDITIONAL_ENVIRONMENT_PROPERTY,
Bindable.mapOf(String.class, String.class)
)
.orElse(new HashMap<>()),
// Container Attributes
this.binder
.bind(
TitusAgentLauncherProperties.CONTAINER_ATTRIBUTES_PROPERTY,
Bindable.mapOf(String.class, String.class)
)
.orElse(new HashMap<>())
),
new TitusBatchJobRequest.Batch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public static class Container {
private final Image image;
private final List<String> entryPoint;
private final Map<String, String> env;
private final Map<String, String> attributes;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public class TitusAgentLauncherProperties {
*/
public static final String CAPACITY_GROUP_PROPERTY = PREFIX + ".capacityGroup";

/**
* Any attributes that should be added to the request specifically for the container.
*/
public static final String CONTAINER_ATTRIBUTES_PROPERTY = PREFIX + ".container-attributes";

/**
* Name of the property that enables {@link TitusAgentLauncherImpl}.
*/
Expand Down Expand Up @@ -328,4 +333,10 @@ public class TitusAgentLauncherProperties {
*/
@NotNull
private DataSize minimumMemory = DataSize.ofGigabytes(4);

/**
* A map of container attributes.
*/
@NotNull
private Map<String, String> containerAttributes = new HashMap<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class TitusAgentLauncherImplSpec extends Specification {
"--server-port", launcherProperties.getGenieServerPort().toString()
]
requestCapture.getContainer().getEnv() == launcherProperties.getAdditionalEnvironment()
requestCapture.getContainer().getAttributes() == this.launcherProperties.getContainerAttributes()
requestCapture.getBatch().getSize() == 1
requestCapture.getBatch().getRetryPolicy().getImmediate().getRetries() == launcherProperties.getRetries()
requestCapture.getBatch().getRuntimeLimitSec() == launcherProperties.getRuntimeLimit().getSeconds()
Expand Down Expand Up @@ -539,4 +540,51 @@ class TitusAgentLauncherImplSpec extends Specification {
requestCapture.getContainer().getEnv().get(prop1Key) == prop1Value
requestCapture.getContainer().getEnv().get(prop2Key) == prop2Value
}

def "Check container attributes resolution"() {
TitusBatchJobResponse response = toTitusResponse("{ \"id\" : \"" + TITUS_JOB_ID + "\" }")
TitusBatchJobRequest requestCapture

when:
Optional<JsonNode> launcherExt = this.launcher.launchAgent(this.resolvedJob, null)

then:
1 * this.restTemplate.postForObject(TITUS_ENDPOINT, _ as TitusBatchJobRequest, TitusBatchJobResponse.class) >> {
args ->
requestCapture = args[1] as TitusBatchJobRequest
return response
}
1 * this.cache.put(JOB_ID, TITUS_JOB_ID)
launcherExt.isPresent()
requestCapture != null
requestCapture.getContainer().getAttributes().isEmpty()

when:
def prop1Key = "${UUID.randomUUID()}.${UUID.randomUUID()}.${UUID.randomUUID()}".toString()
def prop1Value = UUID.randomUUID().toString()
def prop2Key = "${UUID.randomUUID()}-${UUID.randomUUID()}".toString()
def prop2Value = UUID.randomUUID().toString()
this.environment.withProperty(
"${TitusAgentLauncherProperties.CONTAINER_ATTRIBUTES_PROPERTY}.${prop1Key}",
prop1Value
)
this.environment.withProperty(
"${TitusAgentLauncherProperties.CONTAINER_ATTRIBUTES_PROPERTY}.${prop2Key}",
prop2Value
)
launcherExt = this.launcher.launchAgent(this.resolvedJob, null)

then:
1 * this.restTemplate.postForObject(TITUS_ENDPOINT, _ as TitusBatchJobRequest, TitusBatchJobResponse.class) >> {
args ->
requestCapture = args[1] as TitusBatchJobRequest
return response
}
1 * this.cache.put(JOB_ID, TITUS_JOB_ID)
launcherExt.isPresent()
requestCapture != null
requestCapture.getContainer().getAttributes().size() == 2
requestCapture.getContainer().getAttributes().get(prop1Key) == prop1Value
requestCapture.getContainer().getAttributes().get(prop2Key) == prop2Value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class TitusAgentLauncherPropertiesSpec extends Specification {
p.getMinimumDiskSize().toGigabytes() == 10
p.getMinimumMemory().toGigabytes() == 4
p.getMinimumGPU() == 0
p.getContainerAttributes() == [:]

when:
p.setEnabled(true)
Expand Down Expand Up @@ -103,6 +104,7 @@ class TitusAgentLauncherPropertiesSpec extends Specification {
p.setMinimumDiskSize(DataSize.ofGigabytes(20))
p.setMinimumMemory(DataSize.ofGigabytes(8))
p.setMinimumGPU(1)
p.setContainerAttributes(["hi": "bye"])

then:
p.isEnabled()
Expand Down Expand Up @@ -142,5 +144,6 @@ class TitusAgentLauncherPropertiesSpec extends Specification {
p.getMinimumDiskSize().toGigabytes() == 20
p.getMinimumMemory().toGigabytes() == 8
p.getMinimumGPU() == 1
p.getContainerAttributes() == ["hi": "bye"]
}
}

0 comments on commit 33a9369

Please sign in to comment.