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;
}
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);
}
}
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");
}
}
}
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;
}
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() + "]");
}
}
}
Aggregations