Class OperationSupport
- java.lang.Object
-
- io.fabric8.kubernetes.client.dsl.internal.OperationSupport
-
- Direct Known Subclasses:
CreateOnlyResourceOperation,MetricOperationsImpl
public class OperationSupport extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected StringapiGroupNameprotected StringapiGroupVersionprotected io.fabric8.kubernetes.client.Configconfigprotected OperationContextcontextprotected booleandryRunprotected io.fabric8.kubernetes.client.http.HttpClienthttpClientstatic StringJSONstatic StringJSON_MERGE_PATCHstatic StringJSON_PATCHprotected Stringnameprotected Stringnamespaceprotected StringresourceTstatic StringSTRATEGIC_MERGE_JSON_PATCHprotected Stringsubresource
-
Constructor Summary
Constructors Constructor Description OperationSupport(io.fabric8.kubernetes.client.Client client)OperationSupport(OperationContext ctx)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddNamespacedUrlPathParts(List<String> parts, String namespace, String type)protected voidassertResponseCode(io.fabric8.kubernetes.client.http.HttpRequest request, io.fabric8.kubernetes.client.http.HttpResponse<?> response)Checks if the response status code is the expected and throws the appropriate KubernetesClientException if not.protected <T> StringcheckName(T item)protected <T> StringcheckNamespace(T item)protected <T> TcorrectNamespace(T item)static io.fabric8.kubernetes.api.model.StatuscreateStatus(int statusCode, String message)static io.fabric8.kubernetes.api.model.StatuscreateStatus(io.fabric8.kubernetes.client.http.HttpResponse<?> response, io.fabric8.kubernetes.client.utils.KubernetesSerialization kubernetesSerialization)StringgetAPIGroupName()StringgetAPIGroupVersion()io.fabric8.kubernetes.client.ConfiggetConfig()io.fabric8.kubernetes.client.utils.KubernetesSerializationgetKubernetesSerialization()StringgetName()StringgetNamespace()URLgetNamespacedUrl()URLgetNamespacedUrl(String namespace)protected URLgetNamespacedUrl(String namespace, String type)OperationContextgetOperationContext()io.fabric8.kubernetes.client.RequestConfiggetRequestConfig()StringgetResourceT()URLgetResourceUrl()URLgetResourceUrl(String namespace, String name)URLgetResourceUrl(String namespace, String name, String... subresources)URLgetResourceURLForPatchOperation(URL resourceUrl, io.fabric8.kubernetes.client.dsl.base.PatchContext patchContext)URLgetResourceURLForWriteOperation(URL resourceURL)protected List<String>getRootUrlParts()protected <T,I>
ThandleCreate(I resource, Class<T> outputType)Create a resource.protected io.fabric8.kubernetes.api.model.KubernetesResourcehandleDelete(URL requestUrl, long gracePeriodSeconds, io.fabric8.kubernetes.api.model.DeletionPropagation propagationPolicy, String resourceVersion)protected io.fabric8.kubernetes.api.model.StatushandleDeploymentRollback(String resourceUrl, io.fabric8.kubernetes.api.model.extensions.DeploymentRollback deploymentRollback)Create rollback of a Deploymentprotected <T> ThandleGet(URL resourceUrl, Class<T> type)Send an http get.protected <T> ThandleMetric(String resourceUrl, Class<T> type)protected <T> ThandlePatch(io.fabric8.kubernetes.client.dsl.base.PatchContext patchContext, T current, String patchForUpdate, Class<T> type)Send an http patch and handle the response.protected <T> ThandlePatch(io.fabric8.kubernetes.client.dsl.base.PatchContext patchContext, T current, T updated, Class<T> type)Send an http patch and handle the response.<R1> R1handleRaw(Class<R1> result, String uri, String method, Object payload)Send a raw request - where the type should be one of String, Reader, InputStreamprotected <T> ThandleRawGet(URL resourceUrl, Class<T> type)Send a raw get - where the type should be one of String, Reader, InputStreamprotected <T> CompletableFuture<T>handleResponse(io.fabric8.kubernetes.client.http.HttpClient client, io.fabric8.kubernetes.client.http.HttpRequest.Builder requestBuilder, com.fasterxml.jackson.core.type.TypeReference<T> type)Send an http request and handle the response, optionally performing placeholder substitution to the response.protected <T> ThandleResponse(io.fabric8.kubernetes.client.http.HttpRequest.Builder requestBuilder, Class<T> type)Send an http request and handle the response.protected <T> ThandleScale(String resourceUrl, T scale, Class<T> scaleType)Replace Scale of specified Kubernetes Resourceprotected <T> ThandleUpdate(T updated, Class<T> type)Replace a resource.booleanisResourceNamespaced()static io.fabric8.kubernetes.client.KubernetesClientExceptionrequestException(io.fabric8.kubernetes.client.http.HttpRequest request, Exception e)static io.fabric8.kubernetes.client.KubernetesClientExceptionrequestException(io.fabric8.kubernetes.client.http.HttpRequest request, Throwable e, String message)static io.fabric8.kubernetes.client.KubernetesClientExceptionrequestFailure(io.fabric8.kubernetes.client.http.HttpRequest request, io.fabric8.kubernetes.api.model.Status status)static io.fabric8.kubernetes.client.KubernetesClientExceptionrequestFailure(io.fabric8.kubernetes.client.http.HttpRequest request, io.fabric8.kubernetes.api.model.Status status, String message)<R1> R1restCall(Class<R1> result, String... path)protected <T> TwaitForResult(CompletableFuture<T> future)Waits for the providedCompletableFutureto complete and returns the result in case of success.
-
-
-
Field Detail
-
JSON
public static final String JSON
- See Also:
- Constant Field Values
-
JSON_PATCH
public static final String JSON_PATCH
- See Also:
- Constant Field Values
-
STRATEGIC_MERGE_JSON_PATCH
public static final String STRATEGIC_MERGE_JSON_PATCH
- See Also:
- Constant Field Values
-
JSON_MERGE_PATCH
public static final String JSON_MERGE_PATCH
- See Also:
- Constant Field Values
-
context
protected OperationContext context
-
httpClient
protected final io.fabric8.kubernetes.client.http.HttpClient httpClient
-
config
protected final io.fabric8.kubernetes.client.Config config
-
resourceT
protected final String resourceT
-
namespace
protected String namespace
-
name
protected String name
-
subresource
protected String subresource
-
apiGroupName
protected String apiGroupName
-
apiGroupVersion
protected String apiGroupVersion
-
dryRun
protected boolean dryRun
-
-
Constructor Detail
-
OperationSupport
public OperationSupport(io.fabric8.kubernetes.client.Client client)
-
OperationSupport
public OperationSupport(OperationContext ctx)
-
-
Method Detail
-
getAPIGroupName
public String getAPIGroupName()
-
getAPIGroupVersion
public String getAPIGroupVersion()
-
getResourceT
public String getResourceT()
-
getNamespace
public String getNamespace()
-
getName
public String getName()
-
isResourceNamespaced
public boolean isResourceNamespaced()
-
getNamespacedUrl
protected URL getNamespacedUrl(String namespace, String type) throws MalformedURLException
- Throws:
MalformedURLException
-
getNamespacedUrl
public URL getNamespacedUrl(String namespace) throws MalformedURLException
- Throws:
MalformedURLException
-
addNamespacedUrlPathParts
protected void addNamespacedUrlPathParts(List<String> parts, String namespace, String type)
-
getNamespacedUrl
public URL getNamespacedUrl() throws MalformedURLException
- Throws:
MalformedURLException
-
getResourceUrl
public URL getResourceUrl(String namespace, String name, String... subresources) throws MalformedURLException
- Throws:
MalformedURLException
-
getResourceUrl
public URL getResourceUrl(String namespace, String name) throws MalformedURLException
- Throws:
MalformedURLException
-
getResourceUrl
public URL getResourceUrl() throws MalformedURLException
- Throws:
MalformedURLException
-
getResourceURLForWriteOperation
public URL getResourceURLForWriteOperation(URL resourceURL) throws MalformedURLException
- Throws:
MalformedURLException
-
getResourceURLForPatchOperation
public URL getResourceURLForPatchOperation(URL resourceUrl, io.fabric8.kubernetes.client.dsl.base.PatchContext patchContext) throws MalformedURLException
- Throws:
MalformedURLException
-
correctNamespace
protected <T> T correctNamespace(T item)
-
checkNamespace
protected <T> String checkNamespace(T item)
-
checkName
protected <T> String checkName(T item)
-
handleMetric
protected <T> T handleMetric(String resourceUrl, Class<T> type) throws InterruptedException, IOException
- Throws:
InterruptedExceptionIOException
-
handleDelete
protected io.fabric8.kubernetes.api.model.KubernetesResource handleDelete(URL requestUrl, long gracePeriodSeconds, io.fabric8.kubernetes.api.model.DeletionPropagation propagationPolicy, String resourceVersion) throws InterruptedException, IOException
- Throws:
InterruptedExceptionIOException
-
handleCreate
protected <T,I> T handleCreate(I resource, Class<T> outputType) throws InterruptedException, IOExceptionCreate a resource.- Type Parameters:
T- template argument for output typeI- template argument for resource- Parameters:
resource- resource providedoutputType- resource type you want as output- Returns:
- returns de-serialized version of apiserver response in form of type provided
- Throws:
InterruptedException- Interrupted ExceptionIOException- IOException
-
handleUpdate
protected <T> T handleUpdate(T updated, Class<T> type) throws IOExceptionReplace a resource.- Type Parameters:
T- template argument provided- Parameters:
updated- updated objecttype- type of the object provided- Returns:
- returns de-serialized version of api server response
- Throws:
IOException- IOException
-
handlePatch
protected <T> T handlePatch(io.fabric8.kubernetes.client.dsl.base.PatchContext patchContext, T current, T updated, Class<T> type) throws InterruptedException, IOExceptionSend an http patch and handle the response. If current is not null and patchContext does not specify a patch type, then a JSON patch is assumed. Otherwise a STRATEGIC MERGE is assumed.- Type Parameters:
T- template argument provided- Parameters:
patchContext- patch options for patch requestcurrent- current objectupdated- updated objecttype- type of object- Returns:
- returns de-serialized version of api server response
- Throws:
InterruptedException- Interrupted ExceptionIOException- IOException
-
handlePatch
protected <T> T handlePatch(io.fabric8.kubernetes.client.dsl.base.PatchContext patchContext, T current, String patchForUpdate, Class<T> type) throws InterruptedException, IOExceptionSend an http patch and handle the response.- Type Parameters:
T- template argument provided- Parameters:
patchContext- patch options for patch requestcurrent- current objectpatchForUpdate- Patch stringtype- type of object- Returns:
- returns de-serialized version of api server response
- Throws:
InterruptedException- Interrupted ExceptionIOException- IOException in case of network errors
-
handleScale
protected <T> T handleScale(String resourceUrl, T scale, Class<T> scaleType) throws InterruptedException, IOException
Replace Scale of specified Kubernetes Resource- Parameters:
resourceUrl- Kubernetes resource URLscale- Scale object which we want to inject- Returns:
- updated Scale object
- Throws:
InterruptedException- in case thread is interruptedIOException- in some other I/O problem
-
handleDeploymentRollback
protected io.fabric8.kubernetes.api.model.Status handleDeploymentRollback(String resourceUrl, io.fabric8.kubernetes.api.model.extensions.DeploymentRollback deploymentRollback) throws InterruptedException, IOException
Create rollback of a Deployment- Parameters:
resourceUrl- resource urldeploymentRollback- DeploymentRollback resource- Returns:
- Status
- Throws:
InterruptedException- in case thread is interruptedIOException- in some other I/O problem
-
handleGet
protected <T> T handleGet(URL resourceUrl, Class<T> type) throws IOException
Send an http get.- Type Parameters:
T- template argument provided- Parameters:
resourceUrl- resource URL to be processedtype- type of resource- Returns:
- returns a deserialized object as api server response of provided type.
- Throws:
IOException- IOException
-
handleRawGet
protected <T> T handleRawGet(URL resourceUrl, Class<T> type) throws IOException
Send a raw get - where the type should be one of String, Reader, InputStream- Throws:
IOException
-
waitForResult
protected <T> T waitForResult(CompletableFuture<T> future) throws IOException
Waits for the providedCompletableFutureto complete and returns the result in case of success.- Type Parameters:
T- the type of the result- Parameters:
future- the CompletableFuture to wait for- Returns:
- the result of the completed future
- Throws:
IOException- in case there's an I/O problem
-
handleResponse
protected <T> T handleResponse(io.fabric8.kubernetes.client.http.HttpRequest.Builder requestBuilder, Class<T> type) throws IOExceptionSend an http request and handle the response.- Type Parameters:
T- template argument provided- Parameters:
requestBuilder- Request Builder objecttype- type of resource- Returns:
- Returns a de-serialized object as api server response of provided type.
- Throws:
IOException- IOException
-
handleResponse
protected <T> CompletableFuture<T> handleResponse(io.fabric8.kubernetes.client.http.HttpClient client, io.fabric8.kubernetes.client.http.HttpRequest.Builder requestBuilder, com.fasterxml.jackson.core.type.TypeReference<T> type)
Send an http request and handle the response, optionally performing placeholder substitution to the response.- Type Parameters:
T- Template argument provided- Parameters:
client- the clientrequestBuilder- Request buildertype- Type of object provided- Returns:
- Returns a de-serialized object as api server response of provided type.
-
assertResponseCode
protected void assertResponseCode(io.fabric8.kubernetes.client.http.HttpRequest request, io.fabric8.kubernetes.client.http.HttpResponse<?> response)Checks if the response status code is the expected and throws the appropriate KubernetesClientException if not.- Parameters:
request- The {#link HttpRequest} object.response- TheHttpResponseobject.
-
createStatus
public static io.fabric8.kubernetes.api.model.Status createStatus(io.fabric8.kubernetes.client.http.HttpResponse<?> response, io.fabric8.kubernetes.client.utils.KubernetesSerialization kubernetesSerialization)
-
createStatus
public static io.fabric8.kubernetes.api.model.Status createStatus(int statusCode, String message)
-
requestFailure
public static io.fabric8.kubernetes.client.KubernetesClientException requestFailure(io.fabric8.kubernetes.client.http.HttpRequest request, io.fabric8.kubernetes.api.model.Status status)
-
requestFailure
public static io.fabric8.kubernetes.client.KubernetesClientException requestFailure(io.fabric8.kubernetes.client.http.HttpRequest request, io.fabric8.kubernetes.api.model.Status status, String message)
-
requestException
public static io.fabric8.kubernetes.client.KubernetesClientException requestException(io.fabric8.kubernetes.client.http.HttpRequest request, Throwable e, String message)
-
requestException
public static io.fabric8.kubernetes.client.KubernetesClientException requestException(io.fabric8.kubernetes.client.http.HttpRequest request, Exception e)
-
getConfig
public io.fabric8.kubernetes.client.Config getConfig()
-
getOperationContext
public OperationContext getOperationContext()
-
getRequestConfig
public io.fabric8.kubernetes.client.RequestConfig getRequestConfig()
-
handleRaw
public <R1> R1 handleRaw(Class<R1> result, String uri, String method, Object payload)
Send a raw request - where the type should be one of String, Reader, InputStream
-
getKubernetesSerialization
public io.fabric8.kubernetes.client.utils.KubernetesSerialization getKubernetesSerialization()
-
-