@Test public void testCreateJobWithNoRolloutOptions() throws Exception { final JobId jobId = JobId.parse("foobar:1"); final Job job = Job.newBuilder() .setName("foobar") .setVersion("1") .setImage("busybox:latest") .setCreatingUser("user1") .setCreated(0L) .build(); final CreateJobResponse jobResponse = resource.post(job, "user1"); assertThat(jobResponse, new CustomTypeSafeMatcher<CreateJobResponse>("CreateJobResponse that is OK") { @Override protected boolean matchesSafely(final CreateJobResponse response) { return response.getStatus() == OK && response.getErrors().isEmpty() && response.getId().contains(jobId.toString()); } } ); verify(model).addJob(job); }
@POST @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public CreateJobResponse post(@Valid final Job job, @RequestUser final String username) { final Job.Builder clone = job.toBuilder() .setCreatingUser(username) .setCreated(clock.now().getMillis()) .setHash(job.getId().getHash()); final Job actualJob = clone.build(); final Collection<String> errors = jobValidator.validate(actualJob); final String jobIdString = actualJob.getId().toString(); if (!errors.isEmpty()) { throw badRequest(new CreateJobResponse(INVALID_JOB_DEFINITION, ImmutableList.copyOf(errors), jobIdString)); } try { model.addJob(actualJob); } catch (JobExistsException e) { throw badRequest(new CreateJobResponse(JOB_ALREADY_EXISTS, ImmutableList.<String>of(), jobIdString)); } log.info("created job: {}", actualJob); return new CreateJobResponse(CreateJobResponse.Status.OK, ImmutableList.<String>of(), jobIdString); }
JobsResource { @POST @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public CreateJobResponse post(@Valid final Job job, @RequestUser final String username) { final Job.Builder clone = job.toBuilder() .setCreatingUser(username) .setCreated(clock.now().getMillis()) .setHash(job.getId().getHash()); final Job actualJob = clone.build(); final Collection<String> errors = jobValidator.validate(actualJob); final String jobIdString = actualJob.getId().toString(); if (!errors.isEmpty()) { throw badRequest(new CreateJobResponse(INVALID_JOB_DEFINITION, ImmutableList.copyOf(errors), jobIdString)); } try { model.addJob(actualJob); } catch (JobExistsException e) { throw badRequest(new CreateJobResponse(JOB_ALREADY_EXISTS, ImmutableList.<String>of(), jobIdString)); } log.info("created job: {}", actualJob); return new CreateJobResponse(CreateJobResponse.Status.OK, ImmutableList.<String>of(), jobIdString); } }
JobsResource { @POST @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public CreateJobResponse post(@Valid final Job job, @RequestUser final String username) { final Job.Builder clone = job.toBuilder() .setCreatingUser(username) .setCreated(clock.now().getMillis()) .setHash(job.getId().getHash()); final Job actualJob = clone.build(); final Collection<String> errors = jobValidator.validate(actualJob); final String jobIdString = actualJob.getId().toString(); if (!errors.isEmpty()) { throw badRequest(new CreateJobResponse(INVALID_JOB_DEFINITION, ImmutableList.copyOf(errors), jobIdString)); } try { model.addJob(actualJob); } catch (JobExistsException e) { throw badRequest(new CreateJobResponse(JOB_ALREADY_EXISTS, ImmutableList.<String>of(), jobIdString)); } log.info("created job: {}", actualJob); return new CreateJobResponse(CreateJobResponse.Status.OK, ImmutableList.<String>of(), jobIdString); } JobsResource(final MasterModel model, final MasterMetrics metrics,
                      final Set<String> whitelistedCapabilities); @VisibleForTesting  JobsResource(final MasterModel model, final MasterMetrics metrics,
               final Set<String> whitelistedCapabilities, final Clock clock); }
JobsResource { @POST @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public CreateJobResponse post(@Valid final Job job, @RequestUser final String username) { final Job.Builder clone = job.toBuilder() .setCreatingUser(username) .setCreated(clock.now().getMillis()) .setHash(job.getId().getHash()); final Job actualJob = clone.build(); final Collection<String> errors = jobValidator.validate(actualJob); final String jobIdString = actualJob.getId().toString(); if (!errors.isEmpty()) { throw badRequest(new CreateJobResponse(INVALID_JOB_DEFINITION, ImmutableList.copyOf(errors), jobIdString)); } try { model.addJob(actualJob); } catch (JobExistsException e) { throw badRequest(new CreateJobResponse(JOB_ALREADY_EXISTS, ImmutableList.<String>of(), jobIdString)); } log.info("created job: {}", actualJob); return new CreateJobResponse(CreateJobResponse.Status.OK, ImmutableList.<String>of(), jobIdString); } JobsResource(final MasterModel model, final MasterMetrics metrics,
                      final Set<String> whitelistedCapabilities); @VisibleForTesting  JobsResource(final MasterModel model, final MasterMetrics metrics,
               final Set<String> whitelistedCapabilities, final Clock clock); @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Map<JobId, Job> list(
      @QueryParam("q") @DefaultValue("") final String query,
      @QueryParam("hostPattern") @DefaultValue("") final String hostPattern); @Path("{id}") @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Optional<Job> get(@InjectParam @PathParam("id") @Valid final JobId id); @POST @Produces(APPLICATION_JSON) @Timed @ExceptionMetered CreateJobResponse post(@Valid final Job job,
                                @RequestUser final String username); @Path("{id}") @DELETE @Produces(APPLICATION_JSON) @Timed @ExceptionMetered JobDeleteResponse delete(@PathParam("id") @Valid final JobId id,
                                  @QueryParam("token") @DefaultValue("") final String token); @Path("{id}/status") @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Optional<JobStatus> statusGet(@PathParam("id") @Valid final JobId id); @Path("/statuses") @POST @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Map<JobId, JobStatus> jobStatuses(@Valid final Set<JobId> ids); }
JobsResource { @POST @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public CreateJobResponse post(@Valid final Job job, @RequestUser final String username) { final Job.Builder clone = job.toBuilder() .setCreatingUser(username) .setCreated(clock.now().getMillis()) .setHash(job.getId().getHash()); final Job actualJob = clone.build(); final Collection<String> errors = jobValidator.validate(actualJob); final String jobIdString = actualJob.getId().toString(); if (!errors.isEmpty()) { throw badRequest(new CreateJobResponse(INVALID_JOB_DEFINITION, ImmutableList.copyOf(errors), jobIdString)); } try { model.addJob(actualJob); } catch (JobExistsException e) { throw badRequest(new CreateJobResponse(JOB_ALREADY_EXISTS, ImmutableList.<String>of(), jobIdString)); } log.info("created job: {}", actualJob); return new CreateJobResponse(CreateJobResponse.Status.OK, ImmutableList.<String>of(), jobIdString); } JobsResource(final MasterModel model, final MasterMetrics metrics,
                      final Set<String> whitelistedCapabilities); @VisibleForTesting  JobsResource(final MasterModel model, final MasterMetrics metrics,
               final Set<String> whitelistedCapabilities, final Clock clock); @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Map<JobId, Job> list(
      @QueryParam("q") @DefaultValue("") final String query,
      @QueryParam("hostPattern") @DefaultValue("") final String hostPattern); @Path("{id}") @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Optional<Job> get(@InjectParam @PathParam("id") @Valid final JobId id); @POST @Produces(APPLICATION_JSON) @Timed @ExceptionMetered CreateJobResponse post(@Valid final Job job,
                                @RequestUser final String username); @Path("{id}") @DELETE @Produces(APPLICATION_JSON) @Timed @ExceptionMetered JobDeleteResponse delete(@PathParam("id") @Valid final JobId id,
                                  @QueryParam("token") @DefaultValue("") final String token); @Path("{id}/status") @GET @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Optional<JobStatus> statusGet(@PathParam("id") @Valid final JobId id); @Path("/statuses") @POST @Produces(APPLICATION_JSON) @Timed @ExceptionMetered Map<JobId, JobStatus> jobStatuses(@Valid final Set<JobId> ids);  }