use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.
the class DockerContainer method remove.
/**
* Remove this {@link DockerContainer}.
* <p>
* This equates to running the <code>docker rm</code> command for
* this {@link DockerContainer}.
* <p>
* This command will fail to execute if the {@link DockerContainer} is still running.
*
* @param force whether to add --force to the Docker rm command
*
* @throws IllegalStateException if this {@link DockerContainer} has not been added
* to an {@link Application} as a {@link Feature}.
*/
public void remove(boolean force) {
if (platform == null) {
throw new IllegalStateException("No Platform is available, is this container a feature of an Application");
}
Docker docker = optionsByType.get(Docker.class);
Remove.RemoveContainer removeCommand;
if (force) {
removeCommand = Remove.containers(name).force(true);
} else {
removeCommand = Remove.containers(name);
}
try (Application app = platform.launch(removeCommand, docker)) {
app.waitFor();
}
}
use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.
the class DockerPlatform method launch.
@Override
public <A extends Application> A launch(MetaClass<A> metaClass, Option... options) {
// establish the initial launch options based on those defined by the platform
OptionsByType launchOptions = OptionsByType.of(getOptions());
// include the options specified when this method was called
launchOptions.addAll(options);
launchOptions.addIfAbsent(docker);
if (metaClass instanceof AbstractDockerCommand) {
// The options contain a Docker command so just run it on the client platform
return clientPlatform.launch(metaClass, launchOptions.asArray());
} else {
// This is a normal launch command so we will build and image and run
// it in a container
DockerRemoteTerminal terminal = new DockerRemoteTerminal(clientPlatform);
RemoteTerminalBuilder builder = (platform) -> terminal;
launchOptions.add(builder);
launchOptions.add(terminal);
return super.launch(metaClass, launchOptions.asArray());
}
}
use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.
the class DockerFunctionalTest method createPlatform.
@BeforeClass
public static void createPlatform() {
if (hasDockerMachine()) {
Docker docker = Docker.auto().withBaseImage(JavaApplication.class, javaImageName);
platformName = "bedrock-" + System.currentTimeMillis();
machine = DockerMachine.local();
platform = machine.create(platformName, docker, JavaHome.at("/java"), Argument.of("-d", "virtualbox"), Argument.of(platformName));
// Pull the oraclelinux:7.1 base image now - it might take a while
RemotePlatform remotePlatform = platform.getRemotePlatform();
try (Application pull = remotePlatform.launch("docker", Argument.of("pull"), Argument.of("oraclelinux:7.1"))) {
pull.waitFor(Timeout.after(10, TimeUnit.MINUTES));
}
}
}
use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.
the class DockerContainerTest method shouldStopContainer.
@Test
public void shouldStopContainer() throws Exception {
Docker docker = Docker.auto();
Platform platform = mock(Platform.class);
Application application = mock(Application.class, "App");
Application removeApp = mock(Application.class, "Inspect");
DockerContainer container = new DockerContainer("foo", OptionsByType.of(docker));
when(application.getPlatform()).thenReturn(platform);
when(platform.launch(any(MetaClass.class), anyVararg())).thenReturn(removeApp);
container.onAddingTo(application);
container.stop();
ArgumentCaptor<MetaClass> captor = ArgumentCaptor.forClass(MetaClass.class);
verify(platform).launch(captor.capture(), anyVararg());
OptionsByType optionsByType = OptionsByType.empty();
Stop stop = (Stop) captor.getValue();
assertThat(stop, is(notNullValue()));
stop.onLaunch(platform, optionsByType);
Arguments arguments = optionsByType.get(Arguments.class);
List<String> values = arguments.resolve(mock(Platform.class), OptionsByType.empty());
assertThat(values, contains("stop", "foo"));
}
use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.
the class DockerContainerTest method shouldRunInspectWithoutFilter.
@Test
@Ignore("Mockito upgrade has broken compatibility")
public void shouldRunInspectWithoutFilter() throws Exception {
Docker docker = Docker.auto();
Platform platform = mock(Platform.class);
Application application = mock(Application.class, "App");
Application inspectApp = mock(Application.class, "Inspect");
Inspect inspect = mock(Inspect.class);
DockerContainer container = new DockerContainer("foo", OptionsByType.of(docker));
DockerContainer containerSpy = spy(container);
when(application.getPlatform()).thenReturn(platform);
when(platform.launch(any(MetaClass.class))).thenReturn(inspectApp);
when(inspect.format(anyString())).thenReturn(inspect);
doReturn(inspect).when(containerSpy).createInspectCommand();
containerSpy.onAddingTo(application);
containerSpy.inspect();
verify(inspect).run(same(platform), same(docker));
verify(inspect).format((String) isNull());
}
Aggregations