|
@@ -5,6 +5,7 @@ import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.FileReader;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStreamReader;
|
|
|
import java.net.URI;
|
|
|
import java.net.URISyntaxException;
|
|
|
import java.security.KeyManagementException;
|
|
@@ -28,6 +29,7 @@ import jakarta.annotation.PostConstruct;
|
|
|
import jakarta.enterprise.context.ApplicationScoped;
|
|
|
import jakarta.ws.rs.POST;
|
|
|
import jakarta.ws.rs.Path;
|
|
|
+import jakarta.ws.rs.client.ClientResponseContext;
|
|
|
|
|
|
@ApplicationScoped
|
|
|
@Path("/jobs")
|
|
@@ -129,13 +131,33 @@ public class Activator {
|
|
|
@POST
|
|
|
public String createJob(JobDescription job) {
|
|
|
LOG.info("Sending request: " + this.apiserver.get());
|
|
|
- String response = k8s.createJob(
|
|
|
- "Bearer " + token.get(),
|
|
|
- job.getNamespace(),
|
|
|
- new Job(job.getNamespace(),
|
|
|
- job.getName(),
|
|
|
- job.getCommand()).getApiResource());
|
|
|
- LOG.debug("Received: " + response);
|
|
|
- return response;
|
|
|
+ ClientResponseContext response = k8s.createJob(
|
|
|
+ "Bearer " + token.get(),
|
|
|
+ job.getNamespace(),
|
|
|
+ new Job(job.getNamespace(),
|
|
|
+ job.getName(),
|
|
|
+ job.getCommand()).getApiResource());
|
|
|
+
|
|
|
+ // Log response next. Real status might be in X-Original-Status though.
|
|
|
+ int status = 0;
|
|
|
+ if (response.getHeaders().containsKey("X-Original-Status")) {
|
|
|
+ status = Integer.valueOf(response.getHeaders().get("X-Original-Status").get(0));
|
|
|
+ } else {
|
|
|
+ status = response.getStatus();
|
|
|
+ }
|
|
|
+ LOG.info("Got response: HTTP/" + status);
|
|
|
+ LOG.debug("Response Headers:");
|
|
|
+ response.getHeaders().forEach((k, v) -> {
|
|
|
+ LOG.info(k + ": " + v);
|
|
|
+ });
|
|
|
+
|
|
|
+ // Aggregate the body.
|
|
|
+ StringBuffer body = new StringBuffer();
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntityStream()));
|
|
|
+ br.lines().forEach((l) -> body.append(l));
|
|
|
+
|
|
|
+ LOG.debug("Response Body: " + body.toString());
|
|
|
+
|
|
|
+ return body.toString();
|
|
|
}
|
|
|
}
|