Search in sources :

Example 1 with Nodes

use of com.sun.enterprise.config.serverbeans.Nodes 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;
}
Also used : Dom(org.jvnet.hk2.config.Dom) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) Node(com.sun.enterprise.config.serverbeans.Node) Domain(com.sun.enterprise.config.serverbeans.Domain) Nodes(com.sun.enterprise.config.serverbeans.Nodes)

Example 2 with Nodes

use of com.sun.enterprise.config.serverbeans.Nodes 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;
}
Also used : SSHLauncher(org.glassfish.cluster.ssh.launcher.SSHLauncher) Node(com.sun.enterprise.config.serverbeans.Node) SFTPClient(org.glassfish.cluster.ssh.sftp.SFTPClient) WindowsException(com.sun.enterprise.util.cluster.windows.process.WindowsException) Nodes(com.sun.enterprise.config.serverbeans.Nodes) WindowsException(com.sun.enterprise.util.cluster.windows.process.WindowsException) DcomInfo(org.glassfish.cluster.ssh.util.DcomInfo) SFTPv3DirectoryEntry(com.trilead.ssh2.SFTPv3DirectoryEntry) WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile) WindowsRemoteFileSystem(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFileSystem) ArrayList(java.util.ArrayList) List(java.util.List) SFTPv3FileAttributes(com.trilead.ssh2.SFTPv3FileAttributes) WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile)

Example 3 with Nodes

use of com.sun.enterprise.config.serverbeans.Nodes in project Payara by payara.

the class LogFilterForInstance method downloadAllInstanceLogFiles.

public void downloadAllInstanceLogFiles(ServiceLocator habitat, Server targetServer, Domain domain, Logger logger, String instanceName, String tempDirectoryOnServer, String instanceLogFileDirectory) throws IOException {
    // method is used from collect-log-files command
    // for Instance it's going through this loop. This will use ssh utility to get file from instance machine(remote machine) and
    // store in  tempDirectoryOnServer which is used to create zip file.
    // 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);
        List<String> allInstanceLogFileName = getInstanceLogFileNames(habitat, targetServer, domain, logger, instanceName, instanceLogFileDirectory);
        boolean noFileFound = true;
        String sourceDir = getLoggingDirectoryForNode(instanceLogFileDirectory, node, sNode, instanceName);
        SFTPClient sftpClient = sshL.getSFTPClient();
        try {
            List instanceLogFileNames = sftpClient.ls(sourceDir);
            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.
            sourceDir = getLoggingDirectoryForNodeWhenNoFilesFound(instanceLogFileDirectory, node, sNode, instanceName);
        }
        String[] remoteFileNames = new String[allInstanceLogFileName.size()];
        for (int i = 0; i < allInstanceLogFileName.size(); i++) {
            remoteFileNames[i] = sourceDir + File.separator + allInstanceLogFileName.get(i);
        }
        sftpClient.close();
        SCPClient scpClient = sshL.getSCPClient();
        scpClient.get(remoteFileNames, tempDirectoryOnServer);
    } else if (node.getType().equals("DCOM")) {
        List instanceLogFileNames = getInstanceLogFileNames(habitat, targetServer, domain, logger, instanceName, instanceLogFileDirectory);
        String sourceDir = getLoggingDirectoryForNode(instanceLogFileDirectory, node, sNode, instanceName);
        try {
            DcomInfo info = new DcomInfo(node);
            WindowsRemoteFileSystem wrfs = new WindowsRemoteFileSystem(info.getHost(), info.getUser(), info.getPassword());
            for (int i = 0; i < instanceLogFileNames.size(); i++) {
                String logFileName = (String) instanceLogFileNames.get(i);
                WindowsRemoteFile wrf = new WindowsRemoteFile(wrfs, sourceDir + File.separator + logFileName);
                File instanceLogFile = new File(tempDirectoryOnServer + File.separator + logFileName);
                wrf.copyTo(instanceLogFile);
            }
        } catch (WindowsException ex) {
            throw new IOException("Unable to download instance log file from DCOM Instance Node");
        }
    }
}
Also used : SCPClient(com.trilead.ssh2.SCPClient) SSHLauncher(org.glassfish.cluster.ssh.launcher.SSHLauncher) Node(com.sun.enterprise.config.serverbeans.Node) SFTPClient(org.glassfish.cluster.ssh.sftp.SFTPClient) WindowsException(com.sun.enterprise.util.cluster.windows.process.WindowsException) Nodes(com.sun.enterprise.config.serverbeans.Nodes) WindowsException(com.sun.enterprise.util.cluster.windows.process.WindowsException) DcomInfo(org.glassfish.cluster.ssh.util.DcomInfo) SFTPv3DirectoryEntry(com.trilead.ssh2.SFTPv3DirectoryEntry) WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile) WindowsRemoteFileSystem(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFileSystem) ArrayList(java.util.ArrayList) List(java.util.List) WindowsRemoteFile(com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile)

Example 4 with Nodes

use of com.sun.enterprise.config.serverbeans.Nodes in project Payara by payara.

the class InstanceRegisterInstanceCommand method execute.

@Override
public void execute(AdminCommandContext ctxt) {
    final ActionReport report = ctxt.getActionReport();
    try {
        // create node if it doesn't exist
        Node n = domain.getNodes().getNode(node);
        if (n == null) {
            ConfigSupport.apply(new SingleConfigCode<Nodes>() {

                @Override
                public Object run(Nodes param) throws PropertyVetoException, TransactionFailure {
                    Node newNode = param.createChild(Node.class);
                    newNode.setName(node);
                    if (installdir != null && !"".equals(installdir))
                        newNode.setInstallDir(installdir);
                    if (nodedir != null && !"".equals(nodedir))
                        newNode.setNodeDir(nodedir);
                    if (nodehost != null && !"".equals(nodehost))
                        newNode.setNodeHost(nodehost);
                    newNode.setType(type);
                    // comment out - not needed
                    /*if (type.equals("SSH")) {
                            SshConnector sshC = param.createChild(SshConnector.class);
                            if (sshHost != null && sshHost != "") {
                                sshC.setSshHost(sshHost);

                            }
                            if (sshPort != "-1" && sshPort != "") {
                                sshC.setSshPort(sshPort);

                            }
                            if (sshuser != null || sshkeyfile != null || sshpassword != null
                                    || sshkeypassphrase != null) {
                                SshAuth sshA = sshC.createChild(SshAuth.class);
                                if (sshuser != null && sshuser != "") {
                                    sshA.setUserName(sshuser);
                                }
                                if (sshkeyfile != null && sshkeyfile != "") {
                                    sshA.setKeyfile(sshkeyfile);
                                }
                                if (sshpassword != null && sshpassword != "") {
                                    sshA.setPassword(sshpassword);
                                }
                                if (sshkeypassphrase != null && sshkeypassphrase != "") {
                                    sshA.setKeyPassphrase(sshkeypassphrase);
                                }
                                sshC.setSshAuth(sshA);
                            }
                            if (sshC != null) {
                                newNode.setSshConnector(sshC);
                            }
                        }*/
                    param.getNode().add(newNode);
                    return newNode;
                }
            }, domain.getNodes());
        }
        // create server if it doesn't exist
        Server s = domain.getServers().getServer(instanceName);
        if (s == null) {
            ConfigSupport.apply(new SingleConfigCode<Servers>() {

                public Object run(Servers param) throws PropertyVetoException, TransactionFailure {
                    Server newServer = param.createChild(Server.class);
                    newServer.setConfigRef(config);
                    // newServer.setLbWeight(lbWeight);
                    newServer.setName(instanceName);
                    newServer.setNodeRef(node);
                    if (systemProperties != null) {
                        for (final Map.Entry<Object, Object> entry : systemProperties.entrySet()) {
                            final String propName = (String) entry.getKey();
                            final String propValue = (String) entry.getValue();
                            SystemProperty newSP = newServer.createChild(SystemProperty.class);
                            // newSP.setDescription(sp.getDescription());
                            newSP.setName(propName);
                            newSP.setValue(propValue);
                            newServer.getSystemProperty().add(newSP);
                        }
                    }
                    param.getServer().add(newServer);
                    return newServer;
                }
            }, domain.getServers());
            // create server-ref on cluster
            Cluster thisCluster = domain.getClusterNamed(clusterName);
            if (thisCluster != null) {
                ConfigSupport.apply(new SingleConfigCode<Cluster>() {

                    public Object run(Cluster param) throws PropertyVetoException, TransactionFailure {
                        ServerRef newServerRef = param.createChild(ServerRef.class);
                        newServerRef.setRef(instanceName);
                        newServerRef.setLbEnabled(lbEnabled);
                        param.getServerRef().add(newServerRef);
                        return param;
                    }
                }, thisCluster);
            }
        }
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (TransactionFailure tfe) {
        report.setMessage(localStrings.getLocalString("register.instance.failed", "Instance {0} registration failed on {1}", instanceName, server.getName()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
        return;
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("register.instance.failed", "Instance {0} registration failed on {1}", instanceName, server.getName()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Server(com.sun.enterprise.config.serverbeans.Server) Node(com.sun.enterprise.config.serverbeans.Node) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ActionReport(org.glassfish.api.ActionReport) Servers(com.sun.enterprise.config.serverbeans.Servers) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) Nodes(com.sun.enterprise.config.serverbeans.Nodes) PropertyVetoException(java.beans.PropertyVetoException) PropertyVetoException(java.beans.PropertyVetoException) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef)

Example 5 with Nodes

use of com.sun.enterprise.config.serverbeans.Nodes in project Payara by payara.

the class NodeAgentConfigUpgrade method postConstruct.

public void postConstruct() {
    final NodeAgents nodeAgents = domain.getNodeAgents();
    if (nodeAgents == null) {
        createDefaultNodeList();
        return;
    }
    final List<NodeAgent> agList = nodeAgents.getNodeAgent();
    if (agList.size() == 0) {
        createDefaultNodeList();
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Domain>() {

            public Object run(Domain d) throws PropertyVetoException, TransactionFailure {
                Nodes nodes = d.createChild(Nodes.class);
                Transaction t = Transaction.getTransaction(d);
                if (t == null)
                    return null;
                for (NodeAgent na : agList) {
                    String host = null;
                    Node node = nodes.createChild(Node.class);
                    node.setName(na.getName());
                    node.setType("CONFIG");
                    JmxConnector jc = na.getJmxConnector();
                    if (jc != null) {
                        // get the properties and see if host name is specified
                        List<Property> agentProp = jc.getProperty();
                        for (Property p : agentProp) {
                            String name = p.getName();
                            if (name.equals("client-hostname")) {
                                // create the node with a host name
                                node.setNodeHost(p.getValue());
                                node.setInstallDir("${com.sun.aas.productRoot}");
                            }
                        }
                    }
                    nodes.getNode().add(node);
                }
                // Now add the builtin localhost node
                createDefaultNode(d, nodes);
                d.setNodes(nodes);
                List<Server> serverList = servers.getServer();
                if (serverList.size() <= 0)
                    return null;
                for (Server s : serverList) {
                    s = t.enroll(s);
                    s.setNodeRef(s.getNodeAgentRef());
                    s.setNodeAgentRef(null);
                }
                // remove the node-agent element
                // d.getNodeAgents().getNodeAgent().clear();
                d.setNodeAgents(null);
                return null;
            }
        }, domain);
    } catch (Exception e) {
        Logger.getAnonymousLogger().log(Level.SEVERE, "Failure while upgrading node-agent from V2 to V3", e);
        throw new RuntimeException(e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Server(com.sun.enterprise.config.serverbeans.Server) Node(com.sun.enterprise.config.serverbeans.Node) NodeAgent(com.sun.enterprise.config.serverbeans.NodeAgent) JmxConnector(com.sun.enterprise.config.serverbeans.JmxConnector) NodeAgents(com.sun.enterprise.config.serverbeans.NodeAgents) Nodes(com.sun.enterprise.config.serverbeans.Nodes) PropertyVetoException(java.beans.PropertyVetoException) PropertyVetoException(java.beans.PropertyVetoException) Domain(com.sun.enterprise.config.serverbeans.Domain) Property(org.jvnet.hk2.config.types.Property)

Aggregations

Node (com.sun.enterprise.config.serverbeans.Node)5 Nodes (com.sun.enterprise.config.serverbeans.Nodes)5 Domain (com.sun.enterprise.config.serverbeans.Domain)2 Server (com.sun.enterprise.config.serverbeans.Server)2 WindowsRemoteFile (com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFile)2 WindowsRemoteFileSystem (com.sun.enterprise.util.cluster.windows.io.WindowsRemoteFileSystem)2 WindowsException (com.sun.enterprise.util.cluster.windows.process.WindowsException)2 SFTPv3DirectoryEntry (com.trilead.ssh2.SFTPv3DirectoryEntry)2 PropertyVetoException (java.beans.PropertyVetoException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SSHLauncher (org.glassfish.cluster.ssh.launcher.SSHLauncher)2 SFTPClient (org.glassfish.cluster.ssh.sftp.SFTPClient)2 DcomInfo (org.glassfish.cluster.ssh.util.DcomInfo)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1 JmxConnector (com.sun.enterprise.config.serverbeans.JmxConnector)1 NodeAgent (com.sun.enterprise.config.serverbeans.NodeAgent)1 NodeAgents (com.sun.enterprise.config.serverbeans.NodeAgents)1 ServerRef (com.sun.enterprise.config.serverbeans.ServerRef)1