Search in sources :

Example 1 with ProgressStatus

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

the class ProgressStatusMirroringImplTest method testTotalStepCount.

@Test
public void testTotalStepCount() {
    ProgressStatusMirroringImpl prog = new ProgressStatusMirroringImpl("first", parent, null);
    assertEquals(-1, prog.getTotalStepCount());
    assertEquals(0, prog.currentStepCount);
    ProgressStatus ch1 = prog.createChild("A1", 0);
    assertNotNull(ch1);
    ProgressStatus ch2 = prog.createChild("A2", 0);
    assertNotNull(ch2);
    ProgressStatus chm = prog.createChild(null, 0, 10);
    assertNotNull(chm);
    assertEquals(-1, prog.getTotalStepCount());
    assertEquals(0, prog.currentStepCount);
    ch1.setTotalStepCount(4);
    assertEquals(-1, prog.getTotalStepCount());
    assertEquals(0, prog.currentStepCount);
    ch2.setTotalStepCount(6);
    assertEquals(20, prog.getTotalStepCount());
    assertEquals(0, prog.currentStepCount);
    prog = new ProgressStatusMirroringImpl("second", parent, null);
    assertEquals(-1, prog.getTotalStepCount());
    ch1 = prog.createChild("A1", 0, 10);
    assertEquals(10, prog.getTotalStepCount());
    ch2 = prog.createChild("A2", 0);
    assertEquals(-1, prog.getTotalStepCount());
}
Also used : ProgressStatus(org.glassfish.api.admin.ProgressStatus) Test(org.junit.Test)

Example 2 with ProgressStatus

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

the class ProgressStatusMirroringImplTest method testComplete.

@Test
public void testComplete() {
    ProgressStatusMirroringImpl prog = new ProgressStatusMirroringImpl("first", parent, null);
    ProgressStatus ch1 = prog.createChild("A1", 0, 10);
    assertNotNull(ch1);
    ProgressStatus ch2 = prog.createChild("A2", 0, 20);
    assertNotNull(ch2);
    assertEquals(0, prog.currentStepCount);
    ch1.progress(2);
    ch2.progress(3);
    assertEquals(25, prog.getRemainingStepCount());
    assertFalse(prog.isComplete());
    assertFalse(ch1.isComplete());
    assertFalse(ch2.isComplete());
    ch2.complete();
    assertTrue(ch2.isComplete());
    assertEquals(8, prog.getRemainingStepCount());
    prog.complete();
    assertTrue(ch2.isComplete());
    assertTrue(prog.isComplete());
}
Also used : ProgressStatus(org.glassfish.api.admin.ProgressStatus) Test(org.junit.Test)

Example 3 with ProgressStatus

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

the class ProgressComplexCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ProgressStatus ps = context.getProgressStatus();
    ProgressStatus ch1 = ps.createChild("ch1", 5);
    ProgressStatus ch2 = ps.createChild("ch2-paral", 5);
    ProgressStatus ch3 = ps.createChild("ch3", 6);
    // Prepare ch1
    ch1.setTotalStepCount(10);
    ProgressStatus ch11 = ch1.createChild("ch11", 5);
    ch11.setTotalStepCount(5);
    ProgressStatus ch12 = ch1.createChild("ch12", 5);
    // Prepare ch2
    ch2.setTotalStepCount(50);
    ProgressStatus ch21 = ch2.createChild("ch21", 10);
    ch21.setTotalStepCount(25);
    ProgressStatus ch22 = ch2.createChild("ch22", 10);
    ch22.setTotalStepCount(25);
    ProgressStatus ch23 = ch2.createChild("ch23", 10);
    ch23.setTotalStepCount(25);
    ProgressStatus ch24 = ch2.createChild("ch24", 15);
    ch24.setTotalStepCount(25);
    // First move ch1
    doProgress(ch11, 4, 200, "progress ch1.1");
    // Init ch3
    ch3.setTotalStepCount(112);
    ProgressStatus ch31 = ch3.createChild("ch31", 100);
    ch31.setTotalStepCount(5);
    ProgressStatus ch32 = ch3.createChild("ch32", 8);
    ch32.setTotalStepCount(5);
    // Move ch3 then ch1 and then ch3 and then finish ch1
    doProgress(ch3, 4, 150, "progress ch3");
    doProgress(ch11, 1, 150, "progress ch1.1");
    doProgress(ch32, 5, 150, "progress ch3.2");
    ch12.setTotalStepCount(6);
    doProgress(ch31, 5, 150, "progress ch3.1");
    doProgress(ch12, 6, 150, "progress ch1.2");
    // Do paralel progress of ch2.x
    Thread th21 = new Thread(new ProgressRunnable(ch21, 25, 100, "progress ch2.1"));
    Thread th22 = new Thread(new ProgressRunnable(ch22, 25, 100, "progress ch2.2"));
    Thread th23 = new Thread(new ProgressRunnable(ch23, 25, 100, "progress ch2.3"));
    Thread th24 = new Thread(new ProgressRunnable(ch24, 25, 100, "progress ch2.4"));
    th21.start();
    th22.start();
    th23.start();
    th24.start();
    try {
        th21.join();
        th22.join();
        th23.join();
        th24.join();
    } catch (InterruptedException ex) {
        context.getActionReport().failure(Logger.global, "Unexpected interrupt", ex);
        return;
    }
    doProgress(ps, 4, 100, "progress main");
    doProgress(ch2, 5, 100, "progress ch2");
    context.getActionReport().appendMessage("All done");
}
Also used : ProgressStatus(org.glassfish.api.admin.ProgressStatus)

Example 4 with ProgressStatus

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

the class ProgressDoubleTotalsCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ProgressStatus ps = context.getProgressStatus();
    ps.progress("Parsing");
    doSomeLogic();
    ps.progress(1, "Working");
    for (int i = 0; i < 2; i++) {
        doSomeLogic();
        ps.progress(1);
    }
    ps.setTotalStepCount(12);
    ps.progress("Double");
    for (int i = 0; i < 4; i++) {
        doSomeLogic();
        ps.progress(2);
    }
    doSomeLogic();
    ps.progress(1);
    ps.complete("Finished");
    context.getActionReport().appendMessage("All done");
}
Also used : ProgressStatus(org.glassfish.api.admin.ProgressStatus)

Example 5 with ProgressStatus

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

the class ProgressFailInHalfCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ProgressStatus ps = context.getProgressStatus();
    ps.progress("Parsing");
    doSomeLogic();
    ps.progress(1, "Working");
    for (int i = 0; i < 4; i++) {
        doSomeLogic();
        ps.progress(1);
    }
    ActionReport ar = context.getActionReport();
    ar.setActionExitCode(ActionReport.ExitCode.FAILURE);
    ar.setMessage("Something failed");
}
Also used : ProgressStatus(org.glassfish.api.admin.ProgressStatus) ActionReport(org.glassfish.api.ActionReport)

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