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