forked from arquillian/arquillian-cube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ecdd7f1
Showing
26 changed files
with
1,526 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Eclipse | ||
.project | ||
.classpath | ||
.settings/ | ||
|
||
# IntelliJ | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea | ||
|
||
# Gradle | ||
.gradle/ | ||
.ivy/ | ||
|
||
# Maven | ||
target/ | ||
|
||
# TestNG | ||
test-output/ | ||
|
||
# JBoss AS | ||
transaction.log | ||
|
||
# Infinitest configuration | ||
infinitest.filters | ||
|
||
# Logs | ||
*.log | ||
*.log~ | ||
|
||
# Libreoffice leftovers (XLS) | ||
.~lock* | ||
|
||
atlassian-ide-plugin.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jboss.arquillian.extension</groupId> | ||
<artifactId>arquillian-cube</artifactId> | ||
<version>1.0.0.Alpha1</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>arquillian-cube-api</artifactId> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jboss.arquillian.extension</groupId> | ||
<artifactId>arquillian-cube</artifactId> | ||
<version>1.0.0.Alpha1</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>arquillian-cube-docker</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.arquillian.core</groupId> | ||
<artifactId>arquillian-core-spi</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.arquillian.test</groupId> | ||
<artifactId>arquillian-test-spi</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.arquillian.container</groupId> | ||
<artifactId>arquillian-container-test-spi</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.arquillian.junit</groupId> | ||
<artifactId>arquillian-junit-container</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-all</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.github.docker-java</groupId> | ||
<artifactId>docker-java</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.yaml</groupId> | ||
<artifactId>snakeyaml</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
9 changes: 9 additions & 0 deletions
9
docker/src/main/java/org/arquillian/cube/await/AwaitStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.arquillian.cube.await; | ||
|
||
import com.github.dockerjava.api.command.CreateContainerResponse; | ||
|
||
public interface AwaitStrategy { | ||
|
||
boolean await(); | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
docker/src/main/java/org/arquillian/cube/await/AwaitStrategyFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.arquillian.cube.await; | ||
|
||
import java.util.Map; | ||
|
||
import org.arquillian.cube.docker.DockerClientExecutor; | ||
|
||
import com.github.dockerjava.api.command.CreateContainerResponse; | ||
|
||
public class AwaitStrategyFactory { | ||
|
||
private static final String AWAIT = "await"; | ||
private static final String STRATEGY = "strategy"; | ||
|
||
private AwaitStrategyFactory() { | ||
super(); | ||
} | ||
|
||
public static final AwaitStrategy create(DockerClientExecutor dockerClientExecutor, CreateContainerResponse createContainerResponse, Map<String, Object> options) { | ||
|
||
if(options.containsKey(AWAIT)) { | ||
|
||
Map<String, Object> awaitOptions = (Map<String, Object>) options.get(AWAIT); | ||
|
||
if(awaitOptions.containsKey(STRATEGY)) { | ||
|
||
String strategy = ((String) awaitOptions.get(STRATEGY)).toLowerCase(); | ||
|
||
switch(strategy) { | ||
case PollingAwaitStrategy.TAG: return new PollingAwaitStrategy(dockerClientExecutor, createContainerResponse); | ||
case NativeAwaitStrategy.TAG: return new NativeAwaitStrategy(dockerClientExecutor, createContainerResponse); | ||
case StaticAwaitStrategy.TAG: return new StaticAwaitStrategy(awaitOptions); | ||
default: return new NativeAwaitStrategy(dockerClientExecutor, createContainerResponse); | ||
} | ||
|
||
} else { | ||
return new NativeAwaitStrategy(dockerClientExecutor, createContainerResponse); | ||
} | ||
|
||
} else { | ||
return new NativeAwaitStrategy(dockerClientExecutor, createContainerResponse); | ||
} | ||
|
||
} | ||
|
||
|
||
} |
29 changes: 29 additions & 0 deletions
29
docker/src/main/java/org/arquillian/cube/await/NativeAwaitStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.arquillian.cube.await; | ||
|
||
import org.arquillian.cube.docker.DockerClientExecutor; | ||
|
||
import com.github.dockerjava.api.command.CreateContainerResponse; | ||
|
||
public class NativeAwaitStrategy implements AwaitStrategy { | ||
|
||
public static final String TAG = "native"; | ||
|
||
private DockerClientExecutor dockerClientExecutor; | ||
private CreateContainerResponse createContainerResponse; | ||
|
||
public NativeAwaitStrategy(DockerClientExecutor dockerClientExecutor, CreateContainerResponse createContainerResponse) { | ||
this.dockerClientExecutor = dockerClientExecutor; | ||
this.createContainerResponse = createContainerResponse; | ||
} | ||
|
||
@Override | ||
public boolean await() { | ||
|
||
if (this.dockerClientExecutor.waitContainer(this.createContainerResponse) == 0) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
docker/src/main/java/org/arquillian/cube/await/PollingAwaitStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.arquillian.cube.await; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.arquillian.cube.docker.DockerClientExecutor; | ||
import org.arquillian.cube.util.Ping; | ||
|
||
import com.github.dockerjava.api.command.CreateContainerResponse; | ||
import com.github.dockerjava.api.command.InspectContainerResponse; | ||
import com.github.dockerjava.api.command.InspectContainerResponse.HostConfig; | ||
import com.github.dockerjava.api.command.InspectContainerResponse.NetworkSettings; | ||
import com.github.dockerjava.api.model.ExposedPort; | ||
import com.github.dockerjava.api.model.Ports; | ||
import com.github.dockerjava.api.model.Ports.Binding; | ||
|
||
public class PollingAwaitStrategy implements AwaitStrategy { | ||
|
||
public static final String TAG = "polling"; | ||
|
||
private static final int DEFAULT_POLL_ITERATIONS = 10; | ||
private static final int DEFAULT_SLEEP_POLL_TIME = 500; | ||
|
||
private DockerClientExecutor dockerClientExecutor; | ||
private CreateContainerResponse createContainer; | ||
|
||
public PollingAwaitStrategy(DockerClientExecutor dockerClientExecutor, CreateContainerResponse createContainer) { | ||
this.dockerClientExecutor = dockerClientExecutor; | ||
this.createContainer = createContainer; | ||
} | ||
|
||
@Override | ||
public boolean await() { | ||
InspectContainerResponse inspectContainer = this.dockerClientExecutor.inspectContainer(this.createContainer); | ||
|
||
HostConfig hostConfig = inspectContainer.getHostConfig(); | ||
Ports portBindings = hostConfig.getPortBindings(); | ||
|
||
Map<ExposedPort, Binding> bindings = portBindings.getBindings(); | ||
|
||
NetworkSettings networkSettings = inspectContainer.getNetworkSettings(); | ||
// this approach only works if you are not using boot2docker. In next versions we will add support for | ||
// boot2docker | ||
String containerIp = networkSettings.getIpAddress(); | ||
Collection<Binding> hostIpPort = bindings.values(); | ||
|
||
// wait until container available | ||
for (Binding binding : hostIpPort) { | ||
if(!Ping.ping(containerIp, binding.getHostPort(), DEFAULT_POLL_ITERATIONS, DEFAULT_SLEEP_POLL_TIME, | ||
TimeUnit.MILLISECONDS)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
docker/src/main/java/org/arquillian/cube/await/StaticAwaitStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.arquillian.cube.await; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.arquillian.cube.util.Ping; | ||
|
||
public class StaticAwaitStrategy implements AwaitStrategy { | ||
|
||
private static final String PORTS = "ports"; | ||
|
||
private static final String IP = "ip"; | ||
|
||
public static final String TAG = "static"; | ||
|
||
private static final int DEFAULT_POLL_ITERATIONS = 10; | ||
private static final int DEFAULT_SLEEP_POLL_TIME = 500; | ||
|
||
private String ip; | ||
private List<Integer> ports = new ArrayList<Integer>(); | ||
|
||
public StaticAwaitStrategy(Map<String, Object> params) { | ||
this.ip = (String) params.get(IP); | ||
this.ports.addAll((Collection<? extends Integer>) params.get(PORTS)); | ||
} | ||
|
||
@Override | ||
public boolean await() { | ||
|
||
for (Integer port : this.ports) { | ||
if(!Ping.ping(this.ip, port, DEFAULT_POLL_ITERATIONS, DEFAULT_SLEEP_POLL_TIME, TimeUnit.MILLISECONDS )) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public String getIp() { | ||
return ip; | ||
} | ||
|
||
public List<Integer> getPorts() { | ||
return ports; | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
docker/src/main/java/org/arquillian/cube/client/CubeConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.arquillian.cube.client; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Properties; | ||
|
||
import org.yaml.snakeyaml.Yaml; | ||
|
||
public class CubeConfiguration { | ||
|
||
private static final String DOCKER_VERSION = "serverVersion"; | ||
private static final String DOCKER_URI = "serverUri"; | ||
private static final String DOCKER_CONTAINERS = "dockerContainers"; | ||
private static final String DOCKER_CONTAINERS_FILE = "dockerContainersFile"; | ||
|
||
private String dockerServerVersion; | ||
private String dockerServerUri; | ||
private Map<String, Object> dockerContainersContent; | ||
|
||
public String getDockerServerUri() { | ||
return dockerServerUri; | ||
} | ||
|
||
public String getDockerServerVersion() { | ||
return dockerServerVersion; | ||
} | ||
|
||
public Map<String, Object> getDockerContainersContent() { | ||
return dockerContainersContent; | ||
} | ||
|
||
public static CubeConfiguration fromMap(Map<String, String> map) { | ||
CubeConfiguration cubeConfiguration = new CubeConfiguration(); | ||
|
||
if(map.containsKey(DOCKER_VERSION)) { | ||
cubeConfiguration.dockerServerVersion = map.get(DOCKER_VERSION); | ||
} | ||
|
||
if(map.containsKey(DOCKER_URI)) { | ||
cubeConfiguration.dockerServerUri = map.get(DOCKER_URI); | ||
} | ||
|
||
if(map.containsKey(DOCKER_CONTAINERS)) { | ||
String content = map.get(DOCKER_CONTAINERS); | ||
cubeConfiguration.dockerContainersContent = (Map<String, Object>) new Yaml().load(content); | ||
} | ||
|
||
if(map.containsKey(DOCKER_CONTAINERS_FILE)) { | ||
String location = map.get(DOCKER_CONTAINERS_FILE); | ||
try { | ||
cubeConfiguration.dockerContainersContent = (Map<String, Object>) new Yaml().load(new FileInputStream(location)); | ||
} catch (FileNotFoundException e) { | ||
throw new IllegalArgumentException(e); | ||
} | ||
} | ||
|
||
return cubeConfiguration; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
docker/src/main/java/org/arquillian/cube/client/CubeConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.arquillian.cube.client; | ||
|
||
import java.util.Map; | ||
|
||
import org.jboss.arquillian.config.descriptor.api.ArquillianDescriptor; | ||
import org.jboss.arquillian.core.api.InstanceProducer; | ||
import org.jboss.arquillian.core.api.annotation.ApplicationScoped; | ||
import org.jboss.arquillian.core.api.annotation.Inject; | ||
import org.jboss.arquillian.core.api.annotation.Observes; | ||
|
||
public class CubeConfigurator { | ||
|
||
private static final String EXTENSION_NAME = "docker"; | ||
|
||
@Inject | ||
@ApplicationScoped | ||
private InstanceProducer<CubeConfiguration> configurationProvider; | ||
|
||
public void configure(@Observes ArquillianDescriptor arquillianDescriptor) { | ||
Map<String, String> config = arquillianDescriptor.extension(EXTENSION_NAME).getExtensionProperties(); | ||
configurationProvider.set(CubeConfiguration.fromMap(config)); | ||
} | ||
|
||
} |
Oops, something went wrong.