Search in sources :

Example 1 with ApplicationDescriptor

use of fish.payara.micro.data.ApplicationDescriptor 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)

Example 2 with ApplicationDescriptor

use of fish.payara.micro.data.ApplicationDescriptor in project Payara by payara.

the class ListHazelcastClusterMembersCommand method populateMembers.

private void populateMembers(List members, InstanceDescriptor instance, ColumnFormatter columnFormatter) {
    Object[] values = new Object[10];
    values[0] = instance.getInstanceName();
    values[1] = instance.getInstanceGroup();
    values[2] = instance.getInstanceType();
    values[3] = instance.getHostName();
    if (instance.getHttpPorts().isEmpty()) {
        values[4] = "Disabled";
    } else {
        // Remove the bookended braces and add to the values array
        values[4] = instance.getHttpPorts().toString().substring(1, instance.getHttpPorts().toString().length() - 1);
    }
    if (instance.getHttpsPorts().isEmpty()) {
        values[5] = "Disabled";
    } else {
        // Remove the bookended braces and add to the values array
        values[5] = instance.getHttpsPorts().toString().substring(1, instance.getHttpsPorts().toString().length() - 1);
    }
    values[6] = instance.getAdminPort();
    values[7] = instance.getHazelcastPort();
    values[8] = instance.isLiteMember();
    // Find the deployed applications, remove the bookended braces, and add to the values array
    List<String> applications = new ArrayList<>();
    Collection<ApplicationDescriptor> applicationDescriptors = instance.getDeployedApplications();
    if (applicationDescriptors != null) {
        for (ApplicationDescriptor application : applicationDescriptors) {
            applications.add(application.getName());
        }
        values[9] = Arrays.toString(applications.toArray()).substring(1, Arrays.toString(applications.toArray()).length() - 1);
    } else {
        // Just return nothing if no applications found
        values[9] = "";
    }
    // Add the information to the console output table
    columnFormatter.addRow(values);
    // Add the information to the command output
    Map<String, Object> map = new HashMap<>(7);
    map.put("instanceName", values[0]);
    map.put("instanceGroup", values[1]);
    map.put("instanceType", values[2]);
    map.put("hostName", values[3]);
    map.put("httpPorts", values[4]);
    map.put("httpsPorts", values[5]);
    map.put("adminPort", values[6]);
    map.put("hazelcastPort", values[7]);
    map.put("liteMember", values[8]);
    map.put("applications", values[9]);
    members.add(map);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationDescriptor(fish.payara.micro.data.ApplicationDescriptor)

Example 3 with ApplicationDescriptor

use of fish.payara.micro.data.ApplicationDescriptor in project Payara by payara.

the class InstanceDescriptorImpl method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("\nInstance Configuration\n");
    sb.append("Host: ").append(hostName.getCanonicalHostName()).append('\n');
    sb.append("HTTP Port(s): ");
    for (Integer port : getHttpPorts()) {
        sb.append(port).append(' ');
    }
    sb.append('\n');
    sb.append("HTTPS Port(s): ");
    for (Integer port : getHttpsPorts()) {
        sb.append(port).append(' ');
    }
    sb.append('\n');
    sb.append("Instance Name: ").append(instanceName).append('\n');
    sb.append("Instance Group: ").append(instanceGroup).append('\n');
    if (memberUUID != null) {
        sb.append("Hazelcast Member UUID ").append(this.memberUUID).append('\n');
    }
    for (ApplicationDescriptor applicationDescriptor : getDeployedApplications()) {
        sb.append("Deployed: ");
        sb.append(applicationDescriptor.getName()).append(" ( ");
        for (ModuleDescriptor moduleDescriptor : applicationDescriptor.getModuleDescriptors()) {
            sb.append(moduleDescriptor.getName()).append(' ').append(moduleDescriptor.getType()).append(' ');
            if (moduleDescriptor.getContextRoot() != null) {
                sb.append(moduleDescriptor.getContextRoot());
            } else {
                sb.append("***");
            }
            sb.append(" [ ");
            for (Entry<String, String> servletMapping : moduleDescriptor.getServletMappings().entrySet()) {
                sb.append("< ").append(servletMapping.getValue()).append(' ').append(servletMapping.getKey()).append(" >");
            }
            sb.append(" ] ");
        }
        sb.append(")\n");
        String libraries = applicationDescriptor.getLibraries();
        if (libraries != null) {
            sb.append(' ').append(applicationDescriptor.getLibraries());
        }
    }
    sb.append('\n');
    return sb.toString();
}
Also used : ModuleDescriptor(fish.payara.micro.data.ModuleDescriptor) ApplicationDescriptor(fish.payara.micro.data.ApplicationDescriptor)

Aggregations

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