Search in sources :

Example 6 with ServerEnvironment

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;
}
Also used : ServerEnvironment(org.glassfish.api.admin.ServerEnvironment)

Example 7 with ServerEnvironment

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;
}
Also used : DiscoveryNode(com.hazelcast.spi.discovery.DiscoveryNode) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) InterfaceAddress(java.net.InterfaceAddress) Inet4Address(java.net.Inet4Address) 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 8 with ServerEnvironment

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);
    }
}
Also used : ServerEnvironmentImpl(org.glassfish.server.ServerEnvironmentImpl) XMLStreamException(javax.xml.stream.XMLStreamException) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Aggregations

ServerEnvironment (org.glassfish.api.admin.ServerEnvironment)8 File (java.io.File)3 IOException (java.io.IOException)3 Domain (com.sun.enterprise.config.serverbeans.Domain)2 Node (com.sun.enterprise.config.serverbeans.Node)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)2 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)2 DeploymentContextImpl (org.glassfish.deployment.common.DeploymentContextImpl)2 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)2 Address (com.hazelcast.nio.Address)1 DiscoveryNode (com.hazelcast.spi.discovery.DiscoveryNode)1 SimpleDiscoveryNode (com.hazelcast.spi.discovery.SimpleDiscoveryNode)1 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)1 Applications (com.sun.enterprise.config.serverbeans.Applications)1 Nodes (com.sun.enterprise.config.serverbeans.Nodes)1 InjectionException (com.sun.enterprise.container.common.spi.util.InjectionException)1 Application (com.sun.enterprise.deployment.Application)1 InstanceDirs (com.sun.enterprise.util.io.InstanceDirs)1