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);
}
}
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()");
}
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);
}
}
Aggregations