From d7570974982c6df0189926f1eac63210db467125 Mon Sep 17 00:00:00 2001 From: Shivkumar13 Date: Tue, 25 Aug 2020 00:13:34 +0530 Subject: [PATCH] Refactoring multi-catch blocks, and the InterruptedExceptions, ExecutionException, IOException in the BaseOperation.java --- .../client/dsl/base/BaseOperation.java | 63 +++++++++++++------ 1 file changed, 43 insertions(+), 20 deletions(-) mode change 100644 => 100755 kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java old mode 100644 new mode 100755 index e860e0b0f4..7cac6889ba --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java @@ -170,10 +170,15 @@ private L listRequestHelper(URL url) { L answer = handleResponse(requestBuilder, listType); updateApiVersion(answer); return answer; - } catch (InterruptedException | ExecutionException | IOException e) { + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + throw KubernetesClientException.launderThrowable(forOperationType("list"), ie); + } catch (ExecutionException | IOException e) { throw KubernetesClientException.launderThrowable(forOperationType("list"), e); } - } + + + } protected URL fetchListUrl(URL url, ListOptions listOptions) throws MalformedURLException { return new URL(HttpClientUtils.appendListOptionParams(HttpUrl.get(url.toString()).newBuilder(), listOptions).toString()); @@ -235,19 +240,13 @@ public T getMandatory() { try { URL requestUrl = getCompleteResourceUrl(); return handleGet(requestUrl); - } catch (KubernetesClientException e) { - throw KubernetesClientException.launderThrowable(forOperationType("get"), e); - //if (e.getCode() != HttpURLConnection.HTTP_NOT_FOUND) { - // throw e; - //} else { - // String resourceType = type != null ? type.getSimpleName() : "Resource"; - // String msg = resourceType + " with name: [" + getName() + "] not found in namespace: [" + (Utils.isNotNullOrEmpty(getNamespace()) ? getName() : getConfig().getNamespace()) + "]"; - // throw new KubernetesClientException(msg, HttpURLConnection.HTTP_NOT_FOUND, new StatusBuilder().withCode(HttpURLConnection.HTTP_NOT_FOUND).withMessage(msg).build()); - // } - } catch (InterruptedException | ExecutionException | IOException e) { + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + throw KubernetesClientException.launderThrowable(forOperationType("get"), ie); + } catch (ExecutionException | IOException e) { throw KubernetesClientException.launderThrowable(forOperationType("get"), e); } - } + } public RootPaths getRootPaths() { try { @@ -259,10 +258,13 @@ public RootPaths getRootPaths() { throw e; } return null; - } catch (InterruptedException | ExecutionException | IOException e) { + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + throw KubernetesClientException.launderThrowable(ie); + } catch (ExecutionException | IOException e) { throw KubernetesClientException.launderThrowable(e); } - } + } @Override public D edit() throws KubernetesClientException { @@ -344,9 +346,13 @@ public T create(T... resources) throws KubernetesClientException { } else { return handleCreate(getItem()); } - } catch (InterruptedException | ExecutionException | IOException e) { + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + throw KubernetesClientException.launderThrowable(forOperationType("create"), ie); + } catch (ExecutionException | IOException e) { throw KubernetesClientException.launderThrowable(forOperationType("create"), e); } + } @Override @@ -357,9 +363,13 @@ public T create(T resource) { } else { throw new IllegalArgumentException("Nothing to create."); } - } catch (InterruptedException | ExecutionException | IOException e) { + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + throw KubernetesClientException.launderThrowable(forOperationType("create"), ie); + } catch (ExecutionException | IOException e) { throw KubernetesClientException.launderThrowable(forOperationType("create"), e); } + } @Override @@ -744,9 +754,13 @@ public Boolean delete(List items) { public T updateStatus(T item) { try { return handleStatusUpdate(item, getType()); - } catch (InterruptedException | ExecutionException | IOException e) { + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + throw KubernetesClientException.launderThrowable(forOperationType("statusUpdate"), ie); + } catch (ExecutionException | IOException e) { throw KubernetesClientException.launderThrowable(forOperationType("statusUpdate"), e); } + } public BaseOperation withItem(T item) { @@ -896,17 +910,25 @@ protected T sendPatchedObject(T oldObject, T updatedObject) { protected Scale handleScale(Scale scaleParam) { try { return handleScale(getCompleteResourceUrl().toString(), scaleParam); - } catch (InterruptedException | ExecutionException | IOException e) { + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + throw KubernetesClientException.launderThrowable(forOperationType("scale"), ie); + } catch (ExecutionException | IOException e) { throw KubernetesClientException.launderThrowable(forOperationType("scale"), e); } + } protected Status handleDeploymentRollback(DeploymentRollback deploymentRollback) { try { return handleDeploymentRollback(getCompleteResourceUrl().toString(), deploymentRollback); - } catch (InterruptedException | ExecutionException | IOException e) { + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + throw KubernetesClientException.launderThrowable(forOperationType("rollback"), ie); + } catch (ExecutionException | IOException e) { throw KubernetesClientException.launderThrowable(forOperationType("rollback"), e); } + } protected T handleGet(URL resourceUrl) throws InterruptedException, ExecutionException, IOException { @@ -1167,3 +1189,4 @@ public void setNamespace(String namespace) { this.namespace = namespace; } } +