protected void assertJobEquals(final Job expected, final Job actual) { final Builder expectedBuilder = expected.toBuilder(); // hack to make sure that any environment variables that were folded into the created job // because of environment variables set at runtime on the test-running-agent are removed // from the actual when we assert the equality below final Builder actualBuilder = actual.toBuilder(); final Map<String, String> metadata = Maps.newHashMap(actual.getMetadata()); for (final Map.Entry<String, String> entry : DEFAULT_METADATA_ENVVARS.entrySet()) { final String envVar = entry.getKey(); final String metadataKey = entry.getValue(); final String envValue = System.getenv(envVar); if (envValue != null && actual.getMetadata().containsKey(metadataKey) && actual.getMetadata().get(metadataKey).equals(envValue)) { metadata.remove(metadataKey); } } actualBuilder.setMetadata(metadata); // Remove created timestamp set by master actualBuilder.setCreated(null); // copy the hash expectedBuilder.setHash(actualBuilder.build().getId().getHash()); assertEquals(expectedBuilder.build(), actualBuilder.build()); }
/** * Validate the Job's JobId by checking name, version, and hash are * not null or empty, don't contain invalid characters. * * @param job The Job to check. * * @return A set of error Strings */ private Set<String> validateJobId(final Job job) { final Set<String> errors = Sets.newHashSet(); final JobId jobId = job.getId(); if (jobId == null) { errors.add("Job id was not specified."); return errors; } final String jobIdVersion = jobId.getVersion(); final String jobIdHash = jobId.getHash(); final JobId recomputedId = job.toBuilder().build().getId(); errors.addAll(validateJobName(jobId, recomputedId)); errors.addAll(validateJobVersion(jobIdVersion, recomputedId)); if (this.shouldValidateJobHash) { errors.addAll(validateJobHash(jobIdHash, recomputedId)); } return errors; }
public CreateJobResponse post(@Valid final Job job, @RequestUser final String username) { final Job.Builder clone = job.toBuilder() .setCreatingUser(username) .setCreated(clock.now().getMillis())
final Job.Builder actualJobBuilder = actualJob.toBuilder(); builder.setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX) .setEnv(ImmutableMap.of(redundantEnvKey, "FOOD"));
final Job.Builder actualJobBuilder = actualJob.toBuilder(); builder.setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX); assertJobEquals(builder.build(), actualJobBuilder.build());
final String config = new String(bytes, UTF_8); final Job job = Json.read(config, Job.class); builder = job.toBuilder(); } else if (templateJobId != null) { final Map<JobId, Job> jobs = client.jobs(templateJobId).get(); builder = template.toBuilder(); if (id == null) { throw new IllegalArgumentException("Please specify new job name and version");
final Job expectedCloned = expected.toBuilder() .setVersion(expected.getId().getVersion() + "-cloned") .build();
@RequestUser final String username) { final Collection<String> errors = JOB_VALIDATOR.validate(job); final Job actualJob = job.toBuilder() .setCreatingUser(username)
final String config = new String(bytes, UTF_8); final Job job = Json.read(config, Job.class); builder = job.toBuilder(); } else if (templateJobId != null) { final Map<JobId, Job> jobs = client.jobs(templateJobId).get(); builder = template.toBuilder(); if (id == null) { throw new IllegalArgumentException("Please specify new job name and version");