use of io.kubernetes.client.openapi.ApiException in project java by kubernetes-client.
the class PodLogsTest method testNotFound.
@Test
public void testNotFound() throws ApiException, IOException {
V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(podName).namespace(namespace)).spec(new V1PodSpec().containers(Arrays.asList(new V1Container().name(container).image("nginx"))));
wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/log")).willReturn(aResponse().withStatus(404).withHeader("Content-Type", "text/plain").withBody("Not Found")));
PodLogs logs = new PodLogs(client);
boolean thrown = false;
try {
logs.streamNamespacedPodLog(pod);
} catch (ApiException ex) {
assertEquals(404, ex.getCode());
thrown = true;
}
assertEquals(thrown, true);
wireMockRule.verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/log")).withQueryParam("container", equalTo(container)).withQueryParam("follow", equalTo("true")).withQueryParam("pretty", equalTo("false")).withQueryParam("previous", equalTo("false")).withQueryParam("timestamps", equalTo("false")));
}
use of io.kubernetes.client.openapi.ApiException in project java by kubernetes-client.
the class GenericKubernetesApi method executeCall.
private <DataType extends KubernetesType> KubernetesApiResponse<DataType> executeCall(ApiClient apiClient, Class<DataType> dataClass, CallBuilder callBuilder) {
try {
Call call = callBuilder.build();
call = tweakCallForCoreV1Group(call);
JsonElement element = apiClient.<JsonElement>execute(call, JsonElement.class).getData();
return getKubernetesApiResponse(dataClass, element, apiClient.getJSON().getGson());
} catch (ApiException e) {
if (e.getCause() instanceof IOException) {
// make this a checked exception?
throw new IllegalStateException(e.getCause());
}
final V1Status status;
try {
status = apiClient.getJSON().deserialize(e.getResponseBody(), V1Status.class);
} catch (JsonSyntaxException jsonEx) {
// craft a status object
return new KubernetesApiResponse<>(new V1Status().code(e.getCode()).message(e.getResponseBody()), e.getCode());
}
if (null == status) {
// this line should never reach?
throw new RuntimeException(e);
}
return new KubernetesApiResponse<>(status, e.getCode());
}
}
use of io.kubernetes.client.openapi.ApiException in project twister2 by DSC-SPIDAL.
the class WorkerLogger method run.
@Override
public void run() {
Path logfile = createLogFile();
LOG.info("Starting to log for " + id + " to: " + logFileName);
try {
logStream = streamContainerLog();
Files.copy(logStream, logfile, StandardCopyOption.REPLACE_EXISTING);
if (!stop) {
logStream.close();
response.close();
LOG.info("Logging completed for " + id + " to: " + logFileName);
}
} catch (ApiException e) {
if (!stop) {
LOG.log(Level.SEVERE, "Cannot get the log stream for " + id, e);
}
} catch (IOException e) {
if (!stop) {
LOG.log(Level.SEVERE, "Cannot get the log stream for " + id, e);
}
}
jobLogger.workerLoggerCompleted(id);
}
use of io.kubernetes.client.openapi.ApiException in project twister2 by DSC-SPIDAL.
the class KubernetesController method getUploaderWebServerPods.
public List<String> getUploaderWebServerPods(String uploaderLabel) {
V1PodList podList = null;
try {
podList = coreApi.listNamespacedPod(namespace, null, null, null, null, uploaderLabel, null, null, null, null);
} catch (ApiException e) {
LOG.log(Level.SEVERE, "Exception when getting uploader pod list.", e);
throw new RuntimeException(e);
}
List<String> podNames = podList.getItems().stream().map(v1pod -> v1pod.getMetadata().getName()).collect(Collectors.toList());
return podNames;
}
use of io.kubernetes.client.openapi.ApiException in project twister2 by DSC-SPIDAL.
the class PodWatchUtils method getNodeIP.
/**
* get the IP of the node where the pod with that name is running
*/
public static String getNodeIP(String namespace, String jobID, String podIP) {
if (apiClient == null || coreApi == null) {
createApiInstances();
}
// this is better but it does not work with another installation
// String podNameLabel = "statefulset.kubernetes.io/pod-name=" + podName;
String workerRoleLabel = KubernetesUtils.workerPodLabelSelector(jobID);
V1PodList podList = null;
try {
podList = coreApi.listNamespacedPod(namespace, null, null, null, null, workerRoleLabel, null, null, null, null);
} catch (ApiException e) {
LOG.log(Level.SEVERE, "Exception when getting PodList.", e);
throw new RuntimeException(e);
}
for (V1Pod pod : podList.getItems()) {
if (podIP.equals(pod.getStatus().getPodIP())) {
return pod.getStatus().getHostIP();
}
}
return null;
}
Aggregations