Search in sources :

Example 1 with InstanceDirs

use of com.sun.enterprise.util.io.InstanceDirs in project Payara by payara.

the class InstanceDirUtils method getLocalInstanceDir.

/**
 * Returns the directory for the selected instance that is on the local
 * system.
 * @param instanceName name of the instance
 * @return File for the local file system location of the instance directory
 * @throws IOException
 */
File getLocalInstanceDir(String instance) throws IOException {
    /*
         * Pass the node directory parent and the node directory name explicitly
         * or else InstanceDirs will not work as we want if there are multiple
         * nodes registered on this node.
         *
         * If the configuration recorded an explicit directory for the node,
         * then use it.  Otherwise, use the default node directory of
         * ${installDir}/glassfish/nodes/${nodeName}.
         */
    String nodeDir = node.getNodeDirAbsolute();
    final File nodeDirFile = (nodeDir != null ? new File(nodeDir) : defaultLocalNodeDirFile());
    InstanceDirs instanceDirs = new InstanceDirs(nodeDirFile.toString(), node.getName(), instance);
    return instanceDirs.getInstanceDir();
}
Also used : InstanceDirs(com.sun.enterprise.util.io.InstanceDirs) File(java.io.File)

Example 2 with InstanceDirs

use of com.sun.enterprise.util.io.InstanceDirs in project Payara by payara.

the class LocalInstanceCommand method initInstance.

protected void initInstance() throws CommandException {
    /* node dir - parent directory of all node(s) */
    String nodeDirRootPath = null;
    if (ok(nodeDir))
        nodeDirRootPath = nodeDir;
    else
        // node dir = <install-root>/nodes
        nodeDirRootPath = getNodeDirRootDefault();
    nodeDirRoot = new File(nodeDirRootPath);
    mkdirs(nodeDirRoot);
    if (ok(nodeDir)) {
        // Ensure later uses of nodeDir get an absolute path
        // See bug 15014. Don't use getCanonicalPath(). See bug
        // 15889
        nodeDir = nodeDirRoot.getAbsolutePath();
    }
    if (!isDirectory(nodeDirRoot)) {
        throw new CommandException(Strings.get("Instance.badNodeDir", nodeDirRoot));
    }
    /* <node_dir>/<node> */
    if (node != null) {
        nodeDirChild = new File(nodeDirRoot, node);
    } else {
        nodeDirChild = getTheOneAndOnlyNode(nodeDirRoot);
    }
    /* <node_dir>/<node>/<instance name> */
    if (getInstanceName() != null) {
        instanceDir = new File(nodeDirChild, getInstanceName());
        mkdirs(instanceDir);
    } else {
        instanceDir = getTheOneAndOnlyInstance(nodeDirChild);
        setInstanceName(instanceDir.getName());
    }
    if (!isDirectory(instanceDir)) {
        throw new CommandException(Strings.get("Instance.badInstanceDir", instanceDir));
    }
    nodeDirChild = SmartFile.sanitize(nodeDirChild);
    instanceDir = SmartFile.sanitize(instanceDir);
    try {
        if (setServerDirs()) {
            instanceDirs = new InstanceDirs(instanceDir);
            setServerDirs(instanceDirs.getServerDirs());
        }
    } catch (IOException e) {
        throw new CommandException(e);
    }
    logger.log(Level.FINER, "nodeDirChild: {0}", nodeDirChild);
    logger.log(Level.FINER, "instanceDir: {0}", instanceDir);
}
Also used : InstanceDirs(com.sun.enterprise.util.io.InstanceDirs) CommandException(org.glassfish.api.admin.CommandException) IOException(java.io.IOException) SmartFile(com.sun.enterprise.universal.io.SmartFile) File(java.io.File)

Example 3 with InstanceDirs

use of com.sun.enterprise.util.io.InstanceDirs 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();
            }
            dasHost = Optional.ofNullable(initAddress(dasHost, 0)).map(InetSocketAddress::getHostString).orElse("");
            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");
                nodes.add(new SimpleDiscoveryNode(new Address(chosenAddress.get(), Integer.parseInt(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 = Optional.ofNullable(initAddress(hzConfig.getDASPublicAddress(), 0)).map(InetSocketAddress::getHostString).orElse("");
            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")) {
                nodes.add(new SimpleDiscoveryNode(new Address(chosenAddress.get(), Integer.parseInt(hzConfig.getDasPort()))));
            } else {
                nodes.add(new SimpleDiscoveryNode(new Address(InetAddress.getByName(dasHost), Integer.valueOf(hzConfig.getDasPort()))));
            }
        } catch (UnknownHostException | 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) {
            nodes.add(new SimpleDiscoveryNode(new Address(chosenAddress.get(), Integer.parseInt(hzConfig.getStartPort()))));
        } 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
                        nodes.add(new SimpleDiscoveryNode(new Address(chosenAddress.get(), Integer.parseInt(hzConfig.getStartPort()))));
                    }
                } catch (IOException ex) {
                    Logger.getLogger(DomainDiscoveryService.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
    return nodes;
}
Also used : DiscoveryNode(com.hazelcast.spi.discovery.DiscoveryNode) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress) InetSocketAddress(java.net.InetSocketAddress) MemberAddressPicker.initAddress(fish.payara.nucleus.hazelcast.MemberAddressPicker.initAddress) InetSocketAddress(java.net.InetSocketAddress) Node(com.sun.enterprise.config.serverbeans.Node) DiscoveryNode(com.hazelcast.spi.discovery.DiscoveryNode) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) IOException(java.io.IOException) Properties(java.util.Properties) LinkedList(java.util.LinkedList) FileInputStream(java.io.FileInputStream) ServerContext(org.glassfish.internal.api.ServerContext) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) InstanceDirs(com.sun.enterprise.util.io.InstanceDirs) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) Domain(com.sun.enterprise.config.serverbeans.Domain) InetAddress(java.net.InetAddress)

Example 4 with InstanceDirs

use of com.sun.enterprise.util.io.InstanceDirs in project Payara by payara.

the class CreateInstanceCommand method getLocalInstanceDir.

/**
 * Returns the directory for the selected instance that is on the local
 * system.
 * @param instanceName name of the instance
 * @return File for the local file system location of the instance directory
 * @throws IOException
 */
private File getLocalInstanceDir() throws IOException {
    /*
         * Pass the node directory parent and the node directory name explicitly
         * or else InstanceDirs will not work as we want if there are multiple
         * nodes registered on this node.
         *
         * If the configuration recorded an explicit directory for the node,
         * then use it.  Otherwise, use the default node directory of
         * ${installDir}/glassfish/nodes/${nodeName}.
         */
    final File nodeDirFile = (nodeDir != null ? new File(nodeDir) : defaultLocalNodeDirFile());
    InstanceDirs instanceDirs = new InstanceDirs(nodeDirFile.toString(), theNode.getName(), instance);
    return instanceDirs.getInstanceDir();
}
Also used : InstanceDirs(com.sun.enterprise.util.io.InstanceDirs) File(java.io.File)

Aggregations

InstanceDirs (com.sun.enterprise.util.io.InstanceDirs)4 File (java.io.File)3 IOException (java.io.IOException)2 Address (com.hazelcast.cluster.Address)1 DiscoveryNode (com.hazelcast.spi.discovery.DiscoveryNode)1 SimpleDiscoveryNode (com.hazelcast.spi.discovery.SimpleDiscoveryNode)1 Domain (com.sun.enterprise.config.serverbeans.Domain)1 Node (com.sun.enterprise.config.serverbeans.Node)1 SmartFile (com.sun.enterprise.universal.io.SmartFile)1 MemberAddressPicker.initAddress (fish.payara.nucleus.hazelcast.MemberAddressPicker.initAddress)1 FileInputStream (java.io.FileInputStream)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 CommandException (org.glassfish.api.admin.CommandException)1 ServerEnvironment (org.glassfish.api.admin.ServerEnvironment)1 ServerContext (org.glassfish.internal.api.ServerContext)1