Search in sources :

Example 46 with Application

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();
    }
}
Also used : Remove(com.oracle.bedrock.runtime.docker.commands.Remove) Application(com.oracle.bedrock.runtime.Application)

Example 47 with Application

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());
    }
}
Also used : AbstractDockerCommand(com.oracle.bedrock.runtime.docker.commands.AbstractDockerCommand) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) Version(com.oracle.bedrock.util.Version) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) OperatingSystem(com.oracle.bedrock.runtime.OperatingSystem) Option(com.oracle.bedrock.Option) InetAddress(java.net.InetAddress) RemoteJavaApplicationLauncher(com.oracle.bedrock.runtime.remote.java.RemoteJavaApplicationLauncher) AbstractPlatform(com.oracle.bedrock.runtime.AbstractPlatform) MetaClass(com.oracle.bedrock.runtime.MetaClass) RemoteTerminalBuilder(com.oracle.bedrock.runtime.remote.RemoteTerminalBuilder) Platform(com.oracle.bedrock.runtime.Platform) SimpleRemoteApplicationLauncher(com.oracle.bedrock.runtime.remote.SimpleRemoteApplicationLauncher) ApplicationLauncher(com.oracle.bedrock.runtime.ApplicationLauncher) OptionsByType(com.oracle.bedrock.OptionsByType) Application(com.oracle.bedrock.runtime.Application) RemoteTerminalBuilder(com.oracle.bedrock.runtime.remote.RemoteTerminalBuilder) AbstractDockerCommand(com.oracle.bedrock.runtime.docker.commands.AbstractDockerCommand) OptionsByType(com.oracle.bedrock.OptionsByType)

Example 48 with Application

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));
        }
    }
}
Also used : JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) Application(com.oracle.bedrock.runtime.Application) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) BeforeClass(org.junit.BeforeClass)

Example 49 with Application

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"));
}
Also used : Platform(com.oracle.bedrock.runtime.Platform) MetaClass(com.oracle.bedrock.runtime.MetaClass) Stop(com.oracle.bedrock.runtime.docker.commands.Stop) Arguments(com.oracle.bedrock.runtime.options.Arguments) Matchers.anyString(org.mockito.Matchers.anyString) Application(com.oracle.bedrock.runtime.Application) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 50 with Application

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());
}
Also used : Inspect(com.oracle.bedrock.runtime.docker.commands.Inspect) Platform(com.oracle.bedrock.runtime.Platform) MetaClass(com.oracle.bedrock.runtime.MetaClass) Application(com.oracle.bedrock.runtime.Application) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Application (com.oracle.bedrock.runtime.Application)57 Test (org.junit.Test)23 CapturingApplicationConsole (com.oracle.bedrock.runtime.console.CapturingApplicationConsole)22 Platform (com.oracle.bedrock.runtime.Platform)16 Arguments (com.oracle.bedrock.runtime.options.Arguments)13 OptionsByType (com.oracle.bedrock.OptionsByType)12 File (java.io.File)12 JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)11 Timeout (com.oracle.bedrock.options.Timeout)9 MetaClass (com.oracle.bedrock.runtime.MetaClass)9 List (java.util.List)7 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)6 Remove (com.oracle.bedrock.runtime.docker.commands.Remove)5 RemotePlatform (com.oracle.bedrock.runtime.remote.RemotePlatform)5 InetAddress (java.net.InetAddress)5 SleepingApplication (applications.SleepingApplication)4 ContainerCloseBehaviour (com.oracle.bedrock.runtime.docker.options.ContainerCloseBehaviour)4 TimeUnit (java.util.concurrent.TimeUnit)4 Collectors (java.util.stream.Collectors)4 EventingApplication (classloader.applications.EventingApplication)3