use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class RunDockerImageLaunchConfigurationDelegate method launch.
@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) {
try {
ILaunchConfiguration config = launch.getLaunchConfiguration();
final IDockerContainerConfig containerConfig = getDockerContainerConfig(config);
final IDockerHostConfig hostConfig = getDockerHostConfig(config);
final IDockerConnection connection = getDockerConnection(config);
if (connection == null)
return;
final IDockerImage image = getDockerImage(config, connection);
RunImageCommandHandler.runImage(image, containerConfig, hostConfig, config.getAttribute(IRunDockerImageLaunchConfigurationConstants.CONTAINER_NAME, (String) null), config.getAttribute(IRunDockerImageLaunchConfigurationConstants.AUTO_REMOVE, false));
} catch (CoreException e) {
Activator.log(e);
}
}
use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class RunDockerImageLaunchConfigurationDelegate method getDockerConnection.
private IDockerConnection getDockerConnection(ILaunchConfiguration config) throws CoreException {
String configName = config.getAttribute(IRunDockerImageLaunchConfigurationConstants.CONNECTION_NAME, // $NON-NLS-1$
"");
IDockerConnection connection = DockerConnectionManager.getInstance().findConnection(configName);
if (connection == null) {
connection = chooseConnection(DockerConnectionManager.getInstance().getConnections());
}
return connection;
}
use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class RunImageMainTab method isValid.
@Override
public boolean isValid(ILaunchConfiguration launchConfig) {
try {
if (model == null)
return false;
String connectionName = launchConfig.getAttribute(IRunDockerImageLaunchConfigurationConstants.CONNECTION_NAME, // $NON-NLS-1$
"");
if (connectionName.isEmpty()) {
return false;
} else {
// Verify Connection is active
IDockerConnection connection = DockerConnectionManager.getInstance().findConnection(connectionName);
if (connection == null || !connection.isOpen()) {
setErrorMessage(WizardMessages.getFormattedString(// $NON-NLS-1$
"ErrorInactiveConnection.msg", connectionName));
return false;
}
}
final IStatus imageSelectionValidationStatus = new ImageSelectionValidator().validate(model.getSelectedImageName());
if (!imageSelectionValidationStatus.isOK()) {
setErrorMessage(imageSelectionValidationStatus.getMessage());
return false;
}
final IStatus imageNameValidationStatus = new ImageNameValidator().validate(model.getSelectedImageName());
if (!imageNameValidationStatus.isOK()) {
setErrorMessage(imageNameValidationStatus.getMessage());
return false;
}
final IStatus containerNameValidationStatus = new ContainerNameValidator().validate(model.getContainerName());
if (!containerNameValidationStatus.isOK()) {
setErrorMessage(containerNameValidationStatus.getMessage());
return false;
}
} catch (CoreException e) {
Activator.log(e);
}
setErrorMessage(null);
return true;
}
use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class ImageSelectionDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
Label connLbl = new Label(composite, SWT.NONE);
connLbl.setText(Messages.ImageSelectionDialog_connection_label);
ComboViewer connCmb = new ComboViewer(composite, SWT.READ_ONLY);
connCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
connCmb.setContentProvider(new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
for (IDockerConnection conn : DockerConnectionManager.getInstance().getAllConnections()) {
try {
((DockerConnection) conn).open(false);
} catch (DockerException e) {
}
}
return DockerConnectionManager.getInstance().getAllConnections().stream().filter(c -> c.isOpen()).toArray(size -> new IDockerConnection[size]);
}
});
// $NON-NLS-1$
connCmb.setInput("place_holder");
Label imageLbl = new Label(composite, SWT.NONE);
imageLbl.setText(Messages.ImageSelectionDialog_image_label);
ComboViewer imageCmb = new ComboViewer(composite, SWT.READ_ONLY);
imageCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
imageCmb.setContentProvider(new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
IDockerConnection conn = (IDockerConnection) inputElement;
return conn.getImages().stream().filter(// $NON-NLS-1$
i -> !i.repoTags().get(0).equals("<none>:<none>")).toArray(size -> new IDockerImage[size]);
}
});
imageCmb.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
IDockerImage img = (IDockerImage) element;
return img.repoTags().get(0);
}
});
imageCmb.setInput(null);
connCmb.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = event.getStructuredSelection();
IDockerConnection conn = (IDockerConnection) sel.getFirstElement();
connection = conn;
imageCmb.setInput(conn);
}
});
imageCmb.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = event.getStructuredSelection();
IDockerImage img = (IDockerImage) sel.getFirstElement();
image = img;
getOkButton().setEnabled(true);
}
});
return composite;
}
use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class DefaultDockerConnectionStorageManager method loadConnections.
@Override
public List<IDockerConnection> loadConnections() {
final List<IDockerConnection> connections = new ArrayList<>();
final IPath stateLocation = Activator.getDefault().getStateLocation();
final File connectionFile = stateLocation.append(CONNECTIONS_FILE_NAME).toFile();
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
if (connectionFile.exists()) {
Document d = db.parse(connectionFile);
Element e = d.getDocumentElement();
// Get the stored configuration data
// $NON-NLS-1$
NodeList connectionNodes = e.getElementsByTagName("connection");
for (int x = 0; x < connectionNodes.getLength(); ++x) {
Node n = connectionNodes.item(x);
NamedNodeMap attrs = n.getAttributes();
// $NON-NLS-1$
Node nameNode = attrs.getNamedItem("name");
// $NON-NLS-1$
Node uriNode = attrs.getNamedItem("uri");
// $NON-NLS-1$
Node usernameNode = attrs.getNamedItem("username");
// $NON-NLS-1$
Node certNode = attrs.getNamedItem("cert");
if (uriNode != null) {
String uri = uriNode.getNodeValue();
String name = nameNode.getNodeValue();
if (usernameNode != null) {
String username = usernameNode.getNodeValue();
String key = DockerConnection.getPreferencesKey(uri, username);
ISecurePreferences root = SecurePreferencesFactory.getDefault();
ISecurePreferences node = root.node(key);
@SuppressWarnings("unused") String password;
try {
// $NON-NLS-1$
password = node.get("password", null);
} catch (StorageException e1) {
e1.printStackTrace();
}
}
final DockerConnection.Builder builder = new DockerConnection.Builder().name(name);
if (uri.startsWith("unix:")) {
// $NON-NLS-1$
final DockerConnection connection = builder.unixSocketConnection(new UnixSocketConnectionSettings(uri));
connections.add(connection);
} else {
final String pathToCertificates = certNode != null ? certNode.getNodeValue() : null;
final DockerConnection connection = builder.tcpConnection(new TCPConnectionSettings(uri, pathToCertificates));
connections.add(connection);
}
}
}
}
} catch (ParserConfigurationException | SAXException | IOException e) {
Activator.log(e);
}
return connections;
}
Aggregations