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

Set env var BD_USER #1218

Merged
merged 1 commit into from
Jun 22, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
public class TitusAgentLauncherImpl implements AgentLauncher {

static final int MEGABYTE_TO_MEGABIT = 8;
private static final String BD_USER_ENV_VAR = "BD_USER";
private static final String GENIE_USER_ATTR = "genie.user";
private static final String GENIE_SOURCE_HOST_ATTR = "genie.sourceHost";
private static final String GENIE_ENDPOINT_ATTR = "genie.endpoint";
Expand Down Expand Up @@ -246,6 +247,8 @@ public Health health() {
private TitusBatchJobRequest createJobRequest(final ResolvedJob resolvedJob) throws AgentLaunchException {
final String jobId = resolvedJob.getJobSpecification().getJob().getId();

final String jobUser = resolvedJob.getJobMetadata().getUser();

// Map placeholders in entry point template to their values
final Map<String, String> placeholdersMap = Map.of(
TitusAgentLauncherProperties.JOB_ID_PLACEHOLDER,
Expand All @@ -267,7 +270,7 @@ private TitusBatchJobRequest createJobRequest(final ResolvedJob resolvedJob) thr
);
final Duration runtimeLimit = this.titusAgentLauncherProperties.getRuntimeLimit();

final Map<String, String> jobAttributes = this.createJobAttributes(jobId, resolvedJob);
final Map<String, String> jobAttributes = this.createJobAttributes(jobId, jobUser);

final TitusBatchJobRequest.TitusBatchJobRequestBuilder requestBuilder = TitusBatchJobRequest.builder()
.owner(
Expand Down Expand Up @@ -299,7 +302,7 @@ private TitusBatchJobRequest createJobRequest(final ResolvedJob resolvedJob) thr
.image(this.getTitusImage(resolvedJob))
.entryPoint(entryPoint)
.command(command)
.env(this.createJobEnvironment())
.env(this.createJobEnvironment(jobUser))
.attributes(
this.binder
.bind(
Expand Down Expand Up @@ -408,9 +411,9 @@ private DataSize getDataSizeProperty(final String propertyKey, final DataSize de
}
}

private Map<String, String> createJobAttributes(final String jobId, final ResolvedJob resolvedJob) {
private Map<String, String> createJobAttributes(final String jobId, final String jobUser) {
final Map<String, String> jobAttributes = new HashMap<>();
jobAttributes.put(GENIE_USER_ATTR, resolvedJob.getJobMetadata().getUser());
jobAttributes.put(GENIE_USER_ATTR, jobUser);
jobAttributes.put(GENIE_SOURCE_HOST_ATTR, this.genieHostInfo.getHostname());
jobAttributes.put(GENIE_ENDPOINT_ATTR, this.titusAgentLauncherProperties.getGenieServerHost());
jobAttributes.put(GENIE_JOB_ID_ATTR, jobId);
Expand All @@ -425,7 +428,7 @@ private Map<String, String> createJobAttributes(final String jobId, final Resolv
return jobAttributes;
}

private Map<String, String> createJobEnvironment() {
private Map<String, String> createJobEnvironment(final String jobUser) {
final Map<String, String> jobEnvironment = this.binder
.bind(
TitusAgentLauncherProperties.ADDITIONAL_ENVIRONMENT_PROPERTY,
Expand All @@ -438,6 +441,8 @@ private Map<String, String> createJobEnvironment() {
jobEnvironment.putAll(this.tracePropagator.injectForAgent(currentSpan.context()));
}

jobEnvironment.putIfAbsent(BD_USER_ENV_VAR, jobUser);

return jobEnvironment;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class TitusAgentLauncherImplSpec extends Specification {
this.requestedMemory = 1024L
this.launcherProperties = new TitusAgentLauncherProperties()
this.launcherProperties.setEndpoint(URI.create(TITUS_ENDPOINT_PREFIX))
this.launcherProperties.setAdditionalEnvironment(["BD_USER": USER])

this.job = Mock(JobSpecification.ExecutionResource) {
getId() >> JOB_ID
Expand Down Expand Up @@ -508,7 +509,7 @@ class TitusAgentLauncherImplSpec extends Specification {
1 * this.cache.put(JOB_ID, TITUS_JOB_ID)
launcherExt.isPresent()
requestCapture != null
requestCapture.getContainer().getEnv().isEmpty()
requestCapture.getContainer().getEnv() == ["BD_USER": USER]

when:
def prop1Key = "${UUID.randomUUID()}.${UUID.randomUUID()}.${UUID.randomUUID()}".toString()
Expand All @@ -529,7 +530,7 @@ class TitusAgentLauncherImplSpec extends Specification {
1 * this.cache.put(JOB_ID, TITUS_JOB_ID)
launcherExt.isPresent()
requestCapture != null
requestCapture.getContainer().getEnv().size() == 1
requestCapture.getContainer().getEnv().size() == 2
requestCapture.getContainer().getEnv().get(prop1Key) == prop1Value

when:
Expand All @@ -551,7 +552,7 @@ class TitusAgentLauncherImplSpec extends Specification {
1 * this.cache.put(JOB_ID, TITUS_JOB_ID)
launcherExt.isPresent()
requestCapture != null
requestCapture.getContainer().getEnv().size() == 2
requestCapture.getContainer().getEnv().size() == 3
requestCapture.getContainer().getEnv().get(prop1Key) == prop1Value
requestCapture.getContainer().getEnv().get(prop2Key) == prop2Value
}
Expand Down
Loading