use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class WatchExample method main.
public static void main(String[] args) throws IOException, ApiException {
ApiClient client = Config.defaultClient();
// infinite timeout
OkHttpClient httpClient = client.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build();
client.setHttpClient(httpClient);
Configuration.setDefaultApiClient(client);
CoreV1Api api = new CoreV1Api();
Watch<V1Namespace> watch = Watch.createWatch(client, api.listNamespaceCall(null, null, null, null, null, 5, null, null, null, Boolean.TRUE, null), new TypeToken<Watch.Response<V1Namespace>>() {
}.getType());
try {
for (Watch.Response<V1Namespace> item : watch) {
System.out.printf("%s : %s%n", item.type, item.object.getMetadata().getName());
}
} finally {
watch.close();
}
}
use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class LogsExample method main.
public static void main(String[] args) throws IOException, ApiException, InterruptedException {
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
CoreV1Api coreApi = new CoreV1Api(client);
PodLogs logs = new PodLogs();
V1Pod pod = coreApi.listNamespacedPod("default", "false", null, null, null, null, null, null, null, null, null).getItems().get(0);
InputStream is = logs.streamNamespacedPodLog(pod);
Streams.copy(is, System.out);
}
use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class PagerExample method main.
public static void main(String[] args) throws IOException {
ApiClient client = Config.defaultClient();
OkHttpClient httpClient = client.getHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build();
client.setHttpClient(httpClient);
Configuration.setDefaultApiClient(client);
CoreV1Api api = new CoreV1Api();
int i = 0;
Pager<V1Namespace, V1NamespaceList> pager = new Pager<V1Namespace, V1NamespaceList>((Pager.PagerParams param) -> {
try {
return api.listNamespaceCall(null, null, param.getContinueToken(), null, null, param.getLimit(), null, null, 1, null, null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}, client, 10, V1NamespaceList.class);
for (V1Namespace namespace : pager) {
System.out.println(namespace.getMetadata().getName());
}
System.out.println("------------------");
}
use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class ProtoExample method main.
public static void main(String[] args) throws IOException, ApiException, InterruptedException {
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
ProtoClient pc = new ProtoClient(client);
ObjectOrStatus<PodList> list = pc.list(PodList.newBuilder(), "/api/v1/namespaces/default/pods");
if (list.object.getItemsCount() > 0) {
Pod p = list.object.getItems(0);
System.out.println(p);
}
Namespace namespace = Namespace.newBuilder().setMetadata(ObjectMeta.newBuilder().setName("test").build()).build();
ObjectOrStatus<Namespace> ns = pc.create(namespace, "/api/v1/namespaces", "v1", "Namespace");
System.out.println(ns);
if (ns.object != null) {
namespace = ns.object.toBuilder().setSpec(NamespaceSpec.newBuilder().addFinalizers("test").build()).build();
// This is how you would update an object, but you can't actually
// update namespaces, so this returns a 405
ns = pc.update(namespace, "/api/v1/namespaces/test", "v1", "Namespace");
System.out.println(ns.status);
}
ns = pc.delete(Namespace.newBuilder(), "/api/v1/namespaces/test");
System.out.println(ns);
}
use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class WebSocketsExample method main.
public static void main(String... args) throws ApiException, IOException {
final ApiClient client = Config.defaultClient();
WebSockets.stream(args[0], "GET", client, new WebSockets.SocketListener() {
private volatile WebSocket socket;
@Override
public void open(String protocol, WebSocket socket) {
this.socket = socket;
}
@Override
public void close() {
}
@Override
public void bytesMessage(InputStream is) {
}
@Override
public void failure(Throwable t) {
t.printStackTrace();
}
@Override
public void textMessage(Reader in) {
try {
BufferedReader reader = new BufferedReader(in);
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
System.out.println(line);
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
}
Aggregations