Search in sources :

Example 26 with GetApplicationsResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse in project zeppelin by apache.

the class SparkSubmitIntegrationTest method testCancelSparkYarnApp.

@Test
public void testCancelSparkYarnApp() throws InterpreterException, YarnException, TimeoutException, InterruptedException {
    try {
        // test SparkSubmitInterpreterSetting
        Interpreter sparkSubmitInterpreter = interpreterFactory.getInterpreter("spark-submit", new ExecutionContext("user1", "note1", "test"));
        InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build();
        final Waiter waiter = new Waiter();
        Thread thread = new Thread() {

            @Override
            public void run() {
                try {
                    String yarnAppName = "yarn_cancel_example";
                    InterpreterResult interpreterResult = sparkSubmitInterpreter.interpret("--master yarn-cluster --class org.apache.spark.examples.SparkPi " + "--conf spark.app.name=" + yarnAppName + " --conf spark.driver.memory=512m " + "--conf spark.executor.memory=512m " + sparkHome + "/examples/jars/spark-examples_2.11-2.4.7.jar", context);
                    assertEquals(interpreterResult.toString(), InterpreterResult.Code.INCOMPLETE, interpreterResult.code());
                    assertTrue(interpreterResult.toString(), interpreterResult.toString().contains("Paragraph received a SIGTERM"));
                } catch (InterpreterException e) {
                    waiter.fail("Should not throw exception\n" + ExceptionUtils.getStackTrace(e));
                }
                waiter.resume();
            }
        };
        thread.start();
        long start = System.currentTimeMillis();
        long threshold = 120 * 1000;
        while ((System.currentTimeMillis() - start) < threshold) {
            GetApplicationsRequest request = GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING));
            GetApplicationsResponse response = hadoopCluster.getYarnCluster().getResourceManager().getClientRMService().getApplications(request);
            if (response.getApplicationList().size() >= 1) {
                break;
            }
            Thread.sleep(5 * 1000);
        }
        sparkSubmitInterpreter.cancel(context);
        waiter.await(10000);
    } finally {
        interpreterSettingManager.close();
    }
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) ExecutionContext(org.apache.zeppelin.interpreter.ExecutionContext) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) GetApplicationsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) Waiter(net.jodah.concurrentunit.Waiter) GetApplicationsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest) Test(org.junit.Test)

Aggregations

GetApplicationsResponse (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse)26 GetApplicationsRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest)24 Test (org.junit.Test)17 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)13 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)9 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)8 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)6 ExecutionContext (org.apache.zeppelin.interpreter.ExecutionContext)6 Interpreter (org.apache.zeppelin.interpreter.Interpreter)6 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)6 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)5 ApplicationClientProtocol (org.apache.hadoop.yarn.api.ApplicationClientProtocol)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Configuration (org.apache.hadoop.conf.Configuration)3 YarnApplicationState (org.apache.hadoop.yarn.api.records.YarnApplicationState)3 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)3