Search in sources :

Example 16 with GlassFishProperties

use of org.glassfish.embeddable.GlassFishProperties in project Payara by payara.

the class Util method startGlassFish.

public static synchronized GlassFish startGlassFish(String serverID, String installRoot, String instanceRoot, String configFileURI, boolean configFileReadOnly, int httpPort) throws GlassFishException {
    GlassFish glassfish = gfMap.get(serverID);
    if (glassfish != null) {
        return glassfish;
    }
    if (glassfishRuntime == null) {
        BootstrapProperties bootstrapProperties = new BootstrapProperties();
        if (installRoot != null) {
            bootstrapProperties.setInstallRoot(installRoot);
        }
        glassfishRuntime = GlassFishRuntime.bootstrap(bootstrapProperties);
    }
    GlassFishProperties glassfishProperties = new GlassFishProperties();
    if (instanceRoot != null) {
        glassfishProperties.setInstanceRoot(instanceRoot);
    }
    if (configFileURI != null) {
        glassfishProperties.setConfigFileURI(configFileURI);
        glassfishProperties.setConfigFileReadOnly(configFileReadOnly);
    }
    if (instanceRoot == null && configFileURI == null) {
        // only set port if embedded domain.xml is used
        if (httpPort != -1) {
            glassfishProperties.setPort("http-listener", httpPort);
        }
    }
    glassfish = glassfishRuntime.newGlassFish(glassfishProperties);
    glassfish.start();
    gfMap.put(serverID, glassfish);
    System.out.println("Started GlassFish [" + serverID + "]");
    return glassfish;
}
Also used : BootstrapProperties(org.glassfish.embeddable.BootstrapProperties) GlassFish(org.glassfish.embeddable.GlassFish) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties)

Example 17 with GlassFishProperties

use of org.glassfish.embeddable.GlassFishProperties in project Payara by payara.

the class PayaraMicroImpl method bootStrap.

/**
 * Boots the Payara Micro Server. All parameters are checked at this point
 *
 * @return An instance of PayaraMicroRuntime that can be used to access the
 * running server
 * @throws BootstrapException
 */
@Override
public PayaraMicroRuntime bootStrap() throws BootstrapException {
    // First check whether we are already running
    if (isRunning()) {
        throw new IllegalStateException("Payara Micro is already running, calling bootstrap now is meaningless");
    }
    long start = System.currentTimeMillis();
    // Build the runtime directory
    try {
        unPackRuntime();
    } catch (IOException | URISyntaxException ex) {
        throw new BootstrapException("Problem unpacking the Runtime", ex);
    }
    final String loggingProperty = System.getProperty("java.util.logging.config.file");
    resetLogging(loggingProperty);
    // If it's been enabled, watch the log file for changes
    if (enableDynamicLogging) {
        PayaraFileWatcher.watch(new File(loggingProperty).toPath(), () -> {
            LOGGER.info("Logging file modified, resetting logging");
            resetLogging(loggingProperty);
        });
    }
    // Check a supported JDK version is being used
    if (!JDK.isRunningLTSJDK()) {
        LOGGER.warning("You are running the product on an unsupported JDK version and might see unexpected results or exceptions.");
    }
    runtimeDir.processDirectoryInformation();
    // build the runtime
    BootstrapProperties bprops = new BootstrapProperties();
    bprops.setInstallRoot(runtimeDir.getDirectory().getAbsolutePath());
    bprops.setProperty(Constants.PLATFORM_PROPERTY_KEY, Constants.Platform.PayaraMicro.toString());
    GlassFishRuntime gfruntime;
    try {
        gfruntime = GlassFishRuntime.bootstrap(bprops, Thread.currentThread().getContextClassLoader());
        GlassFishProperties gfproperties = new GlassFishProperties();
        gfproperties.setProperty("-type", "MICRO");
        gfproperties.setInstanceRoot(runtimeDir.getDirectory().getAbsolutePath());
        gfproperties.setConfigFileReadOnly(false);
        gfproperties.setConfigFileURI(runtimeDir.getDomainXML().toURI().toString());
        try {
            configureCommandFiles();
        } catch (IOException ex) {
            LOGGER.log(Level.SEVERE, "Unable to load command file", ex);
        }
        gf = gfruntime.newGlassFish(gfproperties);
        configurePorts();
        configureThreads();
        configureAccessLogging();
        configureHazelcast();
        configurePhoneHome();
        configureNotificationService();
        configureHealthCheck();
        configureRequestTracingService();
        configureSecrets();
        // Add additional libraries
        addLibraries();
        // boot the server
        preBootCommands.executeCommands(gf.getCommandRunner());
        callHandler(preBootHandler);
        gf.start();
        // Execute post boot commands
        postBootCommands.executeCommands(gf.getCommandRunner());
        callHandler(postBootHandler);
        this.runtime = new PayaraMicroRuntimeImpl(gf, gfruntime);
        // deploy all applications and then initialize them
        deployAll();
        // These steps are separated in case any steps need to be done in between
        gf.getCommandRunner().run("initialize-all-applications");
        postDeployCommands.executeCommands(gf.getCommandRunner());
        long end = System.currentTimeMillis();
        dumpFinalStatus(end - start);
        return runtime;
    } catch (Exception ex) {
        try {
            if (gf != null) {
                gf.dispose();
            }
        } catch (GlassFishException ex1) {
            LOGGER.log(Level.SEVERE, null, ex1);
        }
        throw new BootstrapException(ex.getMessage(), ex);
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) GlassFishRuntime(org.glassfish.embeddable.GlassFishRuntime) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) BootstrapException(fish.payara.micro.BootstrapException) GlassFishException(org.glassfish.embeddable.GlassFishException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ValidationException(fish.payara.micro.cmd.options.ValidationException) BootstrapProperties(org.glassfish.embeddable.BootstrapProperties) BootstrapException(fish.payara.micro.BootstrapException) JarFile(java.util.jar.JarFile) File(java.io.File) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties)

Example 18 with GlassFishProperties

use of org.glassfish.embeddable.GlassFishProperties in project Payara by payara.

the class CoffeeTest method test.

@Test
public void test() throws Exception {
    // 1. Bootstrap GlassFish DAS in embedded mode.
    GlassFishProperties glassFishProperties = new GlassFishProperties();
    glassFishProperties.setInstanceRoot(System.getenv("S1AS_HOME") + "/domains/domain1");
    glassFishProperties.setConfigFileReadOnly(false);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
    PrintStream sysout = System.out;
    glassfish.start();
    System.setOut(sysout);
    // 2. Deploy the PaaS application.
    File archive = new File(System.getProperty("basedir") + "/target/appscoped_db_with_resources_xml.war");
    // TODO :: use mvn apis to get the archive location.
    Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    CommandRunner commandRunner = glassfish.getCommandRunner();
    try {
        deployer = glassfish.getDeployer();
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        CommandResult result = commandRunner.run("list-services");
        System.out.println("\nlist-services command output [ " + result.getOutput() + "]");
        // 3. Access the app to make sure PaaS app is correctly provisioned.
        String HTTP_PORT = (System.getProperty("http.port") != null) ? System.getProperty("http.port") : "28080";
        String instanceIP = getLBIPAddress(glassfish);
        get("http://" + instanceIP + ":" + HTTP_PORT + "/appscoped_db_with_resources_xml/CoffeeServlet", "Coffee ID");
    // 4. Undeploy the PaaS application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            System.out.println("Destroying the resources created");
        }
    }
}
Also used : PrintStream(java.io.PrintStream) GlassFish(org.glassfish.embeddable.GlassFish) JarFile(java.util.jar.JarFile) File(java.io.File) CommandRunner(org.glassfish.embeddable.CommandRunner) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Deployer(org.glassfish.embeddable.Deployer) CommandResult(org.glassfish.embeddable.CommandResult) Test(org.junit.Test)

Example 19 with GlassFishProperties

use of org.glassfish.embeddable.GlassFishProperties in project Payara by payara.

the class BasicbookstoreDnsPaasTest method bootstrap.

private GlassFish bootstrap() throws Exception {
    GlassFishProperties glassFishProperties = new GlassFishProperties();
    glassFishProperties.setInstanceRoot(System.getenv("S1AS_HOME") + "/domains/domain1");
    glassFishProperties.setConfigFileReadOnly(false);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
    PrintStream sysout = System.out;
    glassfish.start();
    System.setOut(sysout);
    return glassfish;
}
Also used : PrintStream(java.io.PrintStream) GlassFish(org.glassfish.embeddable.GlassFish) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties)

Example 20 with GlassFishProperties

use of org.glassfish.embeddable.GlassFishProperties in project Payara by payara.

the class CoffeeTest method test.

@Test
public void test() throws Exception {
    // 1. Bootstrap GlassFish DAS in embedded mode.
    GlassFishProperties glassFishProperties = new GlassFishProperties();
    glassFishProperties.setInstanceRoot(System.getenv("S1AS_HOME") + "/domains/domain1");
    glassFishProperties.setConfigFileReadOnly(false);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
    PrintStream sysout = System.out;
    glassfish.start();
    System.setOut(sysout);
    // 2. Deploy the PaaS application.
    File archive = new File(System.getProperty("basedir") + "/target/basic_db_teardown_sql.war");
    // TODO :: use mvn apis to get the archive location.
    Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    List dbConnectionDetails = null;
    CommandRunner commandRunner = glassfish.getCommandRunner();
    try {
        // 2.1. Create the shared DB service
        CommandResult createSharedServiceResult = commandRunner.run("create-shared-service", "--characteristics", "service-type=Database", "--configuration", "database.name=foobar", "--servicetype", "Database", "coffee-service");
        System.out.println("\ncreate-shared-service command output [ " + createSharedServiceResult.getOutput() + "]");
        // 2.2. List services to check for the shared service
        CommandResult listSharedServicesResult = commandRunner.run("list-services", "--scope", "shared", "--output", "service-name, state");
        System.out.println("\nlist-services command output [ " + listSharedServicesResult.getOutput() + "]");
        // 2.3. Deploy app
        deployer = glassfish.getDeployer();
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        CommandResult result = commandRunner.run("list-services");
        System.out.println("\nlist-services command output [ " + result.getOutput() + "]");
        // 3. Access the app to make sure PaaS app is correctly provisioned.
        String HTTP_PORT = (System.getProperty("http.port") != null) ? System.getProperty("http.port") : "28080";
        String instanceIP = getLBIPAddress(glassfish);
        get("http://" + instanceIP + ":" + HTTP_PORT + "/basic_db_teardown_sql/CoffeeServlet", "Coffee ID");
        dbConnectionDetails = getDbConnectionDetails("http://" + instanceIP + ":" + HTTP_PORT + "/basic_db_teardown_sql/DbConnectionDetailsServlet");
    // 4. Undeploy the PaaS application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            testTearDownSql(dbConnectionDetails);
            System.out.println("Destroying the resources created");
            // 4.1. Delete Shared DB Service.
            CommandResult deleteResult = commandRunner.run("delete-shared-service", "coffee-service");
            System.out.println("\ndelete-shared-service command output [" + deleteResult.getOutput() + "]");
        }
    }
}
Also used : PrintStream(java.io.PrintStream) ArrayList(java.util.ArrayList) List(java.util.List) GlassFish(org.glassfish.embeddable.GlassFish) File(java.io.File) CommandRunner(org.glassfish.embeddable.CommandRunner) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Deployer(org.glassfish.embeddable.Deployer) CommandResult(org.glassfish.embeddable.CommandResult) Test(org.junit.Test)

Aggregations

GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)35 GlassFish (org.glassfish.embeddable.GlassFish)30 File (java.io.File)24 PrintStream (java.io.PrintStream)21 Deployer (org.glassfish.embeddable.Deployer)21 Test (org.junit.Test)21 CommandRunner (org.glassfish.embeddable.CommandRunner)18 CommandResult (org.glassfish.embeddable.CommandResult)17 JarFile (java.util.jar.JarFile)13 IOException (java.io.IOException)6 BootstrapProperties (org.glassfish.embeddable.BootstrapProperties)6 GlassFishException (org.glassfish.embeddable.GlassFishException)4 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)4 URI (java.net.URI)3 ScatteredArchive (org.glassfish.embeddable.archive.ScatteredArchive)3 HttpListener (org.glassfish.embeddable.web.HttpListener)3 WebContainer (org.glassfish.embeddable.web.WebContainer)3 GlassFishRuntime (org.glassfish.embeddable.GlassFishRuntime)2 ArchiveFactory (com.sun.enterprise.deploy.shared.ArchiveFactory)1 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)1