use of org.apache.flink.kubernetes.kubeclient.FlinkKubeClient in project flink by apache.
the class KubernetesStateHandleStoreTest method testAddWithPossiblyInconsistentStateHandling.
@Test
public void testAddWithPossiblyInconsistentStateHandling() throws Exception {
new Context() {
{
runTest(() -> {
leaderCallbackGrantLeadership();
final FlinkKubeClient anotherFlinkKubeClient = createFlinkKubeClientBuilder().setCheckAndUpdateConfigMapFunction((configMapName, function) -> FutureUtils.completedExceptionally(new PossibleInconsistentStateException())).build();
final KubernetesStateHandleStore<TestingLongStateHandleHelper.LongStateHandle> store = new KubernetesStateHandleStore<>(anotherFlinkKubeClient, LEADER_CONFIGMAP_NAME, longStateStorage, filter, LOCK_IDENTITY);
try {
store.addAndLock(key, state);
fail("PossibleInconsistentStateException should have been thrown.");
} catch (PossibleInconsistentStateException ex) {
// PossibleInconsistentStateException is expected
}
assertThat(TestingLongStateHandleHelper.getGlobalStorageSize(), is(1));
assertThat(TestingLongStateHandleHelper.getGlobalDiscardCount(), is(0));
});
}
};
}
use of org.apache.flink.kubernetes.kubeclient.FlinkKubeClient in project flink by apache.
the class KubernetesSessionCli method run.
private int run(String[] args) throws FlinkException, CliArgsException {
final Configuration configuration = getEffectiveConfiguration(args);
final ClusterClientFactory<String> kubernetesClusterClientFactory = clusterClientServiceLoader.getClusterClientFactory(configuration);
final ClusterDescriptor<String> kubernetesClusterDescriptor = kubernetesClusterClientFactory.createClusterDescriptor(configuration);
try {
final ClusterClient<String> clusterClient;
String clusterId = kubernetesClusterClientFactory.getClusterId(configuration);
final boolean detached = !configuration.get(DeploymentOptions.ATTACHED);
final FlinkKubeClient kubeClient = FlinkKubeClientFactory.getInstance().fromConfiguration(configuration, "client");
// Retrieve or create a session cluster.
if (clusterId != null && kubeClient.getService(KubernetesService.ServiceType.REST_SERVICE, clusterId).isPresent()) {
clusterClient = kubernetesClusterDescriptor.retrieve(clusterId).getClusterClient();
} else {
clusterClient = kubernetesClusterDescriptor.deploySessionCluster(kubernetesClusterClientFactory.getClusterSpecification(configuration)).getClusterClient();
clusterId = clusterClient.getClusterId();
}
try {
if (!detached) {
Tuple2<Boolean, Boolean> continueRepl = new Tuple2<>(true, false);
try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
while (continueRepl.f0) {
continueRepl = repStep(in);
}
} catch (Exception e) {
LOG.warn("Exception while running the interactive command line interface.", e);
}
if (continueRepl.f1) {
kubernetesClusterDescriptor.killCluster(clusterId);
}
}
clusterClient.close();
kubeClient.close();
} catch (Exception e) {
LOG.info("Could not properly shutdown cluster client.", e);
}
} finally {
try {
kubernetesClusterDescriptor.close();
} catch (Exception e) {
LOG.info("Could not properly close the kubernetes cluster descriptor.", e);
}
}
return 0;
}
Aggregations