/** Finds the id for the running job of the given name. */ private String getJobIdFromName(String jobName) { try { ListJobsResponse listResult; String token = null; do { listResult = dataflowClient.listJobs(token); token = listResult.getNextPageToken(); for (Job job : listResult.getJobs()) { if (job.getName().equals(jobName) && MonitoringUtil.toState(job.getCurrentState()).equals(State.RUNNING)) { return job.getId(); } } } while (token != null); } catch (GoogleJsonResponseException e) { throw new RuntimeException( "Got error while looking up jobs: " + (e.getDetails() != null ? e.getDetails().getMessage() : e), e); } catch (IOException e) { throw new RuntimeException("Got error while looking up jobs: ", e); } throw new IllegalArgumentException("Could not find running job named " + jobName); }