use of org.eclipse.jkube.kit.build.service.docker.watch.WatchContext in project jkube by eclipse.
the class WatchServiceTest method testRestartContainerAndCallPostGoalRestartEnabled.
@Test
public void testRestartContainerAndCallPostGoalRestartEnabled() throws Exception {
// Given
AtomicBoolean restarted = new AtomicBoolean(false);
WatchContext watchContext = WatchContext.builder().watchMode(WatchMode.both).containerRestarter(// Override Restart task to set this value to true
i -> restarted.set(true)).build();
WatchService.ImageWatcher imageWatcher = new WatchService.ImageWatcher(imageConfiguration, watchContext, "test-img", "efe1234");
WatchService watchService = new WatchService(archiveService, buildService, queryService, runService, logger);
// When
watchService.restartContainerAndCallPostGoal(imageWatcher, true);
// Then
assertTrue(restarted.get());
}
use of org.eclipse.jkube.kit.build.service.docker.watch.WatchContext in project jkube by eclipse.
the class WatchServiceTest method testRestartContainerAndCallPostGoalRestartDisabled.
@Test
public void testRestartContainerAndCallPostGoalRestartDisabled() throws Exception {
// Given
AtomicReference<String> stringAtomicReference = new AtomicReference<>("oldVal");
String mavenGoalToExecute = "org.apache.maven.plugins:maven-help-plugin:help";
WatchContext watchContext = WatchContext.builder().watchMode(WatchMode.both).postGoalTask(() -> stringAtomicReference.compareAndSet("oldVal", mavenGoalToExecute)).build();
WatchService.ImageWatcher imageWatcher = new WatchService.ImageWatcher(imageConfiguration, watchContext, "test-img", "efe1234");
WatchService watchService = new WatchService(archiveService, buildService, queryService, runService, logger);
// When
watchService.restartContainerAndCallPostGoal(imageWatcher, false);
// Then
assertEquals(mavenGoalToExecute, stringAtomicReference.get());
}
use of org.eclipse.jkube.kit.build.service.docker.watch.WatchContext in project jkube by eclipse.
the class DockerImageWatcher method watch.
@Override
public void watch(List<ImageConfiguration> configs, String namespace, final Collection<HasMetadata> resources, PlatformMode mode) {
WatchContext watchContext = getContext().getWatchContext();
watchContext = watchContext.toBuilder().imageCustomizer(this::buildImage).containerRestarter(imageWatcher -> restartContainer(imageWatcher, resources)).containerCommandExecutor(command -> executeCommandInPod(command, resources)).containerCopyTask(f -> copyFileToPod(f, resources)).build();
DockerServiceHub hub = getContext().getJKubeServiceHub().getDockerServiceHub();
try {
hub.getWatchService().watch(watchContext, getContext().getBuildContext(), configs);
} catch (Exception ex) {
throw new RuntimeException("Error while watching", ex);
}
}
use of org.eclipse.jkube.kit.build.service.docker.watch.WatchContext in project jkube by eclipse.
the class DockerImageWatcherTest method setUp.
@Before
public void setUp() {
dockerImageWatcher = new DockerImageWatcher(watcherContext);
// @formatter:off
new Expectations() {
{
watcherContext.getWatchContext();
result = new WatchContext();
minTimes = 0;
}
};
// @formatter:on
new MockUp<WatchService>() {
@Mock
void watch(WatchContext context, JKubeConfiguration buildContext, List<ImageConfiguration> images) {
watchContext = context;
}
};
}
use of org.eclipse.jkube.kit.build.service.docker.watch.WatchContext in project jkube by eclipse.
the class WatchMojo method getWatcherContext.
private WatcherContext getWatcherContext() throws MojoExecutionException {
try {
JKubeConfiguration buildContext = initJKubeConfiguration();
WatchContext watchContext = jkubeServiceHub.getDockerServiceHub() != null ? getWatchContext() : null;
return WatcherContext.builder().buildContext(buildContext).watchContext(watchContext).config(extractWatcherConfig()).logger(log).newPodLogger(createLogger("[[C]][NEW][[C]] ")).oldPodLogger(createLogger("[[R]][OLD][[R]] ")).useProjectClasspath(useProjectClasspath).jKubeServiceHub(jkubeServiceHub).build();
} catch (DependencyResolutionRequiredException dependencyException) {
throw new MojoExecutionException("Instructed to use project classpath, but cannot. Continuing build if we can: " + dependencyException.getMessage());
} catch (IOException ioException) {
throw new MojoExecutionException(ioException.getMessage());
}
}
Aggregations