use of com.marcnuri.yakc.api.KubernetesException in project yakc by manusa.
the class WipIT method namespaceWatchBlocksUntilOneIsAdded.
@Test
void namespaceWatchBlocksUntilOneIsAdded() throws KubernetesException {
final AtomicInteger count = new AtomicInteger(0);
final Disposable namespaceWatch = KC.create(CoreV1Api.class).listNamespace().watch().takeUntil(we -> we.getType() == Type.ADDED).subscribe(we -> count.incrementAndGet());
assertThat(namespaceWatch.isDisposed()).isEqualTo(true);
assertThat(count.get()).isEqualTo(1);
}
use of com.marcnuri.yakc.api.KubernetesException in project yakc by manusa.
the class ExecOnSubscribe method subscribe.
@Override
public void subscribe(ObservableEmitter<ExecMessage> emitter) throws Exception {
emitter.setDisposable(this);
final CountDownLatch cdl = new CountDownLatch(1);
final HttpUrl updatedUrl = request.url().newBuilder().addQueryParameter("stdout", "true").addQueryParameter("stderr", "true").build();
final Request updatedRequest = request.newBuilder().url(updatedUrl).build();
webSocket.set(kubernetesClient.getOkHttpClient().newWebSocket(updatedRequest, new WebSocketListener() {
@Override
public void onMessage(WebSocket webSocket, String text) {
emitter.onNext(ExecMessage.builder().standardStream(StandardStream.STDOUT).message(text).build());
}
@Override
public void onMessage(WebSocket webSocket, ByteString bytes) {
emitter.onNext(ExecMessage.builder().standardStream(StandardStream.fromByte(bytes.getByte(0))).message(bytes.substring(1).utf8()).build());
}
@Override
public void onClosing(WebSocket webSocket, int code, String reason) {
dispose();
}
@Override
public void onClosed(WebSocket webSocket, int code, String reason) {
emitter.onComplete();
close();
}
@Override
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
final String message = Optional.ofNullable(response).map(Response::body).map(rb -> {
try {
return rb.string();
} catch (IOException ex) {
return null;
}
}).orElse(t.getMessage());
emitter.onError(new KubernetesException(message, response));
close();
}
private void close() {
disposed.set(true);
cdl.countDown();
}
}));
cdl.await();
}
Aggregations