Skip to content

Commit

Permalink
addressing some code smells
Browse files Browse the repository at this point in the history
moving the rest call down to operation support
  • Loading branch information
shawkins committed Sep 23, 2021
1 parent 23d5b9d commit 829d647
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@

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;
import io.fabric8.kubernetes.api.model.APIGroup;
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;

Expand Down Expand Up @@ -139,11 +137,7 @@ public <C> C adapt(Class<C> 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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -194,32 +193,6 @@ public T getMandatory() {
}
}

public RootPaths getRootPaths() {
return restCall(RootPaths.class);
}

public <Res> Res restCall(Class<Res> 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<T> function) {
throw new KubernetesClientException(READ_ONLY_EDIT_EXCEPTION_MESSAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -721,4 +722,27 @@ private MediaType getMediaTypeFromPatchContextOrDefault(PatchContext patchContex
}
return STRATEGIC_MERGE_JSON_PATCH;
}

public <R1> R1 restCall(Class<R1> 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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 829d647

Please sign in to comment.