Search in sources :

Example 1 with CloudFileDirectory

use of com.microsoft.azure.storage.file.CloudFileDirectory 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 CloudFileDirectory

use of com.microsoft.azure.storage.file.CloudFileDirectory 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 CloudFileDirectory

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

the class AzureNotebookRepo method list.

@Override
public List<NoteInfo> list(AuthenticationInfo subject) throws IOException {
    List<NoteInfo> infos = new LinkedList<>();
    NoteInfo info = null;
    for (ListFileItem item : rootDir.listFilesAndDirectories()) {
        if (item.getClass() == CloudFileDirectory.class) {
            CloudFileDirectory dir = (CloudFileDirectory) item;
            try {
                if (dir.getFileReference("note.json").exists()) {
                    info = new NoteInfo(getNote(dir.getName()));
                    if (info != null) {
                        infos.add(info);
                    }
                }
            } catch (StorageException | URISyntaxException e) {
                String msg = "Error enumerating notebooks from Azure storage";
                LOG.error(msg, e);
            } catch (Exception e) {
                LOG.error(e.getMessage(), e);
            }
        }
    }
    return infos;
}
Also used : NoteInfo(org.apache.zeppelin.notebook.NoteInfo) ListFileItem(com.microsoft.azure.storage.file.ListFileItem) CloudFileDirectory(com.microsoft.azure.storage.file.CloudFileDirectory) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException) LinkedList(java.util.LinkedList) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException)

Example 4 with CloudFileDirectory

use of com.microsoft.azure.storage.file.CloudFileDirectory 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 5 with CloudFileDirectory

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

the class AzureNotebookRepo method init.

@Override
public void init(ZeppelinConfiguration conf) throws IOException {
    this.conf = conf;
    user = conf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_USER);
    shareName = conf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_SHARE);
    try {
        CloudStorageAccount account = CloudStorageAccount.parse(conf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_AZURE_CONNECTION_STRING));
        CloudFileClient client = account.createCloudFileClient();
        CloudFileShare share = client.getShareReference(shareName);
        share.createIfNotExists();
        CloudFileDirectory userDir = StringUtils.isBlank(user) ? share.getRootDirectoryReference() : share.getRootDirectoryReference().getDirectoryReference(user);
        userDir.createIfNotExists();
        rootDir = userDir.getDirectoryReference("notebook");
        rootDir.createIfNotExists();
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : CloudFileShare(com.microsoft.azure.storage.file.CloudFileShare) CloudFileDirectory(com.microsoft.azure.storage.file.CloudFileDirectory) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) CloudFileClient(com.microsoft.azure.storage.file.CloudFileClient) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) StorageException(com.microsoft.azure.storage.StorageException)

Aggregations

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