Search in sources :

Example 1 with ExposedPortModel

use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel in project linuxtools by eclipse.

the class RunImagePortsTab method onAddPort.

private SelectionListener onAddPort(final CheckboxTableViewer exposedPortsTableViewer) {
    return SelectionListener.widgetSelectedAdapter(e -> {
        final ContainerPortDialog dialog = new ContainerPortDialog(getShell());
        dialog.create();
        if (dialog.open() == IDialogConstants.OK_ID) {
            final ExposedPortModel port = dialog.getPort();
            model.addAvailablePort(port);
            model.getSelectedPorts().add(port);
            port.setSelected(true);
            exposedPortsTableViewer.setChecked(port, true);
            updateLaunchConfigurationDialog();
        }
    });
}
Also used : ContainerPortDialog(org.eclipse.linuxtools.internal.docker.ui.wizards.ContainerPortDialog) ExposedPortModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel)

Example 2 with ExposedPortModel

use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel in project linuxtools by eclipse.

the class RunImagePortsTab method onEditPort.

private SelectionListener onEditPort(final CheckboxTableViewer exposedPortsTableViewer) {
    return SelectionListener.widgetSelectedAdapter(e -> {
        final IStructuredSelection selection = exposedPortsTableViewer.getStructuredSelection();
        final ExposedPortModel selectedContainerPort = (ExposedPortModel) selection.getFirstElement();
        final ContainerPortDialog dialog = new ContainerPortDialog(getShell(), selectedContainerPort);
        dialog.create();
        if (dialog.open() == IDialogConstants.OK_ID) {
            final ExposedPortModel configuredPort = dialog.getPort();
            selectedContainerPort.setContainerPort(configuredPort.getContainerPort());
            selectedContainerPort.setHostAddress(configuredPort.getHostAddress());
            selectedContainerPort.setHostPort(configuredPort.getHostPort());
        }
        updateLaunchConfigurationDialog();
    });
}
Also used : ExposedPortModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel) ContainerPortDialog(org.eclipse.linuxtools.internal.docker.ui.wizards.ContainerPortDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 3 with ExposedPortModel

use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel in project linuxtools by eclipse.

the class ImageRun method getDockerContainerConfig.

public DockerContainerConfig getDockerContainerConfig() {
    final ImageRunSelectionModel selectionModel = this.imageRunSelectionPage.getModel();
    final ImageRunResourceVolumesVariablesModel resourcesModel = this.imageRunResourceVolumesPage.getModel();
    final Builder config = new DockerContainerConfig.Builder().cmd(selectionModel.getCommand()).entryPoint(selectionModel.getEntrypoint()).image(selectionModel.getSelectedImageName()).tty(selectionModel.isAllocatePseudoTTY()).openStdin(selectionModel.isInteractiveMode());
    if (resourcesModel.isEnableResourceLimitations()) {
        // memory limit must be converted from MB to bytes
        config.memory(resourcesModel.getMemoryLimit() * MB);
        config.cpuShares(resourcesModel.getCpuShareWeight());
    }
    // environment variables
    final List<String> environmentVariables = new ArrayList<>();
    for (Iterator<EnvironmentVariableModel> iterator = resourcesModel.getEnvironmentVariables().iterator(); iterator.hasNext(); ) {
        final EnvironmentVariableModel var = iterator.next();
        // $NON-NLS-1$
        environmentVariables.add(var.getName() + "=" + var.getValue());
    }
    config.env(environmentVariables);
    // container labels
    final Map<String, String> labelVariables = new HashMap<>();
    for (Iterator<LabelVariableModel> iterator = resourcesModel.getLabelVariables().iterator(); iterator.hasNext(); ) {
        final LabelVariableModel var = iterator.next();
        // $NON-NLS-1$
        labelVariables.put(var.getName(), var.getValue());
    }
    config.labels(labelVariables);
    if (!selectionModel.isPublishAllPorts()) {
        final Set<String> exposedPorts = new HashSet<>();
        for (Iterator<ExposedPortModel> iterator = selectionModel.getExposedPorts().iterator(); iterator.hasNext(); ) {
            final ExposedPortModel exposedPort = iterator.next();
            // only selected Ports in the CheckboxTableViewer are exposed.
            if (!selectionModel.getSelectedPorts().contains(exposedPort)) {
                continue;
            }
            exposedPorts.add(exposedPort.getContainerPort() + exposedPort.getPortType());
        }
        config.exposedPorts(exposedPorts);
    }
    return config.build();
}
Also used : ExposedPortModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel) HashMap(java.util.HashMap) Builder(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig.Builder) ArrayList(java.util.ArrayList) Builder(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig.Builder) DockerContainerConfig(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig) HashSet(java.util.HashSet)

Example 4 with ExposedPortModel

use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel in project linuxtools by eclipse.

the class ImageRunSelectionPage method setDefaultValues.

/**
 * Sets the default values from the optional given {@link IDockerImage} and
 * {@link ILaunchConfiguration} elements
 */
private void setDefaultValues() {
    final IDockerImage selectedImage = model.getSelectedImage();
    if (selectedImage == null) {
        return;
    }
    final IDockerImageInfo selectedImageInfo = getImageInfo(selectedImage);
    // skip if a previous launch configuration was provided
    if (this.lastLaunchConfiguration != null) {
        try {
            this.model.setContainerName(lastLaunchConfiguration.getAttribute(CONTAINER_NAME, ""));
            this.model.setEntrypoint(lastLaunchConfiguration.getAttribute(ENTRYPOINT, ""));
            this.model.setCommand(lastLaunchConfiguration.getAttribute(COMMAND, ""));
            this.model.setPublishAllPorts(lastLaunchConfiguration.getAttribute(PUBLISH_ALL_PORTS, false));
            final List<String> exposedPortInfos = lastLaunchConfiguration.getAttribute(PUBLISHED_PORTS, Collections.<String>emptyList());
            // by the user.
            if (selectedImageInfo != null) {
                final List<ExposedPortModel> exposedPorts = ExposedPortModel.fromStrings(selectedImageInfo.config().exposedPorts());
                model.setExposedPorts(exposedPorts);
                final List<ExposedPortModel> selectedExposedPorts = ExposedPortModel.fromStrings(exposedPortInfos);
                this.model.setSelectedPorts(new HashSet<>(selectedExposedPorts));
            }
            // links
            this.model.setLinks(lastLaunchConfiguration.getAttribute(LINKS, Collections.<String>emptyList()));
            // other options
            this.model.setRemoveWhenExits(lastLaunchConfiguration.getAttribute(AUTO_REMOVE, false));
            this.model.setInteractiveMode(lastLaunchConfiguration.getAttribute(INTERACTIVE, false));
            this.model.setAllocatePseudoTTY(lastLaunchConfiguration.getAttribute(ALLOCATE_PSEUDO_CONSOLE, false));
            this.model.setPrivileged(lastLaunchConfiguration.getAttribute(PRIVILEGED, false));
            this.model.setBasicSecurity(lastLaunchConfiguration.getAttribute(READONLY, false));
        } catch (CoreException e) {
            Activator.log(e);
        }
    } else {
        applyImageInfo(selectedImageInfo);
    }
}
Also used : ExposedPortModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel) CoreException(org.eclipse.core.runtime.CoreException) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage)

Example 5 with ExposedPortModel

use of org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel in project linuxtools by eclipse.

the class ImageRunSelectionPage method onRemovePorts.

private SelectionListener onRemovePorts(final TableViewer portsTableViewer) {
    return SelectionListener.widgetSelectedAdapter(e -> {
        final IStructuredSelection selection = portsTableViewer.getStructuredSelection();
        for (@SuppressWarnings("unchecked") Iterator<ExposedPortModel> iterator = selection.iterator(); iterator.hasNext(); ) {
            final ExposedPortModel port = iterator.next();
            model.removeAvailablePort(port);
            model.getSelectedPorts().remove(port);
        }
    });
}
Also used : ExposedPortModel(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

ExposedPortModel (org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ExposedPortModel)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 CoreException (org.eclipse.core.runtime.CoreException)2 IDockerImageInfo (org.eclipse.linuxtools.docker.core.IDockerImageInfo)2 Builder (org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig.Builder)2 ContainerPortDialog (org.eclipse.linuxtools.internal.docker.ui.wizards.ContainerPortDialog)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IDockerHostConfig (org.eclipse.linuxtools.docker.core.IDockerHostConfig)1 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)1 IDockerPortBinding (org.eclipse.linuxtools.docker.core.IDockerPortBinding)1 DockerContainerConfig (org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig)1 DockerHostConfig (org.eclipse.linuxtools.internal.docker.core.DockerHostConfig)1 DockerPortBinding (org.eclipse.linuxtools.internal.docker.core.DockerPortBinding)1 ImageRunSelectionModel (org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel)1 ContainerLinkModel (org.eclipse.linuxtools.internal.docker.ui.wizards.ImageRunSelectionModel.ContainerLinkModel)1