Search in sources :

Example 36 with Server

use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.

the class IiopFolbGmsClient method getClusterInstanceInfo.

// For addMember.
private ClusterInstanceInfo getClusterInstanceInfo(String instanceName) {
    fineLog("getClusterInstanceInfo: instanceName {0}", instanceName);
    final Servers servers = services.getService(Servers.class);
    fineLog("getClusterInstanceInfo: servers {0}", servers);
    final Server server = servers.getServer(instanceName);
    fineLog("getClusterInstanceInfo: server {0}", server);
    final Config config = getConfigForServer(server);
    fineLog("getClusterInstanceInfo: servers {0}", servers);
    // assumeInstanceIsRunning is set to true since this is
    // coming from addMember, because shoal just told us that the instance is up.
    ClusterInstanceInfo result = getClusterInstanceInfo(server, config, true);
    fineLog("getClusterInstanceInfo: result {0}", result);
    return result;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) Servers(com.sun.enterprise.config.serverbeans.Servers) ClusterInstanceInfo(com.sun.corba.ee.spi.folb.ClusterInstanceInfo)

Example 37 with Server

use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.

the class OSGIConsoleHandlers method getConsoleUrl.

@Handler(id = "getConsoleUrl", input = { @HandlerInput(name = "instanceName", type = String.class, required = true) }, output = { @HandlerOutput(name = "consoleUrl", type = String.class) })
public static void getConsoleUrl(HandlerContext handlerCtx) {
    String instanceName = (String) handlerCtx.getInputValue("instanceName");
    Domain domain = Globals.get(Domain.class);
    Server server = domain.getServerNamed(instanceName);
    String port = null;
    SystemProperty httpPort = server.getSystemProperty(http_port);
    if (httpPort != null) {
        port = httpPort.getValue();
    } else {
        // if port is not set as system property, get it from config
        Config cfg = server.getConfig();
        SystemProperty httpConfigPort = cfg.getSystemProperty(http_port);
        if (httpConfigPort != null) {
            port = httpConfigPort.getValue();
        }
    }
    if (port == null) {
        throw new RuntimeException("Not able to get HTTP_LISTENER_PORT " + "for instance : " + instanceName);
    }
    Node node = domain.getNodeNamed(server.getNodeRef());
    String host = node.getNodeHost();
    String consoleUrl = "http://" + host + ":" + port + consolePath;
    handlerCtx.setOutputValue("consoleUrl", consoleUrl);
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) Node(com.sun.enterprise.config.serverbeans.Node) Domain(com.sun.enterprise.config.serverbeans.Domain) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) Handler(com.sun.jsftemplating.annotation.Handler)

Example 38 with Server

use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.

the class MigrateTimers method validateDG.

private String validateDG() {
    List<DeploymentGroup> dgs = targetUtil.getDGForInstance(fromServer);
    if (dgs == null) {
        return localStrings.getString("migrate.timers.fromServerNotDG", fromServer);
    }
    // in the same cluster as fromServer
    if (target.equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
        List<Server> instances = dgs.get(0).getInstances();
        for (Server instance : instances) {
            if (instance.isRunning() && !instance.getName().equals(fromServer)) {
                target = instance.getName();
                needRedirect = true;
            }
        }
        // if destination is still DAS, that means no running server is available
        if (target.equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
            return localStrings.getString("migrate.timers.noRunningInstanceToChoose", target);
        }
    } else {
        // verify fromServer and destinationServer are in the same dg, and
        boolean inSameDG = false;
        for (DeploymentGroup dg : dgs) {
            for (Server instance : dg.getInstances()) {
                if (instance.getName().equals(target)) {
                    inSameDG = true;
                    break;
                }
            }
        }
        if (!inSameDG) {
            return localStrings.getString("migrate.timers.destinationIsNotInDG", target);
        }
        // verify destinationServer is running
        if (!isServerRunning(target)) {
            return localStrings.getString("migrate.timers.destinationServerIsNotAlive", target);
        }
    }
    return null;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Example 39 with Server

use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.

the class MicroProfileHealthChecker method pingAllInstances.

/**
 * Pings MP health check endpoint of all instances and returns a map containing a {@link Future} returning the ping
 * status code for that instance. Any exceptions thrown in the process will raise a {@link ExecutionException} when
 * the {@link Future} is resolved.
 */
private Map<String, Future<Integer>> pingAllInstances(long timeoutMillis) {
    Map<String, Future<Integer>> tasks = new ConcurrentHashMap<>();
    Map<UUID, Future<ClusterCommandResult>> configs = payaraMicro.executeClusteredASAdmin(GET_MP_CONFIG_STRING);
    for (Server server : domain.getServers().getServer()) {
        @Pattern(regexp = "[A-Za-z0-9_][A-Za-z0-9\\-_\\.;]*", message = "{server.invalid.name}", payload = Server.class) String instanceName = server.getName();
        tasks.put(instanceName, payaraExecutorService.submit(() -> {
            // get the remote server's MP HealthCheck config
            MicroprofileHealthCheckConfiguration healthCheckConfig = server.getConfig().getExtensionByType(MicroprofileHealthCheckConfiguration.class);
            if (healthCheckConfig != null && Boolean.valueOf(healthCheckConfig.getEnabled())) {
                return pingHealthEndpoint(buildURI(server, healthCheckConfig.getEndpoint()));
            }
            return -1;
        }));
    }
    for (InstanceDescriptor instance : payaraMicro.getClusteredPayaras()) {
        String instanceName = instance.getInstanceName();
        if (tasks.containsKey(instanceName)) {
            continue;
        }
        tasks.put(instanceName, payaraExecutorService.submit(() -> {
            ClusterCommandResult mpHealthConfigResult = // 
            configs.get(instance.getMemberUUID()).get(timeoutMillis, MILLISECONDS);
            String values = mpHealthConfigResult.getOutput().split("\n")[1];
            Boolean enabled = Boolean.parseBoolean(values.split(" ")[0]);
            if (enabled) {
                String endpoint = values.split(" ", 2)[1].trim();
                return pingHealthEndpoint(buildURI(instance, endpoint));
            }
            return -1;
        }));
    }
    return tasks;
}
Also used : InstanceDescriptor(fish.payara.micro.data.InstanceDescriptor) Pattern(javax.validation.constraints.Pattern) ClusterCommandResult(fish.payara.micro.ClusterCommandResult) Server(com.sun.enterprise.config.serverbeans.Server) Future(java.util.concurrent.Future) MicroprofileHealthCheckConfiguration(fish.payara.microprofile.healthcheck.config.MicroprofileHealthCheckConfiguration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID)

Example 40 with Server

use of com.sun.enterprise.config.serverbeans.Server in project Payara by payara.

the class ListTimers method execute.

/**
 * Executes the command
 *
 * @param context information
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    String[] serverIds = null;
    if (targetUtil.isCluster(target) || targetUtil.isDeploymentGroup(target)) {
        List<Server> serversInCluster = targetUtil.getInstances(target);
        serverIds = new String[serversInCluster.size()];
        for (int i = 0; i < serverIds.length; i++) {
            serverIds[i] = serversInCluster.get(i).getName();
        }
    } else {
        serverIds = new String[] { target };
    }
    try {
        String[] timerCounts = listTimers(serverIds);
        ActionReport actionReport = context.getActionReport();
        Properties extraProperties = actionReport.getExtraProperties();
        if (extraProperties == null) {
            extraProperties = new Properties();
            actionReport.setExtraProperties(extraProperties);
        }
        List<Map<String, String>> property = new LinkedList<>();
        extraProperties.put("ejbTimers", property);
        for (int i = 0; i < serverIds.length; i++) {
            final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
            part.setMessage(serverIds[i] + ": " + timerCounts[i]);
            HashMap<String, String> values = new HashMap<>();
            values.put("server", serverIds[i]);
            values.put("timerCount", timerCounts[i]);
            property.add(values);
        }
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("list.timers.failed", "List Timers command failed"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) HashMap(java.util.HashMap) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) RestEndpoint(org.glassfish.api.admin.RestEndpoint) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Server (com.sun.enterprise.config.serverbeans.Server)101 ActionReport (org.glassfish.api.ActionReport)32 Cluster (com.sun.enterprise.config.serverbeans.Cluster)25 Domain (com.sun.enterprise.config.serverbeans.Domain)15 Node (com.sun.enterprise.config.serverbeans.Node)15 Config (com.sun.enterprise.config.serverbeans.Config)14 Properties (java.util.Properties)14 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 PropertyVetoException (java.beans.PropertyVetoException)11 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)9 ParameterMap (org.glassfish.api.admin.ParameterMap)9 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)8 File (java.io.File)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)8 Logger (java.util.logging.Logger)7 Map (java.util.Map)6 ServerContext (org.glassfish.internal.api.ServerContext)6