本文整理汇总了Java中com.github.dockerjava.api.command.InspectContainerResponse类的典型用法代码示例。如果您正苦于以下问题:Java InspectContainerResponse类的具体用法?Java InspectContainerResponse怎么用?Java InspectContainerResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InspectContainerResponse类属于com.github.dockerjava.api.command包,在下文中一共展示了InspectContainerResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doDiscovery
import com.github.dockerjava.api.command.InspectContainerResponse; //导入依赖的package包/类
private Service doDiscovery(Service s) {
List<SrvRecord> records;
try {
records = resolver.resolveSRV(s.getName() + CONSUL_DNS_SUFFIX, s.getInstances().size(),
discoveryTimeout, dnsPollingFrequency);
} catch (Throwable t) {
return s.withInstances(s.getInstances().stream()
.map(i -> i.withStatus(Status.ABORTED)
.withStatusDetails(t.getMessage()))
.collect(Collectors.toSet()));
}
Set<ServiceInstance> withPorts = s.getInstances().stream()
.map(si -> {
InspectContainerResponse r = dockerClient.inspectContainerCmd(si.getContainerId()).exec();
return si.withPort(findPort(r, records))
.withIp(DOCKER_HOST)
.withStatus(Status.DISCOVERED)
.withStatusDetails("Discovered via consul + registrator");
}).collect(Collectors.toSet());
return s.withInstances(withPorts);
}
示例2: containerInfo
import com.github.dockerjava.api.command.InspectContainerResponse; //导入依赖的package包/类
@GetMapping ( "/container/info" )
public ObjectNode containerInfo (
String id,
String name )
throws Exception {
ObjectNode result = jacksonMapper.createObjectNode();
try {
InspectContainerResponse info = dockerHelper.containerConfiguration( name );
return jacksonMapper.convertValue( info, ObjectNode.class );
} catch (Exception e) {
String reason = CSAP.getCsapFilteredStackTrace( e );
logger.warn( "Failed starting {}, {}", name, reason );
result.put( DockerJson.error.key, "Failed starting: " + name );
result.put( DockerJson.errorReason.key, reason );
}
return result;
}
示例3: containerSockets
import com.github.dockerjava.api.command.InspectContainerResponse; //导入依赖的package包/类
@GetMapping ( "/container/sockets" )
public ObjectNode containerSockets (
String id,
String name )
throws Exception {
ObjectNode result = jacksonMapper.createObjectNode();
try {
InspectContainerResponse info = dockerHelper.containerConfiguration( name );
String socketInfo = dockerHelper.dockerOpenSockets( info.getState().getPid() + "" );
result.put( "result", "socket info for pid: " + info.getState().getPid() );
result.put( "plainText", socketInfo );
} catch (Exception e) {
String reason = CSAP.getCsapFilteredStackTrace( e );
logger.warn( "Failed starting {}, {}", name, reason );
result.put( DockerJson.error.key, "Failed starting: " + name );
result.put( DockerJson.errorReason.key, reason );
}
return result;
}
示例4: containerProcessTree
import com.github.dockerjava.api.command.InspectContainerResponse; //导入依赖的package包/类
@GetMapping ( "/container/processTree" )
public ObjectNode containerProcessTree (
String id,
String name )
throws Exception {
ObjectNode result = jacksonMapper.createObjectNode();
try {
InspectContainerResponse info = dockerHelper.containerConfiguration( name );
String socketInfo = osManager.getProcessTree( info.getState().getPid() + "", name );
result.put( "result", "process tree for pid: " + info.getState().getPid() );
result.put( "plainText", socketInfo );
} catch (Exception e) {
String reason = CSAP.getCsapFilteredStackTrace( e );
logger.warn( "Failed starting {}, {}", name, reason );
result.put( DockerJson.error.key, "Failed starting: " + name );
result.put( DockerJson.errorReason.key, reason );
}
return result;
}
示例5: waitForRunning
import com.github.dockerjava.api.command.InspectContainerResponse; //导入依赖的package包/类
private InspectContainerResponse waitForRunning ( String containerName, boolean isRunning ) {
InspectContainerResponse containerInfo;
while (true) {
containerInfo = getContainerStatus( containerName );
logger.info( "Waiting for: {} current: {}", isRunning, containerInfo.getState().getRunning() );
if ( isRunning == containerInfo.getState().getRunning() ) {
break;
}
try {
Thread.sleep( 10 );
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return containerInfo;
}
示例6: deleteContainer
import com.github.dockerjava.api.command.InspectContainerResponse; //导入依赖的package包/类
@Override
public void deleteContainer(ContainerName containerName) {
try {
dockerImageGC.ifPresent(imageGC -> {
Optional<InspectContainerResponse> inspectResponse = inspectContainerCmd(containerName.asString());
inspectResponse.ifPresent(response -> imageGC.updateLastUsedTimeFor(response.getImageId()));
});
dockerClient.removeContainerCmd(containerName.asString()).exec();
} catch (NotFoundException ignored) {
// If container doesn't exist ignore
} catch (RuntimeException e) {
numberOfDockerDaemonFails.add();
throw new DockerException("Failed to delete container '" + containerName.asString() + "'", e);
}
}
示例7: isContainerRunning
import com.github.dockerjava.api.command.InspectContainerResponse; //导入依赖的package包/类
/**
* Based on this status, is this container running, and has it been doing so for the specified amount of time?
*
* @param state the state provided by InspectContainer
* @param minimumRunningDuration minimum duration to consider this as "solidly" running, or null
* @param now the time to consider as the current time
* @return true if we can conclude that the container is running, false otherwise
*/
public static boolean isContainerRunning(InspectContainerResponse.ContainerState state,
Duration minimumRunningDuration,
Instant now) {
if (state.getRunning()) {
if (minimumRunningDuration == null) {
return true;
}
Instant startedAt = DateTimeFormatter.ISO_INSTANT.parse(
state.getStartedAt(), Instant::from);
if (startedAt.isBefore(now.minus(minimumRunningDuration))) {
return true;
}
}
return false;
}
示例8: getDockerEvent
import com.github.dockerjava.api.command.InspectContainerResponse; //导入依赖的package包/类
private DockerEvent getDockerEvent(String containerId){
DockerEvent result = null;
try{
InspectContainerResponse inspectResponse = dockerClient.inspectContainerCmd(containerId).exec();
ContainerConfig config = inspectResponse.getConfig();
Map<String,String> labels = config.getLabels();
String taskId = labels.get(TASK_ID);
if(this.taskId.getValue().equals(taskId)){
ContainerState state = inspectResponse.getState();
String name = inspectResponse.getName();
int exitCode = state.getExitCode();
int pid = state.getPid();
result= new DockerEvent(containerId, name, pid, exitCode);
}
}catch(NotFoundException exception){
log.debug("tried to debug non-existent containerId",exception);
}
return result;
}
示例9: testCreateContainer
import com.github.dockerjava.api.command.InspectContainerResponse; //导入依赖的package包/类
@Test
public void testCreateContainer() throws MalformedURLException {
Container container = createContainer("toscaruntime/ubuntu-trusty");
try {
container.create();
container.start();
InspectContainerResponse containerInspect = container.getDockerClient().inspectContainerCmd(container.getContainerId()).exec();
Assert.assertTrue(!containerInspect.getNetworkSettings().getPorts().getBindings().isEmpty());
Assert.assertEquals(80, containerInspect.getNetworkSettings().getPorts().getBindings().keySet().iterator().next().getPort());
Assert.assertEquals(InternetProtocol.TCP, containerInspect.getNetworkSettings().getPorts().getBindings().keySet().iterator().next().getProtocol());
Assert.assertNotNull(container.getAttribute("ip_address"));
Map<String, String> outputs = container.execute("test", "testScript.sh", ImmutableMap.<String, Object>builder().put("HELLO_ARGS", "I'm John").build(), ImmutableMap.<String, String>builder().put("conf_artifact", "path/to/confDir").build());
Assert.assertEquals("Hello I'm John", outputs.get("OUTPUT_TEST"));
Assert.assertEquals(Container.RECIPE_LOCATION + "/path/to/confDir", outputs.get("conf_artifact"));
} catch (Exception e) {
logger.error("Error in test", e);
throw e;
} finally {
cleanContainer(container);
}
}
示例10: call
import com.github.dockerjava.api.command.InspectContainerResponse; //导入依赖的package包/类
public Void call() throws Exception {
final ConsoleLogger console = new ConsoleLogger(listener);
DockerClient client = DockerCommand.getClient(descriptor, cfgData.dockerUrlRes, cfgData.dockerVersionRes, cfgData.dockerCertPathRes, null);
Map<String, List<Integer>> containers = PortUtils.parsePorts(waitForPorts);
for (String cId : containers.keySet()) {
InspectContainerResponse response = client.inspectContainerCmd(cId).exec();
String ip = response.getNetworkSettings().getIpAddress();
List<Integer> ports = containers.get(cId);
for (Integer port : ports) {
console.logInfo("Waiting for port " + port + " on " + ip + " (container ID " + cId + ")");
boolean portReady = PortUtils.waitForPort(ip, port);
if (portReady) {
console.logInfo(ip + ":" + port + " ready");
} else {
// TODO fail the build, but make timeout configurable first
console.logWarn(ip + ":" + port + " still not available (container ID " + cId
+ "), but build continues ...");
}
}
}
return null;
}
示例11: setName
import com.github.dockerjava.api.command.InspectContainerResponse; //导入依赖的package包/类
private void setName(Instance instance, InspectContainerResponse inspect, Map<String, Object> fromInspect) {
String name = inspect.getName();
Object displayNameLabel = CollectionUtils.getNestedValue(fromInspect, "Config", "Labels", SystemLabels.LABEL_DISPLAY_NAME);
if (displayNameLabel == null) {
displayNameLabel = DataAccessor.fieldMap(instance, FIELD_LABELS).get(SystemLabels.LABEL_DISPLAY_NAME);
}
if (displayNameLabel != null) {
String displayName = displayNameLabel.toString();
if (StringUtils.isNotBlank(displayName)) {
name = displayName;
}
}
if (name != null) {
name = name.replaceFirst("/", "");
instance.setName(name);
}
}
示例12: inspectDockerContainer
import com.github.dockerjava.api.command.InspectContainerResponse; //导入依赖的package包/类
@VsoMethod(showInApi = false)
public InspectContainerResponse inspectDockerContainer(DockerContainer container) throws Exception
{
log.debug("Running inspectDockerContainer...");
DockerClient dockerClient = null;
try
{
configureNode();
dockerClient = getDockerClient();
return dockerClient.inspectContainerCmd(container.getContainerId()).exec();
}
catch (Exception e)
{
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw, true);
e.printStackTrace(pw);
log.error("Error running inspectDockerContainer: " + sw.getBuffer().toString());
throw e;
}
}
示例13: inspectContainerWithSize
import com.github.dockerjava.api.command.InspectContainerResponse; //导入依赖的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);
}
}
示例14: renameContainer
import com.github.dockerjava.api.command.InspectContainerResponse; //导入依赖的package包/类
@Test
public void renameContainer() 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();
InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();
LOG.info("Container Inspect: {}", inspectContainerResponse.toString());
String name1 = inspectContainerResponse.getName();
dockerRule.getClient().renameContainerCmd(container.getId())
.withName(dockerRule.getKind() + "renameContainer")
.exec();
InspectContainerResponse inspectContainerResponse2 = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();
LOG.info("Container Inspect After Rename: {}", inspectContainerResponse2.toString());
String name2 = inspectContainerResponse2.getName();
assertNotEquals(name1, name2);
dockerRule.getClient().killContainerCmd(container.getId()).exec();
}
示例15: createContainerWithName
import com.github.dockerjava.api.command.InspectContainerResponse; //导入依赖的package包/类
@Test(expected = ConflictException.class)
public void createContainerWithName() throws DockerException {
String containerName = "container_" + dockerRule.getKind();
CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
.withName(containerName)
.withCmd("env").exec();
LOG.info("Created container {}", container.toString());
assertThat(container.getId(), not(isEmptyString()));
InspectContainerResponse inspectContainerResponse = dockerRule.getClient().inspectContainerCmd(container.getId()).exec();
assertThat(inspectContainerResponse.getName(), equalTo("/" + containerName));
dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE)
.withName(containerName)
.withCmd("env")
.exec();
}