use of org.glassfish.embeddable.GlassFishException in project Payara by payara.
the class PayaraMicroImpl method getGAVURLs.
/**
* Converts the GAVs provided to a URLs, and stores them in the
* deploymentURLsMap.
*/
private void getGAVURLs() throws GlassFishException {
GAVConvertor gavConvertor = new GAVConvertor();
for (String gav : GAVs) {
try {
Map.Entry<String, URL> artefactMapEntry = gavConvertor.getArtefactMapEntry(gav, repositoryURLs);
if (deploymentURLsMap == null) {
deploymentURLsMap = new LinkedHashMap<>();
}
String contextRoot = artefactMapEntry.getKey();
if ("ROOT".equals(contextRoot)) {
contextRoot = "/";
}
deploymentURLsMap.put(contextRoot, artefactMapEntry.getValue());
} catch (MalformedURLException ex) {
throw new GlassFishException(ex.getMessage());
}
}
}
use of org.glassfish.embeddable.GlassFishException 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);
}
resetLogging();
// 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());
HazelcastCore.setThreadLocalDisabled(true);
try {
gf.start();
// Attempt paranoid unbinding of all reserved ports.
MicroNetworkListener.clearReservedSockets();
// Execute post boot commands
postBootCommands.executeCommands(gf.getCommandRunner());
this.runtime = new PayaraMicroRuntimeImpl(gf, gfruntime);
// load all applications, but do not start them until Hazelcast gets a chance to initialize
deployAll();
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Error unbinding reserved port.", ex);
} finally {
HazelcastCore.setThreadLocalDisabled(false);
}
if (!noCluster) {
gf.getCommandRunner().run("set-hazelcast-configuration", "--enabled", "true", "--dynamic", "true", "--target", "server-config", "--hostawarepartitioning", Boolean.toString(hostAware), "--lite", Boolean.toString(liteMember));
}
gf.getCommandRunner().run("initialize-all-applications");
postDeployCommands.executeCommands(gf.getCommandRunner());
long end = System.currentTimeMillis();
dumpFinalStatus(end - start);
return runtime;
} catch (Exception ex) {
try {
gf.dispose();
} catch (GlassFishException ex1) {
LOGGER.log(Level.SEVERE, null, ex1);
}
throw new BootstrapException(ex.getMessage(), ex);
}
}
use of org.glassfish.embeddable.GlassFishException in project Payara by payara.
the class PayaraMicroImpl method configurePorts.
private void configurePorts() throws GlassFishException {
PortBinder portBinder = new PortBinder();
if (httpPort != Integer.MIN_VALUE) {
if (autoBindHttp == true) {
// Log warnings if overriding other options
logPortPrecedenceWarnings(false);
// Search for an available port from the specified port
try {
int port = portBinder.findAvailablePort(httpPort, autoBindRange);
preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.http-listener.port=" + port));
preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.http-listener.enabled=true"));
} catch (BindException ex) {
LOGGER.log(Level.SEVERE, "No available port found in range: " + httpPort + " - " + (httpPort + autoBindRange), ex);
throw new GlassFishException("Could not bind HTTP port");
}
} else {
// Log warnings if overriding other options
logPortPrecedenceWarnings(false);
preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.http-listener.port=" + httpPort));
}
} else if (autoBindHttp == true) {
// Log warnings if overriding other options
logPortPrecedenceWarnings(false);
// Search for an available port from the default HTTP port
try {
int port = portBinder.findAvailablePort(defaultHttpPort, autoBindRange);
preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.http-listener.port=" + port));
preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.http-listener.enabled=true"));
} catch (BindException ex) {
LOGGER.log(Level.SEVERE, "No available port found in range: " + defaultHttpPort + " - " + (defaultHttpPort + autoBindRange), ex);
throw new GlassFishException("Could not bind HTTP port");
}
}
if (sslPort != Integer.MIN_VALUE) {
if (autoBindSsl == true) {
// Log warnings if overriding other options
logPortPrecedenceWarnings(true);
// Search for an available port from the specified port
try {
int port = portBinder.findAvailablePort(sslPort, autoBindRange);
preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.https-listener.port=" + port));
preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.https-listener.enabled=true"));
} catch (BindException ex) {
LOGGER.log(Level.SEVERE, "No available port found in range: " + sslPort + " - " + (sslPort + autoBindRange), ex);
throw new GlassFishException("Could not bind SSL port");
}
} else {
// Log warnings if overriding other options
logPortPrecedenceWarnings(true);
// Set the port as normal
preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.https-listener.port=" + sslPort));
preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.https-listener.enabled=true"));
}
} else if (autoBindSsl == true) {
// Log warnings if overriding other options
logPortPrecedenceWarnings(true);
// Search for an available port from the default HTTPS port
try {
int port = portBinder.findAvailablePort(defaultHttpsPort, autoBindRange);
preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.https-listener.port=" + port));
preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.network-listeners.network-listener.https-listener.enabled=true"));
} catch (BindException ex) {
LOGGER.log(Level.SEVERE, "No available port found in range: " + defaultHttpsPort + " - " + (defaultHttpsPort + autoBindRange), ex);
throw new GlassFishException("Could not bind SSL port");
}
}
if (sslCert != null) {
preBootCommands.add(new BootCommand("set", "configs.config.server-config.network-config.protocols.protocol.https-listener.ssl.cert-nickname=" + sslCert));
}
}
use of org.glassfish.embeddable.GlassFishException in project Payara by payara.
the class PayaraMicroImpl method dumpFinalStatus.
private void dumpFinalStatus(long bootTime) {
// Print instance descriptor
InstanceDescriptor id = getRuntime().getLocalDescriptor();
LOGGER.log(Level.INFO, id.toJsonString(showServletMappings));
// Get Payara Micro endpoints
StringBuilder sb = new StringBuilder();
sb.append("\nPayara Micro URLs:\n");
List<URL> urls = id.getApplicationURLS();
for (URL url : urls) {
sb.append(url.toString()).append('\n');
}
// Count through applications and add their REST endpoints
try {
ListRestEndpointsCommand cmd = gf.getService(ListRestEndpointsCommand.class);
id.getDeployedApplications().forEach(app -> {
Map<String, Set<String>> endpoints = null;
try {
endpoints = cmd.getEndpointMap(app.getName());
} catch (IllegalArgumentException ex) {
// The application has no endpoints
endpoints = null;
}
if (endpoints != null) {
sb.append("\n'" + app.getName() + "' REST Endpoints:\n");
endpoints.forEach((path, methods) -> {
methods.forEach(method -> {
sb.append(method + "\t" + path + "\n");
});
});
}
});
} catch (GlassFishException ex) {
// Really shouldn't happen, the command catches it's own errors most of the time
LOGGER.log(Level.SEVERE, "Failed to get REST endpoints for application", ex);
}
sb.append("\n");
// Print out all endpoints
LOGGER.log(Level.INFO, sb.toString());
// Print the logo if it's enabled
if (generateLogo) {
generateLogo();
}
// Print final ready message
LOGGER.log(Level.INFO, "{0} ready in {1} (ms)", new Object[] { Version.getFullVersion(), bootTime });
}
use of org.glassfish.embeddable.GlassFishException in project Payara by payara.
the class DeployerImpl method undeploy.
@Override
public void undeploy(String appName, String... params) throws GlassFishException {
String[] newParams = new String[params.length + 1];
System.arraycopy(params, 0, newParams, 0, params.length);
newParams[params.length] = appName;
CommandExecutorImpl executer = habitat.getService(CommandExecutorImpl.class);
try {
ActionReport actionReport = executer.executeCommand("undeploy", newParams);
if (actionReport.hasSuccesses()) {
logger.log(Level.INFO, "{0} was successfully undeployed", appName);
}
} catch (CommandException e) {
throw new GlassFishException(e);
}
}
Aggregations