use of org.eclipse.linuxtools.docker.core.DockerException 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.DockerException in project linuxtools by eclipse.
the class DockerConnection method attachCommand.
public void attachCommand(final String id, final InputStream in, @SuppressWarnings("unused") final DockerConsoleOutputStream out) throws DockerException {
final byte[] prevCmd = new byte[1024];
try {
final LogStream pty_stream = client.attachContainer(id, AttachParameter.STDIN, AttachParameter.STDOUT, AttachParameter.STDERR, AttachParameter.STREAM, AttachParameter.LOGS);
final IDockerContainerInfo info = getContainerInfo(id);
final boolean isTtyEnabled = info.config().tty();
final boolean isOpenStdin = info.config().openStdin();
if (isTtyEnabled) {
openTerminal(pty_stream, info.name(), out);
}
// Data from the given input stream
// Written to container's STDIN
Thread t_in = new Thread(() -> {
byte[] buff = new byte[1024];
int n;
try {
WritableByteChannel pty_out = HttpHijackWorkaround.getOutputStream(pty_stream, getUri());
while ((n = in.read(buff)) != -1 && getContainerInfo(id).state().running()) {
synchronized (prevCmd) {
pty_out.write(ByteBuffer.wrap(buff, 0, n));
for (int i = 0; i < prevCmd.length; i++) {
prevCmd[i] = buff[i];
}
}
buff = new byte[1024];
}
} catch (Exception e) {
}
});
if (!isTtyEnabled && isOpenStdin) {
t_in.start();
}
} catch (Exception e) {
throw new DockerException(e.getMessage(), e.getCause());
}
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class DockerConnection method pushImage.
@Override
public void pushImage(final String name, final IRegistryAccount info, final IDockerProgressHandler handler) throws DockerException, InterruptedException {
try {
final DockerClient client = dockerClientFactory.getClient(this.connectionSettings, info);
final DockerProgressHandler d = new DockerProgressHandler(handler);
client.push(name, d);
} catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
throw new DockerException(e.message());
} catch (com.spotify.docker.client.exceptions.DockerException | DockerCertificateException e) {
DockerException f = new DockerException(e);
throw f;
}
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class DockerConnection method createNetwork.
@Override
public IDockerNetworkCreation createNetwork(IDockerNetworkConfig cfg) throws DockerException, InterruptedException {
try {
Ipam.Builder ipamBuilder = Ipam.builder().driver(cfg.ipam().driver());
List<IDockerIpamConfig> ipamCfgs = cfg.ipam().config();
for (IDockerIpamConfig ipamCfg : ipamCfgs) {
ipamBuilder = ipamBuilder.config(ipamCfg.subnet(), ipamCfg.ipRange(), ipamCfg.gateway());
}
Ipam ipam = ipamBuilder.build();
NetworkConfig.Builder networkConfigBuilder = NetworkConfig.builder().name(cfg.name()).driver(cfg.driver()).ipam(ipam);
networkConfigBuilder.options(cfg.options());
NetworkConfig networkConfig = networkConfigBuilder.build();
com.spotify.docker.client.messages.NetworkCreation creation = client.createNetwork(networkConfig);
return new DockerNetworkCreation(creation);
} catch (com.spotify.docker.client.exceptions.DockerException e) {
throw new DockerException(e.getMessage(), e.getCause());
}
}
use of org.eclipse.linuxtools.docker.core.DockerException in project linuxtools by eclipse.
the class DockerConnection method getInfo.
@Override
public IDockerConnectionInfo getInfo() throws DockerException {
if (this.client == null) {
return null;
}
try {
final Info info = this.client.info();
final Version version = this.client.version();
return new DockerConnectionInfo(info, version);
} catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
throw new DockerException(e.message());
} catch (com.spotify.docker.client.exceptions.DockerException | InterruptedException e) {
throw new DockerException(Messages.Docker_General_Info_Failure, e);
}
}
Aggregations