Search in sources :

Example 1 with QueryableStateClient

use of org.apache.flink.queryablestate.client.QueryableStateClient in project flink by apache.

the class QsStateClient method main.

public static void main(final String[] args) throws Exception {
    ParameterTool parameters = ParameterTool.fromArgs(args);
    // setup values
    String jobId = parameters.getRequired("job-id");
    String host = parameters.get("host", "localhost");
    int port = parameters.getInt("port", 9069);
    int numIterations = parameters.getInt("iterations", 1500);
    QueryableStateClient client = new QueryableStateClient(host, port);
    client.setExecutionConfig(new ExecutionConfig());
    MapStateDescriptor<EmailId, EmailInformation> stateDescriptor = new MapStateDescriptor<>(QsConstants.STATE_NAME, TypeInformation.of(new TypeHint<EmailId>() {
    }), TypeInformation.of(new TypeHint<EmailInformation>() {
    }));
    System.out.println("Wait until the state can be queried.");
    // wait for state to exist
    for (int i = 0; i < BOOTSTRAP_RETRIES; i++) {
        // ~120s
        try {
            getMapState(jobId, client, stateDescriptor);
            break;
        } catch (ExecutionException e) {
            if (e.getCause() instanceof UnknownKeyOrNamespaceException) {
                System.err.println("State does not exist yet; sleeping 500ms");
                Thread.sleep(500L);
            } else {
                throw e;
            }
        }
        if (i == (BOOTSTRAP_RETRIES - 1)) {
            throw new RuntimeException("Timeout: state doesn't exist after 120s");
        }
    }
    System.out.println(String.format("State exists. Start querying it %d times.", numIterations));
    // query state
    for (int iterations = 0; iterations < numIterations; iterations++) {
        MapState<EmailId, EmailInformation> mapState = getMapState(jobId, client, stateDescriptor);
        int counter = 0;
        for (Map.Entry<EmailId, EmailInformation> entry : mapState.entries()) {
            // this is to force deserialization
            entry.getKey();
            entry.getValue();
            counter++;
        }
        System.out.println(// we look for it in the test
        "MapState has " + counter + " entries");
        Thread.sleep(100L);
    }
}
Also used : ParameterTool(org.apache.flink.api.java.utils.ParameterTool) MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) TypeHint(org.apache.flink.api.common.typeinfo.TypeHint) UnknownKeyOrNamespaceException(org.apache.flink.queryablestate.exceptions.UnknownKeyOrNamespaceException) QueryableStateClient(org.apache.flink.queryablestate.client.QueryableStateClient) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) TypeHint(org.apache.flink.api.common.typeinfo.TypeHint) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map)

Example 2 with QueryableStateClient

use of org.apache.flink.queryablestate.client.QueryableStateClient in project flink by apache.

the class NonHAQueryableStateRocksDBBackendITCase method setup.

@BeforeClass
public static void setup() throws Exception {
    client = new QueryableStateClient("localhost", QS_PROXY_PORT_RANGE_START);
    clusterClient = MINI_CLUSTER_RESOURCE.getClusterClient();
}
Also used : QueryableStateClient(org.apache.flink.queryablestate.client.QueryableStateClient) BeforeClass(org.junit.BeforeClass)

Example 3 with QueryableStateClient

use of org.apache.flink.queryablestate.client.QueryableStateClient in project flink by apache.

the class HAQueryableStateRocksDBBackendITCase method setup.

@BeforeClass
public static void setup() throws Exception {
    zkServer = new TestingServer();
    // we have to manage this manually because we have to create the ZooKeeper server
    // ahead of this
    miniClusterResource = new MiniClusterWithClientResource(new MiniClusterResourceConfiguration.Builder().setConfiguration(getConfig()).setNumberTaskManagers(NUM_TMS).setNumberSlotsPerTaskManager(NUM_SLOTS_PER_TM).build());
    miniClusterResource.before();
    client = new QueryableStateClient("localhost", QS_PROXY_PORT_RANGE_START);
    clusterClient = miniClusterResource.getClusterClient();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) QueryableStateClient(org.apache.flink.queryablestate.client.QueryableStateClient) BeforeClass(org.junit.BeforeClass)

Example 4 with QueryableStateClient

use of org.apache.flink.queryablestate.client.QueryableStateClient in project flink by apache.

the class HAQueryableStateFsBackendITCase method setup.

@BeforeClass
public static void setup() throws Exception {
    zkServer = new TestingServer();
    // we have to manage this manually because we have to create the ZooKeeper server
    // ahead of this
    miniClusterResource = new MiniClusterWithClientResource(new MiniClusterResourceConfiguration.Builder().setConfiguration(getConfig()).setNumberTaskManagers(NUM_TMS).setNumberSlotsPerTaskManager(NUM_SLOTS_PER_TM).build());
    miniClusterResource.before();
    client = new QueryableStateClient("localhost", QS_PROXY_PORT_RANGE_START);
    clusterClient = miniClusterResource.getClusterClient();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) QueryableStateClient(org.apache.flink.queryablestate.client.QueryableStateClient) BeforeClass(org.junit.BeforeClass)

Example 5 with QueryableStateClient

use of org.apache.flink.queryablestate.client.QueryableStateClient in project flink by apache.

the class NonHAQueryableStateFsBackendITCase method setup.

@BeforeClass
public static void setup() throws Exception {
    client = new QueryableStateClient("localhost", QS_PROXY_PORT_RANGE_START);
    clusterClient = MINI_CLUSTER_RESOURCE.getClusterClient();
}
Also used : QueryableStateClient(org.apache.flink.queryablestate.client.QueryableStateClient) BeforeClass(org.junit.BeforeClass)

Aggregations

QueryableStateClient (org.apache.flink.queryablestate.client.QueryableStateClient)5 BeforeClass (org.junit.BeforeClass)4 TestingServer (org.apache.curator.test.TestingServer)2 MiniClusterWithClientResource (org.apache.flink.test.util.MiniClusterWithClientResource)2 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 MapStateDescriptor (org.apache.flink.api.common.state.MapStateDescriptor)1 TypeHint (org.apache.flink.api.common.typeinfo.TypeHint)1 ParameterTool (org.apache.flink.api.java.utils.ParameterTool)1 UnknownKeyOrNamespaceException (org.apache.flink.queryablestate.exceptions.UnknownKeyOrNamespaceException)1