Search in sources :

Example 31 with ContainerInfo

use of com.spotify.docker.client.messages.ContainerInfo in project kie-wb-common by kiegroup.

the class DockerRuntimeManager method refresh.

@Override
public void refresh(RuntimeId runtimeId) throws RuntimeOperationException {
    DockerRuntime runtime = (DockerRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId());
    try {
        ContainerInfo containerInfo = docker.getDockerClient(runtime.getProviderId()).inspectContainer(runtime.getId());
        ContainerState state = containerInfo.state();
        String stateString = STOPPED;
        if (state.running() && !state.paused()) {
            stateString = RUNNING;
        } else if (state.paused()) {
            stateString = "Paused";
        } else if (state.restarting()) {
            stateString = "Restarting";
        } else if (state.oomKilled()) {
            stateString = "Killed";
        }
        DockerRuntime newRuntime = new DockerRuntime(runtime.getId(), runtime.getName(), runtime.getConfig(), runtime.getProviderId(), runtime.getEndpoint(), runtime.getInfo(), new DockerRuntimeState(stateString, state.startedAt().toString()));
        runtimeRegistry.registerRuntime(newRuntime);
    } catch (DockerException | InterruptedException ex) {
        LOG.error("Error Refreshing container: " + runtimeId.getId(), ex);
        throw new RuntimeOperationException("Error Refreshing container: " + runtimeId.getId(), ex);
    }
}
Also used : DockerRuntime(org.guvnor.ala.docker.model.DockerRuntime) DockerException(com.spotify.docker.client.DockerException) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) DockerRuntimeState(org.guvnor.ala.docker.model.DockerRuntimeState) RuntimeOperationException(org.guvnor.ala.exceptions.RuntimeOperationException) ContainerState(com.spotify.docker.client.messages.ContainerState)

Example 32 with ContainerInfo

use of com.spotify.docker.client.messages.ContainerInfo in project opennms by OpenNMS.

the class SyslogKafkaElasticsearch5OutageIT method getEs5Address.

protected InetSocketAddress getEs5Address() {
    try {
        // Fetch an up-to-date ContainerInfo for the ELASTICSEARCH_5 container
        final DockerClient docker = ((AbstractTestEnvironment) testEnvironment).getDockerClient();
        final String id = testEnvironment.getContainerInfo(ContainerAlias.ELASTICSEARCH_5).id();
        ContainerInfo info = docker.inspectContainer(id);
        return testEnvironment.getServiceAddress(info, 9200, "tcp");
    } catch (DockerException | InterruptedException e) {
        LOG.error("Unexpected exception trying to fetch Elassticsearch port", e);
        return null;
    }
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) DockerClient(com.spotify.docker.client.DockerClient) AbstractTestEnvironment(org.opennms.test.system.api.AbstractTestEnvironment) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo)

Example 33 with ContainerInfo

use of com.spotify.docker.client.messages.ContainerInfo in project opennms by OpenNMS.

the class SyslogKafkaElasticsearchBufferingIT method getServiceAddress.

protected static InetSocketAddress getServiceAddress(AbstractTestEnvironment env, ContainerAlias alias, int port, String protocol) {
    try {
        // Fetch an up-to-date ContainerInfo for the ELASTICSEARCH_5 container
        final DockerClient docker = env.getDockerClient();
        final String id = env.getContainerInfo(alias).id();
        ContainerInfo info = docker.inspectContainer(id);
        return env.getServiceAddress(info, port, protocol);
    } catch (DockerException | InterruptedException e) {
        LOG.error("Unexpected exception trying to fetch Elassticsearch port", e);
        return null;
    }
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) DockerClient(com.spotify.docker.client.DockerClient) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo)

Example 34 with ContainerInfo

use of com.spotify.docker.client.messages.ContainerInfo in project opennms by OpenNMS.

the class RequisitionBuilder method withContainer.

public RequisitionBuilder withContainer(final ContainerAlias alias, final String... services) {
    // We're assuming that the Minion container is on the same
    // host as the service containers
    final ContainerInfo containerInfo = minionSystem.getContainerInfo(alias);
    final String containerIpAddr = containerInfo.networkSettings().ipAddress();
    RequisitionNode node = new RequisitionNode();
    node.setNodeLabel(alias.toString());
    node.setForeignId(alias.toString());
    RequisitionInterface iface = new RequisitionInterface();
    iface.setSnmpPrimary(PrimaryType.PRIMARY);
    iface.setIpAddr(containerIpAddr);
    for (String svcName : services) {
        RequisitionMonitoredService svc = new RequisitionMonitoredService();
        svc.setServiceName(svcName);
        iface.putMonitoredService(svc);
    }
    node.putInterface(iface);
    requisition.putNode(node);
    return this;
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService)

Example 35 with ContainerInfo

use of com.spotify.docker.client.messages.ContainerInfo in project linuxtools by eclipse.

the class DockerConnection method commitContainer.

@Override
public void commitContainer(final String id, final String repo, final String tag, final String comment, final String author) throws DockerException {
    ContainerInfo info;
    try {
        info = client.inspectContainer(id);
        client.commitContainer(id, repo, tag, info.config(), comment, author);
        // update images list
        // FIXME: are we refreshing the list of images twice ?
        listImages();
        getImages(true);
    } 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(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo)

Aggregations

ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)68 ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)45 Test (org.junit.Test)41 ContainerCreation (com.spotify.docker.client.messages.ContainerCreation)35 Matchers.containsString (org.hamcrest.Matchers.containsString)33 Long.toHexString (java.lang.Long.toHexString)31 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)31 DockerException (com.spotify.docker.client.exceptions.DockerException)15 HostConfig (com.spotify.docker.client.messages.HostConfig)15 IOException (java.io.IOException)9 DockerClient (com.spotify.docker.client.DockerClient)8 ContainerNotFoundException (com.spotify.docker.client.exceptions.ContainerNotFoundException)7 DockerRequestException (com.spotify.docker.client.exceptions.DockerRequestException)5 Container (com.spotify.docker.client.messages.Container)5 ImageInfo (com.spotify.docker.client.messages.ImageInfo)5 LogStream (com.spotify.docker.client.LogStream)4 ImageNotFoundException (com.spotify.docker.client.exceptions.ImageNotFoundException)4 AttachedNetwork (com.spotify.docker.client.messages.AttachedNetwork)4 Path (java.nio.file.Path)4 ContainerMount (com.spotify.docker.client.messages.ContainerMount)3