Search in sources :

Example 1 with InterpreterInstallationRequest

use of org.apache.zeppelin.rest.message.InterpreterInstallationRequest in project zeppelin by apache.

the class InterpreterServiceTest method downloadInterpreter.

@Test
public void downloadInterpreter() throws IOException {
    final String interpreterName = "test-interpreter";
    String artifactName = "junit:junit:4.11";
    Path specificInterpreterPath = Files.createDirectory(Paths.get(interpreterDir.toString(), interpreterName));
    DependencyResolver dependencyResolver = new DependencyResolver(localRepoDir.toString());
    doNothing().when(mockInterpreterSettingManager).refreshInterpreterTemplates();
    interpreterService.downloadInterpreter(new InterpreterInstallationRequest(interpreterName, artifactName), dependencyResolver, specificInterpreterPath, new SimpleServiceCallback<String>() {

        @Override
        public void onStart(String message, ServiceContext context) {
            assertEquals("Starting to download " + interpreterName + " interpreter", message);
        }

        @Override
        public void onSuccess(String message, ServiceContext context) {
            assertEquals(interpreterName + " downloaded", message);
        }

        @Override
        public void onFailure(Exception ex, ServiceContext context) {
            fail();
        }
    });
    verify(mockInterpreterSettingManager, times(1)).refreshInterpreterTemplates();
}
Also used : Path(java.nio.file.Path) InterpreterInstallationRequest(org.apache.zeppelin.rest.message.InterpreterInstallationRequest) IOException(java.io.IOException) DependencyResolver(org.apache.zeppelin.dep.DependencyResolver) Test(org.junit.Test)

Example 2 with InterpreterInstallationRequest

use of org.apache.zeppelin.rest.message.InterpreterInstallationRequest in project zeppelin by apache.

the class InterpreterServiceTest method interpreterAlreadyExistWithDifferentName.

@Test(expected = Exception.class)
public void interpreterAlreadyExistWithDifferentName() throws Exception {
    String interpreterName = "in";
    Files.createDirectory(Paths.get(interpreterDir.toString(), interpreterName));
    String anotherButSameInterpreterName = "zeppelin-" + interpreterName;
    interpreterService.installInterpreter(new InterpreterInstallationRequest(anotherButSameInterpreterName, "artifact"), null);
}
Also used : InterpreterInstallationRequest(org.apache.zeppelin.rest.message.InterpreterInstallationRequest) Test(org.junit.Test)

Example 3 with InterpreterInstallationRequest

use of org.apache.zeppelin.rest.message.InterpreterInstallationRequest in project zeppelin by apache.

the class InterpreterServiceTest method interpreterAlreadyExist.

@Test(expected = Exception.class)
public void interpreterAlreadyExist() throws Exception {
    String alreadyExistName = "aen";
    Path specificInterpreterDir = Files.createDirectory(Paths.get(interpreterDir.toString(), alreadyExistName));
    interpreterService.installInterpreter(new InterpreterInstallationRequest(alreadyExistName, "artifact"), null);
}
Also used : Path(java.nio.file.Path) InterpreterInstallationRequest(org.apache.zeppelin.rest.message.InterpreterInstallationRequest) Test(org.junit.Test)

Example 4 with InterpreterInstallationRequest

use of org.apache.zeppelin.rest.message.InterpreterInstallationRequest in project zeppelin by apache.

the class InterpreterRestApi method installInterpreter.

/**
 * Install interpreter
 */
@POST
@Path("install")
@ZeppelinApi
public Response installInterpreter(@NotNull String message) {
    LOGGER.info("Install interpreter: {}", message);
    InterpreterInstallationRequest request = InterpreterInstallationRequest.fromJson(message);
    try {
        interpreterService.installInterpreter(request, new SimpleServiceCallback<String>() {

            @Override
            public void onStart(String message, ServiceContext context) {
                Message m = new Message(OP.INTERPRETER_INSTALL_STARTED);
                Map<String, Object> data = new HashMap<>();
                data.put("result", "Starting");
                data.put("message", message);
                m.data = data;
                notebookServer.broadcast(m);
            }

            @Override
            public void onSuccess(String message, ServiceContext context) {
                Message m = new Message(OP.INTERPRETER_INSTALL_RESULT);
                Map<String, Object> data = new HashMap<>();
                data.put("result", "Succeed");
                data.put("message", message);
                m.data = data;
                notebookServer.broadcast(m);
            }

            @Override
            public void onFailure(Exception ex, ServiceContext context) {
                Message m = new Message(OP.INTERPRETER_INSTALL_RESULT);
                Map<String, Object> data = new HashMap<>();
                data.put("result", "Failed");
                data.put("message", ex.getMessage());
                m.data = data;
                notebookServer.broadcast(m);
            }
        });
    } catch (Throwable t) {
        return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, t.getMessage()).build();
    }
    return new JsonResponse<>(Status.OK).build();
}
Also used : InterpreterInstallationRequest(org.apache.zeppelin.rest.message.InterpreterInstallationRequest) Message(org.apache.zeppelin.common.Message) ServiceContext(org.apache.zeppelin.service.ServiceContext) HashMap(java.util.HashMap) Map(java.util.Map) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) IOException(java.io.IOException) JsonResponse(org.apache.zeppelin.server.JsonResponse) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Aggregations

InterpreterInstallationRequest (org.apache.zeppelin.rest.message.InterpreterInstallationRequest)4 Test (org.junit.Test)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)1 Message (org.apache.zeppelin.common.Message)1 DependencyResolver (org.apache.zeppelin.dep.DependencyResolver)1 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)1 JsonResponse (org.apache.zeppelin.server.JsonResponse)1 ServiceContext (org.apache.zeppelin.service.ServiceContext)1