use of com.sun.enterprise.config.serverbeans.Node in project Payara by payara.
the class ServerHelper method getAdminHost.
public final String getAdminHost() {
if (server == null || config == null) {
return null;
}
// Look at the address for the admin-listener first
String addr = translateAddressAndPort(getAdminListener(config), server, config)[0];
if (addr != null && !addr.equals("0.0.0.0")) {
return addr;
}
Dom serverDom = Dom.unwrap(server);
Domain domain = serverDom.getHabitat().getService(Domain.class);
Nodes nodes = serverDom.getHabitat().getService(Nodes.class);
ServerEnvironment env = serverDom.getHabitat().getService(ServerEnvironment.class);
if (server.isDas()) {
if (env.isDas()) {
// We are the DAS. Return our hostname
return System.getProperty(SystemPropertyConstants.HOST_NAME_PROPERTY);
} else {
// IT 12778 -- it is impossible to know
return null;
}
}
String hostName = null;
// Get it from the node associated with the server
String nodeName = server.getNodeRef();
if (StringUtils.ok(nodeName)) {
Node node = nodes.getNode(nodeName);
if (node != null) {
hostName = node.getNodeHost();
}
// node entry is malformed
if (hostName == null && nodeName.equals("localhost-" + domain.getName())) {
hostName = "localhost";
}
}
if (StringUtils.ok(hostName)) {
return hostName;
}
return null;
}
use of com.sun.enterprise.config.serverbeans.Node in project Payara by payara.
the class LogFilterForInstance method downloadGivenInstanceLogFile.
public File downloadGivenInstanceLogFile(ServiceLocator habitat, Server targetServer, Domain domain, Logger logger, String instanceName, String domainRoot, String logFileName, String instanceLogFileName) throws IOException {
File instanceLogFile = null;
// method is used from logviewer back end code logfilter.
// for Instance it's going through this loop. This will use ssh utility to get file from instance machine(remote machine) and
// store in domains/domain1/logs/<instance name> which is used to get LogFile object.
// Right now user needs to go through this URL to setup and configure ssh http://wikis.sun.com/display/GlassFish/3.1SSHSetup
SSHLauncher sshL = getSSHL(habitat);
String sNode = targetServer.getNodeRef();
Nodes nodes = domain.getNodes();
Node node = nodes.getNode(sNode);
if (node.getType().equals("SSH")) {
sshL.init(node, logger);
SFTPClient sftpClient = sshL.getSFTPClient();
File logFileDirectoryOnServer = makingDirectory(domainRoot + File.separator + "logs" + File.separator + instanceName);
boolean noFileFound = true;
String loggingDir = getLoggingDirectoryForNode(instanceLogFileName, node, sNode, instanceName);
try {
List instanceLogFileNames = sftpClient.ls(loggingDir);
for (int i = 0; i < instanceLogFileNames.size(); i++) {
SFTPv3DirectoryEntry file = (SFTPv3DirectoryEntry) instanceLogFileNames.get(i);
String fileName = file.filename;
// code to remove . and .. file which is return from sftpclient ls method
if (!file.attributes.isDirectory() && !fileName.equals(".") && !fileName.equals("..") && fileName.contains(".log") && !fileName.contains(".log.")) {
noFileFound = false;
break;
}
}
} catch (Exception e) {
// if directory doesn't present or missing on remote machine. It happens due to bug 16451
noFileFound = true;
}
if (noFileFound) {
// this loop is used when user has changed value for server.log but not restarted the server.
loggingDir = getLoggingDirectoryForNodeWhenNoFilesFound(instanceLogFileName, node, sNode, instanceName);
}
String loggingFile = loggingDir + File.separator + logFileName;
if (!sftpClient.exists(loggingFile)) {
loggingFile = loggingDir + File.separator + "server.log";
} else if (!sftpClient.exists(loggingFile)) {
loggingFile = instanceLogFileName;
}
// creating local file name on DAS
long instanceLogFileSize = 0;
instanceLogFile = new File(logFileDirectoryOnServer.getAbsolutePath() + File.separator + loggingFile.substring(loggingFile.lastIndexOf(File.separator), loggingFile.length()));
// getting size of the file on DAS
if (instanceLogFile.exists())
instanceLogFileSize = instanceLogFile.length();
SFTPv3FileAttributes sftPv3FileAttributes = sftpClient._stat(loggingFile);
// getting size of the file on instance machine
long fileSizeOnNode = sftPv3FileAttributes.size;
// if differ both size then downloading
if (instanceLogFileSize != fileSizeOnNode) {
BufferedInputStream in = null;
FileOutputStream file = null;
BufferedOutputStream out = null;
try {
InputStream inputStream = sftpClient.read(loggingFile);
in = new BufferedInputStream(inputStream);
file = new FileOutputStream(instanceLogFile);
out = new BufferedOutputStream(file);
int i;
while ((i = in.read()) != -1) {
out.write(i);
}
out.flush();
} finally {
if (out != null)
try {
out.close();
} catch (IOException ex) {
}
if (in != null)
try {
in.close();
} catch (IOException ex) {
}
}
}
sftpClient.close();
} else if (node.getType().equals("DCOM")) {
File logFileDirectoryOnServer = makingDirectory(domainRoot + File.separator + "logs" + File.separator + instanceName);
String loggingDir = getLoggingDirectoryForNode(instanceLogFileName, node, sNode, instanceName);
try {
DcomInfo info = new DcomInfo(node);
WindowsRemoteFileSystem wrfs = new WindowsRemoteFileSystem(info.getHost(), info.getUser(), info.getPassword());
if (logFileName == null || logFileName.equals("")) {
logFileName = "server.log";
}
WindowsRemoteFile wrf = new WindowsRemoteFile(wrfs, loggingDir + File.separator + logFileName);
instanceLogFile = new File(logFileDirectoryOnServer + File.separator + logFileName);
wrf.copyTo(instanceLogFile);
} catch (WindowsException ex) {
throw new IOException("Unable to download instance log file from DCOM Instance Node");
}
}
return instanceLogFile;
}
use of com.sun.enterprise.config.serverbeans.Node in project Payara by payara.
the class ListNodesHelper method getNodeList.
public String getNodeList() {
StringBuilder sb = new StringBuilder();
boolean firstNode = true;
for (Node n : nodeList) {
String name = n.getName();
String nodeType = n.getType();
String host = n.getNodeHost();
String installDir = n.getInstallDir();
if (!listType.equals(nodeType) && !listType.equals("ALL"))
continue;
if (firstNode)
firstNode = false;
else
sb.append(EOL);
if (terse)
sb.append(name);
else if (!long_opt)
sb.append(name).append(" ").append(nodeType).append(" ").append(host);
if (long_opt) {
List<Server> serversOnNode = servers.getServersOnNode(n);
StringBuilder instanceList = new StringBuilder();
if (serversOnNode.size() > 0) {
int i = 0;
for (Server server : serversOnNode) {
if (i > 0)
instanceList.append(", ");
instanceList.append(server.getName());
i++;
}
}
NodeInfo ni = new NodeInfo(name, host, installDir, nodeType, instanceList.toString());
infos.add(ni);
}
}
if (long_opt)
return NodeInfo.format(infos);
else
return sb.toString();
}
use of com.sun.enterprise.config.serverbeans.Node in project Payara by payara.
the class LogFilter method getLogFileForGivenTarget.
/*
* This method is used by LogViewerResource which is used to display raw log data like 'tail -f server.log'.
*/
public String getLogFileForGivenTarget(String targetServerName) throws IOException {
Server targetServer = domain.getServerNamed(targetServerName);
String serverNode = targetServer.getNodeRef();
if (targetServer.isDas()) {
// getting log file for DAS from logging.properties and returning the same
String logFileDetailsForServer = loggingConfig.getLoggingFileDetails();
logFileDetailsForServer = TranslatedConfigView.getTranslatedValue(logFileDetailsForServer).toString();
logFileDetailsForServer = new File(logFileDetailsForServer).getAbsolutePath();
return logFileDetailsForServer;
} else {
// getting log file for instance from logging.properties
String logFileDetailsForInstance = getInstanceLogFileDetails(targetServer);
Node node = domain.getNodes().getNode(serverNode);
String loggingDir = "";
String loggingFile = "";
// replacing instanceRoot value if it's there
if (logFileDetailsForInstance.contains("${com.sun.aas.instanceRoot}/logs") && node.getNodeDir() != null) {
// this code is used if no changes made in logging.properties file
loggingDir = node.getNodeDir() + File.separator + serverNode + File.separator + targetServerName;
loggingFile = logFileDetailsForInstance.replace("${com.sun.aas.instanceRoot}", loggingDir);
} else if (logFileDetailsForInstance.contains("${com.sun.aas.instanceRoot}/logs") && node.getInstallDir() != null) {
loggingDir = node.getInstallDir() + File.separator + "glassfish" + File.separator + "nodes" + File.separator + serverNode + File.separator + targetServerName;
loggingFile = logFileDetailsForInstance.replace("${com.sun.aas.instanceRoot}", loggingDir);
} else {
loggingFile = logFileDetailsForInstance;
}
if (node.isLocal()) {
// if local just returning log file to view
return loggingFile;
} else {
// if remote then need to download log file on DAS and returning that log file for view
String logFileName = logFileDetailsForInstance.substring(logFileDetailsForInstance.lastIndexOf(File.separator) + 1, logFileDetailsForInstance.length());
File instanceFile = null;
instanceFile = new LogFilterForInstance().downloadGivenInstanceLogFile(habitat, targetServer, domain, LOGGER, targetServerName, env.getDomainRoot().getAbsolutePath(), logFileName, logFileDetailsForInstance);
return instanceFile.getAbsolutePath();
}
}
}
use of com.sun.enterprise.config.serverbeans.Node 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;
}
Aggregations