Search in sources :

Example 1 with InstanceDescriptorImpl

use of fish.payara.appserver.micro.services.data.InstanceDescriptorImpl in project Payara by payara.

the class PayaraInstanceImpl method initialiseInstanceDescriptor.

private void initialiseInstanceDescriptor() {
    boolean liteMember = false;
    int hazelcastPort = 5900;
    InetAddress hostname = null;
    // Get the Hazelcast specific information
    if (hazelcast.isEnabled()) {
        instanceName = hazelcast.getMemberName();
        instanceGroup = hazelcast.getMemberGroup();
        myCurrentID = hazelcast.getUUID();
        liteMember = hazelcast.isLite();
        hazelcastPort = hazelcast.getPort();
        hostname = hazelcast.getInstance().getCluster().getLocalMember().getSocketAddress().getAddress();
    } else {
        instanceName = "payara-micro";
        instanceGroup = "no-cluster";
    }
    // Get this instance's runtime type
    String instanceType = environment.getRuntimeType().toString();
    // Get the ports in use by this instance from its network listener configs
    List<Integer> ports = new ArrayList<>();
    List<Integer> sslPorts = new ArrayList<>();
    int adminPort = 0;
    for (NetworkListener networkListener : context.getConfigBean().getConfig().getNetworkConfig().getNetworkListeners().getNetworkListener()) {
        // Skip the network listener if it isn't enabled
        if (Boolean.parseBoolean(networkListener.getEnabled())) {
            // Check if this listener is using HTTP or HTTPS
            if (networkListener.findProtocol().getSecurityEnabled().equals("false")) {
                // Check if this listener is the admin listener
                if (networkListener.getName().equals(context.getConfigBean().getConfig().getAdminListener().getName())) {
                    // Micro instances can use the admin listener as both an admin and HTTP port
                    if (instanceType.equals("MICRO")) {
                        ports.add(Integer.parseInt(networkListener.getPort()));
                    }
                    adminPort = Integer.parseInt(networkListener.getPort());
                } else {
                    // If this listener isn't the admin listener, it must be an HTTP listener
                    ports.add(Integer.parseInt(networkListener.getPort()));
                }
            } else if (networkListener.findProtocol().getSecurityEnabled().equals("true")) {
                if (networkListener.getName().equals(context.getConfigBean().getConfig().getAdminListener().getName())) {
                    // Micro instances can use the admin listener as both an admin and HTTPS port
                    if (instanceType.equals("MICRO")) {
                        ports.add(Integer.parseInt(networkListener.getPort()));
                    }
                    adminPort = Integer.parseInt(networkListener.getPort());
                } else {
                    // If this listener isn't the admin listener, it must be an HTTPS listener
                    sslPorts.add(Integer.parseInt(networkListener.getPort()));
                }
            }
        }
    }
    // Initialise the instance descriptor and set all of its attributes
    try {
        // If Hazelcast is being rebooted dynamically, we don't want to lose the already registered applications
        Collection<ApplicationDescriptor> deployedApplications = new ArrayList<>();
        if (me != null) {
            deployedApplications = me.getDeployedApplications();
        }
        me = new InstanceDescriptorImpl(myCurrentID);
        me.setInstanceName(instanceName);
        me.setInstanceGroup(instanceGroup);
        for (int port : ports) {
            me.addHttpPort(port);
        }
        for (int sslPort : sslPorts) {
            me.addHttpsPort(sslPort);
        }
        me.setAdminPort(adminPort);
        me.setHazelcastPort(hazelcastPort);
        me.setLiteMember(liteMember);
        me.setInstanceType(instanceType);
        if (hostname != null) {
            me.setHostName(hostname);
        }
        // one
        if (!deployedApplications.isEmpty()) {
            for (ApplicationDescriptor application : deployedApplications) {
                me.addApplication(application);
            }
        }
        // Register the instance descriptor to the cluster if it's enabled
        if (cluster.isEnabled()) {
            cluster.getClusteredStore().set(INSTANCE_STORE_NAME, myCurrentID, me);
        }
    } catch (UnknownHostException ex) {
        logger.log(Level.SEVERE, "Could not find local hostname", ex);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) ApplicationDescriptor(fish.payara.micro.data.ApplicationDescriptor) InstanceDescriptorImpl(fish.payara.appserver.micro.services.data.InstanceDescriptorImpl) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

InstanceDescriptorImpl (fish.payara.appserver.micro.services.data.InstanceDescriptorImpl)1 ApplicationDescriptor (fish.payara.micro.data.ApplicationDescriptor)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)1