Search in sources :

Example 1 with Pair

use of io.kubernetes.client.openapi.Pair in project java by kubernetes-client.

the class ProtoClient method request.

/**
 * Generic protocol buffer based HTTP request. Not intended for general consumption, but public
 * for advance use cases.
 *
 * @param builder The appropriate Builder for the object received from the request.
 * @param method The HTTP method (e.g. GET) for this request.
 * @param path The URL path to call (e.g. /api/v1/namespaces/default/pods/pod-name)
 * @param body The body to send with the request (optional)
 * @param apiVersion The 'apiVersion' to use when encoding, required if body is non-null, ignored
 *     otherwise.
 * @param kind The 'kind' field to use when encoding, required if body is non-null, ignored
 *     otherwise.
 * @return An ObjectOrStatus which contains the Object requested, or a Status about the request.
 */
public <T extends Message> ObjectOrStatus<T> request(T.Builder builder, String path, String method, T body, String apiVersion, String kind) throws ApiException, IOException {
    HashMap<String, String> headers = new HashMap<>();
    headers.put("Content-Type", MEDIA_TYPE);
    headers.put("Accept", MEDIA_TYPE);
    String[] localVarAuthNames = new String[] { "BearerToken" };
    Request request = apiClient.buildRequest(path, method, new ArrayList<Pair>(), new ArrayList<Pair>(), null, headers, new HashMap<String, String>(), new HashMap<String, Object>(), localVarAuthNames, null);
    if (body != null) {
        byte[] bytes = encode(body, apiVersion, kind);
        switch(method) {
            case "POST":
                request = request.newBuilder().post(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
                break;
            case "PUT":
                request = request.newBuilder().put(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
                break;
            case "PATCH":
                request = request.newBuilder().patch(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
                break;
            default:
                throw new ApiException("Unknown proto client API method: " + method);
        }
    }
    return getObjectOrStatusFromServer(builder, request);
}
Also used : HashMap(java.util.HashMap) Request(okhttp3.Request) Pair(io.kubernetes.client.openapi.Pair) ApiException(io.kubernetes.client.openapi.ApiException)

Example 2 with Pair

use of io.kubernetes.client.openapi.Pair in project java by kubernetes-client.

the class PortForward method forward.

/**
 * PortForward to a container.
 *
 * @param namespace The namespace of the Pod
 * @param name The name of the Pod
 * @param ports The ports to forward
 * @return The result of the Port Forward request.
 */
public PortForwardResult forward(String namespace, String name, List<Integer> ports) throws ApiException, IOException {
    String path = makePath(namespace, name);
    WebSocketStreamHandler handler = new WebSocketStreamHandler();
    PortForwardResult result = new PortForwardResult(handler, ports);
    List<Pair> queryParams = new ArrayList<>(ports.size());
    for (Integer port : ports) {
        queryParams.add(new Pair("ports", port.toString()));
    }
    WebSockets.stream(path, "GET", queryParams, apiClient, handler);
    try {
        handler.waitForInitialized();
    } catch (InterruptedException ex) {
        throw new ApiException(ex);
    }
    Throwable err = handler.getError();
    if (err != null) {
        throw new ApiException(err);
    }
    // Wait for streams to start.
    result.init();
    return result;
}
Also used : WebSocketStreamHandler(io.kubernetes.client.util.WebSocketStreamHandler) ArrayList(java.util.ArrayList) Pair(io.kubernetes.client.openapi.Pair) ApiException(io.kubernetes.client.openapi.ApiException)

Example 3 with Pair

use of io.kubernetes.client.openapi.Pair in project java by kubernetes-client.

the class ProtoClient method delete.

/**
 * Delete a kubernetes API object using protocol buffer encoding.
 *
 * @param builder The builder for the response
 * @param path The path to call in the API server
 * @param deleteOptions optional deleteOptions
 * @return The response status
 */
public <T extends Message> ObjectOrStatus<T> delete(T.Builder builder, String path, DeleteOptions deleteOptions) throws ApiException, IOException {
    if (deleteOptions == null) {
        return delete(builder, path);
    }
    HashMap<String, String> headers = new HashMap<>();
    headers.put("Content-Type", MEDIA_TYPE);
    headers.put("Accept", MEDIA_TYPE);
    String[] localVarAuthNames = new String[] { "BearerToken" };
    Request request = apiClient.buildRequest(path, "DELETE", new ArrayList<Pair>(), new ArrayList<Pair>(), null, headers, new HashMap<String, String>(), new HashMap<String, Object>(), localVarAuthNames, null);
    byte[] bytes = encode(deleteOptions, "v1", "DeleteOptions");
    request = request.newBuilder().delete(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
    return getObjectOrStatusFromServer(builder, request);
}
Also used : HashMap(java.util.HashMap) Request(okhttp3.Request) Pair(io.kubernetes.client.openapi.Pair)

Example 4 with Pair

use of io.kubernetes.client.openapi.Pair in project java by kubernetes-client.

the class WebSockets method stream.

public static void stream(String path, String method, List<Pair> queryParams, ApiClient client, SocketListener listener) throws ApiException, IOException {
    HashMap<String, String> headers = new HashMap<String, String>();
    headers.put(STREAM_PROTOCOL_HEADER, V4_STREAM_PROTOCOL);
    headers.put(WebSockets.CONNECTION, WebSockets.UPGRADE);
    headers.put(WebSockets.UPGRADE, SPDY_3_1);
    String[] localVarAuthNames = new String[] { "BearerToken" };
    Request request = client.buildRequest(path, method, queryParams, new ArrayList<Pair>(), null, headers, new HashMap<String, String>(), new HashMap<String, Object>(), localVarAuthNames, null);
    streamRequest(request, client, listener);
}
Also used : HashMap(java.util.HashMap) Request(okhttp3.Request) ByteString(okio.ByteString) Pair(io.kubernetes.client.openapi.Pair)

Aggregations

Pair (io.kubernetes.client.openapi.Pair)4 HashMap (java.util.HashMap)3 Request (okhttp3.Request)3 ApiException (io.kubernetes.client.openapi.ApiException)2 WebSocketStreamHandler (io.kubernetes.client.util.WebSocketStreamHandler)1 ArrayList (java.util.ArrayList)1 ByteString (okio.ByteString)1