Search in sources :

Example 1 with DeploymentEventListener

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

the class WindowsAzureActivityLogView method registerDeploymentListener.

public void registerDeploymentListener() {
    Activator.getDefault().addDeploymentEventListener(new DeploymentEventListener() {

        @Override
        public void onDeploymentStep(final DeploymentEventArgs args) {
            if (rows.containsKey(args.getId())) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        TableRowDescriptor row = rows.get(args.getId());
                        if (!row.getProgressBar().isDisposed()) {
                            if (args.getDeployCompleteness() >= 0) {
                                row.getProgressBar().setSelection(row.getProgressBar().getSelection() + args.getDeployCompleteness());
                                if (row.getProgressBar().getMaximum() <= (row.getProgressBar().getSelection())) {
                                    row.getProgressBar().setVisible(false);
                                    /*
												 * Need link only if args.getDeploymentURL() is not null.
												 */
                                    Link link = row.getLink();
                                    TableEditor editor = new TableEditor(table);
                                    editor.grabHorizontal = editor.grabVertical = true;
                                    if (args.getDeploymentURL() != null) {
                                        link.setVisible(true);
                                        // Published
                                        link.setText(String.format("  <a>%s</a>", Messages.runStatusVisible));
                                        //													link.setText(String.format("%s%s%s%s", "  ", "<a>", Messages.runStatusVisible, "</a>"));
                                        row.getLink().addSelectionListener(new SelectionAdapter() {

                                            @Override
                                            public void widgetSelected(SelectionEvent event) {
                                                try {
                                                    PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(args.getDeploymentURL()));
                                                } catch (Exception e) {
                                                }
                                            }
                                        });
                                        editor.setEditor(link, row.getItem(), 1);
                                    } else {
                                        link.setVisible(false);
                                    }
                                }
                            } else {
                                row.getProgressBar().setVisible(false);
                            // row.getProgressBar().dispose();
                            }
                            row.getItem().setText(2, args.getDeployMessage());
                        }
                    }
                });
            }
        }
    });
}
Also used : DeploymentEventArgs(com.microsoft.azuretools.azurecommons.deploy.DeploymentEventArgs) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DeploymentEventListener(com.microsoft.azuretools.azurecommons.deploy.DeploymentEventListener) TableEditor(org.eclipse.swt.custom.TableEditor) Link(org.eclipse.swt.widgets.Link) URL(java.net.URL)

Example 2 with DeploymentEventListener

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

the class DockerContainerDeployTask method run.

@Override
public void run(@NotNull final ProgressIndicator indicator) {
    openViews(project);
    AzurePlugin.removeUnNecessaryListener();
    DeploymentEventListener deployListnr = new DeploymentEventListener() {

        @Override
        public void onDeploymentStep(DeploymentEventArgs args) {
            indicator.setFraction(args.getDeployCompleteness() / 100.0);
            indicator.setText(AzureBundle.message("deployingToAzure"));
            indicator.setText2(args.toString());
        }
    };
    AzurePlugin.addDeploymentEventListener(deployListnr);
    AzurePlugin.depEveList.add(deployListnr);
    new AzureDeploymentProgressNotification(project).deployToDockerContainer(dockerImageInstance, url);
    new Thread("Warm up the target site") {

        public void run() {
            try {
                LOG.info("To warm the site up - implicitly trying to connect it");
                WebAppUtils.sendGet(url);
            } catch (Exception ex) {
                LOG.info(ex.getMessage(), ex);
            }
        }
    }.start();
}
Also used : DeploymentEventArgs(com.microsoft.azuretools.azurecommons.deploy.DeploymentEventArgs) AzureDeploymentProgressNotification(com.microsoft.intellij.deploy.AzureDeploymentProgressNotification) DeploymentEventListener(com.microsoft.azuretools.azurecommons.deploy.DeploymentEventListener)

Example 3 with DeploymentEventListener

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

the class AzureSelectDockerWizard method createDockerContainerDeployTask.

public void createDockerContainerDeployTask(IProject project, AzureDockerImageInstance dockerImageInstance, AzureDockerHostsManager dockerManager) {
    String url = AzureDockerUtils.getUrl(dockerImageInstance);
    String deploymentName = url;
    String jobDescription = String.format("Publishing %s as Docker Container", new File(dockerImageInstance.artifactPath).getName());
    AzureDeploymentProgressNotification.createAzureDeploymentProgressNotification(deploymentName, jobDescription);
    Map<String, String> postEventProperties = new HashMap<String, String>();
    postEventProperties.put("DockerFileOption", dockerImageInstance.predefinedDockerfile);
    Job createDockerHostJob = new Job(jobDescription) {

        @Override
        protected IStatus run(IProgressMonitor progressMonitor) {
            try {
                // Setup Azure Console and Azure Activity Log Window notifications
                MessageConsole console = com.microsoft.azuretools.core.Activator.findConsole(com.microsoft.azuretools.core.Activator.CONSOLE_NAME);
                console.activate();
                final MessageConsoleStream azureConsoleOut = console.newMessageStream();
                progressMonitor.beginTask("start task", 100);
                //		            com.microsoft.azuretools.core.Activator.removeUnNecessaryListener();
                DeploymentEventListener undeployListnr = new DeploymentEventListener() {

                    @Override
                    public void onDeploymentStep(DeploymentEventArgs args) {
                        progressMonitor.subTask(args.getDeployMessage());
                        progressMonitor.worked(args.getDeployCompleteness());
                        azureConsoleOut.println(String.format("%s: %s", deploymentName, args.getDeployMessage()));
                    }
                };
                com.microsoft.azuretools.core.Activator.getDefault().addDeploymentEventListener(undeployListnr);
                com.microsoft.azuretools.core.Activator.depEveList.add(undeployListnr);
                // Start the real job here
                String msg = String.format("Publishing %s to Docker host %s ...", new File(dockerImageInstance.artifactPath).getName(), dockerImageInstance.host.name);
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 0, msg);
                msg = "Connecting to Azure...";
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 5, msg);
                AzureManager azureAuthManager = AuthMethodManager.getInstance().getAzureManager();
                // not signed in
                if (azureAuthManager == null) {
                    throw new RuntimeException("User not signed in");
                }
                AzureDockerHostsManager dockerManager = AzureDockerHostsManager.getAzureDockerHostsManagerEmpty(azureAuthManager);
                Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerImageInstance.host.sid).azureClient;
                if (progressMonitor.isCanceled()) {
                    displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                    return Status.CANCEL_STATUS;
                }
                if (dockerImageInstance.hasNewDockerHost) {
                    msg = String.format("Creating new virtual machine %s ...", dockerImageInstance.host.name);
                    AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 20, msg);
                    AzureDockerUIResources.printDebugMessage(this, "Creating new virtual machine: " + new Date().toString());
                    AzureDockerVMOps.createDockerHostVM(azureClient, dockerImageInstance.host);
                    AzureDockerUIResources.printDebugMessage(this, "Done creating new virtual machine: " + new Date().toString());
                    if (progressMonitor.isCanceled()) {
                        displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                        return Status.CANCEL_STATUS;
                    }
                    msg = String.format("Updating Docker hosts ...");
                    AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 5, msg);
                    AzureDockerUIResources.printDebugMessage(this, "Getting the new docker host details: " + new Date().toString());
                    //			            dockerManager.refreshDockerHostDetails();
                    VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(dockerImageInstance.host.hostVM.resourceGroupName, dockerImageInstance.host.hostVM.name);
                    if (vm != null) {
                        DockerHost updatedHost = AzureDockerVMOps.getDockerHost(vm, dockerManager.getDockerVaultsMap());
                        if (updatedHost != null) {
                            dockerImageInstance.host.hostVM = updatedHost.hostVM;
                            dockerImageInstance.host.apiUrl = updatedHost.apiUrl;
                        }
                    }
                    AzureDockerUIResources.printDebugMessage(this, "Done getting new Docker host details: " + new Date().toString());
                    msg = String.format("Waiting for virtual machine to be up %s ...", dockerImageInstance.host.name);
                    AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 10, msg);
                    AzureDockerUIResources.printDebugMessage(this, "Waiting for virtual machine to be up: " + new Date().toString());
                    AzureDockerVMOps.waitForVirtualMachineStartup(azureClient, dockerImageInstance.host);
                    AzureDockerUIResources.printDebugMessage(this, "Done Waiting for virtual machine to be up: " + new Date().toString());
                    if (progressMonitor.isCanceled()) {
                        displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                        return Status.CANCEL_STATUS;
                    }
                    msg = String.format("Configuring Docker service for %s ...", dockerImageInstance.host.name);
                    AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 10, msg);
                    AzureDockerUIResources.printDebugMessage(this, "Configuring Docker host: " + new Date().toString());
                    AzureDockerVMOps.installDocker(dockerImageInstance.host);
                    AzureDockerUIResources.printDebugMessage(this, "Done configuring Docker host: " + new Date().toString());
                    msg = String.format("Updating Docker hosts ...");
                    AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 5, msg);
                    AzureDockerUIResources.printDebugMessage(this, "Refreshing docker hosts: " + new Date().toString());
                    //			            dockerManager.refreshDockerHostDetails();
                    vm = azureClient.virtualMachines().getByResourceGroup(dockerImageInstance.host.hostVM.resourceGroupName, dockerImageInstance.host.hostVM.name);
                    if (vm != null) {
                        DockerHost updatedHost = AzureDockerVMOps.getDockerHost(vm, dockerManager.getDockerVaultsMap());
                        if (updatedHost != null) {
                            updatedHost.sid = dockerImageInstance.host.sid;
                            updatedHost.hostVM.sid = dockerImageInstance.host.hostVM.sid;
                            if (updatedHost.certVault == null) {
                                updatedHost.certVault = dockerImageInstance.host.certVault;
                                updatedHost.hasPwdLogIn = dockerImageInstance.host.hasPwdLogIn;
                                updatedHost.hasSSHLogIn = dockerImageInstance.host.hasSSHLogIn;
                                updatedHost.isTLSSecured = dockerImageInstance.host.isTLSSecured;
                            }
                            dockerManager.addDockerHostDetails(updatedHost);
                            if (AzureUIRefreshCore.listeners != null) {
                                AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.ADD, updatedHost));
                            }
                        }
                    }
                    AzureDockerUIResources.printDebugMessage(this, "Done refreshing Docker hosts: " + new Date().toString());
                    AzureDockerUIResources.printDebugMessage(this, "Finished setting up Docker host");
                } else {
                    msg = String.format("Using virtual machine %s ...", dockerImageInstance.host.name);
                    AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 55, msg);
                }
                if (progressMonitor.isCanceled()) {
                    displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                    return Status.CANCEL_STATUS;
                }
                if (dockerImageInstance.host.session == null) {
                    AzureDockerUIResources.printDebugMessage(this, "Opening a remote connection to the Docker host: " + new Date().toString());
                    dockerImageInstance.host.session = AzureDockerSSHOps.createLoginInstance(dockerImageInstance.host);
                    AzureDockerUIResources.printDebugMessage(this, "Done opening a remote connection to the Docker host: " + new Date().toString());
                }
                if (dockerImageInstance.hasNewDockerHost) {
                    if (dockerImageInstance.host.certVault != null && dockerImageInstance.host.certVault.hostName != null) {
                        AzureDockerUIResources.createDockerKeyVault(dockerImageInstance.host, dockerManager);
                    }
                }
                msg = String.format("Uploading Dockerfile and artifact %s on %s ...", dockerImageInstance.artifactName, dockerImageInstance.host.name);
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 15, msg);
                AzureDockerUIResources.printDebugMessage(this, "Uploading Dockerfile and artifact: " + new Date().toString());
                AzureDockerVMOps.uploadDockerfileAndArtifact(dockerImageInstance, dockerImageInstance.host.session);
                AzureDockerUIResources.printDebugMessage(this, "Uploading Dockerfile and artifact: " + new Date().toString());
                if (progressMonitor.isCanceled()) {
                    displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                    return Status.CANCEL_STATUS;
                }
                msg = String.format("Creating Docker image %s on %s ...", dockerImageInstance.dockerImageName, dockerImageInstance.host.name);
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 15, msg);
                AzureDockerUIResources.printDebugMessage(this, "Creating a Docker image to the Docker host: " + new Date().toString());
                AzureDockerImageOps.create(dockerImageInstance, dockerImageInstance.host.session);
                AzureDockerUIResources.printDebugMessage(this, "Done creating a Docker image to the Docker host: " + new Date().toString());
                if (progressMonitor.isCanceled()) {
                    displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                    return Status.CANCEL_STATUS;
                }
                msg = String.format("Creating Docker container %s for image %s on %s ...", dockerImageInstance.dockerContainerName, dockerImageInstance.dockerImageName, dockerImageInstance.host.name);
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 5, msg);
                AzureDockerUIResources.printDebugMessage(this, "Creating a Docker container to the Docker host: " + new Date().toString());
                AzureDockerContainerOps.create(dockerImageInstance, dockerImageInstance.host.session);
                AzureDockerUIResources.printDebugMessage(this, "Done creating a Docker container to the Docker host: " + new Date().toString());
                if (progressMonitor.isCanceled()) {
                    displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                    return Status.CANCEL_STATUS;
                }
                msg = String.format("Starting Docker container %s for image %s on %s ...", dockerImageInstance.dockerContainerName, dockerImageInstance.dockerImageName, dockerImageInstance.host.name);
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 5, msg);
                AzureDockerUIResources.printDebugMessage(this, "Starting a Docker container to the Docker host: " + new Date().toString());
                AzureDockerContainerOps.start(dockerImageInstance, dockerImageInstance.host.session);
                AzureDockerUIResources.printDebugMessage(this, "Done starting a Docker container to the Docker host: " + new Date().toString());
                if (progressMonitor.isCanceled()) {
                    displayWarningOnCreateDockerContainerDeployTask(this, progressMonitor, deploymentName);
                    return Status.CANCEL_STATUS;
                }
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, url, 100, "");
                try {
                    com.microsoft.azuretools.core.Activator.depEveList.remove(undeployListnr);
                    com.microsoft.azuretools.core.Activator.removeDeploymentEventListener(undeployListnr);
                } catch (Exception ignored) {
                }
                progressMonitor.done();
                AppInsightsClient.create("Deploy as DockerContainer", "", postEventProperties);
                return Status.OK_STATUS;
            } catch (Exception e) {
                String msg = "An error occurred while attempting to publish a Docker container!" + "\n" + e.getMessage();
                log.log(Level.SEVERE, "createDockerContainerDeployTask: " + msg, e);
                e.printStackTrace();
                AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, null, -1, "Error: " + e.getMessage());
                return Status.CANCEL_STATUS;
            }
        }
    };
    createDockerHostJob.schedule();
}
Also used : Azure(com.microsoft.azure.management.Azure) MessageConsole(org.eclipse.ui.console.MessageConsole) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) HashMap(java.util.HashMap) DeploymentEventArgs(com.microsoft.azuretools.azurecommons.deploy.DeploymentEventArgs) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) Date(java.util.Date) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) DockerHost(com.microsoft.azure.docker.model.DockerHost) DeploymentEventListener(com.microsoft.azuretools.azurecommons.deploy.DeploymentEventListener) Job(org.eclipse.core.runtime.jobs.Job) AzureDockerHostsManager(com.microsoft.azure.docker.AzureDockerHostsManager) File(java.io.File) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Example 4 with DeploymentEventListener

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

the class ActivityLogToolWindowFactory method registerDeploymentListener.

public void registerDeploymentListener() {
    AzurePlugin.addDeploymentEventListener(new DeploymentEventListener() {

        @Override
        public void onDeploymentStep(final DeploymentEventArgs args) {
            // unique identifier for deployment
            String key = args.getId() + args.getStartTime().getTime();
            if (rows.containsKey(key)) {
                final DeploymentTableItem item = rows.get(key);
                ApplicationManager.getApplication().invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        item.progress = args.getDeployCompleteness();
                        if (args.getDeployMessage().equalsIgnoreCase(message("runStatus"))) {
                            String html = String.format("%s%s%s%s", "  ", "<html><a href=\"" + args.getDeploymentURL() + "\">", message("runStatusVisible"), "</a></html>");
                            item.description = message("runStatusVisible");
                            item.link = args.getDeploymentURL();
                            if (!ToolWindowManager.getInstance(project).getToolWindow(ActivityLogToolWindowFactory.ACTIVITY_LOG_WINDOW).isVisible()) {
                                ToolWindowManager.getInstance(project).notifyByBalloon(ACTIVITY_LOG_WINDOW, MessageType.INFO, html, null, new BrowserHyperlinkListener());
                            }
                        } else {
                            item.description = args.getDeployMessage();
                        }
                        table.getListTableModel().fireTableDataChanged();
                    }
                });
            } else {
                final DeploymentTableItem item = new DeploymentTableItem(args.getId(), args.getDeployMessage(), dateFormat.format(args.getStartTime()), args.getDeployCompleteness());
                rows.put(key, item);
                ApplicationManager.getApplication().invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        table.getListTableModel().addRow(item);
                    }
                });
            }
        }
    });
}
Also used : DeploymentEventArgs(com.microsoft.azuretools.azurecommons.deploy.DeploymentEventArgs) BrowserHyperlinkListener(com.intellij.ui.BrowserHyperlinkListener) DeploymentEventListener(com.microsoft.azuretools.azurecommons.deploy.DeploymentEventListener)

Aggregations

DeploymentEventArgs (com.microsoft.azuretools.azurecommons.deploy.DeploymentEventArgs)4 DeploymentEventListener (com.microsoft.azuretools.azurecommons.deploy.DeploymentEventListener)4 BrowserHyperlinkListener (com.intellij.ui.BrowserHyperlinkListener)1 AzureDockerHostsManager (com.microsoft.azure.docker.AzureDockerHostsManager)1 DockerHost (com.microsoft.azure.docker.model.DockerHost)1 EditableDockerHost (com.microsoft.azure.docker.model.EditableDockerHost)1 Azure (com.microsoft.azure.management.Azure)1 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)1 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)1 AzureUIRefreshEvent (com.microsoft.azuretools.utils.AzureUIRefreshEvent)1 AzureDeploymentProgressNotification (com.microsoft.intellij.deploy.AzureDeploymentProgressNotification)1 File (java.io.File)1 URL (java.net.URL)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 TableEditor (org.eclipse.swt.custom.TableEditor)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1