Search in sources :

Example 31 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 32 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)

Example 33 with AzureCmdException

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

the class TableFileEditor method createVirtualNode.

private FileEditorVirtualNode<EditorPart> createVirtualNode(final String name) {
    final FileEditorVirtualNode<EditorPart> node = new FileEditorVirtualNode<EditorPart>(this, name);
    node.addAction(DELETE, new NodeActionListener() {

        @Override
        protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
            deleteSelection();
        }
    });
    node.addAction(REFRESH, new NodeActionListener() {

        @Override
        protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
            fillGrid();
        }
    });
    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 34 with AzureCmdException

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

the class StorageClientSDKManager method getBlobItems.

@NotNull
public List<BlobItem> getBlobItems(@NotNull String connectionString, @NotNull BlobDirectory blobDirectory) throws AzureCmdException {
    List<BlobItem> biList = new ArrayList<BlobItem>();
    try {
        CloudBlobClient client = getCloudBlobClient(connectionString);
        String containerName = blobDirectory.getContainerName();
        String delimiter = client.getDirectoryDelimiter();
        CloudBlobContainer container = client.getContainerReference(containerName);
        CloudBlobDirectory directory = container.getDirectoryReference(blobDirectory.getPath());
        for (ListBlobItem item : directory.listBlobs()) {
            String uri = item.getUri() != null ? item.getUri().toString() : "";
            if (item instanceof CloudBlobDirectory) {
                CloudBlobDirectory subDirectory = (CloudBlobDirectory) item;
                String name = extractBlobItemName(subDirectory.getPrefix(), delimiter);
                String path = Strings.nullToEmpty(subDirectory.getPrefix());
                biList.add(new BlobDirectory(name, uri, containerName, path));
            } else if (item instanceof CloudBlob) {
                CloudBlob blob = (CloudBlob) item;
                String name = extractBlobItemName(blob.getName(), delimiter);
                String path = Strings.nullToEmpty(blob.getName());
                String type = "";
                String cacheControlHeader = "";
                String contentEncoding = "";
                String contentLanguage = "";
                String contentType = "";
                String contentMD5Header = "";
                String eTag = "";
                Calendar lastModified = new GregorianCalendar();
                long size = 0;
                BlobProperties properties = blob.getProperties();
                if (properties != null) {
                    if (properties.getBlobType() != null) {
                        type = properties.getBlobType().toString();
                    }
                    cacheControlHeader = Strings.nullToEmpty(properties.getCacheControl());
                    contentEncoding = Strings.nullToEmpty(properties.getContentEncoding());
                    contentLanguage = Strings.nullToEmpty(properties.getContentLanguage());
                    contentType = Strings.nullToEmpty(properties.getContentType());
                    contentMD5Header = Strings.nullToEmpty(properties.getContentMD5());
                    eTag = Strings.nullToEmpty(properties.getEtag());
                    if (properties.getLastModified() != null) {
                        lastModified.setTime(properties.getLastModified());
                    }
                    size = properties.getLength();
                }
                biList.add(new BlobFile(name, uri, containerName, path, type, cacheControlHeader, contentEncoding, contentLanguage, contentType, contentMD5Header, eTag, lastModified, size));
            }
        }
        return biList;
    } catch (Throwable t) {
        throw new AzureCmdException("Error retrieving the Blob Item list", t);
    }
}
Also used : BlobDirectory(com.microsoft.tooling.msservices.model.storage.BlobDirectory) BlobFile(com.microsoft.tooling.msservices.model.storage.BlobFile) BlobItem(com.microsoft.tooling.msservices.model.storage.BlobItem) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 35 with AzureCmdException

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

the class StorageClientSDKManager method getQueueMessages.

@NotNull
public List<QueueMessage> getQueueMessages(@NotNull StorageAccount storageAccount, @NotNull Queue queue) throws AzureCmdException {
    List<QueueMessage> qmList = new ArrayList<QueueMessage>();
    try {
        CloudQueueClient client = getCloudQueueClient(storageAccount);
        String queueName = queue.getName();
        CloudQueue cloudQueue = client.getQueueReference(queueName);
        for (CloudQueueMessage cqm : cloudQueue.peekMessages(32)) {
            String id = Strings.nullToEmpty(cqm.getId());
            String content = Strings.nullToEmpty(cqm.getMessageContentAsString());
            Calendar insertionTime = new GregorianCalendar();
            if (cqm.getInsertionTime() != null) {
                insertionTime.setTime(cqm.getInsertionTime());
            }
            Calendar expirationTime = new GregorianCalendar();
            if (cqm.getExpirationTime() != null) {
                expirationTime.setTime(cqm.getExpirationTime());
            }
            int dequeueCount = cqm.getDequeueCount();
            qmList.add(new QueueMessage(id, queueName, content, insertionTime, expirationTime, dequeueCount));
        }
        return qmList;
    } catch (Throwable t) {
        throw new AzureCmdException("Error retrieving the Queue Message list", t);
    }
}
Also used : QueueMessage(com.microsoft.tooling.msservices.model.storage.QueueMessage) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueueClient(com.microsoft.azure.storage.queue.CloudQueueClient) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudQueueMessage(com.microsoft.azure.storage.queue.CloudQueueMessage) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

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