@Test public void register_error() throws Exception { JsonObject result = new JsonObject(); result.addProperty("status", "error"); JsonHandler handler = new JsonHandler(result); server.register("/jobs", handler); HttpJobClient client = new HttpJobClient(baseUrl); JobScript script = new JobScript(); script.setBatchId("b"); script.setFlowId("f"); script.setPhase(ExecutionPhase.MAIN); script.setStageId("s"); script.setExecutionId("e"); script.setMainClassName("Cls"); script.setProperties(new HashMap<String, String>()); script.setEnvironmentVariables(new HashMap<String, String>()); try { client.register(script); fail(); } catch (IOException e) { LOG.debug("OK.", e); } assertThat(handler.requestElement, is(notNullValue())); }
@Override public JobId register(JobScript script) throws IOException, InterruptedException { if (script == null) { throw new IllegalArgumentException("script must not be null"); } HttpPost request = new HttpPost(); URI uri = createUri("jobs"); request.setURI(uri); request.setEntity(createEntity(script)); if (LOG.isDebugEnabled()) { LOG.debug("Registering a job: method=post, uri={}, script={}", uri, script); } HttpResponse response = http.execute(request); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { JobStatus status = extractJobStatus(request, response); if (status.getKind() == JobStatus.Kind.ERROR) { throw toException(request, response, status, MessageFormat.format( "Failed to register a job ({1}): {0}", script, status.getErrorMessage())); } return new JobId(status.getJobId()); } else { throw toException(request, response, MessageFormat.format( "Failed to register a job: {0}", script)); } }
HttpJobClient implements JobClient { @Override public JobId register(JobScript script) throws IOException, InterruptedException { if (script == null) { throw new IllegalArgumentException("script must not be null"); } HttpPost request = new HttpPost(); URI uri = createUri("jobs"); request.setURI(uri); request.setEntity(createEntity(script)); if (LOG.isDebugEnabled()) { LOG.debug("Registering a job: method=post, uri={}, script={}", uri, script); } HttpResponse response = http.execute(request); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { JobStatus status = extractJobStatus(request, response); if (status.getKind() == JobStatus.Kind.ERROR) { throw toException(request, response, status, MessageFormat.format( "Failed to register a job ({1}): {0}", script, status.getErrorMessage())); } return new JobId(status.getJobId()); } else { throw toException(request, response, MessageFormat.format( "Failed to register a job: {0}", script)); } } }
HttpJobClient implements JobClient { @Override public JobId register(JobScript script) throws IOException, InterruptedException { if (script == null) { throw new IllegalArgumentException("script must not be null"); } HttpPost request = new HttpPost(); URI uri = createUri("jobs"); request.setURI(uri); request.setEntity(createEntity(script)); if (LOG.isDebugEnabled()) { LOG.debug("Registering a job: method=post, uri={}, script={}", uri, script); } HttpResponse response = http.execute(request); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { JobStatus status = extractJobStatus(request, response); if (status.getKind() == JobStatus.Kind.ERROR) { throw toException(request, response, status, MessageFormat.format( "Failed to register a job ({1}): {0}", script, status.getErrorMessage())); } return new JobId(status.getJobId()); } else { throw toException(request, response, MessageFormat.format( "Failed to register a job: {0}", script)); } } HttpJobClient(String baseUri);  HttpJobClient(String baseUri, String user, String password); }
HttpJobClient implements JobClient { @Override public JobId register(JobScript script) throws IOException, InterruptedException { if (script == null) { throw new IllegalArgumentException("script must not be null"); } HttpPost request = new HttpPost(); URI uri = createUri("jobs"); request.setURI(uri); request.setEntity(createEntity(script)); if (LOG.isDebugEnabled()) { LOG.debug("Registering a job: method=post, uri={}, script={}", uri, script); } HttpResponse response = http.execute(request); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { JobStatus status = extractJobStatus(request, response); if (status.getKind() == JobStatus.Kind.ERROR) { throw toException(request, response, status, MessageFormat.format( "Failed to register a job ({1}): {0}", script, status.getErrorMessage())); } return new JobId(status.getJobId()); } else { throw toException(request, response, MessageFormat.format( "Failed to register a job: {0}", script)); } } HttpJobClient(String baseUri);  HttpJobClient(String baseUri, String user, String password); String getBaseUri(); String getUser(); @Override JobId register(JobScript script); @Override JobStatus getStatus(JobId id); @Override void submit(JobId id); @Override String toString(); }
HttpJobClient implements JobClient { @Override public JobId register(JobScript script) throws IOException, InterruptedException { if (script == null) { throw new IllegalArgumentException("script must not be null"); } HttpPost request = new HttpPost(); URI uri = createUri("jobs"); request.setURI(uri); request.setEntity(createEntity(script)); if (LOG.isDebugEnabled()) { LOG.debug("Registering a job: method=post, uri={}, script={}", uri, script); } HttpResponse response = http.execute(request); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { JobStatus status = extractJobStatus(request, response); if (status.getKind() == JobStatus.Kind.ERROR) { throw toException(request, response, status, MessageFormat.format( "Failed to register a job ({1}): {0}", script, status.getErrorMessage())); } return new JobId(status.getJobId()); } else { throw toException(request, response, MessageFormat.format( "Failed to register a job: {0}", script)); } } HttpJobClient(String baseUri);  HttpJobClient(String baseUri, String user, String password); String getBaseUri(); String getUser(); @Override JobId register(JobScript script); @Override JobStatus getStatus(JobId id); @Override void submit(JobId id); @Override String toString();  }