Search in sources :

Example 1 with ModuleDescriptor

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

Example 2 with ModuleDescriptor

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

the class InstanceDescriptorImpl method toJsonObject.

private JsonObject toJsonObject(boolean verbose) {
    // Create a builder to store the object
    JsonObjectBuilder configBuilder = Json.createObjectBuilder();
    // Add all the instance information
    configBuilder.add("Host", hostName.getCanonicalHostName());
    configBuilder.add("Http Port(s)", Arrays.toString(getHttpPorts().toArray()).replaceAll("[\\[\\]]", ""));
    configBuilder.add("Https Port(s)", Arrays.toString(getHttpsPorts().toArray()).replaceAll("[\\[\\]]", ""));
    configBuilder.add("Instance Name", this.instanceName);
    configBuilder.add("Instance Group", this.instanceGroup);
    if (memberUUID != null) {
        configBuilder.add("Hazelcast Member UUID", this.memberUUID);
    }
    // Create array of applications
    JsonArrayBuilder deploymentBuilder = Json.createArrayBuilder();
    getDeployedApplications().forEach(app -> {
        // Construct object for each application
        JsonObjectBuilder appBuilder = Json.createObjectBuilder();
        // Add the name of the application
        appBuilder.add("Name", app.getName());
        // If there's only one module in the application, print the module info with the application name
        if (app.getModuleDescriptors().size() == 1) {
            ModuleDescriptor module = app.getModuleDescriptors().get(0);
            appBuilder.add("Type", module.getType());
            appBuilder.add("Context Root", (module.getContextRoot() == null) ? "N/A" : module.getContextRoot());
            // List the module mappings if verbose is specified
            if (verbose) {
                JsonObjectBuilder servletMappings = Json.createObjectBuilder();
                module.getServletMappings().forEach((key, value) -> {
                    servletMappings.add(key, value);
                });
                appBuilder.add("Mappings", servletMappings.build());
            }
        // If there's more modules, print info for each module
        } else {
            JsonArrayBuilder modules = Json.createArrayBuilder();
            // Construct object for each module
            app.getModuleDescriptors().forEach(module -> {
                JsonObjectBuilder moduleBuilder = Json.createObjectBuilder();
                // Add basic information for the module
                moduleBuilder.add("Name", module.getName());
                moduleBuilder.add("Type", module.getType());
                moduleBuilder.add("Context Root", (module.getContextRoot() == null) ? "***" : module.getContextRoot());
                // Create an object of mappings if verbose is specified
                if (verbose) {
                    JsonObjectBuilder servletMappings = Json.createObjectBuilder();
                    module.getServletMappings().forEach((key, value) -> {
                        servletMappings.add(key, value);
                    });
                    moduleBuilder.add("Mappings", servletMappings.build());
                }
                modules.add(moduleBuilder.build());
            });
            appBuilder.add("Modules", modules.build());
        }
        deploymentBuilder.add(appBuilder.build());
    });
    configBuilder.add("Deployed", deploymentBuilder.build());
    return Json.createObjectBuilder().add("Instance Configuration", configBuilder.build()).build();
}
Also used : ModuleDescriptor(fish.payara.micro.data.ModuleDescriptor) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Aggregations

ModuleDescriptor (fish.payara.micro.data.ModuleDescriptor)2 ApplicationDescriptor (fish.payara.micro.data.ApplicationDescriptor)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1