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 String
apiGroupName
protected String
apiGroupVersion
protected Config
config
protected OperationContext
context
protected boolean
dryRun
protected HttpClient
httpClient
static String
JSON
static String
JSON_MERGE_PATCH
static String
JSON_PATCH
protected String
name
protected String
namespace
protected String
resourceT
static String
STRATEGIC_MERGE_JSON_PATCH
protected String
subresource
-
Constructor Summary
Constructors Constructor Description OperationSupport(Client client)
OperationSupport(OperationContext ctx)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addNamespacedUrlPathParts(List<String> parts, String namespace, String type)
protected void
assertResponseCode(HttpRequest request, HttpResponse<?> response)
Checks if the response status code is the expected and throws the appropriate KubernetesClientException if not.protected <T> String
checkName(T item)
protected <T> String
checkNamespace(T item)
protected <T> T
correctNamespace(T item)
static io.fabric8.kubernetes.api.model.Status
createStatus(int statusCode, String message)
static io.fabric8.kubernetes.api.model.Status
createStatus(HttpResponse<?> response, KubernetesSerialization kubernetesSerialization)
String
getAPIGroupName()
String
getAPIGroupVersion()
Config
getConfig()
KubernetesSerialization
getKubernetesSerialization()
String
getName()
String
getNamespace()
URL
getNamespacedUrl()
URL
getNamespacedUrl(String namespace)
protected URL
getNamespacedUrl(String namespace, String type)
OperationContext
getOperationContext()
RequestConfig
getRequestConfig()
String
getResourceT()
URL
getResourceUrl()
URL
getResourceUrl(String namespace, String name)
URL
getResourceUrl(String namespace, String name, String... subresources)
URL
getResourceURLForPatchOperation(URL resourceUrl, PatchContext patchContext)
URL
getResourceURLForWriteOperation(URL resourceURL)
protected List<String>
getRootUrlParts()
protected <T,I>
ThandleCreate(I resource, Class<T> outputType)
Create a resource.protected io.fabric8.kubernetes.api.model.KubernetesResource
handleDelete(URL requestUrl, long gracePeriodSeconds, io.fabric8.kubernetes.api.model.DeletionPropagation propagationPolicy, String resourceVersion)
protected io.fabric8.kubernetes.api.model.Status
handleDeploymentRollback(String resourceUrl, io.fabric8.kubernetes.api.model.extensions.DeploymentRollback deploymentRollback)
Create rollback of a Deploymentprotected <T> T
handleGet(URL resourceUrl, Class<T> type)
Send an http get.protected <T> T
handleMetric(String resourceUrl, Class<T> type)
protected <T> T
handlePatch(PatchContext patchContext, T current, String patchForUpdate, Class<T> type)
Send an http patch and handle the response.protected <T> T
handlePatch(PatchContext patchContext, T current, T updated, Class<T> type)
Send an http patch and handle the response.<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, InputStreamprotected <T> T
handleRawGet(URL resourceUrl, Class<T> type)
Send a raw get - where the type should be one of String, Reader, InputStreamprotected <T> CompletableFuture<T>
handleResponse(HttpClient client, 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> T
handleResponse(HttpRequest.Builder requestBuilder, Class<T> type)
Send an http request and handle the response.protected <T> T
handleScale(String resourceUrl, T scale, Class<T> scaleType)
Replace Scale of specified Kubernetes Resourceprotected <T> T
handleUpdate(T updated, Class<T> type)
Replace a resource.boolean
isResourceNamespaced()
static KubernetesClientException
requestException(HttpRequest request, Exception e)
static KubernetesClientException
requestException(HttpRequest request, Throwable e, String message)
static KubernetesClientException
requestFailure(HttpRequest request, io.fabric8.kubernetes.api.model.Status status)
static KubernetesClientException
requestFailure(HttpRequest request, io.fabric8.kubernetes.api.model.Status status, String message)
<R1> R1
restCall(Class<R1> result, String... path)
protected <T> T
waitForResult(CompletableFuture<T> future)
Waits for the providedCompletableFuture
to 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 HttpClient httpClient
-
config
protected final 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(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, 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:
InterruptedException
IOException
-
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:
InterruptedException
IOException
-
handleCreate
protected <T,I> T handleCreate(I resource, Class<T> outputType) throws InterruptedException, IOException
Create 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 IOException
Replace 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(PatchContext patchContext, T current, T updated, Class<T> type) throws InterruptedException, IOException
Send 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(PatchContext patchContext, T current, String patchForUpdate, Class<T> type) throws InterruptedException, IOException
Send 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 providedCompletableFuture
to 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(HttpRequest.Builder requestBuilder, Class<T> type) throws IOException
Send 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(HttpClient client, 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(HttpRequest request, 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
- TheHttpResponse
object.
-
createStatus
public static io.fabric8.kubernetes.api.model.Status createStatus(HttpResponse<?> response, KubernetesSerialization kubernetesSerialization)
-
createStatus
public static io.fabric8.kubernetes.api.model.Status createStatus(int statusCode, String message)
-
requestFailure
public static KubernetesClientException requestFailure(HttpRequest request, io.fabric8.kubernetes.api.model.Status status)
-
requestFailure
public static KubernetesClientException requestFailure(HttpRequest request, io.fabric8.kubernetes.api.model.Status status, String message)
-
requestException
public static KubernetesClientException requestException(HttpRequest request, Throwable e, String message)
-
requestException
public static KubernetesClientException requestException(HttpRequest request, Exception e)
-
getConfig
public Config getConfig()
-
getOperationContext
public OperationContext getOperationContext()
-
getRequestConfig
public 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 KubernetesSerialization getKubernetesSerialization()
-
-