Search in sources :

Example 1 with InstanceCommandExecutor

use of com.sun.enterprise.admin.util.InstanceCommandExecutor in project Payara by payara.

the class InstanceInfo method getFutureResult.

private void getFutureResult() {
    try {
        InstanceCommandResult r = future.get(timeoutInMsec, TimeUnit.MILLISECONDS);
        InstanceCommandExecutor res = (InstanceCommandExecutor) r.getInstanceCommand();
        String instanceLocation = res.getCommandOutput();
        // Remove the pesky \n out
        instanceLocation = (instanceLocation == null) ? "" : instanceLocation.trim();
        if ((!instanceLocation.endsWith(res.getServer().getName())) || (res.getReport().getActionExitCode() != ActionReport.ExitCode.SUCCESS)) {
            uptime = -1;
            state = NOT_RUNNING;
            running = false;
            pid = -1;
            ssState = stateService.setState(name, InstanceState.StateType.NOT_RUNNING, false);
        } else {
            Properties props = res.getReport().getTopMessagePart().getProps();
            String uptimeStr = props.getProperty("Uptime");
            String pidstr = props.getProperty("Pid");
            String restartstr = props.getProperty("Restart-Required");
            try {
                pid = Integer.parseInt(pidstr);
            } catch (Exception e) {
                // no I don't want to use the enclosing catch...
                pid = -1;
            }
            ssState = stateService.setState(name, Boolean.parseBoolean(restartstr) ? InstanceState.StateType.RESTART_REQUIRED : InstanceState.StateType.RUNNING, false);
            uptime = Long.parseLong(uptimeStr);
            state = formatTime(uptime);
            running = true;
        }
    } catch (Exception e) {
        uptime = -1;
        state = NOT_RUNNING;
        ssState = stateService.setState(name, InstanceState.StateType.NOT_RUNNING, false);
        running = false;
        pid = -1;
    }
}
Also used : InstanceCommandExecutor(com.sun.enterprise.admin.util.InstanceCommandExecutor) InstanceCommandResult(org.glassfish.api.admin.InstanceCommandResult) CommandException(org.glassfish.api.admin.CommandException)

Example 2 with InstanceCommandExecutor

use of com.sun.enterprise.admin.util.InstanceCommandExecutor in project Payara by payara.

the class InstanceInfo method pingInstance.

// TODO what about security????
private Future<InstanceCommandResult> pingInstance() {
    try {
        ActionReport aReport = report.addSubActionsReport();
        InstanceCommandResult aResult = new InstanceCommandResult();
        ParameterMap map = new ParameterMap();
        map.set("type", "terse");
        InstanceCommandExecutor ice = new InstanceCommandExecutor(habitat, "__locations", FailurePolicy.Error, FailurePolicy.Error, svr, host, port, logger, map, aReport, aResult);
        return stateService.submitJob(svr, ice, aResult);
    /*
            String ret = rac.executeCommand(map).trim();

            if (ret == null || (!ret.endsWith("/" + name)))
            return -1;
            running = true;
            String uptimeStr = rac.getAttributes().get("Uptime_value");
            return Long.parseLong(uptimeStr);
             */
    } catch (CommandException ex) {
        running = false;
        return null;
    }
}
Also used : InstanceCommandExecutor(com.sun.enterprise.admin.util.InstanceCommandExecutor) InstanceCommandResult(org.glassfish.api.admin.InstanceCommandResult) ParameterMap(org.glassfish.api.admin.ParameterMap) CommandException(org.glassfish.api.admin.CommandException) ActionReport(org.glassfish.api.ActionReport)

Aggregations

InstanceCommandExecutor (com.sun.enterprise.admin.util.InstanceCommandExecutor)2 CommandException (org.glassfish.api.admin.CommandException)2 InstanceCommandResult (org.glassfish.api.admin.InstanceCommandResult)2 ActionReport (org.glassfish.api.ActionReport)1 ParameterMap (org.glassfish.api.admin.ParameterMap)1