use of org.glassfish.api.admin.ServerEnvironment in project Payara by payara.
the class AutoDeployer method domainRoot.
private synchronized File domainRoot() {
if (domainRoot == null) {
ServerEnvironment serverEnv = habitat.getService(ServerEnvironment.class);
domainRoot = serverEnv.getDomainRoot();
}
return domainRoot;
}
use of org.glassfish.api.admin.ServerEnvironment in project Payara by payara.
the class DomainDiscoveryService method discoverNodes.
@Override
public Iterable<DiscoveryNode> discoverNodes() {
logger.fine("Starting Domain Node Discovery");
List<DiscoveryNode> nodes = new LinkedList<>();
Domain domain = Globals.getDefaultHabitat().getService(Domain.class);
ServerContext ctxt = Globals.getDefaultHabitat().getService(ServerContext.class);
ServerEnvironment env = Globals.getDefaultHabitat().getService(ServerEnvironment.class);
// add the DAS
HazelcastRuntimeConfiguration hzConfig = domain.getExtensionByType(HazelcastRuntimeConfiguration.class);
if (!env.isDas()) {
try {
// first get hold of the DAS host
logger.fine("This is a Standalone Instance");
String dasHost = hzConfig.getDASPublicAddress();
if (dasHost == null || dasHost.isEmpty()) {
dasHost = hzConfig.getDASBindAddress();
}
if (dasHost.isEmpty()) {
// ok drag it off the properties file
logger.fine("Neither DAS Public Address or Bind Address is set in the configuration");
InstanceDirs instance = new InstanceDirs(env.getInstanceRoot());
Properties dasProps = new Properties();
dasProps.load(new FileInputStream(instance.getDasPropertiesFile()));
logger.fine("Loaded the das.properties file from the agent directory");
dasHost = dasProps.getProperty("agent.das.host");
// then do an IP lookup
dasHost = InetAddress.getByName(dasHost).getHostAddress();
logger.log(Level.FINE, "Loaded the das.properties file from the agent directory and found DAS IP {0}", dasHost);
}
if (dasHost.isEmpty() || dasHost.equals("127.0.0.1") || dasHost.equals("localhost")) {
logger.fine("Looks like the DAS IP is loopback or empty let's find the actual IP of this machine as that is where the DAS is");
addLocalNodes(nodes, Integer.valueOf(hzConfig.getDasPort()));
} else {
logger.log(Level.FINE, "DAS should be listening on {0}", dasHost);
nodes.add(new SimpleDiscoveryNode(new Address(dasHost, Integer.valueOf(hzConfig.getDasPort()))));
}
// also add all nodes we are aware of in the domain to see if we can get in using start port
logger.fine("Also adding all known domain nodes and start ports in case the DAS is down");
for (Node node : domain.getNodes().getNode()) {
InetAddress address = InetAddress.getByName(node.getNodeHost());
if (!address.isLoopbackAddress()) {
logger.log(Level.FINE, "Adding Node {0}", address);
nodes.add(new SimpleDiscoveryNode(new Address(address.getHostAddress(), Integer.valueOf(hzConfig.getStartPort()))));
}
}
} catch (IOException ex) {
Logger.getLogger(DomainDiscoveryService.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (env.isMicro()) {
try {
logger.log(Level.FINE, "We are Payara Micro therefore adding DAS {0}", hzConfig.getDASPublicAddress());
// check if user has added locahost as unlikely to work
String dasHost = hzConfig.getDASPublicAddress();
if (hzConfig.getDasPort().equals("4848")) {
logger.log(Level.WARNING, "You have specified 4848 as the datagrid domain port however this is the default DAS admin port, the default domain datagrid port is 4900");
}
if (dasHost.isEmpty() || dasHost.equals("127.0.0.1") || dasHost.equals("localhost")) {
addLocalNodes(nodes, Integer.valueOf(hzConfig.getDasPort()));
} else {
nodes.add(new SimpleDiscoveryNode(new Address(InetAddress.getByName(hzConfig.getDASPublicAddress()), Integer.valueOf(hzConfig.getDasPort()))));
}
} catch (UnknownHostException | SocketException | NumberFormatException ex) {
Logger.getLogger(DomainDiscoveryService.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
// ok this is the DAS
logger.fine("We are the DAS therefore we will add all known nodes with start port as IP addresses to connect to");
// Embedded runtimese don't have nodes
if (domain.getNodes() == null) {
try {
addLocalNodes(nodes, Integer.valueOf(hzConfig.getStartPort()));
} catch (IOException ex) {
Logger.getLogger(DomainDiscoveryService.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
for (Node node : domain.getNodes().getNode()) {
try {
InetAddress address = InetAddress.getByName(node.getNodeHost());
if (!address.isLoopbackAddress()) {
logger.log(Level.FINE, "Adding Node {0}", address);
nodes.add(new SimpleDiscoveryNode(new Address(address.getHostAddress(), Integer.valueOf(hzConfig.getStartPort()))));
} else {
// we need to add our IP address so add each interface address with the start port
addLocalNodes(nodes, Integer.valueOf(hzConfig.getStartPort()));
}
} catch (IOException ex) {
Logger.getLogger(DomainDiscoveryService.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
return nodes;
}
use of org.glassfish.api.admin.ServerEnvironment in project Payara by payara.
the class EmbeddedSecurityUtil method copyConfigFiles.
public void copyConfigFiles(ServiceLocator habitat, File fromInstanceDir, File domainXml) {
// For security reasons, permit only an embedded server instance to carry out the copy operations
ServerEnvironment se = habitat.getService(ServerEnvironment.class);
if (!isEmbedded(se)) {
return;
}
if ((fromInstanceDir == null) || (domainXml == null)) {
throw new IllegalArgumentException("Null inputs");
}
File toInstanceDir = habitat.<ServerEnvironmentImpl>getService(ServerEnvironmentImpl.class).getInstanceRoot();
List<String> fileNames = new ArrayList<String>();
try {
// Add FileRealm keyfiles to the list
fileNames.addAll(new EmbeddedSecurityUtil().new DomainXmlSecurityParser(domainXml).getAbsolutePathKeyFileNames(fromInstanceDir));
// Add keystore and truststore files
// For the embedded server case, will the system properties be set in case of multiple embedded instances?
// Not sure - so obtain the other files from the usual locations instead of from the System properties
String keyStoreFileName = fromInstanceDir + File.separator + "config" + File.separator + "keystore.jks";
String trustStoreFileName = fromInstanceDir + File.separator + "config" + File.separator + "cacerts.jks";
fileNames.add(keyStoreFileName);
fileNames.add(trustStoreFileName);
// Add login.conf and security policy
String loginConf = fromInstanceDir + File.separator + "config" + File.separator + "login.conf";
String secPolicy = fromInstanceDir + File.separator + "config" + File.separator + "server.policy";
fileNames.add(loginConf);
fileNames.add(secPolicy);
File toConfigDir = new File(toInstanceDir, "config");
if (!toConfigDir.exists()) {
if (!toConfigDir.mkdir()) {
throw new IOException();
}
}
// Copy files into new directory
for (String fileName : fileNames) {
FileUtils.copyFile(new File(fileName), new File(toConfigDir, parseFileName(fileName)));
}
} catch (IOException e) {
_logger.log(Level.WARNING, SecurityLoggerInfo.ioError, e);
} catch (XMLStreamException e) {
_logger.log(Level.WARNING, SecurityLoggerInfo.xmlStreamingError, e);
}
}
Aggregations