Search in sources :

Example 1 with JobGroupPath

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

the class RestoreJobTest method jobGroupAtWikiLevel.

@Test
public void jobGroupAtWikiLevel() throws Exception {
    RestoreRequest request = createRequest();
    RestoreJob job = (RestoreJob) getMocker().getComponentUnderTest();
    job.initialize(request);
    JobGroupPath expectedJobGroupPath = new JobGroupPath(wikiReference.getName(), RestoreJob.ROOT_GROUP);
    assertEquals(expectedJobGroupPath, job.getGroupPath());
}
Also used : RestoreRequest(org.xwiki.refactoring.job.RestoreRequest) JobGroupPath(org.xwiki.job.JobGroupPath) Test(org.junit.Test)

Example 2 with JobGroupPath

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

the class RestoreJob method initialize.

@Override
public void initialize(Request request) {
    super.initialize(request);
    // Build the job group path.
    // Note: Because of the nature of the RestoreJob that works with with DeletedDocument IDs and BatchIDs (and not
    // with EntityReferences), the only way we can try to avoid executing operation at the same time on the same
    // reference is to use a group path at the wiki level, hoping most restore operations are fast and do not block
    // for long.
    WikiReference wikiReference = ((RestoreRequest) request).getWikiReference();
    if (wikiReference != null) {
        // Note:
        this.groupPath = new JobGroupPath(wikiReference.getName(), ROOT_GROUP);
    }
}
Also used : RestoreRequest(org.xwiki.refactoring.job.RestoreRequest) JobGroupPath(org.xwiki.job.JobGroupPath) WikiReference(org.xwiki.model.reference.WikiReference)

Example 3 with JobGroupPath

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

the class JobScriptService method getCurrentJobStatus.

/**
 * Get the status of the currently executing job in the specified group job, if any.
 *
 * @param path specifies the job group where to look for a running job
 * @return status of the currently executing job in the specified group, or {@code null} if no job is being executed
 */
public JobStatus getCurrentJobStatus(Collection<String> path) {
    Job job = this.jobExecutor.getCurrentJob(new JobGroupPath(path));
    JobStatus jobStatus = null;
    if (job != null) {
        jobStatus = job.getStatus();
        if (!this.authorization.hasAccess(Right.PROGRAM)) {
            jobStatus = safe(jobStatus);
        }
    }
    return jobStatus;
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) JobGroupPath(org.xwiki.job.JobGroupPath) Job(org.xwiki.job.Job)

Example 4 with JobGroupPath

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

the class EntityJobTest method getGroupPath.

@Test
public void getGroupPath() {
    NoopEntityJob job = new NoopEntityJob();
    EntityRequest request = new EntityRequest();
    DocumentReference aliceReference = new DocumentReference("chess", Arrays.asList("Path", "To"), "Alice");
    request.setEntityReferences(aliceReference.getReversedReferenceChain());
    initialize(job, request);
    assertEquals(new JobGroupPath(Arrays.asList("refactoring", "chess")), job.getGroupPath());
    DocumentReference bobReference = new DocumentReference("dev", Arrays.asList("Path", "To"), "Bob");
    request.setEntityReferences(Arrays.<EntityReference>asList(aliceReference, bobReference));
    initialize(job, request);
    assertEquals(new JobGroupPath(Arrays.asList("refactoring")), job.getGroupPath());
    DocumentReference carolReference = new DocumentReference("chess", Arrays.asList("Path", "To"), "Carol");
    request.setEntityReferences(Arrays.<EntityReference>asList(aliceReference, carolReference));
    initialize(job, request);
    assertEquals(new JobGroupPath(Arrays.asList("refactoring", "chess", "Path", "To")), job.getGroupPath());
    DocumentReference daveReference = new DocumentReference("chess", Arrays.asList("Path", "To2"), "Dave");
    request.setEntityReferences(Arrays.<EntityReference>asList(aliceReference, carolReference, daveReference));
    initialize(job, request);
    assertEquals(new JobGroupPath(Arrays.asList("refactoring", "chess", "Path")), job.getGroupPath());
}
Also used : EntityRequest(org.xwiki.refactoring.job.EntityRequest) JobGroupPath(org.xwiki.job.JobGroupPath) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 5 with JobGroupPath

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

the class AbstractEntityJob method initialize.

@Override
public void initialize(Request request) {
    super.initialize(request);
    // Build the job group path.
    EntityReference commonParent = getCommonParent();
    if (commonParent != null) {
        // Build a JobGroupPath based on the common location of the concerned entities.
        // The intent is to prevent having jobs concerning the same entities to run in parallel.
        // 
        // Examples:
        // - A.B.C and A.B cannot run in parallel
        // But:
        // - A.B.C and A.B.Z can run in parallel
        // - A.B.C and E.F.G can run in parallel
        // 
        // Example of use case:
        // - user A renames A.B.C to A.B.D
        // - user B deletes A.B.C in the same time
        this.groupPath = ROOT_GROUP;
        for (EntityReference reference : commonParent.getReversedReferenceChain()) {
            this.groupPath = new JobGroupPath(reference.getName(), this.groupPath);
        }
    } else {
        this.groupPath = ROOT_GROUP;
    }
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) JobGroupPath(org.xwiki.job.JobGroupPath)

Aggregations

JobGroupPath (org.xwiki.job.JobGroupPath)5 Test (org.junit.Test)2 RestoreRequest (org.xwiki.refactoring.job.RestoreRequest)2 Job (org.xwiki.job.Job)1 JobStatus (org.xwiki.job.event.status.JobStatus)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 EntityReference (org.xwiki.model.reference.EntityReference)1 WikiReference (org.xwiki.model.reference.WikiReference)1 EntityRequest (org.xwiki.refactoring.job.EntityRequest)1