use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class NewDockerConnectionSWTBotTest method configureUnixSocketConnection.
private IDockerConnection configureUnixSocketConnection(final String connectionName, final String pathToSocket) {
final DockerClient client = MockDockerClientFactory.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from(connectionName, client).withUnixSocketConnectionSettings(pathToSocket);
DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
return dockerConnection;
}
use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class DefaultDockerConnectionStorageManager method saveConnections.
@Override
public void saveConnections(List<IDockerConnection> connections) {
final IPath stateLocation = Activator.getDefault().getStateLocation();
final File connectionFile = stateLocation.append(CONNECTIONS_FILE_NAME).toFile();
try {
if (!connectionFile.exists()) {
connectionFile.createNewFile();
}
try (final PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter(connectionFile)))) {
// $NON-NLS-1$
p.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
// $NON-NLS-1$
p.println("<connections>");
for (IDockerConnection d : connections) {
String name = d.getName();
if (name.equals(Messages.Unnamed)) {
name = "";
}
p.print(// $NON-NLS-1$
"<connection name=\"" + name + "\" uri=\"" + // $NON-NLS-1$
d.getUri());
if (d.getUsername() != null) {
// $NON-NLS-1$
p.print("\" username=\"" + d.getUsername());
}
if (d.getTcpCertPath() != null) {
// $NON-NLS-1$
p.print("\" cert=\"" + d.getTcpCertPath());
}
// $NON-NLS-1$
p.println("\"/>");
}
// $NON-NLS-1$
p.println("</connections>");
}
} catch (Exception e) {
Activator.log(e);
}
}
use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class RunDockerImageLaunchConfigurationDelegate method chooseConnection.
/**
* Show a selection dialog that allows the user to choose one of the
* connections to use to build the Image.
*
* @param connections
* Array of connections.
* @return The chosen connection, or <code>null</code> if the user cancelled
* the dialog.
*/
protected IDockerConnection chooseConnection(final IDockerConnection[] connections) {
IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
ElementListSelectionDialog dialog = new ElementListSelectionDialog(getActiveWorkbenchShell(), new ConnectionSelectionLabelProvider() {
});
dialog.setElements(connections);
dialog.setTitle(LaunchMessages.getString(LaunchShortcut_Connection_Selection));
dialog.setMessage(LaunchMessages.getString(LaunchShortcut_Choose_Connection));
dialog.setMultipleSelection(false);
int result = dialog.open();
labelProvider.dispose();
if (result == IStatus.OK) {
return (IDockerConnection) dialog.getFirstResult();
}
return null;
}
use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class ConnectionSettingsPropertySection method setInput.
@Override
public void setInput(final IWorkbenchPart part, final ISelection selection) {
super.setInput(part, selection);
Assert.isTrue(selection instanceof ITreeSelection);
Object input = ((ITreeSelection) selection).getFirstElement();
Assert.isTrue(input instanceof IDockerConnection);
IDockerConnection connection = (IDockerConnection) input;
if (getTreeViewer() != null) {
getTreeViewer().setInput(connection);
getTreeViewer().expandAll();
}
}
use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.
the class DockerExplorerContentProvider method getChildren.
@Override
public Object[] getChildren(final Object parentElement) {
if (parentElement instanceof IDockerConnection) {
// check the connection availability before returning the
// 'containers' and 'images' child nodes.
final IDockerConnection connection = (IDockerConnection) parentElement;
if (connection.isOpen()) {
return new Object[] { new DockerImagesCategory(connection), new DockerContainersCategory(connection) };
} else if (connection.getState() == EnumDockerConnectionState.UNKNOWN) {
open(connection);
return new Object[] { new LoadingStub(connection) };
} else if (connection.getState() == EnumDockerConnectionState.CLOSED) {
synchronized (openRetryJobs) {
Job job = openRetryJobs.get(connection);
if (job == null) {
openRetry(connection);
}
}
return new Object[] { new LoadingStub(connection) };
}
return new Object[0];
} else if (parentElement instanceof DockerContainersCategory) {
final DockerContainersCategory containersCategory = (DockerContainersCategory) parentElement;
final IDockerConnection connection = containersCategory.getConnection();
if (connection.isContainersLoaded()) {
return connection.getContainers().toArray();
}
loadContainers(containersCategory);
return new Object[] { new LoadingStub(containersCategory) };
} else if (parentElement instanceof DockerImagesCategory) {
final DockerImagesCategory imagesCategory = (DockerImagesCategory) parentElement;
final IDockerConnection connection = imagesCategory.getConnection();
if (connection.isImagesLoaded()) {
// here we duplicate the images to show one org/repo with all
// its tags per node in the tree
final List<IDockerImage> allImages = connection.getImages();
final List<IDockerImage> explorerImages = splitImageTagsByRepo(allImages);
return explorerImages.toArray();
}
loadImages(imagesCategory);
return new Object[] { new LoadingStub(imagesCategory) };
} else if (parentElement instanceof IDockerContainer) {
final DockerContainer container = (DockerContainer) parentElement;
if (container.isInfoLoaded()) {
final IDockerContainerInfo info = container.info();
final IDockerNetworkSettings networkSettings = (info != null) ? info.networkSettings() : null;
final IDockerHostConfig hostConfig = (info != null) ? info.hostConfig() : null;
return new Object[] { new DockerContainerPortMappingsCategory(container, (networkSettings != null) ? networkSettings.ports() : Collections.<String, List<IDockerPortBinding>>emptyMap()), new DockerContainerVolumesCategory(container, (hostConfig != null) ? hostConfig.binds() : Collections.<String>emptyList()), new DockerContainerLinksCategory(container, (hostConfig != null) ? hostConfig.links() : Collections.<String>emptyList()) };
}
loadContainerInfo(container);
return new Object[] { new LoadingStub(container) };
} else if (parentElement instanceof DockerContainerLinksCategory) {
final DockerContainerLinksCategory linksCategory = (DockerContainerLinksCategory) parentElement;
return linksCategory.getLinks().toArray();
} else if (parentElement instanceof DockerContainerPortMappingsCategory) {
final DockerContainerPortMappingsCategory portMappingsCategory = (DockerContainerPortMappingsCategory) parentElement;
return portMappingsCategory.getPortMappings().toArray();
} else if (parentElement instanceof DockerContainerVolumesCategory) {
final DockerContainerVolumesCategory volumesCategory = (DockerContainerVolumesCategory) parentElement;
return volumesCategory.getVolumes().toArray();
}
return EMPTY;
}
Aggregations