use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method createVirtualNode.
private FileEditorVirtualNode<EditorPart> createVirtualNode(final String name) {
final FileEditorVirtualNode<EditorPart> node = new FileEditorVirtualNode<EditorPart>(this, name);
node.addAction(COPY_URL, new NodeActionListener() {
@Override
protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
copyURLSelectedFile();
}
});
node.addAction(SAVE_AS, new NodeActionListener() {
@Override
protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
saveAsSelectedFile();
}
});
node.addAction(DELETE, new NodeActionListener() {
@Override
protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
deleteSelectedFile();
}
});
node.addAction(SEARCH, new NodeActionListener() {
@Override
protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
fillGrid();
}
});
node.addAction(UPLOAD_BLOB, new NodeActionListener() {
@Override
protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
uploadFile();
}
});
return node;
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method downloadSelectedFile.
private void downloadSelectedFile(final File targetFile, final boolean open) {
final BlobFile fileSelection = getFileSelection();
if (fileSelection != null) {
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Downloading blob...", true) {
@Override
public void run(@NotNull final ProgressIndicator progressIndicator) {
try {
progressIndicator.setIndeterminate(false);
if (!targetFile.exists()) {
if (!targetFile.createNewFile()) {
throw new IOException("File not created");
}
}
final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(targetFile), 65536) {
private long runningCount = 0;
@Override
public synchronized void write(@NotNull byte[] bytes, int i, int i1) throws IOException {
super.write(bytes, i, i1);
runningCount += i1;
double progress = (double) runningCount / fileSelection.getSize();
progressIndicator.setFraction(progress);
progressIndicator.setText2(String.format("%s%% downloaded", (int) (progress * 100)));
}
};
try {
Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
try {
StorageClientSDKManager.getManager().downloadBlobFileContent(connectionString, fileSelection, bufferedOutputStream);
if (open && targetFile.exists()) {
Desktop.getDesktop().open(targetFile);
}
} catch (AzureCmdException e) {
Throwable connectionFault = e.getCause().getCause();
progressIndicator.setText("Error downloading Blob");
progressIndicator.setText2((connectionFault instanceof SocketTimeoutException) ? "Connection timed out" : connectionFault.getMessage());
} catch (IOException ex) {
try {
final Process p;
Runtime runtime = Runtime.getRuntime();
p = runtime.exec(new String[] { "open", "-R", targetFile.getName() }, null, targetFile.getParentFile());
InputStream errorStream = p.getErrorStream();
String errResponse = new String(IOUtils.readFully(errorStream, -1, true));
if (p.waitFor() != 0) {
throw new Exception(errResponse);
}
} catch (Exception e) {
progressIndicator.setText("Error openning file");
progressIndicator.setText2(ex.getMessage());
}
}
}
});
while (!future.isDone()) {
progressIndicator.checkCanceled();
if (progressIndicator.isCanceled()) {
future.cancel(true);
}
}
} finally {
bufferedOutputStream.close();
}
} catch (IOException e) {
PluginUtil.displayErrorDialogAndLog(message("errTtl"), "An error occurred while attempting to download Blob.", e);
}
}
});
}
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method deleteSelectedFile.
private void deleteSelectedFile() {
final BlobFile blobItem = getFileSelection();
if (blobItem != null) {
if (JOptionPane.showConfirmDialog(mainPanel, "Are you sure you want to delete this blob?", "Delete Blob", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.OK_OPTION) {
setUIState(true);
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Deleting blob...", false) {
@Override
public void run(@NotNull ProgressIndicator progressIndicator) {
progressIndicator.setIndeterminate(true);
try {
StorageClientSDKManager.getManager().deleteBlobFile(connectionString, blobItem);
if (blobItems.size() <= 1) {
directoryQueue.clear();
directoryQueue.addLast(StorageClientSDKManager.getManager().getRootDirectory(connectionString, blobContainer));
queryTextField.setText("");
}
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
fillGrid();
}
});
} catch (AzureCmdException ex) {
String msg = "An error occurred while attempting to delete blob." + "\n" + String.format(message("webappExpMsg"), ex.getMessage());
PluginUtil.displayErrorDialogAndLog(message("errTtl"), msg, ex);
}
}
});
}
}
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class IDEHelperImpl method buildArtifact.
@NotNull
@Override
public ListenableFuture<String> buildArtifact(@NotNull ProjectDescriptor projectDescriptor, @NotNull ArtifactDescriptor artifactDescriptor) {
try {
Project project = findOpenProject(projectDescriptor);
final Artifact artifact = findProjectArtifact(project, artifactDescriptor);
final SettableFuture<String> future = SettableFuture.create();
Futures.addCallback(buildArtifact(project, artifact, false), new FutureCallback<Boolean>() {
@Override
public void onSuccess(@Nullable Boolean succeded) {
if (succeded != null && succeded) {
future.set(artifact.getOutputFilePath());
} else {
future.setException(new AzureCmdException("An error occurred while building the artifact"));
}
}
@Override
public void onFailure(Throwable throwable) {
if (throwable instanceof ExecutionException) {
future.setException(new AzureCmdException("An error occurred while building the artifact", throwable.getCause()));
} else {
future.setException(new AzureCmdException("An error occurred while building the artifact", throwable));
}
}
});
return future;
} catch (AzureCmdException e) {
return Futures.immediateFailedFuture(e);
}
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class StorageAccountFolderNode method refreshItems.
@Override
protected void refreshItems() throws AzureCmdException {
if (clusterDetail != null && !clusterDetail.isEmulator()) {
try {
clusterDetail.getConfigurationInfo(getProject());
addChildNode(new StorageAccountNode(this, clusterDetail.getStorageAccount(), true));
List<HDStorageAccount> additionalStorageAccount = clusterDetail.getAdditionalStorageAccounts();
if (additionalStorageAccount != null) {
for (HDStorageAccount account : additionalStorageAccount) {
addChildNode(new StorageNode(this, account, false));
}
}
} catch (Exception exception) {
DefaultLoader.getUIHelper().showException("Failed to get HDInsight cluster configuration.", exception, "HDInsight Explorer", false, true);
}
}
}
Aggregations