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));
}
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);
}
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);
}
}
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);
}
}
}
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);
}
}
Aggregations