use of io.fabric8.maven.docker.access.ContainerCreateConfig in project docker-maven-plugin by fabric8io.
the class RunServiceTest method retryIfInsufficientPortBindingInformation.
@Test
public void retryIfInsufficientPortBindingInformation(@Mocked Container container, @Mocked ImageConfiguration imageConfiguration, @Mocked PortMapping portMapping) throws DockerAccessException {
new Expectations() {
{
docker.createContainer(withAny(new ContainerCreateConfig("img")), anyString);
result = "containerId";
portMapping.needsPropertiesUpdate();
result = true;
queryService.getMandatoryContainer("containerId");
result = container;
times = 2;
container.isRunning();
result = true;
container.getPortBindings();
result = new PortBindingException("5432/tcp", new Gson().fromJson("{\"5432/tcp\": []}", JsonObject.class));
returns(ImmutableMap.of("5432/tcp", new Container.PortBinding(56741, "0.0.0.0")), ImmutableMap.of("5432/tcp", new Container.PortBinding(56741, "0.0.0.0")));
}
};
String containerId = runService.createAndStartContainer(imageConfiguration, portMapping, new GavLabel("Im:A:Test"), properties, getBaseDirectory(), "blah", new Date());
new Verifications() {
{
assertEquals("containerId", containerId);
}
};
}
use of io.fabric8.maven.docker.access.ContainerCreateConfig in project docker-maven-plugin by fabric8io.
the class DockerAccessWithHcClient method createContainer.
@Override
public String createContainer(ContainerCreateConfig containerConfig, String containerName) throws DockerAccessException {
String createJson = containerConfig.toJson();
log.debug("Container create config: %s", createJson);
try {
String url = urlBuilder.createContainer(containerName);
log.verbose(Logger.LogVerboseCategory.API, API_LOG_FORMAT_POST_WITH_REQUEST, url, createJson);
String response = delegate.post(url, createJson, new ApacheHttpClientDelegate.BodyResponseHandler(), HTTP_CREATED);
JsonObject json = JsonFactory.newJsonObject(response);
logWarnings(json);
// only need first 12 to id a container
return json.get("Id").getAsString().substring(0, 12);
} catch (IOException e) {
throw new DockerAccessException(e, "Unable to create container for [%s]", containerConfig.getImageName());
}
}
use of io.fabric8.maven.docker.access.ContainerCreateConfig in project docker-maven-plugin by fabric8io.
the class StartContainerExecutorTest method testStartContainers.
@Test
public void testStartContainers(@Mocked ServiceHub hub, @Mocked DockerAccess dockerAccess, @Mocked ContainerTracker containerTracker, @Mocked Logger log) throws IOException, ExecException {
// Given
new Expectations() {
{
dockerAccess.createContainer((ContainerCreateConfig) any, anyString);
result = "container-name";
dockerAccess.getContainer(anyString);
result = new ContainerDetails(JsonFactory.newJsonObject("{\"NetworkSettings\":{\"IPAddress\":\"192.168.1.2\"}}"));
QueryService queryService = new QueryService(dockerAccess);
hub.getQueryService();
result = queryService;
hub.getRunService();
result = new RunService(dockerAccess, queryService, containerTracker, new LogOutputSpecFactory(true, true, null), log);
}
};
Properties projectProps = new Properties();
StartContainerExecutor startContainerExecutor = new StartContainerExecutor.Builder().serviceHub(hub).projectProperties(projectProps).portMapping(new PortMapping(Collections.emptyList(), projectProps)).gavLabel(new GavLabel("io.fabric8:test:0.1.0")).basedir(new File("/tmp/foo")).containerNamePattern("test-").buildTimestamp(new Date()).exposeContainerProps("docker.container").imageConfig(new ImageConfiguration.Builder().name("name").alias("alias").runConfig(new RunImageConfiguration.Builder().build()).build()).build();
// When
String containerId = startContainerExecutor.startContainer();
// Then
assertEquals("container-name", containerId);
assertEquals("container-name", projectProps.getProperty("docker.container.alias.id"));
assertEquals("192.168.1.2", projectProps.getProperty("docker.container.alias.ip"));
}
Aggregations