Skip to content

Commit

Permalink
Refactoring multi-catch blocks, and the InterruptedExceptions, Execut…
Browse files Browse the repository at this point in the history
…ionException, IOException in the BaseOperation.java
  • Loading branch information
Shivkumar13 authored and rohanKanojia committed Aug 27, 2020
1 parent 935224a commit d757097
Showing 1 changed file with 43 additions and 20 deletions.
63 changes: 43 additions & 20 deletions kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java 100644 → 100755
Expand Up @@ -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());
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -744,9 +754,13 @@ public Boolean delete(List<T> 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<T, L, D, R> withItem(T item) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1167,3 +1189,4 @@ public void setNamespace(String namespace) {
this.namespace = namespace;
}
}

0 comments on commit d757097

Please sign in to comment.