use of io.fabric8.maven.docker.service.ServiceHub 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"));
}
use of io.fabric8.maven.docker.service.ServiceHub in project fabric8-maven-plugin by fabric8io.
the class DockerImageWatcher method watch.
@Override
public void watch(List<ImageConfiguration> configs, final Set<HasMetadata> resources, PlatformMode mode) {
BuildService.BuildContext buildContext = getContext().getBuildContext();
WatchService.WatchContext watchContext = getContext().getWatchContext();
// add a image customizer
watchContext = new WatchService.WatchContext.Builder(watchContext).imageCustomizer(imageConfiguration -> buildImage(imageConfiguration)).containerRestarter(imageWatcher -> restartContainer(imageWatcher, resources)).build();
ServiceHub hub = getContext().getServiceHub();
try {
hub.getWatchService().watch(watchContext, buildContext, configs);
} catch (Exception ex) {
throw new RuntimeException("Error while watching", ex);
}
}
use of io.fabric8.maven.docker.service.ServiceHub in project fabric8-maven-plugin by fabric8io.
the class WatchMojo method executeInternal.
@Override
protected synchronized void executeInternal(ServiceHub hub) throws MojoExecutionException {
if (hub != null) {
this.hub = hub;
}
URL masterUrl = kubernetes.getMasterUrl();
KubernetesResourceUtil.validateKubernetesMasterUrl(masterUrl);
File manifest;
boolean isOpenshift = OpenshiftHelper.isOpenShift(kubernetes);
if (isOpenshift) {
manifest = openshiftManifest;
} else {
manifest = kubernetesManifest;
}
try {
Set<HasMetadata> resources = KubernetesResourceUtil.loadResources(manifest);
WatcherContext context = getWatcherContext();
WatcherManager.watch(getResolvedImages(), resources, context);
} catch (KubernetesClientException ex) {
KubernetesResourceUtil.handleKubernetesClientException(ex, this.log);
} catch (Exception ex) {
throw new MojoExecutionException("An error has occurred while while trying to watch the resources", ex);
}
}
Aggregations