Search in sources :

Example 1 with UpdateProgressIndicator

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

the class WebAppDeployDialog method updateAndFillTable.

private void updateAndFillTable() {
    try {
        ProgressDialog.get(getShell(), "Update Azure Local Cache Progress").run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Updating Azure local cache...", IProgressMonitor.UNKNOWN);
                try {
                    if (monitor.isCanceled()) {
                        throw new CanceledByUserException();
                    }
                    AzureModelController.updateResourceGroupMaps(new UpdateProgressIndicator(monitor));
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            doFillTable();
                        }
                    });
                } catch (CanceledByUserException ex) {
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            System.out.println("updateAndFillTable(): Canceled by user");
                            cancelPressed();
                        }
                    });
                } catch (Exception ex) {
                    ex.printStackTrace();
                    LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@updateAndFillTable@AppServiceCreateDialog", ex));
                }
                monitor.done();
            }
        });
    } catch (InvocationTargetException | InterruptedException ex) {
        ex.printStackTrace();
        LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "updateAndFillTable@AppServiceCreateDialog", ex));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CanceledByUserException(com.microsoft.azuretools.utils.CanceledByUserException) UpdateProgressIndicator(com.microsoft.azuretools.core.utils.UpdateProgressIndicator) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CanceledByUserException(com.microsoft.azuretools.utils.CanceledByUserException) IOException(java.io.IOException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 2 with UpdateProgressIndicator

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

the class AppServiceCreateDialog method okPressed.

@Override
protected void okPressed() {
    if (validated()) {
        String errTitle = "Create App Service Error";
        try {
            ProgressDialog.get(this.getShell(), "Create App Service Progress").run(true, true, new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor) {
                    monitor.beginTask("Creating App Service....", IProgressMonitor.UNKNOWN);
                    if (monitor.isCanceled()) {
                        AzureModel.getInstance().setResourceGroupToWebAppMap(null);
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                AppServiceCreateDialog.super.cancelPressed();
                            }
                        });
                    }
                    try {
                        webApp = WebAppUtils.createAppService(new UpdateProgressIndicator(monitor), model);
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                AppServiceCreateDialog.super.okPressed();
                            }

                            ;
                        });
                    } catch (Exception ex) {
                        ex.printStackTrace();
                        LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@okPressed@AppServiceCreateDialog", ex));
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                ErrorWindow.go(getShell(), ex.getMessage(), errTitle);
                                ;
                            }
                        });
                    }
                }
            });
        } catch (InvocationTargetException | InterruptedException ex) {
            ex.printStackTrace();
            LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "okPressed@AppServiceCreateDialog", ex));
            ErrorWindow.go(getShell(), ex.getMessage(), errTitle);
            ;
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UpdateProgressIndicator(com.microsoft.azuretools.core.utils.UpdateProgressIndicator) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedURLException(java.net.MalformedURLException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 3 with UpdateProgressIndicator

use of com.microsoft.azuretools.core.utils.UpdateProgressIndicator 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);
    WebAppDetails wad = webAppDetailsMap.get(appServiceName);
    WebApp webApp = wad.webApp;
    boolean isDeployToRoot = btnDeployToRoot.getSelection();
    String errTitle = "Deploy Web App Error";
    String sitePath = buildSiteLink(wad.webApp, isDeployToRoot ? null : artifactName);
    //Map<String, String> threadParams = new HashMap<>();
    //threadParams.put("sitePath", sitePath);
    String jobDescription = String.format("Web App '%s' deployment", webApp.name());
    String deploymentName = UUID.randomUUID().toString();
    AzureDeploymentProgressNotification.createAzureDeploymentProgressNotification(deploymentName, jobDescription);
    Job job = new Job(jobDescription) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            String message = "Deploying Web App...";
            String cancelMessage = "Interrupted by user";
            String successMessage = "";
            String errorMessage = "Error";
            Map<String, String> postEventProperties = new HashMap<String, String>();
            postEventProperties.put("Java App Name", project.getName());
            monitor.beginTask(message, IProgressMonitor.UNKNOWN);
            try {
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, sitePath, 5, message);
                PublishingProfile pp = webApp.getPublishingProfile();
                WebAppUtils.deployArtifact(artifactName, artifactPath, pp, 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);
                //monitor.subTask("Link: " + sitePath);
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, sitePath, 75, message);
                // to make warn up cancelable
                int stepLimit = 5;
                int sleepMs = 1000;
                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 (IOException ex) {
                            ex.printStackTrace();
                            LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@Thread@run@ProgressDialog@deploy@AppServiceCreateDialog@SingInDialog", ex));
                        } catch (InterruptedException ex) {
                            System.out.println("The thread is interupted");
                        }
                    }
                });
                thread.start();
                while (thread.isAlive()) {
                    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;
                    } else
                        Thread.sleep(sleepMs);
                }
                monitor.done();
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, sitePath, 100, successMessage);
            } catch (IOException | InterruptedException ex) {
                //threadParams.put("sitePath", null);
                postEventProperties.put("PublishError", ex.getMessage());
                ex.printStackTrace();
                LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@deploy@AppServiceCreateDialog", ex));
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, null, -1, errorMessage);
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        ErrorWindow.go(parentShell, ex.getMessage(), errTitle);
                        ;
                    }
                });
            }
            AppInsightsClient.create("Deploy as WebApp", "", postEventProperties);
            return Status.OK_STATUS;
        }
    };
    job.schedule();
//        try {
//            ProgressDialog.get(this.getShell(), "Deploy Web App Progress").run(true, true, new IRunnableWithProgress() {
//                @Override
//                public void run(IProgressMonitor monitor) {
//                    monitor.beginTask("Deploying Web App...", IProgressMonitor.UNKNOWN);
//                    try {
//                        PublishingProfile pp = webApp.getPublishingProfile();
//                        WebAppUtils.deployArtifact(artifactName, artifactPath,
//                                pp, isDeployToRoot, new UpdateProgressIndicator(monitor));
//                        monitor.setTaskName("Checking Web App availability...");
//                        monitor.subTask("Link: " + sitePath);
//                        
//                        // to make warn up cancelable
//                        int stepLimit = 5;
//                        int sleepMs = 2000;
//                        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 (IOException | InterruptedException ex) {
//                                    ex.printStackTrace();
//                                    LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@Thread@run@ProgressDialog@deploy@AppServiceCreateDialog@SingInDialog", ex));
//                                }
//                            }
//                        });
//                        thread.run();
//                        while (thread.isAlive()) {
//                            if (monitor.isCanceled()) return;
//                            else Thread.sleep(sleepMs);
//                        }
//                        
//                        monitor.done();
//                    } catch (IOException | InterruptedException ex) {
//                        threadParams.put("sitePath", null);
//                        ex.printStackTrace();
//                        LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@deploy@AppServiceCreateDialog", ex));
//                        Display.getDefault().asyncExec(new Runnable() {
//                            @Override
//                            public void run() {
//                                ErrorWindow.go(parentShell, ex.getMessage(), errTitle);;
//                            }
//                        });
//                    }
//                }
//            });
//        } catch (InvocationTargetException | InterruptedException ex) {
//            threadParams.put("sitePath", null);
//            ex.printStackTrace();
//            LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "deploy@AppServiceCreateDialog", ex));
//            ErrorWindow.go(getShell(), ex.getMessage(), errTitle);;
//        }
//return threadParams.get("sitePath");
}
Also used : WebAppDetails(com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) HashMap(java.util.HashMap) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UpdateProgressIndicator(com.microsoft.azuretools.core.utils.UpdateProgressIndicator) Job(org.eclipse.core.runtime.jobs.Job) PublishingProfile(com.microsoft.azure.management.appservice.PublishingProfile) WebApp(com.microsoft.azure.management.appservice.WebApp)

Example 4 with UpdateProgressIndicator

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

the class AppServiceCreateDialog method updateAndFillSubscriptions.

private void updateAndFillSubscriptions() {
    try {
        ProgressDialog.get(this.getShell(), "Getting App Services...").run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) {
                monitor.beginTask("Updating Azure local cache...", IProgressMonitor.UNKNOWN);
                if (monitor.isCanceled()) {
                    AzureModel.getInstance().setResourceGroupToWebAppMap(null);
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            AppServiceCreateDialog.super.cancelPressed();
                        }
                    });
                }
                try {
                    AzureModelController.updateResourceGroupMaps(new UpdateProgressIndicator(monitor));
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            doFillSubscriptions();
                        }

                        ;
                    });
                } catch (Exception ex) {
                    ex.printStackTrace();
                    LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@updateAndFillSubscriptions@AppServiceCreateDialog", ex));
                }
            }
        });
    } catch (InvocationTargetException | InterruptedException ex) {
        ex.printStackTrace();
        LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "updateAndFillSubscriptions@AppServiceCreateDialog", ex));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UpdateProgressIndicator(com.microsoft.azuretools.core.utils.UpdateProgressIndicator) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedURLException(java.net.MalformedURLException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

UpdateProgressIndicator (com.microsoft.azuretools.core.utils.UpdateProgressIndicator)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IStatus (org.eclipse.core.runtime.IStatus)4 Status (org.eclipse.core.runtime.Status)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 PartInitException (org.eclipse.ui.PartInitException)2 PublishingProfile (com.microsoft.azure.management.appservice.PublishingProfile)1 WebApp (com.microsoft.azure.management.appservice.WebApp)1 CanceledByUserException (com.microsoft.azuretools.utils.CanceledByUserException)1 WebAppDetails (com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails)1 HashMap (java.util.HashMap)1 Job (org.eclipse.core.runtime.jobs.Job)1