Search in sources :

Example 6 with Job

use of org.xwiki.job.Job in project xwiki-platform by xwiki.

the class ExtensionManagerScriptService method getCurrentJobStatus.

/**
 * Get the status of the currently executing job, if any.
 *
 * @return status of the currently executing job, or {@code null} if no job is being executed
 */
public JobStatus getCurrentJobStatus() {
    Job job = getCurrentJobInternal();
    JobStatus jobStatus;
    if (job != null) {
        jobStatus = job.getStatus();
        if (!this.authorization.hasAccess(Right.PROGRAM)) {
            jobStatus = safe(jobStatus);
        }
    } else {
        jobStatus = null;
    }
    return jobStatus;
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) UpgradePlanJob(org.xwiki.extension.job.internal.UpgradePlanJob) UninstallPlanJob(org.xwiki.extension.job.internal.UninstallPlanJob) UninstallJob(org.xwiki.extension.job.internal.UninstallJob) InstallJob(org.xwiki.extension.job.internal.InstallJob) Job(org.xwiki.job.Job) InstallPlanJob(org.xwiki.extension.job.internal.InstallPlanJob) AbstractExtensionJob(org.xwiki.extension.job.internal.AbstractExtensionJob)

Example 7 with Job

use of org.xwiki.job.Job in project xwiki-platform by xwiki.

the class ExtensionHistoryScriptServiceTest method replayWithoutAdmin.

@Test
public void replayWithoutAdmin() throws Exception {
    InstallRequest installRequest = new InstallRequest();
    installRequest.addNamespace("wiki:dev");
    ExtensionJobHistoryRecord install = new ExtensionJobHistoryRecord("install", installRequest, null, null, null);
    List<ExtensionJobHistoryRecord> records = Arrays.asList(install);
    when(this.xcontext.getWikiId()).thenReturn("dev");
    when(this.authorization.hasAccess(Right.ADMIN, new WikiReference("dev"))).thenReturn(false);
    Job replayJob = mock(Job.class);
    ArgumentCaptor<ReplayRequest> requestCaptor = ArgumentCaptor.forClass(ReplayRequest.class);
    when(jobExecutor.execute(eq(ReplayJob.JOB_TYPE), requestCaptor.capture())).thenReturn(replayJob);
    assertSame(replayJob, this.mocker.getComponentUnderTest().replay(records));
    ReplayRequest request = requestCaptor.getValue();
    assertTrue(request.getRecords().isEmpty());
}
Also used : ExtensionJobHistoryRecord(org.xwiki.extension.job.history.ExtensionJobHistoryRecord) ReplayRequest(org.xwiki.extension.job.history.ReplayRequest) InstallRequest(org.xwiki.extension.job.InstallRequest) WikiReference(org.xwiki.model.reference.WikiReference) ReplayJob(org.xwiki.extension.job.history.internal.ReplayJob) Job(org.xwiki.job.Job) Test(org.junit.Test)

Example 8 with Job

use of org.xwiki.job.Job in project xwiki-platform by xwiki.

the class ExtensionHistoryScriptServiceTest method replayWithAdminButNoPR.

@Test
public void replayWithAdminButNoPR() throws Exception {
    InstallRequest installRequest = new InstallRequest();
    installRequest.addNamespace("wiki:drafts");
    installRequest.setProperty("user.reference", new DocumentReference("drafts", "Users", "Alice"));
    ExtensionJobHistoryRecord install = new ExtensionJobHistoryRecord("install", installRequest, null, null, null);
    List<ExtensionJobHistoryRecord> records = Arrays.asList(install);
    when(this.xcontext.getWikiId()).thenReturn("dev");
    when(this.documentAccessBridge.getCurrentUserReference()).thenReturn(new DocumentReference("dev", "Users", "Bob"));
    when(this.authorization.hasAccess(Right.ADMIN, new WikiReference("dev"))).thenReturn(true);
    when(this.authorization.hasAccess(Right.PROGRAM)).thenReturn(false);
    Job replayJob = mock(Job.class);
    ArgumentCaptor<ReplayRequest> requestCaptor = ArgumentCaptor.forClass(ReplayRequest.class);
    when(jobExecutor.execute(eq(ReplayJob.JOB_TYPE), requestCaptor.capture())).thenReturn(replayJob);
    assertSame(replayJob, this.mocker.getComponentUnderTest().replay(records));
    ReplayRequest request = requestCaptor.getValue();
    assertEquals(Arrays.asList(install), request.getRecords());
    assertEquals(Arrays.asList("wiki:dev"), install.getRequest().getNamespaces());
    assertEquals(this.documentAccessBridge.getCurrentUserReference(), install.getRequest().getProperty("user.reference"));
}
Also used : ExtensionJobHistoryRecord(org.xwiki.extension.job.history.ExtensionJobHistoryRecord) ReplayRequest(org.xwiki.extension.job.history.ReplayRequest) InstallRequest(org.xwiki.extension.job.InstallRequest) WikiReference(org.xwiki.model.reference.WikiReference) ReplayJob(org.xwiki.extension.job.history.internal.ReplayJob) Job(org.xwiki.job.Job) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 9 with Job

use of org.xwiki.job.Job in project xwiki-platform by xwiki.

the class ExtensionManagerScriptServiceTest method install.

// tools
private Job install(String id, String version, String namespace) throws Throwable {
    Job job = this.scriptService.install(id, version, namespace);
    if (job == null) {
        throw this.scriptService.getLastError();
    }
    job.join();
    List<LogEvent> errors = job.getStatus().getLog().getLogsFrom(LogLevel.WARN);
    if (!errors.isEmpty()) {
        throw errors.get(0).getThrowable();
    }
    return job;
}
Also used : LogEvent(org.xwiki.logging.event.LogEvent) Job(org.xwiki.job.Job)

Example 10 with Job

use of org.xwiki.job.Job in project xwiki-platform by xwiki.

the class ExtensionManagerScriptServiceTest method uninstall.

private Job uninstall(String id, String namespace) throws Throwable {
    Job job = this.scriptService.uninstall(id, namespace);
    if (job == null) {
        throw this.scriptService.getLastError();
    }
    job.join();
    List<LogEvent> errors = job.getStatus().getLog().getLogsFrom(LogLevel.WARN);
    if (!errors.isEmpty()) {
        throw errors.get(0).getThrowable();
    }
    return job;
}
Also used : LogEvent(org.xwiki.logging.event.LogEvent) Job(org.xwiki.job.Job)

Aggregations

Job (org.xwiki.job.Job)41 Test (org.junit.Test)11 JobStatus (org.xwiki.job.event.status.JobStatus)10 AbstractExtensionJob (org.xwiki.extension.job.internal.AbstractExtensionJob)8 InstallJob (org.xwiki.extension.job.internal.InstallJob)8 UninstallJob (org.xwiki.extension.job.internal.UninstallJob)8 JobException (org.xwiki.job.JobException)8 DocumentReference (org.xwiki.model.reference.DocumentReference)8 InstallRequest (org.xwiki.extension.job.InstallRequest)7 UpgradePlanJob (org.xwiki.extension.job.internal.UpgradePlanJob)7 InstallPlanJob (org.xwiki.extension.job.internal.InstallPlanJob)6 UninstallPlanJob (org.xwiki.extension.job.internal.UninstallPlanJob)6 XWikiException (com.xpn.xwiki.XWikiException)5 LogEvent (org.xwiki.logging.event.LogEvent)5 InstallException (org.xwiki.extension.InstallException)4 UninstallException (org.xwiki.extension.UninstallException)4 XarInstalledExtension (org.xwiki.extension.xar.internal.repository.XarInstalledExtension)4 EntityReference (org.xwiki.model.reference.EntityReference)4 WikiReference (org.xwiki.model.reference.WikiReference)4 IOException (java.io.IOException)3