Search in sources :

Example 6 with WebAppDetails

use of com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails 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 7 with WebAppDetails

use of com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails 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)

Example 8 with WebAppDetails

use of com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails in project azure-tools-for-java by Microsoft.

the class WebAppDeployDialog method deleteAppService.

private void deleteAppService() {
    DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
    int selectedRow = table.getSelectedRow();
    if (selectedRow >= 0) {
        String appServiceName = (String) tableModel.getValueAt(selectedRow, 0);
        WebAppDetails wad = webAppWebAppDetailsMap.get(appServiceName);
        int choice = JOptionPane.showOptionDialog(WebAppDeployDialog.this.getContentPane(), "Do you really want to delete the App Service '" + appServiceName + "'?", "Delete App Service", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
        if (choice == JOptionPane.NO_OPTION) {
            return;
        }
        AppInsightsClient.createByType(AppInsightsClient.EventType.WebApp, appServiceName, "Delete");
        try {
            ProgressManager.getInstance().run(new Task.Modal(project, "Delete App Service Progress", true) {

                @Override
                public void run(ProgressIndicator progressIndicator) {
                    try {
                        progressIndicator.setIndeterminate(true);
                        progressIndicator.setText("Deleting App Service...");
                        WebAppUtils.deleteAppService(wad);
                        ApplicationManager.getApplication().invokeAndWait(new Runnable() {

                            @Override
                            public void run() {
                                tableModel.removeRow(selectedRow);
                                tableModel.fireTableDataChanged();
                                editorPaneAppServiceDetails.setText("");
                            }
                        });
                    } catch (Exception ex) {
                        ex.printStackTrace();
                        //LOGGER.error("deleteAppService : Task.Modal ", ex);
                        ApplicationManager.getApplication().invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                ErrorWindow.show(project, ex.getMessage(), "Delete App Service Error");
                            }
                        });
                    }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            //LOGGER.error("deleteAppService", e);
            ErrorWindow.show(project, e.getMessage(), "Delete App Service Error");
        }
    }
}
Also used : WebAppDetails(com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails) Task(com.intellij.openapi.progress.Task) UpdateProgressIndicator(com.microsoft.azuretools.ijidea.utility.UpdateProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DefaultTableModel(javax.swing.table.DefaultTableModel) AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) CanceledByUserException(com.microsoft.azuretools.utils.CanceledByUserException) IOException(java.io.IOException)

Aggregations

WebAppDetails (com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails)8 DefaultTableModel (javax.swing.table.DefaultTableModel)6 WebApp (com.microsoft.azure.management.appservice.WebApp)4 AppServicePlan (com.microsoft.azure.management.appservice.AppServicePlan)3 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 AnActionButtonRunnable (com.intellij.ui.AnActionButtonRunnable)2 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)2 UpdateProgressIndicator (com.microsoft.azuretools.ijidea.utility.UpdateProgressIndicator)2 CanceledByUserException (com.microsoft.azuretools.utils.CanceledByUserException)2 WebAppUtils (com.microsoft.azuretools.utils.WebAppUtils)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)1 PublishingProfile (com.microsoft.azure.management.appservice.PublishingProfile)1 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)1 AzureDeploymentProgressNotification (com.microsoft.intellij.deploy.AzureDeploymentProgressNotification)1 Date (java.util.Date)1