Search in sources :

Example 1 with AzureDockerPreferredSettings

use of com.microsoft.azure.docker.model.AzureDockerPreferredSettings in project azure-tools-for-java by Microsoft.

the class AzureNewDockerWizardDialog method create.

public void create() {
    DockerHost dockerHost = model.getDockerHost();
    AzureDockerPreferredSettings dockerPreferredSettings = model.getDockerManager().getDockerPreferredSettings();
    if (dockerPreferredSettings == null) {
        dockerPreferredSettings = new AzureDockerPreferredSettings();
    }
    dockerPreferredSettings.dockerApiName = dockerHost.apiUrl;
    dockerPreferredSettings.region = dockerHost.hostVM.region;
    dockerPreferredSettings.vmSize = dockerHost.hostVM.vmSize;
    dockerPreferredSettings.vmOS = dockerHost.hostOSType.name();
    model.getDockerManager().setDockerPreferredSettings(dockerPreferredSettings);
    ProgressManager.getInstance().run(new Task.Backgroundable(model.getProject(), "Creating Docker Host on Azure...", true) {

        @Override
        public void run(ProgressIndicator progressIndicator) {
            try {
                progressIndicator.setFraction(.05);
                progressIndicator.setText2(String.format("Reading subscription details for Docker host %s ...", dockerHost.apiUrl));
                AzureDockerHostsManager dockerManager = model.getDockerManager();
                Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerHost.sid).azureClient;
                if (progressIndicator.isCanceled()) {
                    if (displayWarningOnCreateHostCancelAction() == 1) {
                        return;
                    }
                }
                progressIndicator.setFraction(.10);
                progressIndicator.setText2(String.format("Creating new virtual machine %s ...", dockerHost.name));
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Creating new virtual machine: " + new Date().toString());
                AzureDockerVMOps.createDockerHostVM(azureClient, dockerHost);
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Done creating new virtual machine: " + new Date().toString());
                if (progressIndicator.isCanceled()) {
                    if (displayWarningOnCreateHostCancelAction() == 1) {
                        return;
                    }
                }
                progressIndicator.setFraction(.60);
                progressIndicator.setIndeterminate(true);
                progressIndicator.setText2("Getting the new Docker virtual machines details...");
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Getting the new Docker virtual machines details: " + new Date().toString());
                // dockerManager.refreshDockerHostDetails();
                VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name);
                if (vm != null) {
                    DockerHost updatedHost = AzureDockerVMOps.getDockerHost(vm, dockerManager.getDockerVaultsMap());
                    if (updatedHost != null) {
                        dockerHost.hostVM = updatedHost.hostVM;
                        dockerHost.apiUrl = updatedHost.apiUrl;
                    }
                }
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Done getting the new Docker virtual machines details: " + new Date().toString());
                if (progressIndicator.isCanceled()) {
                    if (displayWarningOnCreateHostCancelAction() == 1) {
                        return;
                    }
                }
                progressIndicator.setFraction(.65);
                progressIndicator.setText2(String.format("Waiting for virtual machine %s to be up...", dockerHost.name));
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Waiting for virtual machine to be up: " + new Date().toString());
                AzureDockerVMOps.waitForVirtualMachineStartup(azureClient, dockerHost);
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Done Waiting for virtual machine to be up: " + new Date().toString());
                if (progressIndicator.isCanceled()) {
                    if (displayWarningOnCreateHostCancelAction() == 1) {
                        return;
                    }
                }
                progressIndicator.setFraction(.75);
                progressIndicator.setText2(String.format("Configuring Docker service for %s ...", dockerHost.apiUrl));
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Configuring Docker host: " + new Date().toString());
                AzureDockerVMOps.installDocker(dockerHost);
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Done configuring Docker host: " + new Date().toString());
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Finished setting up Docker host");
                if (progressIndicator.isCanceled()) {
                    if (displayWarningOnCreateHostCancelAction() == 1) {
                        return;
                    }
                }
                if (dockerHost.certVault != null && dockerHost.certVault.hostName != null) {
                    AzureDockerUIResources.createDockerKeyVault(model.getProject(), dockerHost, dockerManager);
                }
                progressIndicator.setFraction(.90);
                progressIndicator.setIndeterminate(true);
                progressIndicator.setText2("Refreshing the Docker virtual machines details...");
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Refreshing Docker hosts details: " + new Date().toString());
                // dockerManager.refreshDockerHostDetails();
                vm = azureClient.virtualMachines().getByResourceGroup(dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name);
                if (vm != null) {
                    DockerHost updatedHost = AzureDockerVMOps.getDockerHost(vm, dockerManager.getDockerVaultsMap());
                    if (updatedHost != null) {
                        updatedHost.sid = dockerHost.sid;
                        updatedHost.hostVM.sid = dockerHost.hostVM.sid;
                        if (updatedHost.certVault == null) {
                            updatedHost.certVault = dockerHost.certVault;
                            updatedHost.hasPwdLogIn = dockerHost.hasPwdLogIn;
                            updatedHost.hasSSHLogIn = dockerHost.hasSSHLogIn;
                            updatedHost.isTLSSecured = dockerHost.isTLSSecured;
                        }
                        dockerManager.addDockerHostDetails(updatedHost);
                        if (AzureUIRefreshCore.listeners != null) {
                            AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.ADD, updatedHost));
                        }
                    }
                }
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Done refreshing Docker hosts details: " + new Date().toString());
                if (progressIndicator.isCanceled()) {
                    if (displayWarningOnCreateHostCancelAction() == 1) {
                        return;
                    }
                }
                progressIndicator.setFraction(1);
                progressIndicator.setIndeterminate(true);
            } catch (Exception e) {
                String msg = "An error occurred while attempting to create Docker host." + "\n" + e.getMessage();
                LOGGER.error("Failed to Create Docker Host", e);
                PluginUtil.displayErrorDialogInAWTAndLog("Failed to Create Docker Host", msg, e);
            }
        }
    });
}
Also used : Task(com.intellij.openapi.progress.Task) Azure(com.microsoft.azure.management.Azure) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) AzureDockerPreferredSettings(com.microsoft.azure.docker.model.AzureDockerPreferredSettings) Date(java.util.Date) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DockerHost(com.microsoft.azure.docker.model.DockerHost) AzureDockerHostsManager(com.microsoft.azure.docker.AzureDockerHostsManager) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Example 2 with AzureDockerPreferredSettings

use of com.microsoft.azure.docker.model.AzureDockerPreferredSettings in project azure-tools-for-java by Microsoft.

the class AzureSelectDockerWizard method deploy.

public String deploy() {
    AzureDockerPreferredSettings dockerPreferredSettings = dockerManager.getDockerPreferredSettings();
    if (dockerPreferredSettings == null) {
        dockerPreferredSettings = new AzureDockerPreferredSettings();
    }
    dockerPreferredSettings.dockerApiName = dockerImageDescription.host.apiUrl;
    dockerPreferredSettings.dockerfileOption = dockerImageDescription.predefinedDockerfile;
    dockerPreferredSettings.region = dockerImageDescription.host.hostVM.region;
    dockerPreferredSettings.vmSize = dockerImageDescription.host.hostVM.vmSize;
    dockerPreferredSettings.vmOS = dockerImageDescription.host.hostOSType.name();
    dockerManager.setDockerPreferredSettings(dockerPreferredSettings);
    DefaultLoader.getIdeHelper().runInBackground(project, "Deploying Docker Container on Azure", false, true, "Deploying Web app to a Docker host on Azure...", new Runnable() {

        @Override
        public void run() {
            try {
                DefaultLoader.getIdeHelper().invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        if (!dockerImageDescription.hasNewDockerHost) {
                            Session session = null;
                            do {
                                try {
                                    // check if the Docker host is accessible
                                    session = AzureDockerSSHOps.createLoginInstance(dockerImageDescription.host);
                                } catch (Exception e) {
                                    session = null;
                                }
                                if (session == null) {
                                    EditableDockerHost editableDockerHost = new EditableDockerHost(dockerImageDescription.host);
                                    AzureInputDockerLoginCredsDialog loginCredsDialog = new AzureInputDockerLoginCredsDialog(PluginUtil.getParentShell(), project, editableDockerHost, dockerManager, false);
                                    if (loginCredsDialog.open() == Window.OK) {
                                        // Update Docker host log in credentials
                                        dockerImageDescription.host.certVault = editableDockerHost.updatedDockerHost.certVault;
                                        dockerImageDescription.host.hasSSHLogIn = editableDockerHost.updatedDockerHost.hasSSHLogIn;
                                        dockerImageDescription.host.hasPwdLogIn = editableDockerHost.updatedDockerHost.hasPwdLogIn;
                                    //											AzureDockerVMOps.updateDockerHostVM(dockerManager.getSubscriptionsMap().get(dockerImageDescription.sid).azureClient, editableDockerHost.updatedDockerHost);
                                    } else {
                                        return;
                                    }
                                }
                            } while (session == null);
                        }
                        //							Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerImageDescription.sid).azureClient;
                        //							DockerContainerDeployTask task = new DockerContainerDeployTask(project, azureClient, dockerImageDescription);
                        //							task.queue();
                        createDockerContainerDeployTask(project, dockerImageDescription, dockerManager);
                    }
                });
            } catch (Exception e) {
                String msg = "An error occurred while attempting to deploy to the selected Docker host." + "\n" + e.getMessage();
                PluginUtil.displayErrorDialogWithAzureMsg(PluginUtil.getParentShell(), "Failed to Deploy Web App as Docker Container", msg, e);
            }
        }
    });
    return AzureDockerUtils.getUrl(dockerImageDescription);
}
Also used : AzureInputDockerLoginCredsDialog(com.microsoft.azuretools.docker.ui.dialogs.AzureInputDockerLoginCredsDialog) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) AzureDockerPreferredSettings(com.microsoft.azure.docker.model.AzureDockerPreferredSettings) Session(com.jcraft.jsch.Session)

Example 3 with AzureDockerPreferredSettings

use of com.microsoft.azure.docker.model.AzureDockerPreferredSettings in project azure-tools-for-java by Microsoft.

the class AzureNewDockerWizard method createHost.

public void createHost() {
    AzureDockerPreferredSettings dockerPreferredSettings = dockerManager.getDockerPreferredSettings();
    if (dockerPreferredSettings == null) {
        dockerPreferredSettings = new AzureDockerPreferredSettings();
    }
    dockerPreferredSettings.dockerApiName = newHost.apiUrl;
    dockerPreferredSettings.region = newHost.hostVM.region;
    dockerPreferredSettings.vmSize = newHost.hostVM.vmSize;
    dockerPreferredSettings.vmOS = newHost.hostOSType.name();
    dockerManager.setDockerPreferredSettings(dockerPreferredSettings);
    Job createDockerHostJob = new Job("Creating Docker virtual machine " + newHost.name) {

        @Override
        protected IStatus run(IProgressMonitor progressMonitor) {
            progressMonitor.beginTask("start task", 100);
            try {
                DockerHost dockerHost = newHost;
                progressMonitor.subTask(String.format("Reading subscription details for Docker host %s ...", dockerHost.apiUrl));
                progressMonitor.worked(5);
                Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerHost.sid).azureClient;
                if (progressMonitor.isCanceled()) {
                    if (displayWarningOnCreateHostCancelAction() == 0) {
                        progressMonitor.done();
                        return Status.CANCEL_STATUS;
                    }
                }
                progressMonitor.subTask(String.format("Creating new virtual machine %s ...", dockerHost.name));
                progressMonitor.worked(10);
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Creating new virtual machine: " + new Date().toString());
                AzureDockerVMOps.createDockerHostVM(azureClient, dockerHost);
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Done creating new virtual machine: " + new Date().toString());
                if (progressMonitor.isCanceled()) {
                    if (displayWarningOnCreateHostCancelAction() == 0) {
                        progressMonitor.done();
                        return Status.CANCEL_STATUS;
                    }
                }
                progressMonitor.subTask("Getting the new Docker virtual machines details...");
                progressMonitor.worked(5);
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Getting the new Docker hosts details: " + new Date().toString());
                VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name);
                if (vm != null) {
                    DockerHost updatedHost = AzureDockerVMOps.getDockerHost(vm, dockerManager.getDockerVaultsMap());
                    if (updatedHost != null) {
                        dockerHost.hostVM = updatedHost.hostVM;
                        dockerHost.apiUrl = updatedHost.apiUrl;
                    }
                }
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Done getting the new Docker hosts details: " + new Date().toString());
                if (progressMonitor.isCanceled()) {
                    if (displayWarningOnCreateHostCancelAction() == 0) {
                        progressMonitor.done();
                        return Status.CANCEL_STATUS;
                    }
                }
                progressMonitor.subTask(String.format("Waiting for virtual machine %s to be up...", dockerHost.name));
                progressMonitor.worked(55);
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Waiting for virtual machine to be up: " + new Date().toString());
                AzureDockerVMOps.waitForVirtualMachineStartup(azureClient, dockerHost);
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Done Waiting for virtual machine to be up: " + new Date().toString());
                if (progressMonitor.isCanceled()) {
                    if (displayWarningOnCreateHostCancelAction() == 0) {
                        progressMonitor.done();
                        return Status.CANCEL_STATUS;
                    }
                }
                progressMonitor.subTask(String.format("Configuring Docker service for %s ...", dockerHost.apiUrl));
                progressMonitor.worked(15);
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Configuring Docker host: " + new Date().toString());
                AzureDockerVMOps.installDocker(dockerHost);
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Done configuring Docker host: " + new Date().toString());
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Finished setting up Docker host");
                if (progressMonitor.isCanceled()) {
                    if (displayWarningOnCreateHostCancelAction() == 0) {
                        progressMonitor.done();
                        return Status.CANCEL_STATUS;
                    }
                }
                if (dockerHost.certVault != null && dockerHost.certVault.hostName != null) {
                    AzureDockerUIResources.createDockerKeyVault(dockerHost, dockerManager);
                }
                progressMonitor.subTask("Refreshing the Docker virtual machines details...");
                progressMonitor.worked(5);
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Refreshing Docker hosts details: " + new Date().toString());
                vm = azureClient.virtualMachines().getByResourceGroup(dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name);
                if (vm != null) {
                    DockerHost updatedHost = AzureDockerVMOps.getDockerHost(vm, dockerManager.getDockerVaultsMap());
                    if (updatedHost != null) {
                        updatedHost.sid = dockerHost.sid;
                        updatedHost.hostVM.sid = dockerHost.hostVM.sid;
                        if (updatedHost.certVault == null) {
                            updatedHost.certVault = dockerHost.certVault;
                            updatedHost.hasPwdLogIn = dockerHost.hasPwdLogIn;
                            updatedHost.hasSSHLogIn = dockerHost.hasSSHLogIn;
                            updatedHost.isTLSSecured = dockerHost.isTLSSecured;
                        }
                        dockerManager.addDockerHostDetails(updatedHost);
                        if (AzureUIRefreshCore.listeners != null) {
                            AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.ADD, updatedHost));
                        }
                    }
                }
                if (AzureDockerUtils.DEBUG)
                    System.out.println("Done refreshing Docker hosts details: " + new Date().toString());
                if (progressMonitor.isCanceled()) {
                    if (displayWarningOnCreateHostCancelAction() == 0) {
                        progressMonitor.done();
                        return Status.CANCEL_STATUS;
                    }
                }
                progressMonitor.done();
                return Status.OK_STATUS;
            } catch (Exception e) {
                String msg = "An error occurred while attempting to create Docker host." + "\n" + e.getMessage();
                log.log(Level.SEVERE, "createHost: " + msg, e);
                e.printStackTrace();
                return Status.CANCEL_STATUS;
            }
        //				progressMonitor.subTask("");
        //				progressMonitor.worked(1);
        //				if (progressMonitor.isCanceled()) {
        //					if (displayWarningOnCreateHostCancelAction() == 0) {
        //						progressMonitor.done();
        //						return Status.CANCEL_STATUS;
        //					}
        //				}
        //
        //				for (int i = 0; i < 10; i++) {
        //					try {
        //						Thread.sleep(3000);
        //						progressMonitor.subTask("doing " + i);
        //						// Report that 10 units are done
        //						progressMonitor.worked(10);
        //					} catch (InterruptedException e1) {
        //						e1.printStackTrace();
        //					}
        //				}
        }
    };
    createDockerHostJob.schedule();
//    	DefaultLoader.getIdeHelper().runInBackground(null, "Creating Docker virtual machine " + newHost.name + "...", false, true, "Creating Docker virtual machine " + newHost.name + "...", new Runnable() {
//            @Override
//            public void run() {
//                DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
//                    @Override
//                    public void run() {
//                    	
//                    }
//                });
//            }
//        });
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Azure(com.microsoft.azure.management.Azure) DockerHost(com.microsoft.azure.docker.model.DockerHost) Job(org.eclipse.core.runtime.jobs.Job) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) AzureDockerPreferredSettings(com.microsoft.azure.docker.model.AzureDockerPreferredSettings) Date(java.util.Date) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Example 4 with AzureDockerPreferredSettings

use of com.microsoft.azure.docker.model.AzureDockerPreferredSettings in project azure-tools-for-java by Microsoft.

the class AzureSelectDockerHostPage method initUIMainContainer.

private void initUIMainContainer(Composite mainContainer) {
    dockerImageNameTextField.setText(dockerImageDescription.dockerImageName);
    dockerImageNameTextField.setToolTipText(AzureDockerValidationUtils.getDockerImageNameTip());
    dockerImageNameTextField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerImageName(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerImageNameTextField", dockerImageNameTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerImageNameTextField", AzureDockerValidationUtils.getDockerImageNameTip(), null, IMessageProvider.ERROR, dockerImageNameTextField);
                setErrorMessage("Invalid Docker image name");
                setPageComplete(false);
            }
        }
    });
    String artifactPath;
    if (project != null) {
        try {
            String projectName = project.getName();
            artifactPath = project.getLocation() + "/" + projectName + ".war";
        } catch (Exception ignored) {
            artifactPath = "";
        }
    } else {
        artifactPath = "";
    }
    if (artifactPath == null || artifactPath.isEmpty() || !Files.isRegularFile(Paths.get(artifactPath))) {
        errDispatcher.addMessage("dockerArtifactPathTextField", AzureDockerValidationUtils.getDockerArtifactPathTip(), null, IMessageProvider.ERROR, dockerArtifactPathTextField);
        setErrorMessage("Invalid artifact path");
    } else {
        dockerArtifactPathTextField.setText(artifactPath);
    }
    dockerArtifactPathTextField.setToolTipText(AzureDockerValidationUtils.getDockerArtifactPathTip());
    dockerArtifactPathTextField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerArtifactPath(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerArtifactPathTextField", dockerArtifactPathTextField);
                String artifactFileName = new File(((Text) event.getSource()).getText()).getName();
                wizard.setPredefinedDockerfileOptions(artifactFileName);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerArtifactPathTextField", AzureDockerValidationUtils.getDockerArtifactPathTip(), null, IMessageProvider.ERROR, dockerArtifactPathTextField);
                setErrorMessage("Invalid artifact path");
                setPageComplete(false);
            }
        }
    });
    dockerArtifactPathBrowseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fileDialog = new FileDialog(dockerArtifactPathBrowseButton.getShell(), SWT.OPEN);
            fileDialog.setText("Select Artifact .WAR or .JAR");
            fileDialog.setFilterPath(System.getProperty("user.home"));
            fileDialog.setFilterExtensions(new String[] { "*.war;*.jar", "*.jar", "*.*" });
            String path = fileDialog.open();
            if (path == null || (!path.toLowerCase().contains(".war") && !path.toLowerCase().contains(".jar"))) {
                return;
            }
            dockerArtifactPathTextField.setText(path);
            String artifactFileName = new File(path).getName();
            wizard.setPredefinedDockerfileOptions(artifactFileName);
            setPageComplete(doValidate());
        }
    });
    TableViewerColumn colHostName = createTableViewerColumn(dockerHostsTableViewer, "Name", 150, 1);
    colHostName.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((DockerHost) element).name;
        }
    });
    TableViewerColumn colHostState = createTableViewerColumn(dockerHostsTableViewer, "State", 80, 2);
    colHostState.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            DockerHost dockerHost = (DockerHost) element;
            return dockerHost.hostVM.state != null ? dockerHost.hostVM.state.toString() : "TO_BE_CREATED";
        }
    });
    TableViewerColumn colHostOS = createTableViewerColumn(dockerHostsTableViewer, "OS", 200, 3);
    colHostOS.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((DockerHost) element).hostOSType.toString();
        }
    });
    TableViewerColumn colHostApiUrl = createTableViewerColumn(dockerHostsTableViewer, "API URL", 250, 4);
    colHostApiUrl.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((DockerHost) element).apiUrl.toString();
        }
    });
    dockerHostsTableViewer.setContentProvider(new ArrayContentProvider());
    dockerHostsList = new ArrayList<>();
    dockerHostsTableViewer.setInput(dockerHostsList);
    refreshDockerHostsTable(mainContainer);
    if (!dockerHostsList.isEmpty()) {
        if (dockerHostsTableSelection == null) {
            dockerHostsTable.select(0);
            dockerHostsTable.getItem(0).setChecked(true);
            dockerHostsTableSelection = new DockerHostsTableSelection();
            dockerHostsTableSelection.row = 0;
            dockerHostsTableSelection.host = (DockerHost) dockerHostsTable.getItem(0).getData();
        } else {
            dockerHostsTable.select(dockerHostsTableSelection.row);
            dockerHostsTable.getItem(dockerHostsTableSelection.row).setChecked(true);
        }
    } else {
        dockerHostsTableSelection = null;
        setPageComplete(false);
    }
    dockerHostsTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.detail == SWT.CHECK) {
                DockerHost dockerHost = (DockerHost) ((TableItem) e.item).getData();
                if (dockerHostsTableSelection == null || dockerHostsTableSelection.host != dockerHost) {
                    dockerHostsTableSelection = new DockerHostsTableSelection();
                    dockerHostsTableSelection.row = dockerHostsTable.indexOf((TableItem) e.item);
                    dockerHostsTableSelection.host = dockerHost;
                    for (TableItem tableItem : dockerHostsTable.getItems()) {
                        if (tableItem != ((TableItem) e.item) && tableItem.getChecked()) {
                            tableItem.setChecked(false);
                        }
                    }
                    dockerHostsTable.redraw();
                } else {
                    dockerHostsTableSelection = null;
                }
                setPageComplete(doValidate());
            }
        }
    });
    dockerHostsRefreshButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            AzureDockerUIResources.updateAzureResourcesWithProgressDialog(mainContainer.getShell(), project);
            refreshDockerHostsTable(mainContainer);
            setPageComplete(doValidate());
            sendButtonClickedTelemetry(REFRESH);
        }
    });
    dockerHostsViewButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int idx = dockerHostsTable.getSelectionIndex();
            if (idx >= 0 && dockerHostsTable.getItem(idx) != null) {
                DockerHost dockerHost = (DockerHost) dockerHostsTable.getItem(dockerHostsTable.getSelectionIndex()).getData();
                if (dockerHost != null) {
                    AzureViewDockerDialog viewDockerDialog = new AzureViewDockerDialog(mainContainer.getShell(), project, dockerHost, dockerManager);
                    viewDockerDialog.open();
                    if (viewDockerDialog.getInternalExitCode() == AzureViewDockerDialog.UPDATE_EXIT_CODE) {
                        if (dockerHost != null && !dockerHost.isUpdating) {
                            AzureDockerUIResources.updateDockerHost(PluginUtil.getParentShell(), project, new EditableDockerHost(dockerHost), dockerManager, true);
                        } else {
                            PluginUtil.displayErrorDialog(mainContainer.getShell(), "Error: Invalid Edit Selection", "The selected Docker host can not be edited at this time!");
                        }
                    }
                    setPageComplete(doValidate());
                }
            }
            sendButtonClickedTelemetry(VIEW);
        }
    });
    dockerHostsAddButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            AzureNewDockerWizard newDockerWizard = new AzureNewDockerWizard(project, dockerManager);
            WizardDialog createNewDockerHostDialog = new AzureWizardDialog(mainContainer.getShell(), newDockerWizard);
            if (createNewDockerHostDialog.open() == Window.OK) {
                DockerHost host = newDockerWizard.getDockerHost();
                dockerImageDescription.host = host;
                dockerImageDescription.hasNewDockerHost = true;
                dockerImageDescription.sid = host.sid;
                AzureDockerPreferredSettings dockerPrefferedSettings = dockerManager.getDockerPreferredSettings();
                if (dockerPrefferedSettings == null) {
                    dockerPrefferedSettings = new AzureDockerPreferredSettings();
                }
                dockerPrefferedSettings.region = host.hostVM.region;
                dockerPrefferedSettings.vmSize = host.hostVM.vmSize;
                dockerPrefferedSettings.vmOS = host.hostOSType.name();
                dockerManager.setDockerPreferredSettings(dockerPrefferedSettings);
                dockerHostsList.add(0, host);
                dockerHostsTable.setEnabled(false);
                dockerHostsRefreshButton.setEnabled(false);
                dockerHostsAddButton.setEnabled(false);
                dockerHostsDeleteButton.setEnabled(false);
                dockerHostsEditButton.setEnabled(false);
                dockerHostsTableViewer.refresh();
                dockerHostsTable.getItem(0).setChecked(true);
                dockerHostsTable.select(0);
            }
            setPageComplete(doValidate());
            sendButtonClickedTelemetry(ADD);
        }
    });
    dockerHostsDeleteButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            //dockerHostsList
            int idx = dockerHostsTable.getSelectionIndex();
            if (idx >= 0 && dockerHostsTable.getItem(idx) != null) {
                DockerHost deleteHost = (DockerHost) dockerHostsTable.getItem(idx).getData();
                if (deleteHost != null) {
                    Azure azureClient = dockerManager.getSubscriptionsMap().get(deleteHost.sid).azureClient;
                    int option = AzureDockerUIResources.deleteAzureDockerHostConfirmationDialog(mainContainer.getShell(), azureClient, deleteHost);
                    if (option != 1 && option != 2) {
                        if (AzureDockerUtils.DEBUG)
                            System.out.format("User canceled delete Docker host op: %d\n", option);
                        return;
                    }
                    dockerHostsList.remove(deleteHost);
                    if (dockerHostsTableSelection != null && dockerHostsTableSelection.row == idx) {
                        dockerHostsTableSelection = null;
                    }
                    dockerHostsTableViewer.refresh();
                    AzureDockerUIResources.deleteDockerHost(mainContainer.getShell(), project, azureClient, deleteHost, option, new Runnable() {

                        @Override
                        public void run() {
                            dockerManager.getDockerHostsList().remove(deleteHost);
                            dockerManager.refreshDockerHostDetails();
                            DefaultLoader.getIdeHelper().invokeLater(new Runnable() {

                                @Override
                                public void run() {
                                    refreshDockerHostsTable(mainContainer);
                                }
                            });
                        }
                    });
                }
                setPageComplete(doValidate());
            }
            sendButtonClickedTelemetry(DELETE);
        }
    });
    dockerHostsEditButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int idx = dockerHostsTable.getSelectionIndex();
            if (idx >= 0 && dockerHostsTable.getItem(idx) != null) {
                DockerHost updateHost = (DockerHost) dockerHostsTable.getItem(idx).getData();
                if (updateHost != null && !updateHost.isUpdating) {
                    AzureDockerUIResources.updateDockerHost(PluginUtil.getParentShell(), project, new EditableDockerHost(updateHost), dockerManager, true);
                } else {
                    PluginUtil.displayErrorDialog(mainContainer.getShell(), "Error: Invalid Edit Selection", "The selected Docker host can not be edited at this time!");
                }
            }
            setPageComplete(doValidate());
            sendButtonClickedTelemetry(EDIT);
        }
    });
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) TableItem(org.eclipse.swt.widgets.TableItem) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ModifyEvent(org.eclipse.swt.events.ModifyEvent) AzureWizardDialog(com.microsoft.azuretools.core.components.AzureWizardDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Azure(com.microsoft.azure.management.Azure) AzureNewDockerWizard(com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerWizard) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) AzureDockerPreferredSettings(com.microsoft.azure.docker.model.AzureDockerPreferredSettings) AzureViewDockerDialog(com.microsoft.azuretools.docker.ui.dialogs.AzureViewDockerDialog) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) DockerHost(com.microsoft.azure.docker.model.DockerHost) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) AzureWizardDialog(com.microsoft.azuretools.core.components.AzureWizardDialog)

Example 5 with AzureDockerPreferredSettings

use of com.microsoft.azure.docker.model.AzureDockerPreferredSettings in project azure-tools-for-java by Microsoft.

the class AzureSelectDockerHostStep method onAddNewDockerHostAction.

private void onAddNewDockerHostAction() {
    AppInsightsClient.createByType(AppInsightsClient.EventType.DockerHost, "", "Add");
    AzureNewDockerWizardModel newDockerHostModel = new AzureNewDockerWizardModel(model.getProject(), dockerManager);
    AzureNewDockerWizardDialog wizard = new AzureNewDockerWizardDialog(newDockerHostModel);
    wizard.setTitle("Create Docker Host");
    wizard.show();
    if (wizard.getExitCode() == 0) {
        dockerHostsTable.setEnabled(false);
        DockerHost host = newDockerHostModel.getDockerHost();
        dockerImageDescription.host = host;
        dockerImageDescription.hasNewDockerHost = true;
        dockerImageDescription.sid = host.sid;
        model.setSubscription(this.dockerManager.getSubscriptionsMap().get(host.sid));
        AzureDockerPreferredSettings dockerPrefferedSettings = dockerManager.getDockerPreferredSettings();
        if (dockerPrefferedSettings == null) {
            dockerPrefferedSettings = new AzureDockerPreferredSettings();
        }
        dockerPrefferedSettings.region = host.hostVM.region;
        dockerPrefferedSettings.vmSize = host.hostVM.vmSize;
        dockerPrefferedSettings.vmOS = host.hostOSType.name();
        dockerManager.setDockerPreferredSettings(dockerPrefferedSettings);
        final DefaultTableModel tableModel = (DefaultTableModel) dockerHostsTable.getModel();
        if (dockerHostsTableSelection != null && (Boolean) tableModel.getValueAt(dockerHostsTableSelection.row, 0)) {
            tableModel.setValueAt(false, dockerHostsTableSelection.row, 0);
        }
        Vector<Object> row = new Vector<>();
        row.add(false);
        row.add(host.name);
        row.add("TO_BE_CREATED");
        row.add(host.hostOSType.toString());
        row.add(host.apiUrl);
        tableModel.insertRow(0, row);
        tableModel.setValueAt(true, 0, 0);
        dockerHostsTable.setRowSelectionInterval(0, 0);
        setFinishButtonState(doValidate(false) == null);
        setNextButtonState(doValidate(false) == null);
    }
}
Also used : AzureNewDockerWizardDialog(com.microsoft.intellij.docker.wizards.createhost.AzureNewDockerWizardDialog) DockerHost(com.microsoft.azure.docker.model.DockerHost) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) DefaultTableModel(javax.swing.table.DefaultTableModel) AzureNewDockerWizardModel(com.microsoft.intellij.docker.wizards.createhost.AzureNewDockerWizardModel) Vector(java.util.Vector) AzureDockerPreferredSettings(com.microsoft.azure.docker.model.AzureDockerPreferredSettings)

Aggregations

AzureDockerPreferredSettings (com.microsoft.azure.docker.model.AzureDockerPreferredSettings)6 DockerHost (com.microsoft.azure.docker.model.DockerHost)5 EditableDockerHost (com.microsoft.azure.docker.model.EditableDockerHost)4 Azure (com.microsoft.azure.management.Azure)4 Session (com.jcraft.jsch.Session)2 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)2 AzureUIRefreshEvent (com.microsoft.azuretools.utils.AzureUIRefreshEvent)2 Date (java.util.Date)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 AzureDockerHostsManager (com.microsoft.azure.docker.AzureDockerHostsManager)1 AzureDockerImageInstance (com.microsoft.azure.docker.model.AzureDockerImageInstance)1 AzureWizardDialog (com.microsoft.azuretools.core.components.AzureWizardDialog)1 AzureInputDockerLoginCredsDialog (com.microsoft.azuretools.docker.ui.dialogs.AzureInputDockerLoginCredsDialog)1 AzureViewDockerDialog (com.microsoft.azuretools.docker.ui.dialogs.AzureViewDockerDialog)1 AzureNewDockerWizard (com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerWizard)1 AzureInputDockerLoginCredsDialog (com.microsoft.intellij.docker.dialogs.AzureInputDockerLoginCredsDialog)1 AzureNewDockerWizardDialog (com.microsoft.intellij.docker.wizards.createhost.AzureNewDockerWizardDialog)1 AzureNewDockerWizardModel (com.microsoft.intellij.docker.wizards.createhost.AzureNewDockerWizardModel)1 DockerContainerDeployTask (com.microsoft.tasks.DockerContainerDeployTask)1