use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class HDInsightUtil method setHDInsightRootModule.
public static void setHDInsightRootModule(@NotNull AzureModule azureModule) {
HDInsightRootModuleImpl hdInsightRootModule = new HDInsightRootModuleImpl(azureModule);
// add telemetry for HDInsight Node
hdInsightRootModule.addClickActionListener(new NodeActionListener() {
@Override
protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
AppInsightsClient.create(HDInsightBundle.message("HDInsightExplorerHDInsightNodeExpand"), null);
}
});
azureModule.setHdInsightModule(hdInsightRootModule);
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class CreateBlobContainerForm method okPressed.
@Override
protected void okPressed() {
final String name = nameTextField.getText();
if (name.length() < NAME_MIN || name.length() > NAME_MAX || !name.matches(NAME_REGEX)) {
DefaultLoader.getUIHelper().showError("Container names must start with a letter or number, and can contain only letters, numbers, and the dash (-) character.\n" + "Every dash (-) character must be immediately preceded and followed by a letter or number; consecutive dashes are not permitted in container names.\n" + "All letters in a container name must be lowercase.\n" + "Container names must be from 3 through 63 characters long.", "Azure Explorer");
return;
}
DefaultLoader.getIdeHelper().runInBackground(null, "Creating blob container...", false, true, "Creating blob container...", new Runnable() {
@Override
public void run() {
try {
for (BlobContainer blobContainer : StorageClientSDKManager.getManager().getBlobContainers(connectionString)) {
if (blobContainer.getName().equals(name)) {
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
DefaultLoader.getUIHelper().showError("A blob container with the specified name already exists.", "Azure Explorer");
}
});
return;
}
}
BlobContainer blobContainer = new BlobContainer(name, "", /*storageAccount.getBlobsUri() + name*/
"", Calendar.getInstance(), "");
StorageClientSDKManager.getManager().createBlobContainer(connectionString, blobContainer);
if (onCreate != null) {
DefaultLoader.getIdeHelper().invokeLater(onCreate);
}
} catch (AzureCmdException e) {
DefaultLoader.getUIHelper().showException("Error creating blob container", e, "Error creating blob container", false, true);
}
}
});
super.okPressed();
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method uploadFile.
private void uploadFile(final String path, final File selectedFile) {
Job job = new Job("Uploading blob...") {
@Override
protected IStatus run(final IProgressMonitor monitor) {
monitor.beginTask("Uploading blob...", IProgressMonitor.UNKNOWN);
try {
final BlobDirectory blobDirectory = directoryQueue.peekLast();
final BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(selectedFile));
monitor.subTask("0% uploaded");
try {
final CallableSingleArg<Void, Long> callable = new CallableSingleArg<Void, Long>() {
@Override
public Void call(Long uploadedBytes) throws Exception {
double progress = ((double) uploadedBytes) / selectedFile.length();
monitor.worked((int) (100 * progress));
monitor.subTask(String.format("%s%% uploaded", (int) (progress * 100)));
return null;
}
};
try {
StorageClientSDKManager.getManager().uploadBlobFileContent(connectionString, blobContainer, path, bufferedInputStream, callable, 1024 * 1024, selectedFile.length());
} catch (AzureCmdException e) {
e.printStackTrace();
} finally {
try {
bufferedInputStream.close();
} catch (IOException ignored) {
}
}
if (monitor.isCanceled()) {
// future.cancel(true);
bufferedInputStream.close();
for (BlobItem blobItem : StorageClientSDKManager.getManager().getBlobItems(connectionString, blobDirectory)) {
if (blobItem instanceof BlobFile && blobItem.getPath().equals(path)) {
StorageClientSDKManager.getManager().deleteBlobFile(connectionString, (BlobFile) blobItem);
}
}
}
try {
directoryQueue.clear();
directoryQueue.addLast(StorageClientSDKManager.getManager().getRootDirectory(connectionString, blobContainer));
for (String pathDir : path.split("/")) {
for (BlobItem blobItem : StorageClientSDKManager.getManager().getBlobItems(connectionString, directoryQueue.getLast())) {
if (blobItem instanceof BlobDirectory && blobItem.getName().equals(pathDir)) {
directoryQueue.addLast((BlobDirectory) blobItem);
}
}
}
} catch (AzureCmdException e) {
DefaultLoader.getUIHelper().showException("Error showing new blob", e, "Error showing new blob", false, true);
}
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
fillGrid();
}
});
} catch (Exception e) {
Throwable connectionFault = e.getCause();
Throwable realFault = null;
if (connectionFault != null) {
realFault = connectionFault.getCause();
}
monitor.setTaskName("Error uploading Blob");
String message = realFault == null ? null : realFault.getMessage();
if (connectionFault != null && message == null) {
message = "Error type " + connectionFault.getClass().getName();
}
monitor.subTask((connectionFault instanceof SocketTimeoutException) ? "Connection timed out" : message);
}
} catch (Exception e) {
DefaultLoader.getUIHelper().showException("Error uploading Blob", e, "Error uploading Blob", false, true);
return Status.CANCEL_STATUS;
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
job.schedule();
}
use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method fillGrid.
public void fillGrid() {
setUIState(true);
DefaultLoader.getIdeHelper().runInBackground(null, "Loading blobs...", false, true, "Loading blobs...", new Runnable() {
@Override
public void run() {
try {
if (directoryQueue.peekLast() == null) {
directoryQueue.addLast(StorageClientSDKManager.getManager().getRootDirectory(connectionString, blobContainer));
}
blobItems = StorageClientSDKManager.getManager().getBlobItems(connectionString, directoryQueue.peekLast());
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
if (!queryTextField.getText().isEmpty()) {
for (int i = blobItems.size() - 1; i >= 0; i--) {
BlobItem blobItem = blobItems.get(i);
if (blobItem instanceof BlobFile && !blobItem.getName().startsWith(queryTextField.getText())) {
blobItems.remove(i);
}
}
}
pathLabel.setText(directoryQueue.peekLast().getPath());
tableViewer.setInput(blobItems);
tableViewer.refresh();
setUIState(false);
//
// blobListTable.clearSelection();
}
});
} catch (AzureCmdException ex) {
DefaultLoader.getUIHelper().showException("Error querying blob list.", ex, "Error querying blobs", false, true);
}
}
});
}
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) {
Job job = new Job("Downloading blob...") {
@Override
protected IStatus run(final IProgressMonitor monitor) {
monitor.beginTask("Downloading blob...", IProgressMonitor.UNKNOWN);
try {
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();
monitor.worked((int) (100 * progress));
monitor.subTask(String.format("%s%% downloaded", (int) (progress * 100)));
}
};
try {
// public void run() {
try {
StorageClientSDKManager.getManager().downloadBlobFileContent(connectionString, fileSelection, bufferedOutputStream);
if (open && targetFile.exists()) {
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) {
monitor.setTaskName("Error opening file");
monitor.subTask(e.getMessage());
}
// Desktop.getDesktop().open(targetFile);
}
} catch (AzureCmdException e) {
Throwable connectionFault = e.getCause().getCause();
monitor.setTaskName("Error downloading Blob");
monitor.subTask((connectionFault instanceof SocketTimeoutException) ? "Connection timed out" : connectionFault.getMessage());
return Status.CANCEL_STATUS;
}
} finally {
bufferedOutputStream.close();
}
} catch (IOException e) {
DefaultLoader.getUIHelper().showException("Error downloading Blob", e, "Error downloading Blob", false, true);
return Status.CANCEL_STATUS;
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
job.schedule();
}
}
Aggregations