Search in sources :

Example 1 with GetClusterStatusResponse

use of org.apache.flink.runtime.clusterframework.messages.GetClusterStatusResponse in project flink by apache.

the class StandaloneClusterClient method getClusterStatus.

@Override
public GetClusterStatusResponse getClusterStatus() {
    ActorGateway jmGateway;
    try {
        jmGateway = getJobManagerGateway();
        Future<Object> future = jmGateway.ask(GetClusterStatus.getInstance(), timeout);
        Object result = Await.result(future, timeout);
        if (result instanceof GetClusterStatusResponse) {
            return (GetClusterStatusResponse) result;
        } else {
            throw new RuntimeException("Received the wrong reply " + result + " from cluster.");
        }
    } catch (Exception e) {
        throw new RuntimeException("Couldn't retrieve the Cluster status.", e);
    }
}
Also used : GetClusterStatusResponse(org.apache.flink.runtime.clusterframework.messages.GetClusterStatusResponse) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) IOException(java.io.IOException)

Example 2 with GetClusterStatusResponse

use of org.apache.flink.runtime.clusterframework.messages.GetClusterStatusResponse in project flink by apache.

the class YARNSessionFIFOITCase method testJavaAPI.

/**
	 * Test the YARN Java API
	 */
@Test
public void testJavaAPI() {
    final int WAIT_TIME = 15;
    LOG.info("Starting testJavaAPI()");
    AbstractYarnClusterDescriptor flinkYarnClient = new YarnClusterDescriptor();
    Assert.assertNotNull("unable to get yarn client", flinkYarnClient);
    flinkYarnClient.setTaskManagerCount(1);
    flinkYarnClient.setJobManagerMemory(768);
    flinkYarnClient.setTaskManagerMemory(1024);
    flinkYarnClient.setLocalJarPath(new Path(flinkUberjar.getAbsolutePath()));
    flinkYarnClient.addShipFiles(Arrays.asList(flinkLibFolder.listFiles()));
    String confDirPath = System.getenv(ConfigConstants.ENV_FLINK_CONF_DIR);
    flinkYarnClient.setConfigurationDirectory(confDirPath);
    flinkYarnClient.setFlinkConfiguration(GlobalConfiguration.loadConfiguration());
    flinkYarnClient.setConfigurationFilePath(new Path(confDirPath + File.separator + "flink-conf.yaml"));
    // deploy
    ClusterClient yarnCluster = null;
    try {
        yarnCluster = flinkYarnClient.deploy();
    } catch (Exception e) {
        LOG.warn("Failing test", e);
        Assert.fail("Error while deploying YARN cluster: " + e.getMessage());
    }
    GetClusterStatusResponse expectedStatus = new GetClusterStatusResponse(1, 1);
    for (int second = 0; second < WAIT_TIME * 2; second++) {
        // run "forever"
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            LOG.warn("Interrupted", e);
        }
        GetClusterStatusResponse status = yarnCluster.getClusterStatus();
        if (status != null && status.equals(expectedStatus)) {
            LOG.info("ClusterClient reached status " + status);
            // all good, cluster started
            break;
        }
        if (second > WAIT_TIME) {
            // we waited for 15 seconds. cluster didn't come up correctly
            Assert.fail("The custer didn't start after " + WAIT_TIME + " seconds");
        }
    }
    // use the cluster
    Assert.assertNotNull(yarnCluster.getJobManagerAddress());
    Assert.assertNotNull(yarnCluster.getWebInterfaceURL());
    LOG.info("Shutting down cluster. All tests passed");
    // shutdown cluster
    yarnCluster.shutdown();
    LOG.info("Finished testJavaAPI()");
}
Also used : Path(org.apache.hadoop.fs.Path) ClusterClient(org.apache.flink.client.program.ClusterClient) GetClusterStatusResponse(org.apache.flink.runtime.clusterframework.messages.GetClusterStatusResponse) UtilsTest.checkForLogString(org.apache.flink.yarn.UtilsTest.checkForLogString) Test(org.junit.Test)

Example 3 with GetClusterStatusResponse

use of org.apache.flink.runtime.clusterframework.messages.GetClusterStatusResponse in project flink by apache.

the class FlinkYarnSessionCli method runInteractiveCli.

public static void runInteractiveCli(YarnClusterClient yarnCluster, boolean readConsoleInput) {
    final String HELP = "Available commands:\n" + "help - show these commands\n" + "stop - stop the YARN session";
    int numTaskmanagers = 0;
    try {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        label: while (true) {
            // ------------------ check if there are updates by the cluster -----------
            GetClusterStatusResponse status = yarnCluster.getClusterStatus();
            LOG.debug("Received status message: {}", status);
            if (status != null && numTaskmanagers != status.numRegisteredTaskManagers()) {
                System.err.println("Number of connected TaskManagers changed to " + status.numRegisteredTaskManagers() + ". " + "Slots available: " + status.totalNumberOfSlots());
                numTaskmanagers = status.numRegisteredTaskManagers();
            }
            List<String> messages = yarnCluster.getNewMessages();
            if (messages != null && messages.size() > 0) {
                System.err.println("New messages from the YARN cluster: ");
                for (String msg : messages) {
                    System.err.println(msg);
                }
            }
            if (yarnCluster.getApplicationStatus() != ApplicationStatus.SUCCEEDED) {
                System.err.println("The YARN cluster has failed");
                yarnCluster.shutdown();
            }
            // wait until CLIENT_POLLING_INTERVAL is over or the user entered something.
            long startTime = System.currentTimeMillis();
            while ((System.currentTimeMillis() - startTime) < CLIENT_POLLING_INTERVALL * 1000 && (!readConsoleInput || !in.ready())) {
                Thread.sleep(200);
            }
            if (readConsoleInput && in.ready()) {
                String command = in.readLine();
                switch(command) {
                    case "quit":
                    case "stop":
                        yarnCluster.shutdownCluster();
                        break label;
                    case "help":
                        System.err.println(HELP);
                        break;
                    default:
                        System.err.println("Unknown command '" + command + "'. Showing help: \n" + HELP);
                        break;
                }
            }
            if (yarnCluster.hasBeenShutdown()) {
                LOG.info("Stopping interactive command line interface, YARN cluster has been stopped.");
                break;
            }
        }
    } catch (Exception e) {
        LOG.warn("Exception while running the interactive command line interface", e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) GetClusterStatusResponse(org.apache.flink.runtime.clusterframework.messages.GetClusterStatusResponse) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

GetClusterStatusResponse (org.apache.flink.runtime.clusterframework.messages.GetClusterStatusResponse)3 IOException (java.io.IOException)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ClusterClient (org.apache.flink.client.program.ClusterClient)1 IllegalConfigurationException (org.apache.flink.configuration.IllegalConfigurationException)1 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)1 UtilsTest.checkForLogString (org.apache.flink.yarn.UtilsTest.checkForLogString)1 Path (org.apache.hadoop.fs.Path)1 Test (org.junit.Test)1