Search in sources :

Example 6 with LocalPlatform

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

the class MavenTest method shouldOverrideArtifacts.

/**
 * Ensure that {@link Maven} artifacts of the same group, artifactid, classified and extension
 * are overridden when defined multiple times.
 */
@Test
public void shouldOverrideArtifacts() throws IOException {
    LocalPlatform platform = LocalPlatform.get();
    MetaClass metaClass = new JavaApplication.MetaClass();
    OptionsByType optionsByType = OptionsByType.empty();
    optionsByType.addAll(Maven.artifact("junit:junit:jar:4.10"), Maven.artifact("junit:junit:jar:4.11"), Maven.artifact("junit:junit:jar:4.12"));
    Maven maven = optionsByType.get(Maven.class);
    maven.onLaunching(platform, metaClass, optionsByType);
    ClassPath classPath = optionsByType.getOrDefault(ClassPath.class, null);
    assertThat(classPath, is(not(nullValue())));
    // includes transitive dependencies
    assertThat(classPath.size(), is(2));
    assertThat(classPath.toString(), containsString("junit-4.12.jar"));
    assertThat(classPath.toString(), containsString("hamcrest-core-1.3.jar"));
    assertThat(classPath.toString(), not(containsString("junit-4.10.jar")));
    assertThat(classPath.toString(), not(containsString("junit-4.11.jar")));
}
Also used : ClassPath(com.oracle.bedrock.runtime.java.ClassPath) MetaClass(com.oracle.bedrock.runtime.MetaClass) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 7 with LocalPlatform

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

the class MavenTest method shouldIncludeAdditionalClassPaths.

/**
 * Ensure that {@link Maven} includes additional {@link ClassPath}s when requested.
 */
@Test
public void shouldIncludeAdditionalClassPaths() throws IOException {
    LocalPlatform platform = LocalPlatform.get();
    MetaClass metaClass = new JavaApplication.MetaClass();
    OptionsByType optionsByType = OptionsByType.empty();
    optionsByType.addAll(Maven.artifact("junit:junit:jar:4.12"), Maven.include(ClassPath.ofClass(MavenTest.class)), Maven.include(ClassPath.ofResource("example-resource.txt")));
    Maven maven = optionsByType.get(Maven.class);
    maven.onLaunching(platform, metaClass, optionsByType);
    ClassPath classPath = optionsByType.getOrDefault(ClassPath.class, null);
    assertThat(classPath, is(not(nullValue())));
    assertThat(classPath.size(), is(3));
    assertThat(classPath.toString(), containsString("junit-4.12.jar"));
    assertThat(classPath.toString(), containsString("hamcrest-core-1.3.jar"));
    assertThat(classPath.toString(), containsString(ClassPath.ofClass(MavenTest.class).toString()));
    assertThat(classPath.toString(), containsString(ClassPath.ofResource("example-resource.txt").toString()));
}
Also used : ClassPath(com.oracle.bedrock.runtime.java.ClassPath) MetaClass(com.oracle.bedrock.runtime.MetaClass) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 8 with LocalPlatform

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

the class HttpDeployer method createServer.

/**
 * Start the HTTP server that will be used to serve the artifacts
 * to be deployed.
 *
 * @param executor  the {@link Executor} to pass to the {@link HttpServer}
 * @param artifacts a {@link Map} of {@link DeploymentArtifact}s to deploy
 *                  keyed by the URL path for each artifact
 *
 * @return the {@link HttpServer}
 */
protected HttpServer createServer(ExecutorService executor, Map<String, DeploymentArtifact> artifacts) {
    try {
        LocalPlatform platform = LocalPlatform.get();
        InetAddress address = NetworkHelper.getFeasibleLocalHost();
        int port = platform.getAvailablePorts().next();
        HttpServer server = HttpServer.create(new InetSocketAddress(address, port), 0);
        server.createContext("/", new ArtifactsHandler(artifacts, optionsByType.asArray()));
        server.setExecutor(executor);
        server.start();
        return server;
    } catch (IOException e) {
        throw new RuntimeException("Unable to create HTTP server", e);
    }
}
Also used : LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) InetSocketAddress(java.net.InetSocketAddress) HttpServer(com.sun.net.httpserver.HttpServer) IOException(java.io.IOException) InetAddress(java.net.InetAddress)

Example 9 with LocalPlatform

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

the class ClusterPort method onLaunching.

@Override
public void onLaunching(Platform platform, MetaClass metaClass, OptionsByType optionsByType) {
    if (ports != null && !ports.hasNext()) {
        throw new IllegalStateException("Exhausted the available ports for the ClusterPort");
    } else {
        SystemProperties systemProperties = optionsByType.get(SystemProperties.class);
        if (systemProperties != null) {
            int port;
            if (ports == null) {
                if (platform instanceof LocalPlatform || platform instanceof JavaVirtualMachine) {
                    ports = new Capture<>(LocalPlatform.get().getAvailablePorts());
                } else {
                    throw new IllegalStateException("Can't automatically determine a ClusterPort for the non-LocalPlatform, non-JavaVirtualMachine Platform :" + platform.getName());
                }
            }
            // now acquire a port
            port = ports.next();
            optionsByType.add(SystemProperty.of(PROPERTY, port));
        }
    }
}
Also used : SystemProperties(com.oracle.bedrock.runtime.java.options.SystemProperties) JavaVirtualMachine(com.oracle.bedrock.runtime.java.JavaVirtualMachine) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform)

Example 10 with LocalPlatform

use of com.oracle.bedrock.runtime.LocalPlatform in project coherence-visualvm by oracle.

the class AbstractVisualVMTest method startupCacheServers.

// ----- test methods ---------------------------------------------------
/**
 * Start the required cache servers using oracle-tools
 *
 * @param fRestRequestSender  if a REST request sender needs to be used
 */
public static void startupCacheServers(boolean fRestRequestSender) {
    try {
        s_sEdition = CacheFactory.getEdition();
        // setup temporary directories for persistence
        s_fileActiveDirA = FileHelper.createTempDir();
        s_fileSnapshotDirA = FileHelper.createTempDir();
        s_fileTrashDirA = FileHelper.createTempDir();
        s_availablePortIteratorWKA = LocalPlatform.get().getAvailablePorts();
        int nLocalPortA1 = s_availablePortIteratorWKA.next();
        // Iterate to next port and waste this as sometimes the second port will
        // already be used up before the realize()
        s_availablePortIteratorWKA.next();
        int nLocalPortA2 = s_availablePortIteratorWKA.next();
        int nLocalPortB1 = s_availablePortIteratorWKA.next();
        int nLocalPortB2 = s_availablePortIteratorWKA.next();
        // Iterate to next port and waste this as sometimes the second port will
        // already be used up before the realize()
        s_availablePortIteratorWKA.next();
        LocalPlatform platform = LocalPlatform.get();
        OptionsByType optionsByTypeA1 = createCacheServerOptions(CLUSTER_NAME, nLocalPortA1, s_fileActiveDirA, s_fileSnapshotDirA, s_fileTrashDirA, nLocalPortA1, nLocalPortB1);
        OptionsByType optionsByTypeA2 = createCacheServerOptions(CLUSTER_NAME, nLocalPortA2, s_fileActiveDirA, s_fileSnapshotDirA, s_fileTrashDirA, nLocalPortA1, nLocalPortB1);
        OptionsByType optionsByTypeMemberA1 = OptionsByType.of(optionsByTypeA1).add(DisplayName.of("memberA1"));
        OptionsByType optionsByTypeMemberA2 = OptionsByType.of(optionsByTypeA2).add(DisplayName.of("memberA2"));
        if (fRestRequestSender) {
            optionsByTypeMemberA1.add(SystemProperty.of("coherence.management", "dynamic"));
            optionsByTypeMemberA1.add(SystemProperty.of("coherence.management.http", "inherit"));
            optionsByTypeMemberA1.add(SystemProperty.of("coherence.management.http.host", REST_MGMT_HOST));
            optionsByTypeMemberA1.add(SystemProperty.of("coherence.management.http.port", REST_MGMT_PORT));
        }
        s_memberA1 = platform.launch(CoherenceCacheServer.class, optionsByTypeMemberA1.asArray());
        s_memberA2 = platform.launch(CoherenceCacheServer.class, optionsByTypeMemberA2.asArray());
        s_requestSender = fRestRequestSender ? new HttpRequestSender("http://" + REST_MGMT_HOST + ":" + "8080") : new JMXRequestSender(s_memberA1.get(JmxFeature.class).getDeferredJMXConnector().get().getMBeanServerConnection());
        Eventually.assertThat(invoking(s_memberA1).getClusterSize(), is(2));
        // only start second cluster if we are running Commercial version
        if (isCommercial()) {
            // setup temporary directories for persistence
            s_fileActiveDirB = FileHelper.createTempDir();
            s_fileSnapshotDirB = FileHelper.createTempDir();
            s_fileTrashDirB = FileHelper.createTempDir();
            OptionsByType optionsByTypeB1 = createCacheServerOptions(CLUSTER_B_NAME, nLocalPortB1, s_fileActiveDirB, s_fileSnapshotDirB, s_fileTrashDirB, nLocalPortA1, nLocalPortB1);
            OptionsByType optionsByTypeB2 = createCacheServerOptions(CLUSTER_B_NAME, nLocalPortB2, s_fileActiveDirB, s_fileSnapshotDirB, s_fileTrashDirB, nLocalPortA1, nLocalPortB1);
            OptionsByType optionsByTypeMemberB1 = OptionsByType.of(optionsByTypeB1).add(DisplayName.of("memberB1"));
            OptionsByType optionsByTypeMemberB2 = OptionsByType.of(optionsByTypeB2).add(DisplayName.of("memberB2"));
            s_memberB1 = platform.launch(CoherenceCacheServer.class, optionsByTypeMemberB1.asArray());
            s_memberB2 = platform.launch(CoherenceCacheServer.class, optionsByTypeMemberB2.asArray());
            Eventually.assertThat(invoking(s_memberB1).getClusterSize(), is(2));
        }
    } catch (Exception e) {
        System.err.println("Error starting cache servers. " + e.getMessage());
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : CoherenceCacheServer(com.oracle.bedrock.runtime.coherence.CoherenceCacheServer) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) HttpRequestSender(com.oracle.coherence.plugin.visualvm.helper.HttpRequestSender) JMXRequestSender(com.oracle.coherence.plugin.visualvm.helper.JMXRequestSender) OptionsByType(com.oracle.bedrock.OptionsByType)

Aggregations

LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)16 Test (org.junit.Test)7 OptionsByType (com.oracle.bedrock.OptionsByType)6 MetaClass (com.oracle.bedrock.runtime.MetaClass)4 CoherenceClusterMember (com.oracle.bedrock.runtime.coherence.CoherenceClusterMember)4 ClassPath (com.oracle.bedrock.runtime.java.ClassPath)4 JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)4 BeforeAll (org.junit.jupiter.api.BeforeAll)4 File (java.io.File)3 IOException (java.io.IOException)3 SleepingApplication (applications.SleepingApplication)2 ExpressionEvaluator (com.oracle.bedrock.lang.ExpressionEvaluator)2 Application (com.oracle.bedrock.runtime.Application)2 IsServiceRunning (com.oracle.bedrock.runtime.coherence.callables.IsServiceRunning)2 UnknownHostException (java.net.UnknownHostException)2 Timeout (com.oracle.bedrock.options.Timeout)1 CoherenceCacheServer (com.oracle.bedrock.runtime.coherence.CoherenceCacheServer)1 CapturingApplicationConsole (com.oracle.bedrock.runtime.console.CapturingApplicationConsole)1 PipedApplicationConsole (com.oracle.bedrock.runtime.console.PipedApplicationConsole)1 JavaVirtualMachine (com.oracle.bedrock.runtime.java.JavaVirtualMachine)1