public class Fabric8FlinkKubeClient extends Object implements FlinkKubeClient
FlinkKubeClient
.FlinkKubeClient.WatchCallbackHandler<T>
Constructor and Description |
---|
Fabric8FlinkKubeClient(Configuration flinkConfig,
io.fabric8.kubernetes.client.NamespacedKubernetesClient client,
ScheduledExecutorService executorService) |
Modifier and Type | Method and Description |
---|---|
CompletableFuture<Boolean> |
checkAndUpdateConfigMap(String configMapName,
Function<KubernetesConfigMap,Optional<KubernetesConfigMap>> updateFunction)
Update an existing ConfigMap with the data.
|
void |
close()
Close the Kubernetes client with no exception.
|
CompletableFuture<Void> |
createConfigMap(KubernetesConfigMap configMap)
Create the ConfigMap with specified content.
|
KubernetesConfigMapSharedWatcher |
createConfigMapSharedWatcher(String name)
Create a shared watcher for ConfigMaps with specified name.
|
void |
createJobManagerComponent(KubernetesJobManagerSpecification kubernetesJMSpec)
Create the Master components, this can include the Deployment, the ConfigMap(s), and the
Service(s).
|
KubernetesLeaderElector |
createLeaderElector(KubernetesLeaderElectionConfiguration leaderElectionConfiguration,
KubernetesLeaderElector.LeaderCallbackHandler leaderCallbackHandler)
Create a leader elector service based on Kubernetes api.
|
CompletableFuture<Void> |
createTaskManagerPod(KubernetesPod kubernetesPod)
Create task manager pod.
|
CompletableFuture<Void> |
deleteConfigMap(String configMapName)
Delete a Kubernetes ConfigMap by name.
|
Optional<KubernetesConfigMap> |
getConfigMap(String name)
Get the ConfigMap with specified name.
|
List<KubernetesPod> |
getPodsWithLabels(Map<String,String> labels)
List the pods with specified labels.
|
Optional<Endpoint> |
getRestEndpoint(String clusterId)
Get the rest endpoint for access outside cluster.
|
Optional<KubernetesService> |
getService(String serviceName)
Get the kubernetes service of the given flink clusterId.
|
KubernetesPod |
loadPodFromTemplateFile(File file)
Load pod from template file.
|
void |
stopAndCleanupCluster(String clusterId)
Stop cluster and clean up all resources, include services, auxiliary services and all running
pods.
|
CompletableFuture<Void> |
stopPod(String podName)
Stop a specified pod by name.
|
CompletableFuture<Void> |
updateServiceTargetPort(String serviceName,
String portName,
int targetPort)
Update the target ports of the given Kubernetes service.
|
CompletableFuture<KubernetesWatch> |
watchPodsAndDoCallback(Map<String,String> labels,
FlinkKubeClient.WatchCallbackHandler<KubernetesPod> podCallbackHandler)
Watch the pods selected by labels and do the
FlinkKubeClient.WatchCallbackHandler . |
public Fabric8FlinkKubeClient(Configuration flinkConfig, io.fabric8.kubernetes.client.NamespacedKubernetesClient client, ScheduledExecutorService executorService)
public void createJobManagerComponent(KubernetesJobManagerSpecification kubernetesJMSpec)
FlinkKubeClient
createJobManagerComponent
in interface FlinkKubeClient
kubernetesJMSpec
- jobmanager specificationpublic CompletableFuture<Void> createTaskManagerPod(KubernetesPod kubernetesPod)
FlinkKubeClient
createTaskManagerPod
in interface FlinkKubeClient
kubernetesPod
- taskmanager podpublic CompletableFuture<Void> stopPod(String podName)
FlinkKubeClient
stopPod
in interface FlinkKubeClient
podName
- pod namepublic Optional<Endpoint> getRestEndpoint(String clusterId)
FlinkKubeClient
getRestEndpoint
in interface FlinkKubeClient
clusterId
- cluster idpublic List<KubernetesPod> getPodsWithLabels(Map<String,String> labels)
FlinkKubeClient
getPodsWithLabels
in interface FlinkKubeClient
labels
- labels to filter the podspublic void stopAndCleanupCluster(String clusterId)
FlinkKubeClient
stopAndCleanupCluster
in interface FlinkKubeClient
clusterId
- cluster idpublic Optional<KubernetesService> getService(String serviceName)
FlinkKubeClient
getService
in interface FlinkKubeClient
serviceName
- the name of the servicepublic CompletableFuture<KubernetesWatch> watchPodsAndDoCallback(Map<String,String> labels, FlinkKubeClient.WatchCallbackHandler<KubernetesPod> podCallbackHandler)
FlinkKubeClient
FlinkKubeClient.WatchCallbackHandler
.watchPodsAndDoCallback
in interface FlinkKubeClient
labels
- labels to filter the pods to watchpodCallbackHandler
- podCallbackHandler which reacts to pod eventspublic KubernetesLeaderElector createLeaderElector(KubernetesLeaderElectionConfiguration leaderElectionConfiguration, KubernetesLeaderElector.LeaderCallbackHandler leaderCallbackHandler)
FlinkKubeClient
createLeaderElector
in interface FlinkKubeClient
leaderElectionConfiguration
- election configurationleaderCallbackHandler
- Callback when the current instance is leader or not.KubernetesLeaderElector#run
.public CompletableFuture<Void> createConfigMap(KubernetesConfigMap configMap)
FlinkKubeClient
KubernetesException
will be thrown.createConfigMap
in interface FlinkKubeClient
configMap
- ConfigMap to be created.public Optional<KubernetesConfigMap> getConfigMap(String name)
FlinkKubeClient
getConfigMap
in interface FlinkKubeClient
name
- name of the ConfigMap to retrieve.public CompletableFuture<Boolean> checkAndUpdateConfigMap(String configMapName, Function<KubernetesConfigMap,Optional<KubernetesConfigMap>> updateFunction)
FlinkKubeClient
FlinkKubeClient.getConfigMap(String)
, we could perform a
get-check-and-update transactional operation. Since concurrent modification could happen on a
same ConfigMap, the update operation may fail. We need to retry internally in the
implementation.checkAndUpdateConfigMap
in interface FlinkKubeClient
configMapName
- configMapName specifies the name of the ConfigMap which shall be
updated.updateFunction
- Function to be applied to the obtained ConfigMap and get a new updated
one. If the returned optional is empty, we will not do the update.PossibleInconsistentStateException
indicating that no clear
decision can be made on whether the update was successful or not. The PossibleInconsistentStateException
not being present indicates that the failure happened
before writing the updated ConfigMap to Kubernetes. For the latter case, it can be
assumed that the ConfigMap was not updated.public CompletableFuture<Void> deleteConfigMap(String configMapName)
FlinkKubeClient
deleteConfigMap
in interface FlinkKubeClient
configMapName
- ConfigMap namepublic KubernetesConfigMapSharedWatcher createConfigMapSharedWatcher(String name)
FlinkKubeClient
createConfigMapSharedWatcher
in interface FlinkKubeClient
name
- name of the ConfigMap to watch.public void close()
FlinkKubeClient
close
in interface AutoCloseable
close
in interface FlinkKubeClient
public KubernetesPod loadPodFromTemplateFile(File file)
FlinkKubeClient
loadPodFromTemplateFile
in interface FlinkKubeClient
file
- The pod template file.public CompletableFuture<Void> updateServiceTargetPort(String serviceName, String portName, int targetPort)
FlinkKubeClient
updateServiceTargetPort
in interface FlinkKubeClient
serviceName
- The name of the service which needs to be updatedportName
- The port name which needs to be updatedtargetPort
- The updated target portCopyright © 2014–2024 The Apache Software Foundation. All rights reserved.