Search in sources :

Example 11 with MetaClass

use of com.oracle.bedrock.runtime.MetaClass in project oracle-bedrock by coherence-community.

the class JprofilerProfileTest method shouldCreateEnabledProfileWithDefaultAddress.

@Test
public void shouldCreateEnabledProfileWithDefaultAddress() throws Exception {
    Platform platform = LocalPlatform.get();
    MetaClass metaClass = new JavaApplication.MetaClass();
    OptionsByType optionsByType = OptionsByType.empty();
    JprofilerProfile profile = JprofilerProfile.enabled("mylib");
    assertThat(profile.isEnabled(), is(true));
    profile.onLaunching(platform, metaClass, optionsByType);
    assertAgentString(optionsByType, "-agentpath:mylib=", "port=8849");
    JprofilerProfile.ListenAddress address = optionsByType.get(JprofilerProfile.ListenAddress.class);
    assertThat(address.getInetAddress(), is(nullValue()));
    assertThat(address.getPort().get(), is(8849));
}
Also used : LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) Platform(com.oracle.bedrock.runtime.Platform) MetaClass(com.oracle.bedrock.runtime.MetaClass) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 12 with MetaClass

use of com.oracle.bedrock.runtime.MetaClass in project oracle-bedrock by coherence-community.

the class DockerImageTest method shouldRemoveImage.

@Test
public void shouldRemoveImage() throws Exception {
    Docker docker = Docker.auto();
    Platform platform = mock(Platform.class);
    Application application = mock(Application.class, "App");
    Application removeApp = mock(Application.class, "Inspect");
    DockerImage image = new DockerImage(Arrays.asList("foo"), OptionsByType.of(docker));
    when(application.getPlatform()).thenReturn(platform);
    when(platform.launch(any(MetaClass.class), anyVararg())).thenReturn(removeApp);
    image.onAddingTo(application);
    image.remove();
    ArgumentCaptor<MetaClass> captor = ArgumentCaptor.forClass(MetaClass.class);
    verify(platform).launch(captor.capture(), anyVararg());
    Remove.RemoveImage remove = (Remove.RemoveImage) captor.getValue();
    assertThat(remove, is(notNullValue()));
    OptionsByType optionsByType = OptionsByType.empty();
    remove.onLaunch(platform, optionsByType);
    Arguments arguments = optionsByType.get(Arguments.class);
    List<String> values = arguments.resolve(mock(Platform.class), OptionsByType.empty());
    assertThat(values, contains("rmi", "foo"));
}
Also used : Platform(com.oracle.bedrock.runtime.Platform) Arguments(com.oracle.bedrock.runtime.options.Arguments) Remove(com.oracle.bedrock.runtime.docker.commands.Remove) MetaClass(com.oracle.bedrock.runtime.MetaClass) Application(com.oracle.bedrock.runtime.Application) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 13 with MetaClass

use of com.oracle.bedrock.runtime.MetaClass in project oracle-bedrock by coherence-community.

the class StorageDisabledMember method build.

@Override
public ConfigurableCacheFactory build(LocalPlatform platform, CoherenceCluster cluster, OptionsByType optionsByType) {
    // ----- establish the diagnostics output table -----
    Table diagnosticsTable = new Table();
    diagnosticsTable.getOptions().add(Table.orderByColumn(0));
    // establish a new set of options based on those provided
    optionsByType = OptionsByType.of(optionsByType);
    // ----- establish the options for launching a local storage-disabled member -----
    optionsByType.add(RoleName.of("client"));
    optionsByType.add(LocalStorage.disabled());
    optionsByType.addIfAbsent(CacheConfig.of("coherence-cache-config.xml"));
    // ----- notify the Profiles that we're about to launch an application -----
    MetaClass<CoherenceClusterMember> metaClass = new CoherenceClusterMember.MetaClass();
    for (Profile profile : optionsByType.getInstancesOf(Profile.class)) {
        profile.onLaunching(platform, metaClass, optionsByType);
    }
    // ----- create local system properties based on those defined by the launch options -----
    // modify the current system properties to include/override those in the schema
    com.oracle.bedrock.runtime.java.options.SystemProperties systemProperties = optionsByType.get(com.oracle.bedrock.runtime.java.options.SystemProperties.class);
    Properties properties = systemProperties.resolve(platform, optionsByType);
    Table systemPropertiesTable = new Table();
    systemPropertiesTable.getOptions().add(Table.orderByColumn(0));
    systemPropertiesTable.getOptions().add(Cell.Separator.of(""));
    systemPropertiesTable.getOptions().add(Cell.DisplayNull.asEmptyString());
    for (String propertyName : properties.stringPropertyNames()) {
        String propertyValue = properties.getProperty(propertyName);
        systemPropertiesTable.addRow(propertyName + (System.getProperties().containsKey(propertyName) ? "*" : ""), propertyValue);
        System.setProperty(propertyName, propertyValue.isEmpty() ? "" : propertyValue);
    }
    diagnosticsTable.addRow("System Properties", systemPropertiesTable.toString());
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.log(Level.INFO, "Oracle Bedrock " + Bedrock.getVersion() + ": Starting Storage Disabled Member...\n" + "------------------------------------------------------------------------\n" + diagnosticsTable.toString() + "\n" + "------------------------------------------------------------------------\n");
    }
    // ----- establish the session -----
    // create the session
    ConfigurableCacheFactory session = new ScopedCacheFactoryBuilder().getConfigurableCacheFactory(optionsByType.get(CacheConfig.class).getUri(), getClass().getClassLoader());
    // as this is a cluster member we have to join the cluster
    CacheFactory.ensureCluster();
    return session;
}
Also used : Table(com.oracle.bedrock.table.Table) Properties(java.util.Properties) ConfigurableCacheFactory(com.tangosol.net.ConfigurableCacheFactory) Profile(com.oracle.bedrock.runtime.Profile) ScopedCacheFactoryBuilder(com.tangosol.net.ScopedCacheFactoryBuilder) CoherenceClusterMember(com.oracle.bedrock.runtime.coherence.CoherenceClusterMember) MetaClass(com.oracle.bedrock.runtime.MetaClass)

Example 14 with MetaClass

use of com.oracle.bedrock.runtime.MetaClass in project oracle-bedrock by coherence-community.

the class DockerContainerTest method shouldRemoveContainer.

@Test
public void shouldRemoveContainer() 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.remove(false);
    ArgumentCaptor<MetaClass> captor = ArgumentCaptor.forClass(MetaClass.class);
    verify(platform).launch(captor.capture(), anyVararg());
    OptionsByType optionsByType = OptionsByType.empty();
    Remove.RemoveContainer remove = (Remove.RemoveContainer) captor.getValue();
    assertThat(remove, is(notNullValue()));
    remove.onLaunch(platform, optionsByType);
    Arguments arguments = optionsByType.get(Arguments.class);
    List<String> values = arguments.resolve(mock(Platform.class), OptionsByType.empty());
    assertThat(values, contains("rm", "foo"));
}
Also used : Platform(com.oracle.bedrock.runtime.Platform) Arguments(com.oracle.bedrock.runtime.options.Arguments) Remove(com.oracle.bedrock.runtime.docker.commands.Remove) Matchers.anyString(org.mockito.Matchers.anyString) MetaClass(com.oracle.bedrock.runtime.MetaClass) Application(com.oracle.bedrock.runtime.Application) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 15 with MetaClass

use of com.oracle.bedrock.runtime.MetaClass in project oracle-bedrock by coherence-community.

the class JprofilerProfileTest method shouldSetStack.

@Test
public void shouldSetStack() throws Exception {
    Platform platform = LocalPlatform.get();
    MetaClass metaClass = new JavaApplication.MetaClass();
    OptionsByType optionsByType = OptionsByType.empty();
    JprofilerProfile profile = JprofilerProfile.enabled("mylib").stack(1234);
    profile.onLaunching(platform, metaClass, optionsByType);
    assertAgentString(optionsByType, "-agentpath:mylib=", "port=8849", "stack=1234");
}
Also used : LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) Platform(com.oracle.bedrock.runtime.Platform) MetaClass(com.oracle.bedrock.runtime.MetaClass) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Aggregations

MetaClass (com.oracle.bedrock.runtime.MetaClass)25 OptionsByType (com.oracle.bedrock.OptionsByType)23 Test (org.junit.Test)22 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)19 Platform (com.oracle.bedrock.runtime.Platform)19 Application (com.oracle.bedrock.runtime.Application)5 ClassPath (com.oracle.bedrock.runtime.java.ClassPath)4 Arguments (com.oracle.bedrock.runtime.options.Arguments)4 Remove (com.oracle.bedrock.runtime.docker.commands.Remove)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Profile (com.oracle.bedrock.runtime.Profile)2 CoherenceClusterMember (com.oracle.bedrock.runtime.coherence.CoherenceClusterMember)2 Table (com.oracle.bedrock.table.Table)2 ConfigurableCacheFactory (com.tangosol.net.ConfigurableCacheFactory)2 ScopedCacheFactoryBuilder (com.tangosol.net.ScopedCacheFactoryBuilder)2 InetAddress (java.net.InetAddress)2 Properties (java.util.Properties)2 Option (com.oracle.bedrock.Option)1 AbstractPlatform (com.oracle.bedrock.runtime.AbstractPlatform)1 ApplicationLauncher (com.oracle.bedrock.runtime.ApplicationLauncher)1