openvidu-server: docker-java library update to 3.1.1

pull/255/head
pabloFuente 2019-03-29 15:33:42 +01:00
parent c282d53349
commit 52cad41294
3 changed files with 15 additions and 5 deletions

View File

@ -267,7 +267,7 @@
<dependency> <dependency>
<groupId>com.github.docker-java</groupId> <groupId>com.github.docker-java</groupId>
<artifactId>docker-java</artifactId> <artifactId>docker-java</artifactId>
<version>3.0.6</version> <version>3.1.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.openvidu</groupId> <groupId>io.openvidu</groupId>

View File

@ -146,7 +146,11 @@ public class RecordingManager {
} }
}); });
t.start(); t.start();
dockerManager.downloadDockerImage(IMAGE_NAME + ":" + IMAGE_TAG); try {
dockerManager.downloadDockerImage(IMAGE_NAME + ":" + IMAGE_TAG, 600);
} catch (Exception e) {
log.error("Error downloading docker image {}:{}", IMAGE_NAME, IMAGE_TAG);
}
t.interrupt(); t.interrupt();
try { try {
t.join(); t.join();

View File

@ -36,6 +36,7 @@ import com.github.dockerjava.api.exception.InternalServerErrorException;
import com.github.dockerjava.api.exception.NotFoundException; import com.github.dockerjava.api.exception.NotFoundException;
import com.github.dockerjava.api.model.Bind; import com.github.dockerjava.api.model.Bind;
import com.github.dockerjava.api.model.Container; import com.github.dockerjava.api.model.Container;
import com.github.dockerjava.api.model.HostConfig;
import com.github.dockerjava.api.model.Volume; import com.github.dockerjava.api.model.Volume;
import com.github.dockerjava.core.DefaultDockerClientConfig; import com.github.dockerjava.core.DefaultDockerClientConfig;
import com.github.dockerjava.core.DockerClientBuilder; import com.github.dockerjava.core.DockerClientBuilder;
@ -58,9 +59,10 @@ public class DockerManager {
this.dockerClient = DockerClientBuilder.getInstance(config).build(); this.dockerClient = DockerClientBuilder.getInstance(config).build();
} }
public void downloadDockerImage(String image) { public void downloadDockerImage(String image, int secondsOfWait) throws Exception {
try { try {
this.dockerClient.pullImageCmd(image).exec(new PullImageResultCallback()).awaitSuccess(); this.dockerClient.pullImageCmd(image).exec(new PullImageResultCallback()).awaitCompletion(secondsOfWait,
TimeUnit.SECONDS);
} catch (NotFoundException | InternalServerErrorException e) { } catch (NotFoundException | InternalServerErrorException e) {
if (dockerImageExistsLocally(image)) { if (dockerImageExistsLocally(image)) {
log.info("Docker image '{}' exists locally", image); log.info("Docker image '{}' exists locally", image);
@ -70,6 +72,9 @@ public class DockerManager {
} catch (DockerClientException e) { } catch (DockerClientException e) {
log.info("Error on Pulling '{}' image. Probably because the user has stopped the execution", image); log.info("Error on Pulling '{}' image. Probably because the user has stopped the execution", image);
throw e; throw e;
} catch (InterruptedException e) {
log.info("Error on Pulling '{}' image. Thread was interrupted: {}", image, e.getMessage());
throw e;
} }
} }
@ -112,8 +117,9 @@ public class DockerManager {
public String runContainer(String container, String containerName, List<Volume> volumes, List<Bind> binds, public String runContainer(String container, String containerName, List<Volume> volumes, List<Bind> binds,
List<String> envs) throws Exception { List<String> envs) throws Exception {
HostConfig hostConfig = new HostConfig().withNetworkMode("host").withBinds(binds);
CreateContainerCmd cmd = dockerClient.createContainerCmd(container).withName(containerName).withEnv(envs) CreateContainerCmd cmd = dockerClient.createContainerCmd(container).withName(containerName).withEnv(envs)
.withNetworkMode("host").withVolumes(volumes).withBinds(binds); .withHostConfig(hostConfig).withVolumes(volumes);
CreateContainerResponse response = null; CreateContainerResponse response = null;
try { try {
response = cmd.exec(); response = cmd.exec();