Search in sources :

Example 16 with IWebApp

use of com.microsoft.azure.toolkit.lib.appservice.service.IWebApp in project azure-tools-for-java by Microsoft.

the class PublishWebAppOnLinuxDialog method getSelectedWebApp.

// get selected items in Combo
private IWebApp getSelectedWebApp() {
    IWebApp selectedWebApp = null;
    int index = cpExisting.tblWebApps.getSelectionIndex();
    if (webAppList != null && index >= 0 && index < webAppList.size()) {
        selectedWebApp = webAppList.get(index);
    }
    return selectedWebApp;
}
Also used : Point(org.eclipse.swt.graphics.Point) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)

Example 17 with IWebApp

use of com.microsoft.azure.toolkit.lib.appservice.service.IWebApp in project azure-tools-for-java by Microsoft.

the class PublishWebAppOnLinuxDialog method renderWebAppOnLinuxList.

@Override
public void renderWebAppOnLinuxList(List<IWebApp> list) {
    // TODO Auto-generated method stub
    cpExisting.btnRefresh.setEnabled(true);
    webAppList = list.stream().sorted((a, b) -> a.subscriptionId().compareToIgnoreCase(b.subscriptionId())).collect(Collectors.toList());
    // TODO: where to show loading ...
    if (webAppList.size() > 0) {
        cpExisting.tblWebApps.removeAll();
        for (IWebApp app : webAppList) {
            TableItem it = new TableItem(cpExisting.tblWebApps, SWT.NULL);
            it.setText(new String[] { app.name(), app.resourceGroup() });
        }
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)

Example 18 with IWebApp

use of com.microsoft.azure.toolkit.lib.appservice.service.IWebApp in project azure-tools-for-java by Microsoft.

the class WebAppDeployDialog method deleteAppService.

private void deleteAppService() {
    int selectedRow = table.getSelectionIndex();
    if (selectedRow < 0) {
        return;
    }
    String appServiceName = table.getItems()[selectedRow].getText(0);
    IWebApp webApp = webAppDetailsMap.get(appServiceName);
    boolean confirmed = MessageDialog.openConfirm(getShell(), "Delete App Service", "Do you really want to delete the App Service '" + appServiceName + "'?");
    if (!confirmed) {
        return;
    }
    String errTitle = "Delete App Service Error";
    try {
        ProgressDialog.get(this.getShell(), "Delete App Service Progress").run(true, true, (monitor) -> {
            monitor.beginTask("Deleting App Service...", IProgressMonitor.UNKNOWN);
            EventUtil.executeWithLog(WEBAPP, DELETE_WEBAPP, (operation) -> {
                webApp.delete();
                Display.getDefault().asyncExec(() -> {
                    table.remove(selectedRow);
                    fillAppServiceDetails();
                    fillSlot();
                });
            }, (ex) -> {
                LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@deleteAppService@AppServiceCreateDialog", ex));
                Display.getDefault().asyncExec(() -> ErrorWindow.go(getShell(), ex.getMessage(), errTitle));
            });
        });
    } catch (Exception ex) {
        ex.printStackTrace();
        LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "deleteAppService@AppServiceCreateDialog", ex));
        ErrorWindow.go(getShell(), ex.getMessage(), errTitle);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Point(org.eclipse.swt.graphics.Point) IOException(java.io.IOException) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)

Example 19 with IWebApp

use of com.microsoft.azure.toolkit.lib.appservice.service.IWebApp in project azure-tools-for-java by Microsoft.

the class WebAppDeployDialog method deploy.

private void deploy(String artifactName, String artifactPath) {
    int selectedRow = table.getSelectionIndex();
    String appServiceName = table.getItems()[selectedRow].getText(0);
    IWebApp webApp = webAppDetailsMap.get(appServiceName);
    String jobDescription = String.format("Web App '%s' deployment", webApp.name());
    if (isDeployToSlot) {
        jobDescription = String.format("Web App '%s' deploy to slot '%s'", webApp.name(), isCreateNewSlot ? webAppSettingModel.getNewSlotName() : webAppSettingModel.getSlotName());
    }
    String deploymentName = UUID.randomUUID().toString();
    AzureDeploymentProgressNotification.createAzureDeploymentProgressNotification(deploymentName, jobDescription);
    boolean isDeployToRoot = btnDeployToRoot.getSelection();
    Job job = new Job(jobDescription) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            String message = "Packaging Artifact...";
            String cancelMessage = "Interrupted by user";
            String successMessage = "";
            String errorMessage = "Error";
            Map<String, String> postEventProperties = new HashMap<>();
            try {
                boolean isJar = MavenUtils.isMavenProject(project) && MavenUtils.getPackaging(project).equals("jar");
                postEventProperties.put(TelemetryConstants.JAVA_APPNAME, project.getName());
                postEventProperties.put(TelemetryConstants.FILETYPE, isJar ? "jar" : "war");
                Runtime runtime = webApp.getRuntime();
                String osValue = (String) Optional.ofNullable(runtime.getOperatingSystem()).map(com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem::toString).orElse("");
                String webContainerValue = (String) Optional.ofNullable(runtime.getWebContainer()).map(WebContainer::getValue).orElse("");
                String javaVersionValue = (String) Optional.ofNullable(runtime.getJavaVersion()).map(com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion::getValue).orElse("");
                postEventProperties.put(TelemetryConstants.RUNTIME, String.format("%s-%s-%s", osValue, webContainerValue, javaVersionValue));
                postEventProperties.put(TelemetryConstants.WEBAPP_DEPLOY_TO_SLOT, Boolean.valueOf(isDeployToSlot).toString());
            } catch (Exception e) {
            }
            String errTitle = "Deploy Web App Error";
            monitor.beginTask(message, IProgressMonitor.UNKNOWN);
            IWebAppBase<? extends AppServiceBaseEntity> deployTarget = null;
            Operation operation = TelemetryManager.createOperation(WEBAPP, DEPLOY_WEBAPP);
            try {
                operation.start();
                deployTarget = getRealWebApp(webApp, this, monitor, deploymentName);
                String sitePath = buildSiteLink(deployTarget, isDeployToRoot ? null : artifactName);
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, sitePath, 5, message);
                if (!MavenUtils.isMavenProject(project)) {
                    export(artifactName, artifactPath);
                }
                message = "Deploying Web App...";
                if (isDeployToSlot) {
                    message = "Deploying Web App to Slot...";
                }
                monitor.setTaskName(message);
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, sitePath, 30, message);
                AzureWebAppMvpModel.getInstance().deployArtifactsToWebApp(deployTarget, new File(artifactPath), isDeployToRoot, new UpdateProgressIndicator(monitor));
                if (monitor.isCanceled()) {
                    AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, null, -1, cancelMessage);
                    return Status.CANCEL_STATUS;
                }
                message = "Checking Web App availability...";
                monitor.setTaskName(message);
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, sitePath, 20, message);
                // to make warn up cancelable
                int stepLimit = 5;
                int sleepMs = 1000;
                CountDownLatch countDownLatch = new CountDownLatch(1);
                new Thread(() -> {
                    try {
                        for (int step = 0; step < stepLimit; ++step) {
                            if (monitor.isCanceled() || isUrlAccessible(sitePath)) {
                                // warm up
                                break;
                            }
                            Thread.sleep(sleepMs);
                        }
                    } catch (Exception ex) {
                        LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@Thread@run@ProgressDialog@deploy@AppServiceCreateDialog@SingInDialog", ex));
                    } finally {
                        countDownLatch.countDown();
                    }
                }).start();
                try {
                    countDownLatch.await();
                } catch (Exception ignore) {
                }
                if (monitor.isCanceled()) {
                    // it's published but not warmed up yet - consider as success
                    AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, sitePath, 100, successMessage);
                    return Status.CANCEL_STATUS;
                }
                monitor.done();
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, sitePath, 100, successMessage);
                AppInsightsClient.create("Deploy as WebApp", "", postEventProperties);
            } catch (Exception ex) {
                postEventProperties.put("PublishError", ex.getMessage());
                LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@deploy@AppServiceCreateDialog", ex));
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, null, -1, errorMessage);
                if (deployTarget != null) {
                    deployTarget.start();
                }
                Display.getDefault().asyncExec(() -> ErrorWindow.go(parentShell, ex.getMessage(), errTitle));
                EventUtil.logError(operation, ErrorType.systemError, ex, postEventProperties, null);
            } finally {
                EventUtil.logEvent(EventType.info, operation, postEventProperties);
                operation.complete();
            }
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) HashMap(java.util.HashMap) WebContainer(com.microsoft.azure.toolkit.lib.appservice.model.WebContainer) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) JavaVersion(com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion) CountDownLatch(java.util.concurrent.CountDownLatch) Point(org.eclipse.swt.graphics.Point) IOException(java.io.IOException) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Runtime(com.microsoft.azure.toolkit.lib.appservice.model.Runtime) UpdateProgressIndicator(com.microsoft.azuretools.core.utils.UpdateProgressIndicator) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File)

Example 20 with IWebApp

use of com.microsoft.azure.toolkit.lib.appservice.service.IWebApp in project azure-tools-for-java by Microsoft.

the class WebAppDeployDialog method createAppService.

private void createAppService(IProject project) {
    AppServiceCreateDialog d = AppServiceCreateDialog.go(getShell(), project);
    if (d == null) {
        // something went wrong - report an error!
        return;
    }
    IWebApp wa = d.getWebApp();
    doFillTable(true);
    selectTableRowWithWebAppName(wa.name());
    fillAppServiceDetails();
}
Also used : IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)

Aggregations

IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)24 Point (org.eclipse.swt.graphics.Point)8 IAppServicePlan (com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan)5 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)5 PrivateRegistryImageSetting (com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting)5 IWebAppDeploymentSlot (com.microsoft.azure.toolkit.lib.appservice.service.IWebAppDeploymentSlot)4 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)4 IOException (java.io.IOException)4 AzureAppService (com.microsoft.azure.toolkit.lib.appservice.AzureAppService)3 PricingTier (com.microsoft.azure.toolkit.lib.appservice.model.PricingTier)3 Region (com.microsoft.azure.toolkit.lib.common.model.Region)3 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)3 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)3 FileNotFoundException (java.io.FileNotFoundException)3 ISecureStore (com.microsoft.azure.toolkit.ide.common.store.ISecureStore)2 WebAppSettingModel (com.microsoft.azuretools.core.mvp.model.webapp.WebAppSettingModel)2 AzureUIRefreshEvent (com.microsoft.azuretools.utils.AzureUIRefreshEvent)2 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)2 DockerClient (com.spotify.docker.client.DockerClient)2 Path (java.nio.file.Path)2