Search in sources :

Example 16 with ExecutionContext

use of org.apache.zeppelin.interpreter.ExecutionContext in project zeppelin by apache.

the class SparkSubmitIntegrationTest method testYarnMode.

@Test
public void testYarnMode() throws InterpreterException, YarnException {
    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();
        String yarnAppName = "yarn_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.SUCCESS, interpreterResult.code());
        GetApplicationsRequest request = GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.FINISHED));
        GetApplicationsResponse response = hadoopCluster.getYarnCluster().getResourceManager().getClientRMService().getApplications(request);
        assertTrue(response.getApplicationList().size() >= 1);
        List<ApplicationReport> apps = response.getApplicationList().stream().filter(app -> app.getName().equals(yarnAppName)).collect(Collectors.toList());
        assertEquals(1, apps.size());
    } finally {
        interpreterSettingManager.close();
    }
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) GetApplicationsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) BeforeClass(org.junit.BeforeClass) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) Waiter(net.jodah.concurrentunit.Waiter) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) InterpreterFactory(org.apache.zeppelin.interpreter.InterpreterFactory) ExecutionContext(org.apache.zeppelin.interpreter.ExecutionContext) DownloadUtils(org.apache.zeppelin.interpreter.integration.DownloadUtils) EnumSet(java.util.EnumSet) Interpreter(org.apache.zeppelin.interpreter.Interpreter) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) InterpreterSettingManager(org.apache.zeppelin.interpreter.InterpreterSettingManager) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) List(java.util.List) GetApplicationsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState) Assert.assertEquals(org.junit.Assert.assertEquals) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) Interpreter(org.apache.zeppelin.interpreter.Interpreter) ExecutionContext(org.apache.zeppelin.interpreter.ExecutionContext) GetApplicationsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) GetApplicationsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest) Test(org.junit.Test)

Example 17 with ExecutionContext

use of org.apache.zeppelin.interpreter.ExecutionContext in project zeppelin by apache.

the class SparkSubmitIntegrationTest method testLocalMode.

@Test
public void testLocalMode() throws InterpreterException, YarnException {
    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();
        InterpreterResult interpreterResult = sparkSubmitInterpreter.interpret("--master yarn-cluster --class org.apache.spark.examples.SparkPi " + sparkHome + "/examples/jars/spark-examples_2.11-2.4.7.jar", context);
        assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
        // no yarn application launched
        GetApplicationsRequest request = GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING));
        GetApplicationsResponse response = hadoopCluster.getYarnCluster().getResourceManager().getClientRMService().getApplications(request);
        assertEquals(0, response.getApplicationList().size());
    } finally {
        interpreterSettingManager.close();
    }
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) ExecutionContext(org.apache.zeppelin.interpreter.ExecutionContext) GetApplicationsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) GetApplicationsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest) Test(org.junit.Test)

Example 18 with ExecutionContext

use of org.apache.zeppelin.interpreter.ExecutionContext 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

ExecutionContext (org.apache.zeppelin.interpreter.ExecutionContext)18 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)13 Interpreter (org.apache.zeppelin.interpreter.Interpreter)11 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)11 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)11 Test (org.junit.Test)11 GetApplicationsRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest)5 GetApplicationsResponse (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse)5 RemoteInterpreter (org.apache.zeppelin.interpreter.remote.RemoteInterpreter)4 HashMap (java.util.HashMap)2 Waiter (net.jodah.concurrentunit.Waiter)2 Dependency (org.apache.zeppelin.dep.Dependency)2 AbstractInterpreterTest (org.apache.zeppelin.interpreter.AbstractInterpreterTest)2 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)2 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Map (java.util.Map)1