Class Fabric8FlinkKubeClient
java.lang.Object
org.apache.flink.kubernetes.kubeclient.Fabric8FlinkKubeClient
- All Implemented Interfaces:
AutoCloseable,FlinkKubeClient
The implementation of
FlinkKubeClient.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.flink.kubernetes.kubeclient.FlinkKubeClient
FlinkKubeClient.WatchCallbackHandler<T> -
Constructor Summary
ConstructorsConstructorDescriptionFabric8FlinkKubeClient(org.apache.flink.configuration.Configuration flinkConfig, io.fabric8.kubernetes.client.NamespacedKubernetesClient client, ScheduledExecutorService executorService) -
Method Summary
Modifier and TypeMethodDescriptioncheckAndUpdateConfigMap(String configMapName, Function<KubernetesConfigMap, Optional<KubernetesConfigMap>> updateFunction) Update an existing ConfigMap with the data.voidclose()Close the Kubernetes client with no exception.createConfigMap(KubernetesConfigMap configMap) Create the ConfigMap with specified content.Create a shared watcher for ConfigMaps with specified name.voidcreateJobManagerComponent(KubernetesJobManagerSpecification kubernetesJMSpec) Create the Master components, this can include the Deployment, the ConfigMap(s), and the Service(s).createLeaderElector(KubernetesLeaderElectionConfiguration leaderElectionConfiguration, KubernetesLeaderElector.LeaderCallbackHandler leaderCallbackHandler) Create a leader elector service based on Kubernetes api.createTaskManagerPod(KubernetesPod kubernetesPod) Create task manager pod.deleteConfigMap(String configMapName) Delete a Kubernetes ConfigMap by name.getConfigMap(String name) Get the ConfigMap with specified name.getPodsWithLabels(Map<String, String> labels) List the pods with specified labels.getRestEndpoint(String clusterId) Get the rest endpoint for access outside cluster.getService(String serviceName) Get the kubernetes service of the given flink clusterId.loadPodFromTemplateFile(File file) Load pod from template file.voidstopAndCleanupCluster(String clusterId) Stop cluster and clean up all resources, include services, auxiliary services and all running pods.Stop a specified pod by name.updateServiceTargetPort(String serviceName, String portName, int targetPort) Update the target ports of the given Kubernetes service.watchPodsAndDoCallback(Map<String, String> labels, FlinkKubeClient.WatchCallbackHandler<KubernetesPod> podCallbackHandler) Watch the pods selected by labels and do theFlinkKubeClient.WatchCallbackHandler.
-
Constructor Details
-
Fabric8FlinkKubeClient
public Fabric8FlinkKubeClient(org.apache.flink.configuration.Configuration flinkConfig, io.fabric8.kubernetes.client.NamespacedKubernetesClient client, ScheduledExecutorService executorService)
-
-
Method Details
-
createJobManagerComponent
Description copied from interface:FlinkKubeClientCreate the Master components, this can include the Deployment, the ConfigMap(s), and the Service(s).- Specified by:
createJobManagerComponentin interfaceFlinkKubeClient- Parameters:
kubernetesJMSpec- jobmanager specification
-
createTaskManagerPod
Description copied from interface:FlinkKubeClientCreate task manager pod.- Specified by:
createTaskManagerPodin interfaceFlinkKubeClient- Parameters:
kubernetesPod- taskmanager pod- Returns:
- Return the taskmanager pod creation future
-
stopPod
Description copied from interface:FlinkKubeClientStop a specified pod by name.- Specified by:
stopPodin interfaceFlinkKubeClient- Parameters:
podName- pod name- Returns:
- Return the pod stop future
-
getRestEndpoint
Description copied from interface:FlinkKubeClientGet the rest endpoint for access outside cluster.- Specified by:
getRestEndpointin interfaceFlinkKubeClient- Parameters:
clusterId- cluster id- Returns:
- Return empty if the service does not exist or could not extract the Endpoint from the service.
-
getPodsWithLabels
Description copied from interface:FlinkKubeClientList the pods with specified labels.- Specified by:
getPodsWithLabelsin interfaceFlinkKubeClient- Parameters:
labels- labels to filter the pods- Returns:
- pod list
-
stopAndCleanupCluster
Description copied from interface:FlinkKubeClientStop cluster and clean up all resources, include services, auxiliary services and all running pods.- Specified by:
stopAndCleanupClusterin interfaceFlinkKubeClient- Parameters:
clusterId- cluster id
-
getService
Description copied from interface:FlinkKubeClientGet the kubernetes service of the given flink clusterId.- Specified by:
getServicein interfaceFlinkKubeClient- Parameters:
serviceName- the name of the service- Returns:
- Return the optional kubernetes service of the specified name.
-
watchPodsAndDoCallback
public CompletableFuture<KubernetesWatch> watchPodsAndDoCallback(Map<String, String> labels, FlinkKubeClient.WatchCallbackHandler<KubernetesPod> podCallbackHandler) Description copied from interface:FlinkKubeClientWatch the pods selected by labels and do theFlinkKubeClient.WatchCallbackHandler.- Specified by:
watchPodsAndDoCallbackin interfaceFlinkKubeClient- Parameters:
labels- labels to filter the pods to watchpodCallbackHandler- podCallbackHandler which reacts to pod events- Returns:
- Return a watch for pods. It needs to be closed after use.
-
createLeaderElector
public KubernetesLeaderElector createLeaderElector(KubernetesLeaderElectionConfiguration leaderElectionConfiguration, KubernetesLeaderElector.LeaderCallbackHandler leaderCallbackHandler) Description copied from interface:FlinkKubeClientCreate a leader elector service based on Kubernetes api.- Specified by:
createLeaderElectorin interfaceFlinkKubeClient- Parameters:
leaderElectionConfiguration- election configurationleaderCallbackHandler- Callback when the current instance is leader or not.- Returns:
- Return the created leader elector. It should be started manually via
KubernetesLeaderElector#run.
-
createConfigMap
Description copied from interface:FlinkKubeClientCreate the ConfigMap with specified content. If the ConfigMap already exists, aKubernetesExceptionwill be thrown.- Specified by:
createConfigMapin interfaceFlinkKubeClient- Parameters:
configMap- ConfigMap to be created.- Returns:
- Return the ConfigMap create future. The returned future will be completed exceptionally if the ConfigMap already exists.
-
getConfigMap
Description copied from interface:FlinkKubeClientGet the ConfigMap with specified name.- Specified by:
getConfigMapin interfaceFlinkKubeClient- Parameters:
name- name of the ConfigMap to retrieve.- Returns:
- Return the ConfigMap, or empty if the ConfigMap does not exist.
-
checkAndUpdateConfigMap
public CompletableFuture<Boolean> checkAndUpdateConfigMap(String configMapName, Function<KubernetesConfigMap, Optional<KubernetesConfigMap>> updateFunction) Description copied from interface:FlinkKubeClientUpdate an existing ConfigMap with the data. Benefit from resource version and combined withFlinkKubeClient.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.- Specified by:
checkAndUpdateConfigMapin interfaceFlinkKubeClient- Parameters:
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.- Returns:
- Return the ConfigMap update future. The boolean result indicates whether the
ConfigMap is updated. The returned future will be completed exceptionally if the
ConfigMap does not exist. A failure during the update operation will result in the future
failing with a
PossibleInconsistentStateExceptionindicating that no clear decision can be made on whether the update was successful or not. ThePossibleInconsistentStateExceptionnot 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.
-
deleteConfigMap
Description copied from interface:FlinkKubeClientDelete a Kubernetes ConfigMap by name.- Specified by:
deleteConfigMapin interfaceFlinkKubeClient- Parameters:
configMapName- ConfigMap name- Returns:
- Return the delete future.
-
close
public void close()Description copied from interface:FlinkKubeClientClose the Kubernetes client with no exception.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceFlinkKubeClient
-
loadPodFromTemplateFile
Description copied from interface:FlinkKubeClientLoad pod from template file.- Specified by:
loadPodFromTemplateFilein interfaceFlinkKubeClient- Parameters:
file- The pod template file.- Returns:
- Return a Kubernetes pod loaded from the template.
-
updateServiceTargetPort
public CompletableFuture<Void> updateServiceTargetPort(String serviceName, String portName, int targetPort) Description copied from interface:FlinkKubeClientUpdate the target ports of the given Kubernetes service.- Specified by:
updateServiceTargetPortin interfaceFlinkKubeClient- Parameters:
serviceName- The name of the service which needs to be updatedportName- The port name which needs to be updatedtargetPort- The updated target port- Returns:
- Return the update service target port future
-