Search in sources :

Example 31 with WebApp

use of com.microsoft.azure.management.appservice.WebApp in project azure-tools-for-java by Microsoft.

the class WebAppDeployDialog method doFillTable.

private void doFillTable() {
    Map<SubscriptionDetail, List<ResourceGroup>> srgMap = AzureModel.getInstance().getSubscriptionToResourceGroupMap();
    Map<ResourceGroup, List<WebApp>> rgwaMap = AzureModel.getInstance().getResourceGroupToWebAppMap();
    Map<ResourceGroup, List<AppServicePlan>> rgaspMap = AzureModel.getInstance().getResourceGroupToAppServicePlanMap();
    if (srgMap == null)
        throw new NullPointerException("srgMap is null");
    if (rgwaMap == null)
        throw new NullPointerException("rgwaMap is null");
    if (rgaspMap == null)
        throw new NullPointerException("rgaspMap is null");
    cleanTable();
    DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
    for (SubscriptionDetail sd : srgMap.keySet()) {
        if (!sd.isSelected())
            continue;
        Map<String, WebAppUtils.AspDetails> aspMap = new HashMap<>();
        try {
            for (ResourceGroup rg : srgMap.get(sd)) {
                for (AppServicePlan asp : rgaspMap.get(rg)) {
                    aspMap.put(asp.id(), new WebAppUtils.AspDetails(asp, rg));
                }
            }
        } catch (NullPointerException npe) {
            LOGGER.error("NPE while initializing App Service Plan map", npe);
        }
        for (ResourceGroup rg : srgMap.get(sd)) {
            for (WebApp wa : rgwaMap.get(rg)) {
                if (wa.javaVersion() != JavaVersion.OFF) {
                    tableModel.addRow(new String[] { wa.name(), wa.javaVersion().toString(), wa.javaContainer() + " " + wa.javaContainerVersion(), wa.resourceGroupName() });
                } else {
                    tableModel.addRow(new String[] { wa.name(), "Off", "N/A", wa.resourceGroupName() });
                }
                WebAppDetails webAppDetails = new WebAppDetails();
                webAppDetails.webApp = wa;
                webAppDetails.subscriptionDetail = sd;
                webAppDetails.resourceGroup = rg;
                webAppDetails.appServicePlan = aspMap.get(wa.appServicePlanId()).getAsp();
                webAppDetails.appServicePlanResourceGroup = aspMap.get(wa.appServicePlanId()).getRg();
                webAppWebAppDetailsMap.put(wa.name(), webAppDetails);
            }
        }
    }
    table.setModel(tableModel);
    if (tableModel.getRowCount() > 0)
        tableModel.fireTableDataChanged();
}
Also used : WebAppDetails(com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails) HashMap(java.util.HashMap) DefaultTableModel(javax.swing.table.DefaultTableModel) WebAppUtils(com.microsoft.azuretools.utils.WebAppUtils) AppServicePlan(com.microsoft.azure.management.appservice.AppServicePlan) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) List(java.util.List) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) WebApp(com.microsoft.azure.management.appservice.WebApp)

Example 32 with WebApp

use of com.microsoft.azure.management.appservice.WebApp in project azure-tools-for-java by Microsoft.

the class WebAppDeployDialog method deploy.

private void deploy() {
    DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
    int selectedRow = table.getSelectedRow();
    WebAppDetails wad = webAppWebAppDetailsMap.get(tableModel.getValueAt(selectedRow, 0));
    WebApp webApp = wad.webApp;
    boolean isDeployToRoot = deployToRootCheckBox.isSelected();
    ProgressManager.getInstance().run(new Task.Backgroundable(project, "Deploy Web App Progress", true) {

        @Override
        public void run(@NotNull ProgressIndicator progressIndicator) {
            AzureDeploymentProgressNotification azureDeploymentProgressNotification = new AzureDeploymentProgressNotification(project);
            try {
                progressIndicator.setIndeterminate(true);
                PublishingProfile pp = webApp.getPublishingProfile();
                Date startDate = new Date();
                azureDeploymentProgressNotification.notifyProgress(webApp.name(), startDate, null, 5, "Deploying Web App...");
                WebAppUtils.deployArtifact(artifact.getName(), artifact.getOutputFilePath(), pp, isDeployToRoot, new UpdateProgressIndicator(progressIndicator));
                String sitePath = buildSiteLink(wad.webApp, isDeployToRoot ? null : artifact.getName());
                progressIndicator.setText("Checking Web App availability...");
                progressIndicator.setText2("Link: " + sitePath);
                azureDeploymentProgressNotification.notifyProgress(webApp.name(), startDate, sitePath, 75, "Checking Web App availability...");
                int stepLimit = 5;
                int sleepMs = 2000;
                // to make warn up cancelable
                Thread thread = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            for (int step = 0; step < stepLimit; ++step) {
                                if (WebAppUtils.isUrlAccessible(sitePath)) {
                                    // warm up
                                    break;
                                }
                                Thread.sleep(sleepMs);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                            LOGGER.error("deploy::warmup", e);
                        }
                    }
                });
                thread.start();
                while (thread.isAlive()) {
                    if (progressIndicator.isCanceled())
                        return;
                    else
                        Thread.sleep(sleepMs);
                }
                azureDeploymentProgressNotification.notifyProgress(webApp.name(), startDate, sitePath, 100, message("runStatus"));
                showLink(sitePath);
            } catch (IOException | InterruptedException ex) {
                ex.printStackTrace();
                //LOGGER.error("deploy", ex);
                ApplicationManager.getApplication().invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        ErrorWindow.show(project, ex.getMessage(), "Deploy Web App Error");
                    }
                });
            }
        }
    });
}
Also used : WebAppDetails(com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails) Task(com.intellij.openapi.progress.Task) DefaultTableModel(javax.swing.table.DefaultTableModel) AzureDeploymentProgressNotification(com.microsoft.intellij.deploy.AzureDeploymentProgressNotification) Date(java.util.Date) CanceledByUserException(com.microsoft.azuretools.utils.CanceledByUserException) IOException(java.io.IOException) UpdateProgressIndicator(com.microsoft.azuretools.ijidea.utility.UpdateProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) UpdateProgressIndicator(com.microsoft.azuretools.ijidea.utility.UpdateProgressIndicator) PublishingProfile(com.microsoft.azure.management.appservice.PublishingProfile) WebApp(com.microsoft.azure.management.appservice.WebApp)

Aggregations

WebApp (com.microsoft.azure.management.appservice.WebApp)32 AppServicePlan (com.microsoft.azure.management.appservice.AppServicePlan)15 IOException (java.io.IOException)12 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)6 File (java.io.File)6 PublishingProfile (com.microsoft.azure.management.appservice.PublishingProfile)5 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)5 WebAppDetails (com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails)5 AppServiceDomain (com.microsoft.azure.management.appservice.AppServiceDomain)3 TrafficManagerProfile (com.microsoft.azure.management.trafficmanager.TrafficManagerProfile)3 HashMap (java.util.HashMap)3 List (java.util.List)3 DefaultTableModel (javax.swing.table.DefaultTableModel)3 Git (org.eclipse.jgit.api.Git)3 SqlDatabase (com.microsoft.azure.management.sql.SqlDatabase)2 SqlServer (com.microsoft.azure.management.sql.SqlServer)2 StorageAccount (com.microsoft.azure.management.storage.StorageAccount)2 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)2 StorageException (com.microsoft.azure.storage.StorageException)2 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)2