Search in sources :

Example 16 with DockerHost

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

the class AzureSelectDockerHostStep method onEditDockerHostAction.

private void onEditDockerHostAction() {
    try {
        DefaultTableModel tableModel = (DefaultTableModel) dockerHostsTable.getModel();
        String apiURL = (String) tableModel.getValueAt(dockerHostsTable.getSelectedRow(), 4);
        DockerHost updateHost = dockerManager.getDockerHostForURL(apiURL);
        if (updateHost != null && !updateHost.isUpdating) {
            AzureDockerUIResources.updateDockerHost(model.getProject(), new EditableDockerHost(updateHost), model.getDockerHostsManager(), true);
        } else {
            PluginUtil.displayErrorDialog("Error: Invalid Edit Selection", "The selected Docker host can not be edited at this time!");
        }
    } catch (Exception e) {
        setDialogButtonsState(false);
        String msg = "An error occurred while attempting to edit the selected Docker host.\n" + e.getMessage();
        if (AzureDockerUtils.DEBUG)
            e.printStackTrace();
        LOGGER.error("onEditDockerHostAction", e);
        PluginUtil.displayErrorDialog("Update Docker Hosts Error", msg);
    }
}
Also used : EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) DefaultTableModel(javax.swing.table.DefaultTableModel) DockerHost(com.microsoft.azure.docker.model.DockerHost) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost)

Example 17 with DockerHost

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

the class AzureSelectDockerHostStep method refreshDockerHostsTable.

/* Refresh the docker hosts entries in the select host table
   *
   */
private void refreshDockerHostsTable() {
    DefaultTableModel tableModel = (DefaultTableModel) dockerHostsTable.getModel();
    String oldSelection = dockerHostsTableSelection != null ? dockerHostsTableSelection.host.apiUrl : null;
    if (dockerHostsTableSelection != null) {
        tableModel.setValueAt(false, dockerHostsTableSelection.row, 0);
        dockerHostsTableSelection = null;
    }
    if (dockerHostsTable.getSelectedRow() >= 0) {
        dockerHostsTable.removeRowSelectionInterval(dockerHostsTable.getSelectedRow(), dockerHostsTable.getSelectedRow());
    }
    int size = tableModel.getRowCount();
    while (size > 0) {
        size--;
        try {
            tableModel.removeRow(size);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    dockerHostsTable.removeAll();
    dockerHostsTable.repaint();
    try {
        List<DockerHost> dockerHosts = dockerManager.getDockerHostsList();
        boolean selected = false;
        if (dockerHosts != null) {
            int idx = 0;
            for (DockerHost host : dockerHosts) {
                Vector<Object> row = new Vector<>();
                row.add(false);
                row.add(host.name);
                row.add(host.state.toString());
                row.add(host.hostOSType.toString());
                row.add(host.apiUrl);
                tableModel.addRow(row);
                if (oldSelection != null && oldSelection.equals(host.apiUrl)) {
                    tableModel.setValueAt(true, idx, 0);
                    selected = true;
                }
                idx++;
            }
            if (!selected) {
                dockerHostsTableSelection = null;
            }
        }
        dockerHostsTable.repaint();
    } catch (Exception e) {
        setDialogButtonsState(false);
        String msg = "An error occurred while attempting to get the list of recognizable Docker hosts.\n" + e.getMessage();
        if (AzureDockerUtils.DEBUG)
            e.printStackTrace();
        LOGGER.error("refreshDockerHostsTable", e);
        PluginUtil.displayErrorDialog("Refresh Docker Hosts Error", msg);
    }
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) DockerHost(com.microsoft.azure.docker.model.DockerHost) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) Vector(java.util.Vector)

Example 18 with DockerHost

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

the class AzureSelectDockerWizardDialog method deploy.

public String deploy() {
    AzureDockerImageInstance dockerImageInstance = model.getDockerImageDescription();
    AzureDockerPreferredSettings dockerPreferredSettings = model.getDockerHostsManager().getDockerPreferredSettings();
    if (dockerPreferredSettings == null) {
        dockerPreferredSettings = new AzureDockerPreferredSettings();
    }
    dockerPreferredSettings.dockerApiName = dockerImageInstance.host.apiUrl;
    dockerPreferredSettings.dockerfileOption = dockerImageInstance.predefinedDockerfile;
    dockerPreferredSettings.region = dockerImageInstance.host.hostVM.region;
    dockerPreferredSettings.vmSize = dockerImageInstance.host.hostVM.vmSize;
    dockerPreferredSettings.vmOS = dockerImageInstance.host.hostOSType.name();
    model.getDockerHostsManager().setDockerPreferredSettings(dockerPreferredSettings);
    DefaultLoader.getIdeHelper().runInBackground(model.getProject(), "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() {
                        AzureDockerImageInstance dockerImageInstance = model.getDockerImageDescription();
                        if (!dockerImageInstance.hasNewDockerHost) {
                            Session session = null;
                            do {
                                try {
                                    // check if the Docker host is accessible
                                    session = AzureDockerSSHOps.createLoginInstance(dockerImageInstance.host);
                                } catch (Exception e) {
                                    session = null;
                                }
                                if (session == null) {
                                    EditableDockerHost editableDockerHost = new EditableDockerHost(dockerImageInstance.host);
                                    AzureInputDockerLoginCredsDialog loginCredsDialog = new AzureInputDockerLoginCredsDialog(model.getProject(), editableDockerHost, model.getDockerHostsManager(), false);
                                    loginCredsDialog.show();
                                    if (loginCredsDialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
                                        // Update Docker host log in credentials
                                        DockerHost dockerHost = model.getDockerHostsManager().getDockerHostForURL(dockerImageInstance.host.apiUrl);
                                        dockerHost.certVault = editableDockerHost.updatedDockerHost.certVault;
                                        dockerHost.hasPwdLogIn = editableDockerHost.updatedDockerHost.hasPwdLogIn;
                                        dockerHost.hasSSHLogIn = editableDockerHost.updatedDockerHost.hasSSHLogIn;
                                        dockerImageInstance.host = dockerHost;
                                    //                    AzureDockerVMOps.updateDockerHostVM(model.getDockerHostsManager().getSubscriptionsMap().get(model.getDockerImageDescription().sid).azureClient, editableDockerHost.updatedDockerHost);
                                    } else {
                                        return;
                                    }
                                }
                            } while (session == null);
                        }
                        Azure azureClient = model.getDockerHostsManager().getSubscriptionsMap().get(model.getDockerImageDescription().sid).azureClient;
                        DockerContainerDeployTask task = new DockerContainerDeployTask(model.getProject(), azureClient, model.getDockerImageDescription());
                        task.queue();
                        // Update caches here
                        if (onCreate != null) {
                            onCreate.run();
                        }
                    }
                });
            } catch (Exception e) {
                String msg = "An error occurred while attempting to deploy to the selected Docker host." + "\n" + e.getMessage();
                PluginUtil.displayErrorDialogInAWTAndLog("Failed to Deploy Web App as Docker Container", msg, e);
            }
        }
    });
    return AzureDockerUtils.getUrl(dockerImageInstance);
}
Also used : AzureInputDockerLoginCredsDialog(com.microsoft.intellij.docker.dialogs.AzureInputDockerLoginCredsDialog) AzureDockerImageInstance(com.microsoft.azure.docker.model.AzureDockerImageInstance) Azure(com.microsoft.azure.management.Azure) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) DockerHost(com.microsoft.azure.docker.model.DockerHost) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) DockerContainerDeployTask(com.microsoft.tasks.DockerContainerDeployTask) AzureDockerPreferredSettings(com.microsoft.azure.docker.model.AzureDockerPreferredSettings) Session(com.jcraft.jsch.Session)

Example 19 with DockerHost

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

the class AzureSelectDockerHostStep method onViewDockerHostAction.

private void onViewDockerHostAction() {
    try {
        DefaultTableModel tableModel = (DefaultTableModel) dockerHostsTable.getModel();
        String apiURL = (String) tableModel.getValueAt(dockerHostsTable.getSelectedRow(), 4);
        DockerHost dockerHost = dockerManager.getDockerHostForURL(apiURL);
        if (dockerHost == null) {
            throw new RuntimeException(String.format("Unexpected error: can't locate the Docker host for %s!", apiURL));
        }
        // TODO: Check if dockerHost.certVault and dockerHost.hostVM have valid values and if not warn
        AzureViewDockerDialog viewDockerDialog = new AzureViewDockerDialog(model.getProject(), dockerHost, dockerManager);
        viewDockerDialog.show();
        if (viewDockerDialog.getInternalExitCode() == AzureViewDockerDialog.UPDATE_EXIT_CODE) {
            onEditDockerHostAction();
        }
    } catch (Exception e) {
        String msg = "An error occurred while attempting to view the selected Docker host.\n" + e.getMessage();
        PluginUtil.displayErrorDialogAndLog("Error", msg, e);
        if (AzureDockerUtils.DEBUG)
            e.printStackTrace();
        LOGGER.error("onViewDockerHostAction", e);
        PluginUtil.displayErrorDialog("View Docker Hosts Error", msg);
    }
}
Also used : AzureViewDockerDialog(com.microsoft.intellij.docker.dialogs.AzureViewDockerDialog) DefaultTableModel(javax.swing.table.DefaultTableModel) DockerHost(com.microsoft.azure.docker.model.DockerHost) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost)

Example 20 with DockerHost

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

the class DockerHostModule method refreshItems.

@Override
protected void refreshItems() throws AzureCmdException {
    try {
        AzureManager azureAuthManager = AuthMethodManager.getInstance().getAzureManager();
        // not signed in
        if (azureAuthManager == null) {
            return;
        }
        dockerManager = AzureDockerHostsManager.getAzureDockerHostsManager(azureAuthManager);
        if (!dockerManager.isInitialized()) {
            dockerManager.forceRefreshSubscriptions();
            dockerManager = AzureDockerHostsManager.getAzureDockerHostsManagerEmpty(null);
        }
        for (DockerHost host : dockerManager.getDockerHostsList()) {
            addChildNode(new DockerHostNode(this, dockerManager, host));
        }
    } catch (Exception ex) {
        DefaultLoader.getUIHelper().showException("An error occurred while attempting to load the Docker virtual machines from Azure", ex, "Azure Services Explorer - Error Refreshing Docker Hosts", false, true);
    }
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) DockerHost(com.microsoft.azure.docker.model.DockerHost) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Aggregations

DockerHost (com.microsoft.azure.docker.model.DockerHost)21 EditableDockerHost (com.microsoft.azure.docker.model.EditableDockerHost)14 Azure (com.microsoft.azure.management.Azure)7 AzureDockerHostsManager (com.microsoft.azure.docker.AzureDockerHostsManager)6 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)6 AzureDockerPreferredSettings (com.microsoft.azure.docker.model.AzureDockerPreferredSettings)5 DefaultTableModel (javax.swing.table.DefaultTableModel)5 AzureDockerImageInstance (com.microsoft.azure.docker.model.AzureDockerImageInstance)4 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)4 AzureUIRefreshEvent (com.microsoft.azuretools.utils.AzureUIRefreshEvent)4 Date (java.util.Date)4 Session (com.jcraft.jsch.Session)3 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)3 File (java.io.File)3 AzureWizardDialog (com.microsoft.azuretools.core.components.AzureWizardDialog)2 AzureInputDockerLoginCredsDialog (com.microsoft.intellij.docker.dialogs.AzureInputDockerLoginCredsDialog)2 AzureSelectDockerWizardDialog (com.microsoft.intellij.docker.wizards.publish.AzureSelectDockerWizardDialog)2 AzureSelectDockerWizardModel (com.microsoft.intellij.docker.wizards.publish.AzureSelectDockerWizardModel)2 HashMap (java.util.HashMap)2 Vector (java.util.Vector)2