Search in sources :

Example 11 with DockerHost

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

the class AzureSelectDockerHostStep method onRemoveDockerHostAction.

private void onRemoveDockerHostAction() {
    DefaultTableModel tableModel = (DefaultTableModel) dockerHostsTable.getModel();
    String apiURL = (String) tableModel.getValueAt(dockerHostsTable.getSelectedRow(), 4);
    DockerHost deleteHost = dockerManager.getDockerHostForURL(apiURL);
    Azure azureClient = dockerManager.getSubscriptionsMap().get(deleteHost.sid).azureClient;
    int option = AzureDockerUIResources.deleteAzureDockerHostConfirmationDialog(azureClient, deleteHost);
    if (option != 1 && option != 2) {
        if (AzureDockerUtils.DEBUG)
            System.out.format("User canceled delete Docker host op: %d\n", option);
        return;
    }
    AppInsightsClient.createByType(AppInsightsClient.EventType.DockerHost, deleteHost.name, "Remove");
    int currentRow = dockerHostsTable.getSelectedRow();
    tableModel.removeRow(currentRow);
    tableModel.fireTableDataChanged();
    if (dockerHostsTableSelection.row == currentRow) {
        dockerHostsTableSelection = null;
    }
    AzureDockerUIResources.deleteDockerHost(model.getProject(), azureClient, deleteHost, option, new Runnable() {

        @Override
        public void run() {
            dockerManager.refreshDockerHostDetails();
            ApplicationManager.getApplication().invokeLater(new Runnable() {

                @Override
                public void run() {
                    refreshDockerHostsTable();
                }
            });
        }
    });
    setFinishButtonState(doValidate(false) == null);
    setNextButtonState(doValidate(false) == null);
}
Also used : Azure(com.microsoft.azure.management.Azure) DefaultTableModel(javax.swing.table.DefaultTableModel) DockerHost(com.microsoft.azure.docker.model.DockerHost) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost)

Example 12 with DockerHost

use of com.microsoft.azure.docker.model.DockerHost 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)

Example 13 with DockerHost

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

the class DockerHostNode method refreshDockerHostInstance.

private void refreshDockerHostInstance(VirtualMachine vm) {
    if (vm != null) {
        DockerHost updatedDockerHost = AzureDockerVMOps.getDockerHost(vm, dockerManager.getDockerVaultsMap());
        if (updatedDockerHost != null) {
            updatedDockerHost.sid = dockerHost.sid;
            updatedDockerHost.hostVM.sid = dockerHost.hostVM.sid;
            if (updatedDockerHost.certVault == null) {
                updatedDockerHost.certVault = dockerHost.certVault;
                updatedDockerHost.hasPwdLogIn = dockerHost.hasPwdLogIn;
                updatedDockerHost.hasSSHLogIn = dockerHost.hasSSHLogIn;
                updatedDockerHost.isTLSSecured = dockerHost.isTLSSecured;
            }
            dockerManager.updateDockerHost(updatedDockerHost);
            dockerHost = updatedDockerHost;
            if (dockerHost.certVault != null) {
                try {
                    // it might throw here if the credentials are invalid
                    Map<String, DockerImage> dockerImages = AzureDockerImageOps.getImages(dockerHost);
                    Map<String, DockerContainer> dockerContainers = AzureDockerContainerOps.getContainers(dockerHost);
                    AzureDockerContainerOps.setContainersAndImages(dockerContainers, dockerImages);
                    dockerHost.dockerImages = dockerImages;
                } catch (Exception e) {
                    DefaultLoader.getUIHelper().logError(e.getMessage(), e);
                }
            }
            setIconPath(getDockerHostIcon());
            for (DockerImage dockerImage : updatedDockerHost.dockerImages.values()) {
                try {
                    addChildNode(new DockerImageNode(this, dockerManager, updatedDockerHost, dockerImage));
                } catch (Exception ignored) {
                }
            }
        }
    }
}
Also used : DockerContainer(com.microsoft.azure.docker.model.DockerContainer) DockerHost(com.microsoft.azure.docker.model.DockerHost) DockerImage(com.microsoft.azure.docker.model.DockerImage) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Example 14 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 15 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)

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