Search in sources :

Example 6 with FlinkKubeClient

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));
            });
        }
    };
}
Also used : Arrays(java.util.Arrays) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Predicate(java.util.function.Predicate) FlinkMatchers(org.apache.flink.core.testutils.FlinkMatchers) Matchers.not(org.hamcrest.Matchers.not) Test(org.junit.Test) Collectors(java.util.stream.Collectors) StringResourceVersion(org.apache.flink.runtime.persistence.StringResourceVersion) List(java.util.List) JobID(org.apache.flink.api.common.JobID) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) FunctionUtils(org.apache.flink.util.function.FunctionUtils) PossibleInconsistentStateException(org.apache.flink.runtime.persistence.PossibleInconsistentStateException) StateHandleStore(org.apache.flink.runtime.persistence.StateHandleStore) TestingLongStateHandleHelper(org.apache.flink.runtime.persistence.TestingLongStateHandleHelper) Matchers.is(org.hamcrest.Matchers.is) Assert.fail(org.junit.Assert.fail) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) KubernetesLeaderElector(org.apache.flink.kubernetes.kubeclient.resources.KubernetesLeaderElector) Comparator(java.util.Comparator) FlinkKubeClient(org.apache.flink.kubernetes.kubeclient.FlinkKubeClient) Before(org.junit.Before) PossibleInconsistentStateException(org.apache.flink.runtime.persistence.PossibleInconsistentStateException) FlinkKubeClient(org.apache.flink.kubernetes.kubeclient.FlinkKubeClient) Test(org.junit.Test)

Example 7 with FlinkKubeClient

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;
}
Also used : UnmodifiableConfiguration(org.apache.flink.configuration.UnmodifiableConfiguration) Configuration(org.apache.flink.configuration.Configuration) GlobalConfiguration(org.apache.flink.configuration.GlobalConfiguration) InputStreamReader(java.io.InputStreamReader) FlinkException(org.apache.flink.util.FlinkException) CliArgsException(org.apache.flink.client.cli.CliArgsException) IOException(java.io.IOException) Tuple2(org.apache.flink.api.java.tuple.Tuple2) BufferedReader(java.io.BufferedReader) FlinkKubeClient(org.apache.flink.kubernetes.kubeclient.FlinkKubeClient)

Aggregations

FlinkKubeClient (org.apache.flink.kubernetes.kubeclient.FlinkKubeClient)7 Test (org.junit.Test)6 Configuration (org.apache.flink.configuration.Configuration)4 KubernetesLeaderElector (org.apache.flink.kubernetes.kubeclient.resources.KubernetesLeaderElector)4 TestingLongStateHandleHelper (org.apache.flink.runtime.persistence.TestingLongStateHandleHelper)4 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)4 Matchers.is (org.hamcrest.Matchers.is)4 Arrays (java.util.Arrays)3 Comparator (java.util.Comparator)3 List (java.util.List)3 Predicate (java.util.function.Predicate)3 Collectors (java.util.stream.Collectors)3 JobID (org.apache.flink.api.common.JobID)3 FlinkMatchers (org.apache.flink.core.testutils.FlinkMatchers)3 KubernetesLeaderElectionConfiguration (org.apache.flink.kubernetes.configuration.KubernetesLeaderElectionConfiguration)3 PossibleInconsistentStateException (org.apache.flink.runtime.persistence.PossibleInconsistentStateException)3 StateHandleStore (org.apache.flink.runtime.persistence.StateHandleStore)3 StringResourceVersion (org.apache.flink.runtime.persistence.StringResourceVersion)3 FlinkRuntimeException (org.apache.flink.util.FlinkRuntimeException)3 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)3