Search in sources :

Example 6 with ProgressStatus

use of org.glassfish.api.admin.ProgressStatus in project Payara by payara.

the class ProgressPayloadCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    ProgressStatus ps = context.getProgressStatus();
    for (int i = 0; i < 4; i++) {
        doSomeLogic();
        ps.progress(1);
    }
    // Prepare payload
    Outbound out = context.getOutboundPayload();
    StringBuilder msg = new StringBuilder();
    if (down == null || down.isEmpty()) {
        msg.append("No file requested.");
    } else {
        msg.append("You are requesting for ").append(down).append('.').append(StringUtils.EOL);
        File f = new File(down);
        if (!f.exists()) {
            msg.append("But it does not exist!");
        } else {
            try {
                String canonicalPath = f.getCanonicalPath();
                canonicalPath = canonicalPath.replace('\\', '/');
                if (canonicalPath.charAt(1) == ':') {
                    canonicalPath = canonicalPath.substring(2);
                }
                if (f.isDirectory()) {
                    msg.append("It is directory - recursive download");
                    out.attachFile("application/octet-stream", URI.create(canonicalPath), f.getName(), f, true);
                } else {
                    out.attachFile("application/octet-stream", URI.create(canonicalPath), f.getName(), f);
                }
            } catch (IOException ex) {
                report.failure(logger, "Can not append " + f.getAbsolutePath());
            }
        }
    }
    if (report.getActionExitCode() == ActionReport.ExitCode.SUCCESS) {
        report.setMessage(msg.toString());
    }
    // Return
    ps.progress(1);
    ps.complete("Finished");
}
Also used : Outbound(org.glassfish.api.admin.Payload.Outbound) ProgressStatus(org.glassfish.api.admin.ProgressStatus) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) File(java.io.File)

Example 7 with ProgressStatus

use of org.glassfish.api.admin.ProgressStatus in project Payara by payara.

the class ProgressCustomCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ProgressStatus ps = context.getProgressStatus();
    parsedIntervals = new ArrayList<Interval>(intervals != null ? intervals.length : 0);
    ActionReport report = context.getActionReport();
    for (String interval : intervals) {
        parsedIntervals.add(new Interval(interval));
    }
    // Count
    if (parsedIntervals.isEmpty()) {
        report.setMessage("Done command process without waiting interval.");
        return;
    }
    ps.setTotalStepCount(getStepCount());
    int blockId = 0;
    for (Interval interval : parsedIntervals) {
        blockId++;
        if (interval.isValid()) {
            int multip = interval.getMultiplicator();
            if (interval.getMaxSec() == 0) {
                ps.progress(multip, "Finished block without sleeping: [" + blockId + "] " + interval);
            } else {
                for (int i = 0; i < multip; i++) {
                    if (i == 0) {
                        ps.progress(0, "Starting block[" + blockId + "] " + interval, interval.isSpin());
                    }
                    try {
                        Thread.sleep(interval.getMilis());
                    } catch (Exception ex) {
                    }
                    if (i == (multip - 1)) {
                        ps.progress(1, "Finished block [" + blockId + "] " + interval);
                    } else {
                        ps.progress(1, "Block [" + blockId + "] " + interval + ", step: " + (i + 1));
                    }
                }
            }
        } else {
            ps.progress(1, "Finished unparsable block [" + blockId + "] " + interval);
        }
    }
    report.setMessage("Finished command process in " + parsedIntervals.size() + " block(s).");
}
Also used : ProgressStatus(org.glassfish.api.admin.ProgressStatus) ActionReport(org.glassfish.api.ActionReport)

Example 8 with ProgressStatus

use of org.glassfish.api.admin.ProgressStatus in project Payara by payara.

the class ProgressExecOtherCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ProgressStatus ps = context.getProgressStatus();
    // Do some before logic
    ps.progress("Preparing");
    for (int i = 0; i < 10; i++) {
        doSomeLogic();
        ps.progress(1);
    }
    // Execute other command
    final CommandRunner.CommandInvocation commandInvocation = commandRunner.getCommandInvocation("progress-simple", context.getActionReport().addSubActionsReport(), context.getSubject());
    commandInvocation.progressStatusChild(// Number 20 is little bit tricky. Please see javadoc of ProgressStatus
    ps.createChild("subcommand", 20)).execute();
    // Do some after logic
    ps.progress("Finishing outer command");
    for (int i = 0; i < 10; i++) {
        doSomeLogic();
        ps.progress(1);
    }
    ps.complete("Finished outer command");
}
Also used : ProgressStatus(org.glassfish.api.admin.ProgressStatus) CommandRunner(org.glassfish.api.admin.CommandRunner)

Example 9 with ProgressStatus

use of org.glassfish.api.admin.ProgressStatus in project Payara by payara.

the class ProgressWithSupplementCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ProgressStatus ps = context.getProgressStatus();
    ps.setTotalStepCount(4);
    ps.progress("Parsing");
    doSomeLogic();
    ps.progress(1, "Working on main part");
    for (int i = 0; i < 3; i++) {
        doSomeLogic();
        ps.progress(1);
    }
    ps.complete("Finished");
}
Also used : ProgressStatus(org.glassfish.api.admin.ProgressStatus)

Example 10 with ProgressStatus

use of org.glassfish.api.admin.ProgressStatus in project Payara by payara.

the class SupplementBefore method execute.

@Override
public void execute(AdminCommandContext context) {
    ProgressStatus ps = context.getProgressStatus();
    ps.progress("2 seconds supplemental command");
    for (int i = 0; i < 4; i++) {
        try {
            Thread.sleep(500L);
        } catch (InterruptedException ex) {
        }
        ps.progress(1);
    }
    context.getActionReport().setActionExitCode(ActionReport.ExitCode.SUCCESS);
    ps.complete();
}
Also used : ProgressStatus(org.glassfish.api.admin.ProgressStatus)

Aggregations

ProgressStatus (org.glassfish.api.admin.ProgressStatus)20 Test (org.junit.Test)4 ActionReport (org.glassfish.api.ActionReport)3 File (java.io.File)1 IOException (java.io.IOException)1 CommandRunner (org.glassfish.api.admin.CommandRunner)1 Outbound (org.glassfish.api.admin.Payload.Outbound)1 ProgressStatusBase (org.glassfish.api.admin.progress.ProgressStatusBase)1 ProgressStatusDTO (org.glassfish.api.admin.progress.ProgressStatusDTO)1 ProgressStatusEventCreateChild (org.glassfish.api.admin.progress.ProgressStatusEventCreateChild)1 ProgressStatusImpl (org.glassfish.api.admin.progress.ProgressStatusImpl)1 ProgressStatusMirroringImpl (org.glassfish.api.admin.progress.ProgressStatusMirroringImpl)1