use of org.eclipse.jkube.kit.build.service.docker.watch.WatchException in project jkube by eclipse.
the class PodExecutorTest method executeCommandInPodKubernetesError.
@Test
public void executeCommandInPodKubernetesError() {
// Given
// @formatter:off
new Expectations() {
{
kubernetesClient.pods().inNamespace(anyString).withName(anyString);
result = new KubernetesClientException("Mocked Error");
}
};
// @formatter:on
// When
final WatchException result = assertThrows(WatchException.class, () -> podExecutor.executeCommandInPod(Collections.emptySet(), "sh"));
// Then
assertThat(result).hasMessage("Execution failed due to a KubernetesClient error: Mocked Error");
}
use of org.eclipse.jkube.kit.build.service.docker.watch.WatchException in project jkube by eclipse.
the class PodExecutor method executeCommandInPod.
void executeCommandInPod(Collection<HasMetadata> resources, String command) throws IOException, InterruptedException, WatchException {
try (KubernetesClient client = clusterAccess.createDefaultClient();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ByteArrayOutputStream error = new ByteArrayOutputStream()) {
String namespace = clusterAccess.getNamespace();
final ExecListenerLatch latch = new ExecListenerLatch(onOpen);
ExecWatch execWatch = client.pods().inNamespace(namespace).withName(KubernetesHelper.getNewestApplicationPodName(client, namespace, resources)).readingInput(readingInput).writingOutput(outputStream).writingError(outputStream).writingErrorChannel(error).usingListener(latch).exec("sh", "-c", command);
final boolean completed = latch.await(waitTimeout.toMillis(), TimeUnit.MILLISECONDS);
execWatch.close();
output = outputStream.toString();
if (!completed) {
throw new WatchException("Command execution timed out");
}
if (latch.getCloseCode() != 1000) {
throw new WatchException("Command execution socket closed unexpectedly " + latch.getCloseReason());
}
final Map<String, Object> status = objectMapper.readValue(error.toString(), Map.class);
if (status.getOrDefault("status", "Failure").equals("Failure")) {
throw new WatchException("Command execution failed: " + status.getOrDefault("message", ""));
}
} catch (KubernetesClientException e) {
throw new WatchException("Execution failed due to a KubernetesClient error: " + e.getMessage(), e);
}
}
use of org.eclipse.jkube.kit.build.service.docker.watch.WatchException in project jkube by eclipse.
the class PodExecutorTest method executeCommandInPodTimeout.
@Test
public void executeCommandInPodTimeout() {
// When
final WatchException result = assertThrows(WatchException.class, () -> podExecutor.executeCommandInPod(Collections.emptySet(), "sh"));
// Then
assertThat(result).hasMessage("Command execution timed out");
}
use of org.eclipse.jkube.kit.build.service.docker.watch.WatchException in project jkube by eclipse.
the class PodExecutorTest method executeCommandInPodSocketError.
@Test
public void executeCommandInPodSocketError() {
// Given
listenableCloseWithCode(1337);
// When
final WatchException result = assertThrows(WatchException.class, () -> podExecutor.executeCommandInPod(Collections.emptySet(), "sh"));
// Then
assertThat(result).hasMessage("Command execution socket closed unexpectedly Closed by mock");
}
use of org.eclipse.jkube.kit.build.service.docker.watch.WatchException in project jkube by eclipse.
the class PodExecutorTest method executeCommandInPodCommandFailure.
@Test
public void executeCommandInPodCommandFailure() {
// Given
listenableCloseWithCode(1000);
withErrorChannelResponse("{\"message\": \"Deserialized JSON message\"}");
// When
final WatchException result = assertThrows(WatchException.class, () -> podExecutor.executeCommandInPod(Collections.emptySet(), "sh"));
// Then
assertThat(result).hasMessage("Command execution failed: Deserialized JSON message");
}
Aggregations