Search in sources :

Example 26 with AzureCmdException

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;
}
Also used : AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) NodeActionListener(com.microsoft.tooling.msservices.serviceexplorer.NodeActionListener) NodeActionEvent(com.microsoft.tooling.msservices.serviceexplorer.NodeActionEvent) EditorPart(org.eclipse.ui.part.EditorPart)

Example 27 with AzureCmdException

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);
                }
            }
        });
    }
}
Also used : Task(com.intellij.openapi.progress.Task) BlobFile(com.microsoft.tooling.msservices.model.storage.BlobFile) SocketTimeoutException(java.net.SocketTimeoutException) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) SocketTimeoutException(java.net.SocketTimeoutException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) Future(java.util.concurrent.Future)

Example 28 with AzureCmdException

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);
                    }
                }
            });
        }
    }
}
Also used : Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) BlobFile(com.microsoft.tooling.msservices.model.storage.BlobFile)

Example 29 with AzureCmdException

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);
    }
}
Also used : Project(com.intellij.openapi.project.Project) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) ExecutionException(java.util.concurrent.ExecutionException) Artifact(com.intellij.packaging.artifacts.Artifact) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 30 with AzureCmdException

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);
        }
    }
}
Also used : HDStorageAccount(com.microsoft.azure.hdinsight.sdk.storage.HDStorageAccount) StorageNode(com.microsoft.tooling.msservices.serviceexplorer.azure.storage.asm.StorageNode) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Aggregations

AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)55 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)20 BlobFile (com.microsoft.tooling.msservices.model.storage.BlobFile)8 CloudQueue (com.microsoft.azure.storage.queue.CloudQueue)7 CloudQueueClient (com.microsoft.azure.storage.queue.CloudQueueClient)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 Task (com.intellij.openapi.progress.Task)5 Azure (com.microsoft.azure.management.Azure)5 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)5 NodeActionEvent (com.microsoft.tooling.msservices.serviceexplorer.NodeActionEvent)5 NodeActionListener (com.microsoft.tooling.msservices.serviceexplorer.NodeActionListener)5 IOException (java.io.IOException)5 BlobDirectory (com.microsoft.tooling.msservices.model.storage.BlobDirectory)4 BlobItem (com.microsoft.tooling.msservices.model.storage.BlobItem)4 ArrayList (java.util.ArrayList)4 CloudQueueMessage (com.microsoft.azure.storage.queue.CloudQueueMessage)3 SubscriptionManager (com.microsoft.azuretools.authmanage.SubscriptionManager)3 BlobContainer (com.microsoft.tooling.msservices.model.storage.BlobContainer)3 FileInputStream (java.io.FileInputStream)3 SocketTimeoutException (java.net.SocketTimeoutException)3