From 829d647d4529d9d95fdb2daafcd3140a5b1e7d8f Mon Sep 17 00:00:00 2001 From: shawkins Date: Thu, 23 Sep 2021 14:15:12 -0400 Subject: [PATCH] addressing some code smells moving the rest call down to operation support --- .../fabric8/kubernetes/client/BaseClient.java | 16 ++++------- .../client/dsl/base/BaseOperation.java | 27 ------------------- .../client/dsl/base/OperationSupport.java | 24 +++++++++++++++++ .../openshift/client/OpenShiftConfig.java | 9 +++++++ 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BaseClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BaseClient.java index d6a025b02f7..ba4bdbc6bd6 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BaseClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BaseClient.java @@ -16,8 +16,7 @@ package io.fabric8.kubernetes.client; -import io.fabric8.kubernetes.client.dsl.base.OperationContext; - +import io.fabric8.kubernetes.client.dsl.base.OperationSupport; import okhttp3.ConnectionPool; import okhttp3.Dispatcher; import okhttp3.OkHttpClient; @@ -25,7 +24,6 @@ import io.fabric8.kubernetes.api.model.APIGroupList; import io.fabric8.kubernetes.api.model.APIResourceList; import io.fabric8.kubernetes.api.model.RootPaths; -import io.fabric8.kubernetes.client.dsl.base.BaseOperation; import io.fabric8.kubernetes.client.utils.HttpClientUtils; import io.fabric8.kubernetes.client.utils.Utils; @@ -139,11 +137,7 @@ public C adapt(Class type) { @Override public RootPaths rootPaths() { - return newBaseOperation(httpClient, configuration).getRootPaths(); - } - - static BaseOperation newBaseOperation(OkHttpClient httpClient, Config configuration) { - return new BaseOperation(new OperationContext().withOkhttpClient(httpClient).withConfig(configuration)) {}; + return new OperationSupport(httpClient, configuration).restCall(RootPaths.class); } @Override @@ -164,17 +158,17 @@ public boolean supportsApiPath(String apiPath) { @Override public APIGroupList getApiGroups() { - return newBaseOperation(httpClient, configuration).restCall(APIGroupList.class, APIS); + return new OperationSupport(httpClient, configuration).restCall(APIGroupList.class, APIS); } @Override public APIGroup getApiGroup(String name) { - return newBaseOperation(httpClient, configuration).restCall(APIGroup.class, APIS, name); + return new OperationSupport(httpClient, configuration).restCall(APIGroup.class, APIS, name); } @Override public APIResourceList getApiResources(String groupVersion) { - return newBaseOperation(httpClient, configuration).restCall(APIResourceList.class, APIS, groupVersion); + return new OperationSupport(httpClient, configuration).restCall(APIResourceList.class, APIS, groupVersion); } protected OkHttpClient adaptOkHttpClient(OkHttpClient okHttpClient) { 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 index d7bcfa10a02..a816df26551 100755 --- 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 @@ -27,7 +27,6 @@ import io.fabric8.kubernetes.api.model.LabelSelector; import io.fabric8.kubernetes.api.model.ListOptions; import io.fabric8.kubernetes.api.model.ListOptionsBuilder; -import io.fabric8.kubernetes.api.model.RootPaths; import io.fabric8.kubernetes.api.model.Status; import io.fabric8.kubernetes.api.model.autoscaling.v1.Scale; import io.fabric8.kubernetes.api.model.extensions.DeploymentRollback; @@ -194,32 +193,6 @@ public T getMandatory() { } } - public RootPaths getRootPaths() { - return restCall(RootPaths.class); - } - - public Res restCall(Class result, String... path) { - try { - URL requestUrl = new URL(config.getMasterUrl()); - String url = requestUrl.toString(); - if (path != null && path.length > 0) { - url = URLUtils.join(url, URLUtils.pathJoin(path)); - } - Request.Builder req = new Request.Builder().get().url(url); - return handleResponse(req, result); - } catch (KubernetesClientException e) { - if (e.getCode() != HttpURLConnection.HTTP_NOT_FOUND) { - throw e; - } - return null; - } catch (InterruptedException ie) { - Thread.currentThread().interrupt(); - throw KubernetesClientException.launderThrowable(ie); - } catch (ExecutionException | IOException e) { - throw KubernetesClientException.launderThrowable(e); - } - } - @Override public T edit(UnaryOperator function) { throw new KubernetesClientException(READ_ONLY_EDIT_EXCEPTION_MESSAGE); diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/OperationSupport.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/OperationSupport.java index 592bc0e275e..9826788b2fd 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/OperationSupport.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/OperationSupport.java @@ -47,6 +47,7 @@ import java.io.IOException; import java.io.InputStream; +import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.Collections; @@ -721,4 +722,27 @@ private MediaType getMediaTypeFromPatchContextOrDefault(PatchContext patchContex } return STRATEGIC_MERGE_JSON_PATCH; } + + public R1 restCall(Class result, String... path) { + try { + URL requestUrl = new URL(config.getMasterUrl()); + String url = requestUrl.toString(); + if (path != null && path.length > 0) { + url = URLUtils.join(url, URLUtils.pathJoin(path)); + } + Request.Builder req = new Request.Builder().get().url(url); + return handleResponse(req, result); + } catch (KubernetesClientException e) { + if (e.getCode() != HttpURLConnection.HTTP_NOT_FOUND) { + throw e; + } + return null; + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + throw KubernetesClientException.launderThrowable(ie); + } catch (ExecutionException | IOException e) { + throw KubernetesClientException.launderThrowable(e); + } + } + } diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/OpenShiftConfig.java b/openshift-client/src/main/java/io/fabric8/openshift/client/OpenShiftConfig.java index c34da4fdc11..8ab34b96329 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/OpenShiftConfig.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/OpenShiftConfig.java @@ -136,6 +136,9 @@ private static String getDefaultOpenShiftUrl(Config config) { } } + /** + * @deprecated openshiftApiGroupsEnabled is no longer honored + */ @Deprecated public OpenShiftConfig withOpenshiftApiGroupsEnabled(boolean openshiftApiGroupsEnabled) { return new OpenShiftConfigBuilder(this).withOpenshiftApiGroupsEnabled(openshiftApiGroupsEnabled).build(); @@ -185,11 +188,17 @@ public void setDisableApiGroupCheck(boolean disableApiGroupCheck) { this.disableApiGroupCheck = disableApiGroupCheck; } + /** + * @deprecated openshiftApiGroupsEnabled is no longer honored + */ @Deprecated public boolean isOpenshiftApiGroupsEnabled() { return openshiftApiGroupsEnabled; } + /** + * @deprecated openshiftApiGroupsEnabled is no longer honored + */ @Deprecated public void setOpenshiftApiGroupsEnabled(boolean openshiftApiGroupsEnabled) { this.openshiftApiGroupsEnabled = openshiftApiGroupsEnabled;