本文整理汇总了Java中com.github.dockerjava.api.exception.DockerException类的典型用法代码示例。如果您正苦于以下问题:Java DockerException类的具体用法?Java DockerException怎么用?Java DockerException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DockerException类属于com.github.dockerjava.api.exception包,在下文中一共展示了DockerException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createNetwork
import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
/**
* Create network which is used as default in docker-compose.yml
* This should be run before {@link DockerComposeExecutor#run(TestEnvironment)}
*/
@Override
public void createNetwork() {
removeNetwork();
String apmNetwork = apmBindAddress.substring(0, apmBindAddress.lastIndexOf(".")) + ".0/24";
log.info(String.format("Creating network %s:", apmNetwork));
Network.Ipam ipam = new Network.Ipam()
.withConfig(new Network.Ipam.Config()
.withSubnet(apmNetwork)
.withGateway(apmBindAddress));
CreateNetworkResponse createNetworkResponse = dockerClient.createNetworkCmd()
.withName(Constants.HOST_ADDED_TO_ETC_HOSTS)
.withIpam(ipam)
.exec();
try {
network = dockerClient.inspectNetworkCmd().withNetworkId(createNetworkResponse.getId()).exec();
} catch (DockerException ex) {
log.severe(String.format("Could not create network: %s", createNetworkResponse));
throw new EnvironmentException("Could not create network: " + createNetworkResponse, ex);
}
}
示例2: registerContainersForShutdown
import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
private void registerContainersForShutdown() {
// Ensure that all service containers that were launched by compose will be killed at shutdown
try {
final List<Container> containers = listChildContainers();
// register with ResourceReaper to ensure final shutdown with JVM
containers.forEach(container ->
ResourceReaper.instance().registerContainerForCleanup(container.getId(), container.getNames()[0]));
// Compose can define their own networks as well; ensure these are cleaned up
dockerClient.listNetworksCmd().exec().forEach(network -> {
if (network.getName().contains(identifier)) {
spawnedNetworkIds.add(network.getId());
ResourceReaper.instance().registerNetworkIdForCleanup(network.getId());
}
});
// remember the IDs to allow containers to be killed as soon as we reach stop()
spawnedContainerIds.addAll(containers.stream()
.map(Container::getId)
.collect(Collectors.toSet()));
} catch (DockerException e) {
logger().debug("Failed to stop a service container with exception", e);
}
}
示例3: perform
import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Override
public boolean perform(@SuppressWarnings("rawtypes") AbstractBuild build, Launcher launcher, BuildListener listener)
throws AbortException {
ConsoleLogger clog = new ConsoleLogger(listener);
if (getDescriptor().getDockerClient(build, null) == null) {
clog.logError("docker client is not initialized, command '" + dockerCmd.getDescriptor().getDisplayName()
+ "' was aborted. Check Jenkins server log which Docker client wasn't initialized");
throw new AbortException("Docker client wasn't initialized.");
}
try {
dockerCmd.execute(launcher, build, clog);
} catch (DockerException e) {
clog.logError("command '" + dockerCmd.getDescriptor().getDisplayName() + "' failed: " + e.getMessage());
LOGGER.severe("Failed to execute Docker command " + dockerCmd.getDescriptor().getDisplayName() + ": "
+ e.getMessage());
throw new AbortException(e.getMessage());
}
return true;
}
示例4: logCommandResult
import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
public static void logCommandResult(InputStream inputStream,
ConsoleLogger console, String errMessage) {
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
String line = null;
try {
while((line = in.readLine()) != null) {
console.logInfo(line);
JSONObject jsonResponse = JSONObject.fromObject(line);
if (jsonResponse.containsKey("error") || jsonResponse.containsKey("errorDetail")) {
throw new DockerException(line, 200);
}
}
} catch (IOException e) {
throw new DockerException(line == null ? errMessage : line, 200, e);
}
}
示例5: execute
import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Override
public void execute(Launcher launcher, @SuppressWarnings("rawtypes") AbstractBuild build, ConsoleLogger console)
throws DockerException {
if (containerIds == null || containerIds.isEmpty()) {
throw new IllegalArgumentException("At least one parameter is required");
}
String containerIdsRes = Resolver.buildVar(build, containerIds);
List<String> ids = Arrays.asList(containerIdsRes.split(","));
Config cfgData = getConfig(build);
Descriptor<?> descriptor = Jenkins.getInstance().getDescriptor(DockerBuilder.class);
for (String id : ids) {
id = id.trim();
try {
launcher.getChannel().call(new KillContainerRemoteCallable(cfgData, descriptor, id));
console.logInfo("killed container id " + id);
} catch (Exception e) {
console.logError("failed to kill containers " + ids);
e.printStackTrace();
throw new IllegalArgumentException(e);
}
}
}
示例6: execute
import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Override
public void execute(Launcher launcher, @SuppressWarnings("rawtypes") AbstractBuild build, ConsoleLogger console) throws DockerException {
if (containerIds == null || containerIds.isEmpty()) {
throw new IllegalArgumentException("At least one parameter is required");
}
String containerIdsRes = Resolver.buildVar(build, containerIds);
List<String> ids = Arrays.asList(containerIdsRes.split(","));
try {
Config cfgData = getConfig(build);
Descriptor<?> descriptor = Jenkins.getInstance().getDescriptor(DockerBuilder.class);
for (String id : ids) {
id = id.trim();
launcher.getChannel().call(new RestartContainerRemoteCallable(cfgData, descriptor, id, timeout));
console.logInfo("restarted container id " + id);
}
} catch (Exception e) {
console.logError("failed to restart containers ids " + ids);
e.printStackTrace();
throw new IllegalArgumentException(e);
}
}
示例7: execute
import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Override
public void execute(Launcher launcher, @SuppressWarnings("rawtypes") AbstractBuild build, ConsoleLogger console)
throws DockerException {
try {
Config cfgData = getConfig(build);
Descriptor<?> descriptor = Jenkins.getInstance().getDescriptor(DockerBuilder.class);
List<Container> containers = launcher.getChannel().call(new ListContainersRemoteCallable(cfgData, descriptor, false));
for (Container container : containers) {
launcher.getChannel().call(new RemoveContainerRemoteCallable(cfgData, descriptor, container.getId(), force, removeVolumes));
console.logInfo("removed container id " + container.getId());
}
} catch (Exception e) {
console.logError("failed to stop all containers");
e.printStackTrace();
throw new IllegalArgumentException(e);
}
}
示例8: execute
import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Override
public void execute(Run<?, ?> build, Launcher launcher, TaskListener listener)
throws DockerException {
final PrintStream llog = listener.getLogger();
LOG.info("Stopping all containers");
llog.println("Stopping all containers");
for (DockerLaunchAction.Item containerItem : getLaunchAction(build).getRunning()) {
LOG.info("Stopping container {}", containerItem.id);
llog.println("Stopping container " + containerItem.id);
containerItem.client.stopContainerCmd(containerItem.id).exec();
if (remove) {
LOG.info("Removing container {}", containerItem.id);
llog.println("Removing container " + containerItem.id);
containerItem.client.removeContainerCmd(containerItem.id).exec();
}
}
}
示例9: inspectContainerWithSize
import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test()
public void inspectContainerWithSize() throws DockerException {
String containerName = "generated_" + new SecureRandom().nextInt();
CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("top")
.withName(containerName).exec();
LOG.info("Created container {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));
InspectContainerCmd command = dockerRule.getClient().inspectContainerCmd(container.getId()).withSize(true);
assertTrue(command.getSize());
InspectContainerResponse containerInfo = command.exec();
assertEquals(containerInfo.getId(), container.getId());
// TODO check swarm
if (isNotSwarm(dockerRule.getClient())) {
assertNotNull(containerInfo.getSizeRootFs());
assertTrue(containerInfo.getSizeRootFs().intValue() > 0);
}
}
示例10: killContainer
import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test
public void killContainer() throws DockerException {
CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999").exec();
LOG.info("Created container: {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));
dockerRule.getClient().startContainerCmd(container.getId()).exec();
LOG.info("Killing container: {}", container.getId());
dockerRule.getClient().killContainerCmd(container.getId()).exec();
InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();
LOG.info("Container Inspect: {}", inspectContainerResponse.toString());
assertThat(inspectContainerResponse.getState().getRunning(), is(equalTo(false)));
assertThat(inspectContainerResponse.getState().getExitCode(), not(equalTo(0)));
}
示例11: removeVolume
import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test(expected = NotFoundException.class)
public void removeVolume() throws DockerException {
String volumeName = "volume1" + dockerRule.getKind();
CreateVolumeResponse createVolumeResponse = dockerRule.getClient().createVolumeCmd()
.withName(volumeName)
.withDriver("local").exec();
assertThat(createVolumeResponse.getName(), equalTo(volumeName));
assertThat(createVolumeResponse.getDriver(), equalTo("local"));
assertThat(createVolumeResponse.getMountpoint(), containsString(volumeName));
dockerRule.getClient().removeVolumeCmd(volumeName).exec();
dockerRule.getClient().inspectVolumeCmd(volumeName).exec();
}
示例12: inspectNetwork
import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test
public void inspectNetwork() throws DockerException {
assumeNotSwarm("no network in swarm", dockerRule);
List<Network> networks = dockerRule.getClient().listNetworksCmd().exec();
Network expected = findNetwork(networks, "bridge");
Network network = dockerRule.getClient().inspectNetworkCmd().withNetworkId(expected.getId()).exec();
assertThat(network.getName(), equalTo(expected.getName()));
assertThat(network.getScope(), equalTo(expected.getScope()));
assertThat(network.getDriver(), equalTo(expected.getDriver()));
assertThat(network.getIpam().getConfig().get(0).getSubnet(), equalTo(expected.getIpam().getConfig().get(0).getSubnet()));
assertThat(network.getIpam().getDriver(), equalTo(expected.getIpam().getDriver()));
}
示例13: createContainerWithShmPidsLimit
import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@SuppressWarnings("Duplicates")
@Test
public void createContainerWithShmPidsLimit() throws DockerException {
assumeThat("API version should be >= 1.23", dockerRule, isGreaterOrEqual(VERSION_1_23));
HostConfig hostConfig = new HostConfig().withPidsLimit(2L);
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
.withHostConfig(hostConfig).withCmd("true").exec();
LOG.info("Created container {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));
InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();
assertThat(inspectContainerResponse.getHostConfig().getPidsLimit(), is(hostConfig.getPidsLimit()));
}
示例14: createVolumeWithExistingName
import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test
public void createVolumeWithExistingName() throws DockerException {
String volumeName = "volume1";
CreateVolumeResponse createVolumeResponse1 = dockerRule.getClient().createVolumeCmd().withName(volumeName)
.withDriver("local").exec();
assertThat(createVolumeResponse1.getName(), equalTo(volumeName));
assertThat(createVolumeResponse1.getDriver(), equalTo("local"));
assertThat(createVolumeResponse1.getMountpoint(), containsString("/volume1/"));
CreateVolumeResponse createVolumeResponse2 = dockerRule.getClient().createVolumeCmd().withName(volumeName)
.withDriver("local").exec();
assertThat(createVolumeResponse2.getName(), equalTo(volumeName));
assertThat(createVolumeResponse2.getDriver(), equalTo("local"));
assertThat(createVolumeResponse2.getMountpoint(), equalTo(createVolumeResponse1.getMountpoint()));
}
示例15: testCreateService
import com.github.dockerjava.api.exception.DockerException; //导入依赖的package包/类
@Test
public void testCreateService() throws DockerException {
dockerRule.getClient().initializeSwarmCmd(new SwarmSpec())
.withListenAddr("127.0.0.1")
.withAdvertiseAddr("127.0.0.1")
.exec();
dockerRule.getClient().createServiceCmd(new ServiceSpec()
.withName(SERVICE_NAME)
.withTaskTemplate(new TaskSpec()
.withContainerSpec(new ContainerSpec()
.withImage(DEFAULT_IMAGE))))
.exec();
List<Service> services = dockerRule.getClient().listServicesCmd()
.withNameFilter(Lists.newArrayList(SERVICE_NAME))
.exec();
assertThat(services, hasSize(1));
dockerRule.getClient().removeServiceCmd(SERVICE_NAME).exec();
}