Search in sources :

Example 1 with CloudFile

use of com.microsoft.azure.storage.file.CloudFile in project zeppelin by apache.

the class AzureNotebookRepo method delete.

// unfortunately, we need to use a recursive delete here
private void delete(ListFileItem item) throws StorageException {
    if (item.getClass() == CloudFileDirectory.class) {
        CloudFileDirectory dir = (CloudFileDirectory) item;
        for (ListFileItem subItem : dir.listFilesAndDirectories()) {
            delete(subItem);
        }
        dir.deleteIfExists();
    } else if (item.getClass() == CloudFile.class) {
        CloudFile file = (CloudFile) item;
        file.deleteIfExists();
    }
}
Also used : CloudFile(com.microsoft.azure.storage.file.CloudFile) CloudFileDirectory(com.microsoft.azure.storage.file.CloudFileDirectory) ListFileItem(com.microsoft.azure.storage.file.ListFileItem)

Example 2 with CloudFile

use of com.microsoft.azure.storage.file.CloudFile in project zeppelin by apache.

the class AzureNotebookRepo method getNote.

private Note getNote(String noteId) throws IOException {
    InputStream ins = null;
    try {
        CloudFileDirectory dir = rootDir.getDirectoryReference(noteId);
        CloudFile file = dir.getFileReference("note.json");
        ins = file.openRead();
    } catch (URISyntaxException | StorageException e) {
        String msg = String.format("Error reading notebook %s from Azure storage", noteId);
        LOG.error(msg, e);
        throw new IOException(msg, e);
    }
    String json = IOUtils.toString(ins, conf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_ENCODING));
    ins.close();
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setPrettyPrinting();
    Gson gson = gsonBuilder.registerTypeAdapter(Date.class, new NotebookImportDeserializer()).create();
    Note note = gson.fromJson(json, Note.class);
    for (Paragraph p : note.getParagraphs()) {
        if (p.getStatus() == Job.Status.PENDING || p.getStatus() == Job.Status.RUNNING) {
            p.setStatus(Job.Status.ABORT);
        }
    }
    return note;
}
Also used : CloudFileDirectory(com.microsoft.azure.storage.file.CloudFileDirectory) GsonBuilder(com.google.gson.GsonBuilder) InputStream(java.io.InputStream) Gson(com.google.gson.Gson) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) NotebookImportDeserializer(org.apache.zeppelin.notebook.NotebookImportDeserializer) Date(java.util.Date) Paragraph(org.apache.zeppelin.notebook.Paragraph) CloudFile(com.microsoft.azure.storage.file.CloudFile) Note(org.apache.zeppelin.notebook.Note) StorageException(com.microsoft.azure.storage.StorageException)

Example 3 with CloudFile

use of com.microsoft.azure.storage.file.CloudFile in project zeppelin by apache.

the class AzureNotebookRepo method list.

private Map<String, NoteInfo> list(CloudFileDirectory folder) throws IOException {
    Map<String, NoteInfo> notesInfo = new HashMap<>();
    for (ListFileItem item : rootDir.listFilesAndDirectories()) {
        if (item instanceof CloudFileDirectory) {
            CloudFileDirectory dir = (CloudFileDirectory) item;
            notesInfo.putAll(list(dir));
        } else if (item instanceof CloudFile) {
            CloudFile file = (CloudFile) item;
            if (file.getName().endsWith(".zpln")) {
                try {
                    String noteName = getNotePath(rootDir.getUri().getPath(), file.getUri().getPath());
                    String noteId = getNoteId(file.getUri().getPath());
                    notesInfo.put(noteId, new NoteInfo(noteId, noteName));
                } catch (IOException e) {
                    LOGGER.warn(e.getMessage());
                }
            } else {
                LOGGER.debug("Skip invalid note file: {}", file.getUri().getPath());
            }
        }
    }
    return notesInfo;
}
Also used : NoteInfo(org.apache.zeppelin.notebook.NoteInfo) CloudFile(com.microsoft.azure.storage.file.CloudFile) HashMap(java.util.HashMap) ListFileItem(com.microsoft.azure.storage.file.ListFileItem) CloudFileDirectory(com.microsoft.azure.storage.file.CloudFileDirectory) IOException(java.io.IOException)

Example 4 with CloudFile

use of com.microsoft.azure.storage.file.CloudFile in project zeppelin by apache.

the class AzureNotebookRepo method get.

@Override
public Note get(String noteId, String notePath, AuthenticationInfo subject) throws IOException {
    InputStream ins = null;
    try {
        CloudFile noteFile = rootDir.getFileReference(buildNoteFileName(noteId, notePath));
        ins = noteFile.openRead();
    } catch (URISyntaxException | StorageException e) {
        String msg = String.format("Error reading notebook %s from Azure storage", buildNoteFileName(noteId, notePath));
        LOGGER.error(msg, e);
        throw new IOException(msg, e);
    }
    String json = IOUtils.toString(ins, conf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_ENCODING));
    ins.close();
    return Note.fromJson(noteId, json);
}
Also used : CloudFile(com.microsoft.azure.storage.file.CloudFile) InputStream(java.io.InputStream) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) StorageException(com.microsoft.azure.storage.StorageException)

Example 5 with CloudFile

use of com.microsoft.azure.storage.file.CloudFile in project zeppelin by apache.

the class AzureNotebookRepo method remove.

@Override
public void remove(String noteId, String notePath, AuthenticationInfo subject) throws IOException {
    try {
        CloudFile noteFile = rootDir.getFileReference(buildNoteFileName(noteId, notePath));
        noteFile.delete();
    } catch (URISyntaxException | StorageException e) {
        String msg = String.format("Error deleting notebook %s from Azure storage", buildNoteFileName(noteId, notePath));
        LOGGER.error(msg, e);
        throw new IOException(msg, e);
    }
}
Also used : CloudFile(com.microsoft.azure.storage.file.CloudFile) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) StorageException(com.microsoft.azure.storage.StorageException)

Aggregations

CloudFile (com.microsoft.azure.storage.file.CloudFile)6 IOException (java.io.IOException)5 StorageException (com.microsoft.azure.storage.StorageException)4 URISyntaxException (java.net.URISyntaxException)4 CloudFileDirectory (com.microsoft.azure.storage.file.CloudFileDirectory)3 ListFileItem (com.microsoft.azure.storage.file.ListFileItem)2 InputStream (java.io.InputStream)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Note (org.apache.zeppelin.notebook.Note)1 NoteInfo (org.apache.zeppelin.notebook.NoteInfo)1 NotebookImportDeserializer (org.apache.zeppelin.notebook.NotebookImportDeserializer)1 Paragraph (org.apache.zeppelin.notebook.Paragraph)1