Search in sources :

Example 1 with LibraryMetadata

use of org.apache.zeppelin.interpreter.thrift.LibraryMetadata in project zeppelin by apache.

the class RemoteInterpreterEventServer method getAllLibraryMetadatas.

@Override
public List<LibraryMetadata> getAllLibraryMetadatas(String interpreter) throws TException {
    if (StringUtils.isBlank(interpreter)) {
        LOGGER.warn("Interpreter is blank");
        return Collections.emptyList();
    }
    File interpreterLocalRepo = new File(zConf.getAbsoluteDir(ZeppelinConfiguration.ConfVars.ZEPPELIN_DEP_LOCALREPO) + File.separator + interpreter);
    if (!interpreterLocalRepo.exists()) {
        LOGGER.warn("Local interpreter repository {} for interpreter {} doesn't exists", interpreterLocalRepo, interpreter);
        return Collections.emptyList();
    }
    if (!interpreterLocalRepo.isDirectory()) {
        LOGGER.warn("Local interpreter repository {} is no folder", interpreterLocalRepo);
        return Collections.emptyList();
    }
    Collection<File> files = FileUtils.listFiles(interpreterLocalRepo, new String[] { "jar" }, false);
    List<LibraryMetadata> metaDatas = new ArrayList<>(files.size());
    for (File file : files) {
        try {
            metaDatas.add(new LibraryMetadata(file.getName(), FileUtils.checksumCRC32(file)));
        } catch (IOException e) {
            LOGGER.warn(e.getMessage(), e);
        }
    }
    return metaDatas;
}
Also used : LibraryMetadata(org.apache.zeppelin.interpreter.thrift.LibraryMetadata) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 2 with LibraryMetadata

use of org.apache.zeppelin.interpreter.thrift.LibraryMetadata in project zeppelin by apache.

the class RemoteInterpreterDownloader method syncAllLibraries.

private void syncAllLibraries() {
    LOGGER.info("Loading all libraries for interpreter {} to {}", interpreter, localRepoDir);
    List<LibraryMetadata> metadatas = client.getAllLibraryMetadatas(interpreter);
    if (!localRepoDir.isDirectory()) {
        LOGGER.error("{} is no directory", localRepoDir);
        return;
    }
    Set<String> syncedLibraries = new HashSet<>();
    // Add or update new libraries
    for (LibraryMetadata metadata : metadatas) {
        File library = new File(localRepoDir, metadata.getName());
        addOrUpdateLibrary(library, metadata);
        syncedLibraries.add(metadata.getName());
    }
    // Delete old Jar files
    for (File file : FileUtils.listFiles(localRepoDir, new String[] { "jar" }, false)) {
        if (!syncedLibraries.contains(file.getName())) {
            try {
                LOGGER.info("Delete {}, because it's not present on the server side", file.toPath());
                Files.delete(file.toPath());
            } catch (IOException e) {
                LOGGER.error("Unable to delete old library {} during sync.", file, e);
            }
        }
    }
}
Also used : LibraryMetadata(org.apache.zeppelin.interpreter.thrift.LibraryMetadata) IOException(java.io.IOException) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 LibraryMetadata (org.apache.zeppelin.interpreter.thrift.LibraryMetadata)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1