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());
}
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);
}
}
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;
}
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());
}
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;
}
}
Aggregations