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();
}
}
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;
}
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;
}
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);
}
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);
}
}
Aggregations