Search in sources :

Example 51 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 52 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 53 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)

Example 54 with AzureCmdException

use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.

the class WebAppUtils method createAppService.

public static WebApp createAppService(IProgressIndicator progressIndicator, CreateAppServiceModel model) throws IOException, WebAppException, InterruptedException, AzureCmdException {
    AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
    // not signed in
    if (azureManager == null) {
        return null;
    }
    Azure azure = azureManager.getAzure(model.subscriptionDetail.getSubscriptionId());
    AppServicePlan appServicePlan = null;
    if (model.isAppServicePlanCreateNew) {
        AppServicePlan.DefinitionStages.WithGroup ds1 = azure.appServices().appServicePlans().define(model.appServicePlanNameCreateNew).withRegion(model.appServicePlanLocationCreateNew.name());
        AppServicePlan.DefinitionStages.WithPricingTier ds2;
        if (model.isResourceGroupCreateNew) {
            ds2 = ds1.withNewResourceGroup(model.resourceGroupNameCreateNew);
        } else {
            ds2 = ds1.withExistingResourceGroup(model.resourceGroup);
        }
        appServicePlan = ds2.withPricingTier(model.appServicePricingTierCreateNew).withOperatingSystem(OperatingSystem.WINDOWS).create();
    } else {
        appServicePlan = model.appServicePlan;
    }
    WebApp.DefinitionStages.Blank definitionStages = azure.webApps().define(model.webAppName);
    WebAppBase.DefinitionStages.WithCreate<WebApp> withCreate;
    WebApp.DefinitionStages.ExistingWindowsPlanWithGroup ds1 = definitionStages.withExistingWindowsPlan(appServicePlan);
    if (model.isResourceGroupCreateNew) {
        withCreate = ds1.withNewResourceGroup(model.resourceGroupNameCreateNew);
    } else {
        withCreate = ds1.withExistingResourceGroup(model.resourceGroup);
    }
    if (model.jdkDownloadUrl == null) {
        // no custom jdk
        withCreate = withCreate.withJavaVersion(JavaVersion.JAVA_8_NEWEST).withWebContainer(model.webContainer);
    }
    WebApp myWebApp = withCreate.create();
    if (model.jdkDownloadUrl != null) {
        progressIndicator.setText("Deploying custom jdk...");
        WebAppUtils.deployCustomJdk(myWebApp, model.jdkDownloadUrl, model.webContainer, progressIndicator);
    }
    // update cache
    if (model.isResourceGroupCreateNew) {
        ResourceGroup rg = azure.resourceGroups().getByName(model.resourceGroupNameCreateNew);
        if (rg == null) {
            throw new AzureCmdException(String.format("azure.resourceGroups().getByName(%s) returned null"), model.resourceGroupNameCreateNew);
        }
        AzureModelController.addNewResourceGroup(model.subscriptionDetail, rg);
        AzureModelController.addNewWebAppToJustCreatedResourceGroup(rg, myWebApp);
        if (model.isAppServicePlanCreateNew) {
            AzureModelController.addNewAppServicePlanToJustCreatedResourceGroup(rg, appServicePlan);
        } else {
            // add empty list
            AzureModelController.addNewAppServicePlanToJustCreatedResourceGroup(rg, null);
        }
    } else {
        ResourceGroup rg = model.resourceGroup;
        AzureModelController.addNewWebAppToExistingResourceGroup(rg, myWebApp);
        if (model.isAppServicePlanCreateNew) {
            //AppServicePlan asp = azure.appServices().appServicePlans().getById(myWebApp.appServicePlanId());
            AzureModelController.addNewAppServicePlanToExistingResourceGroup(rg, appServicePlan);
        }
    }
    return myWebApp;
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup)

Example 55 with AzureCmdException

use of com.microsoft.azuretools.azurecommons.helpers.AzureCmdException in project azure-tools-for-java by Microsoft.

the class ClusterManager method getClusterDetails.

private List<IClusterDetail> getClusterDetails(List<SubscriptionDetail> subscriptions, final Object project) throws AggregatedException {
    ExecutorService taskExecutor = Executors.newFixedThreadPool(MAX_CONCURRENT);
    final List<IClusterDetail> cachedClusterList = new ArrayList<>();
    final List<Exception> aggregateExceptions = new ArrayList<>();
    for (SubscriptionDetail subscription : subscriptions) {
        taskExecutor.execute(new CommonRunnable<SubscriptionDetail, Exception>(subscription) {

            @Override
            public void runSpecificParameter(SubscriptionDetail parameter) throws IOException, HDIException, AzureCmdException {
                IClusterOperation clusterOperation = new ClusterOperationImpl(project);
                List<ClusterRawInfo> clusterRawInfoList = clusterOperation.listCluster(parameter);
                if (clusterRawInfoList != null) {
                    for (ClusterRawInfo item : clusterRawInfoList) {
                        IClusterDetail tempClusterDetail = new ClusterDetail(parameter, item);
                        synchronized (ClusterManager.class) {
                            cachedClusterList.add(tempClusterDetail);
                        }
                    }
                }
            }

            @Override
            public void exceptionHandle(Exception e) {
                synchronized (aggregateExceptions) {
                    aggregateExceptions.add(e);
                }
            }
        });
    }
    taskExecutor.shutdown();
    try {
        taskExecutor.awaitTermination(TIME_OUT, TimeUnit.SECONDS);
    } catch (InterruptedException exception) {
        aggregateExceptions.add(exception);
    }
    if (aggregateExceptions.size() > 0) {
        throw new AggregatedException(aggregateExceptions);
    }
    return cachedClusterList;
}
Also used : ArrayList(java.util.ArrayList) AggregatedException(com.microsoft.azure.hdinsight.sdk.common.AggregatedException) IOException(java.io.IOException) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) AggregatedException(com.microsoft.azure.hdinsight.sdk.common.AggregatedException) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) IOException(java.io.IOException) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) ExecutorService(java.util.concurrent.ExecutorService) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) List(java.util.List) ArrayList(java.util.ArrayList)

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