Search in sources :

Example 61 with ApiException

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

the class RetryUtilsTest method testRetryUponConflictShouldFailExceedingMaxRetry.

@Test
public void testRetryUponConflictShouldFailExceedingMaxRetry() throws ApiException {
    AtomicInteger conflictCount = new AtomicInteger(3);
    Object expectedReturn = new Object();
    when(apiInvocation.call()).thenAnswer((stub) -> {
        if (conflictCount.get() > 0) {
            conflictCount.decrementAndGet();
            throw new ApiException(HttpURLConnection.HTTP_CONFLICT, "");
        }
        return expectedReturn;
    });
    assertThrows(ApiException.class, () -> RetryUtils.retryUponConflict(apiInvocation, 3));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ApiException(io.kubernetes.client.openapi.ApiException) Test(org.junit.Test)

Example 62 with ApiException

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

the class PortForwardExample method main.

public static void main(String[] args) throws IOException, ApiException, InterruptedException {
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    PortForward forward = new PortForward();
    List<Integer> ports = new ArrayList<>();
    int localPort = 8080;
    int targetPort = 8080;
    ports.add(targetPort);
    final PortForward.PortForwardResult result = forward.forward("default", "camera-viz-7949dbf7c6-lpxkd", ports);
    System.out.println("Forwarding!");
    ServerSocket ss = new ServerSocket(localPort);
    final Socket s = ss.accept();
    System.out.println("Connected!");
    new Thread(new Runnable() {

        public void run() {
            try {
                Streams.copy(result.getInputStream(targetPort), s.getOutputStream());
            } catch (IOException ex) {
                ex.printStackTrace();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }).start();
    new Thread(new Runnable() {

        public void run() {
            try {
                Streams.copy(s.getInputStream(), result.getOutboundStream(targetPort));
            } catch (IOException ex) {
                ex.printStackTrace();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }).start();
    Thread.sleep(10 * 1000);
    System.exit(0);
}
Also used : ArrayList(java.util.ArrayList) PortForward(io.kubernetes.client.PortForward) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) ApiClient(io.kubernetes.client.openapi.ApiClient) ApiException(io.kubernetes.client.openapi.ApiException) IOException(java.io.IOException) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket)

Example 63 with ApiException

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

the class KubectlCopy method execute.

@Override
public Boolean execute() throws KubectlException {
    validate();
    Copy cp = new Copy(apiClient);
    try {
        if (toPod) {
            cp.copyFileToPod(namespace, name, container, Paths.get(from), Paths.get(to));
        } else {
            if (this.dir) {
                cp.copyDirectoryFromPod(namespace, name, container, from, Paths.get(to));
            } else {
                cp.copyFileFromPod(namespace, name, container, from, Paths.get(to));
            }
        }
        return true;
    } catch (ApiException | IOException | CopyNotSupportedException ex) {
        throw new KubectlException(ex);
    }
}
Also used : Copy(io.kubernetes.client.Copy) IOException(java.io.IOException) KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException) CopyNotSupportedException(io.kubernetes.client.util.exception.CopyNotSupportedException) ApiException(io.kubernetes.client.openapi.ApiException)

Example 64 with ApiException

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

the class KubectlDelete method execute.

@Override
public ApiType execute() throws KubectlException {
    verifyArguments();
    refreshDiscovery();
    if (isNamespaced(apiTypeClass)) {
        try {
            return getGenericApi().delete(namespace, name).throwsApiException().getObject();
        } catch (ApiException e) {
            throw new KubectlException(e);
        }
    } else {
        try {
            return getGenericApi().delete(name).throwsApiException().getObject();
        } catch (ApiException e) {
            throw new KubectlException(e);
        }
    }
}
Also used : KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException) ApiException(io.kubernetes.client.openapi.ApiException)

Example 65 with ApiException

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

the class KubectlPatch method execute.

@Override
public ApiType execute() throws KubectlException {
    refreshDiscovery();
    GenericKubernetesApi genericKubernetesApi = getGenericApi();
    try {
        if (ModelMapper.isNamespaced(apiTypeClass)) {
            return (ApiType) genericKubernetesApi.patch(namespace, name, patchType, patchContent).throwsApiException().getObject();
        } else {
            return (ApiType) genericKubernetesApi.patch(name, patchType, patchContent).throwsApiException().getObject();
        }
    } catch (ApiException e) {
        throw new KubectlException(e);
    }
}
Also used : GenericKubernetesApi(io.kubernetes.client.util.generic.GenericKubernetesApi) KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException) ApiException(io.kubernetes.client.openapi.ApiException)

Aggregations

ApiException (io.kubernetes.client.openapi.ApiException)82 V1Pod (io.kubernetes.client.openapi.models.V1Pod)21 IOException (java.io.IOException)21 V1PodList (io.kubernetes.client.openapi.models.V1PodList)18 Test (org.junit.Test)18 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)17 KubectlException (io.kubernetes.client.extended.kubectl.exception.KubectlException)14 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)13 ApiClient (io.kubernetes.client.openapi.ApiClient)10 AppsV1Api (io.kubernetes.client.openapi.apis.AppsV1Api)10 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)8 V1Deployment (io.kubernetes.client.openapi.models.V1Deployment)8 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)8 V1Status (io.kubernetes.client.openapi.models.V1Status)8 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)8 Watch (io.kubernetes.client.util.Watch)8 List (java.util.List)8 Configuration (io.kubernetes.client.openapi.Configuration)6 HashMap (java.util.HashMap)6 V1Patch (io.kubernetes.client.custom.V1Patch)5