InterpreterService { public void installInterpreter( final InterpreterInstallationRequest request, final ServiceCallback<String> serviceCallback) throws Exception { Preconditions.checkNotNull(request); String interpreterName = request.getName(); Preconditions.checkNotNull(interpreterName); Preconditions.checkNotNull(request.getArtifact()); String interpreterBaseDir = conf.getInterpreterDir(); String localRepoPath = conf.getInterpreterLocalRepoPath(); final DependencyResolver dependencyResolver = new DependencyResolver(localRepoPath); String proxyUrl = conf.getZeppelinProxyUrl(); if (null != proxyUrl) { String proxyUser = conf.getZeppelinProxyUser(); String proxyPassword = conf.getZeppelinProxyPassword(); try { dependencyResolver.setProxy(new URL(proxyUrl), proxyUser, proxyPassword); } catch (MalformedURLException e) { throw new Exception("Url is not valid format", e); } } List<String> possibleInterpreterDirectories = Lists.newArrayList(); possibleInterpreterDirectories.add(interpreterName); if (interpreterName.startsWith(ZEPPELIN_ARTIFACT_PREFIX)) { possibleInterpreterDirectories.add(interpreterName.replace(ZEPPELIN_ARTIFACT_PREFIX, "")); } else { possibleInterpreterDirectories.add(ZEPPELIN_ARTIFACT_PREFIX + interpreterName); } for (String pn : possibleInterpreterDirectories) { Path testInterpreterDir = Paths.get(interpreterBaseDir, pn); if (Files.exists(testInterpreterDir)) { throw new Exception("Interpreter " + interpreterName + " already exists with " + pn); } } final Path interpreterDir = Paths.get(interpreterBaseDir, interpreterName); try { Files.createDirectories(interpreterDir); } catch (Exception e) { throw new Exception("Cannot create " + interpreterDir.toString()); } EXECUTOR_SERVICE.execute( new Runnable() { @Override public void run() { downloadInterpreter(request, dependencyResolver, interpreterDir, serviceCallback); } }); } @Inject  InterpreterService(
      ZeppelinConfiguration conf, InterpreterSettingManager interpreterSettingManager); void installInterpreter(
      final InterpreterInstallationRequest request, final ServiceCallback<String> serviceCallback);  }
@Test(expected = Exception.class) public void invalidProxyUrl() throws Exception { when(mockZeppelinConfiguration.getZeppelinProxyUrl()).thenReturn("invalidProxyPath"); interpreterService.installInterpreter( new InterpreterInstallationRequest("name", "artifact"), null); }
@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); }
@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); }