Search in sources :

Example 21 with Job

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

the class WikiCreationJobScriptServicesTest method createWiki.

@Test
public void createWiki() throws Exception {
    Job job = mock(Job.class);
    when(wikiCreator.createWiki(any(WikiCreationRequest.class))).thenReturn(job);
    WikiCreationRequest wikiCreationRequest = new WikiCreationRequest();
    wikiCreationRequest.setExtensionId("authorized-extension", "1.0");
    assertEquals(job, mocker.getComponentUnderTest().createWiki(wikiCreationRequest));
    assertNull(mocker.getComponentUnderTest().getLastError());
}
Also used : WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) Job(org.xwiki.job.Job) Test(org.junit.Test)

Example 22 with Job

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

the class DefaultWikiCreator method getJobStatus.

@Override
public JobStatus getJobStatus(String wikiId) {
    List<String> jobId = getJobId(wikiId);
    Job job = jobExecutor.getJob(jobId);
    if (job != null) {
        return job.getStatus();
    } else {
        return jobStatusStore.getJobStatus(jobId);
    }
}
Also used : Job(org.xwiki.job.Job)

Example 23 with Job

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

the class XarExtensionHandlerTest method uninstall.

private void uninstall(ExtensionId extensionId, String wiki) throws Throwable {
    UninstallRequest uninstallRequest = new UninstallRequest();
    uninstallRequest.setProperty("user.reference", getXWikiContext().getUserReference());
    uninstallRequest.setProperty("checkrights", true);
    uninstallRequest.addExtension(extensionId);
    if (wiki != null) {
        uninstallRequest.addNamespace("wiki:" + wiki);
    }
    Job uninstallJob = this.jobExecutor.execute(UninstallJob.JOBTYPE, uninstallRequest);
    uninstallJob.join();
    List<LogEvent> errors = uninstallJob.getStatus().getLog().getLogsFrom(LogLevel.WARN);
    if (!errors.isEmpty()) {
        if (errors.get(0).getThrowable() != null) {
            throw errors.get(0).getThrowable();
        } else {
            throw new Exception(errors.get(0).getFormattedMessage());
        }
    }
}
Also used : LogEvent(org.xwiki.logging.event.LogEvent) UninstallJob(org.xwiki.extension.job.internal.UninstallJob) InstallJob(org.xwiki.extension.job.internal.InstallJob) Job(org.xwiki.job.Job) UninstallException(org.xwiki.extension.UninstallException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) InstallException(org.xwiki.extension.InstallException) UninstallRequest(org.xwiki.extension.job.UninstallRequest)

Example 24 with Job

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

the class XarExtensionHandlerTest method installOnNamespace.

private XarInstalledExtension installOnNamespace(ExtensionId extensionId, String namespace, DocumentReference user) throws Throwable {
    InstallRequest installRequest = new InstallRequest();
    if (user != null) {
        installRequest.setProperty("user.reference", getXWikiContext().getUserReference());
        installRequest.setProperty("checkrights", true);
    }
    installRequest.addExtension(extensionId);
    if (namespace != null) {
        installRequest.addNamespace(namespace);
    }
    Job installJob = this.jobExecutor.execute(InstallJob.JOBTYPE, installRequest);
    installJob.join();
    List<LogEvent> errors = installJob.getStatus().getLog().getLogsFrom(LogLevel.WARN);
    if (!errors.isEmpty()) {
        if (errors.get(0).getThrowable() != null) {
            throw errors.get(0).getThrowable();
        } else {
            throw new Exception(errors.get(0).getFormattedMessage());
        }
    }
    return (XarInstalledExtension) this.xarExtensionRepository.resolve(extensionId);
}
Also used : LogEvent(org.xwiki.logging.event.LogEvent) XarInstalledExtension(org.xwiki.extension.xar.internal.repository.XarInstalledExtension) InstallRequest(org.xwiki.extension.job.InstallRequest) UninstallJob(org.xwiki.extension.job.internal.UninstallJob) InstallJob(org.xwiki.extension.job.internal.InstallJob) Job(org.xwiki.job.Job) UninstallException(org.xwiki.extension.UninstallException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) InstallException(org.xwiki.extension.InstallException)

Example 25 with Job

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

the class XarExtensionScriptService method repairInstalledExtension.

/**
 * Make sure the provided XAR extension properly is registered in the installed extensions index.
 * <p>
 * Start an asynchronous Job.
 *
 * @param id the extension identifier
 * @param version the extension version
 * @param wiki the wiki where the extension is installed
 * @return the {@link Job} object which can be used to monitor the progress of the installation process, or
 *         {@code null} in case of failure
 */
public Job repairInstalledExtension(String id, String version, String wiki) {
    setError(null);
    if (!this.authorization.hasAccess(Right.PROGRAM)) {
        setError(new JobException("Need programming right to repair a XAR"));
        return null;
    }
    String namespace = getWikiNamespace(wiki);
    InstallRequest installRequest = new InstallRequest();
    installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_ACTION_PREFIX, id, namespace));
    DocumentReference currentUserReference = this.documentAccessBridge.getCurrentUserReference();
    if (currentUserReference != null) {
        installRequest.setProperty(PROPERTY_USER_REFERENCE, currentUserReference);
        // We set the string value because the extension repository doesn't know how to serialize/parse an extension
        // property whose value is a DocumentReference, and adding support for it requires considerable refactoring
        // because ExtensionPropertySerializers are not components (they are currently hard-coded).
        installRequest.setExtensionProperty(PROPERTY_USER_REFERENCE, currentUserReference.toString());
    }
    installRequest.addExtension(new ExtensionId(id, version));
    if (StringUtils.isNotBlank(namespace)) {
        installRequest.addNamespace(namespace);
    }
    Job job = null;
    try {
        job = this.jobExecutor.execute(RepairXarJob.JOBTYPE, installRequest);
    } catch (Exception e) {
        setError(e);
    }
    return job;
}
Also used : JobException(org.xwiki.job.JobException) InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionId(org.xwiki.extension.ExtensionId) DiffXarJob(org.xwiki.extension.xar.internal.job.DiffXarJob) Job(org.xwiki.job.Job) RepairXarJob(org.xwiki.extension.xar.internal.job.RepairXarJob) DocumentReference(org.xwiki.model.reference.DocumentReference) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) XarException(org.xwiki.xar.XarException)

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