Search in sources :

Example 1 with UninstallRequest

use of org.xwiki.extension.job.UninstallRequest in project xwiki-platform by xwiki.

the class ExtensionManagerScriptService method createUninstallPlanRequest.

/**
 * Create an {@link UninstallRequest} instance based on passed parameters.
 *
 * @param extensionId the identifier of the extension to uninstall
 * @param namespace the (optional) namespace from where to uninstall the extension; if {@code null} or empty, the
 *            extension will be uninstalled globally
 * @return the {@link UninstallRequest}
 */
private UninstallRequest createUninstallPlanRequest(ExtensionId extensionId, String namespace) {
    UninstallRequest uninstallRequest = new UninstallRequest();
    uninstallRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, extensionId.getId(), namespace));
    uninstallRequest.setInteractive(true);
    uninstallRequest.addExtension(extensionId);
    if (StringUtils.isNotBlank(namespace)) {
        uninstallRequest.addNamespace(namespace);
    }
    // Indicate if it's allowed to do modification on root namespace
    uninstallRequest.setRootModificationsAllowed(namespace == null || this.xcontextProvider.get().isMainWiki(toWikiId(namespace)));
    contextualize(uninstallRequest);
    setRightsProperties(uninstallRequest);
    return uninstallRequest;
}
Also used : UninstallRequest(org.xwiki.extension.job.UninstallRequest)

Example 2 with UninstallRequest

use of org.xwiki.extension.job.UninstallRequest in project xwiki-platform by xwiki.

the class ExtensionManagerScriptService method createUninstallRequest.

private UninstallRequest createUninstallRequest(ExtensionId extensionId, String namespace) {
    UninstallRequest uninstallRequest = createUninstallPlanRequest(extensionId, namespace);
    uninstallRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_ACTION_PREFIX, extensionId.getId(), namespace));
    return uninstallRequest;
}
Also used : UninstallRequest(org.xwiki.extension.job.UninstallRequest)

Example 3 with UninstallRequest

use of org.xwiki.extension.job.UninstallRequest in project xwiki-platform by xwiki.

the class ExtensionHistoryScriptServiceTest method getRecords.

@Test
public void getRecords() throws Exception {
    InstallRequest devInstallReq = new InstallRequest();
    devInstallReq.addNamespace("wiki:dev");
    ExtensionJobHistoryRecord devInstall = new ExtensionJobHistoryRecord("install", devInstallReq, null, null, null);
    UninstallRequest devUninstallReq = new UninstallRequest();
    devUninstallReq.addNamespace("wiki:dev");
    ExtensionJobHistoryRecord devUninstall = new ExtensionJobHistoryRecord("uninstall", devUninstallReq, null, null, null);
    ExtensionJobHistoryRecord globalInstall = new ExtensionJobHistoryRecord("install", new InstallRequest(), null, null, null);
    ExtensionJobHistoryRecord globalUninstall = new ExtensionJobHistoryRecord("uninstall", new UninstallRequest(), null, null, null);
    InstallRequest draftsInstallReq = new InstallRequest();
    draftsInstallReq.addNamespace("wiki:drafts");
    ExtensionJobHistoryRecord draftsInstall = new ExtensionJobHistoryRecord("install", draftsInstallReq, null, null, null);
    List<ExtensionJobHistoryRecord> records = Arrays.asList(devInstall, globalInstall);
    ExtensionJobHistory history = this.mocker.getInstance(ExtensionJobHistory.class);
    ArgumentCaptor<Predicate<ExtensionJobHistoryRecord>> predicateCaptor = ArgumentCaptor.forClass((Class) Predicate.class);
    when(history.getRecords(predicateCaptor.capture(), eq("offsetRecordId"), eq(5))).thenReturn(records);
    when(this.xcontext.getWikiId()).thenReturn("dev");
    assertEquals(records, this.mocker.getComponentUnderTest().getRecords().fromThisWiki().ofType(Arrays.asList("install")).list("offsetRecordId", 5));
    Predicate<ExtensionJobHistoryRecord> predicate = predicateCaptor.getValue();
    assertTrue(predicate.evaluate(devInstall));
    assertTrue(predicate.evaluate(globalInstall));
    assertFalse(predicate.evaluate(devUninstall));
    assertFalse(predicate.evaluate(globalUninstall));
    assertFalse(predicate.evaluate(draftsInstall));
}
Also used : ExtensionJobHistoryRecord(org.xwiki.extension.job.history.ExtensionJobHistoryRecord) InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionJobHistory(org.xwiki.extension.job.history.ExtensionJobHistory) UninstallRequest(org.xwiki.extension.job.UninstallRequest) Predicate(org.apache.commons.collections4.Predicate) Test(org.junit.Test)

Example 4 with UninstallRequest

use of org.xwiki.extension.job.UninstallRequest 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 5 with UninstallRequest

use of org.xwiki.extension.job.UninstallRequest in project xwiki-platform by xwiki.

the class InstalledExtensionIndexTest method testInstallExtensionOnRoot.

@Test
public void testInstallExtensionOnRoot() throws Exception {
    // Use superadmin
    getUtil().setDefaultCredentials(TestUtils.SUPER_ADMIN_CREDENTIALS);
    ExtensionId extensionId = new ExtensionId("maven:jar", "1.0");
    // ///////////////////////////////////////////
    // Make sure it's not yet installed on node 0 and node 1
    getUtil().switchExecutor(0);
    assertTrue("The extension is already installed on node0", !getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT));
    getUtil().switchExecutor(1);
    assertTrue("The extension is already installed on node1", !getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT));
    // ///////////////////////////////////////////
    // Install extension on node 0
    getUtil().switchExecutor(0);
    InstallRequest installRequest = new InstallRequest();
    installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, extensionId.getId(), null));
    installRequest.setInteractive(false);
    installRequest.addExtension(extensionId);
    executeJob("install", installRequest);
    // ///////////////////////////////////////////
    // Make sure it has been installed on node 0
    assertTrue("The extension was not installed on node0", getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT));
    // ///////////////////////////////////////////
    // Make sure it has been installed on node 1
    getUtil().switchExecutor(1);
    long t1 = System.currentTimeMillis();
    while (!getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT)) {
        if (System.currentTimeMillis() - t1 > 10000L) {
            fail("The extension was not installed on node1");
        }
        Thread.sleep(100);
    }
    // ///////////////////////////////////////////
    // Uninstall extension from node 1
    getUtil().switchExecutor(1);
    UninstallRequest uninstallRequest = new UninstallRequest();
    uninstallRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, extensionId.getId(), null));
    uninstallRequest.setInteractive(false);
    uninstallRequest.addExtension(extensionId);
    executeJob("uninstall", uninstallRequest);
    // ///////////////////////////////////////////
    // Make sure it has been uninstalled from node 1
    assertTrue("The extension is still installed on node1", !getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT));
    // ///////////////////////////////////////////
    // Make sure it has been uninstalled from node 0
    getUtil().switchExecutor(1);
    t1 = System.currentTimeMillis();
    while (getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT)) {
        if (System.currentTimeMillis() - t1 > 10000L) {
            fail("The extension is still installed on node0");
        }
        Thread.sleep(100);
    }
}
Also used : InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionId(org.xwiki.extension.ExtensionId) UninstallRequest(org.xwiki.extension.job.UninstallRequest) Test(org.junit.Test) AbstractTest(org.xwiki.test.ui.AbstractTest) AbstractClusterHttpTest(org.xwiki.test.cluster.framework.AbstractClusterHttpTest)

Aggregations

UninstallRequest (org.xwiki.extension.job.UninstallRequest)5 Test (org.junit.Test)2 InstallRequest (org.xwiki.extension.job.InstallRequest)2 Predicate (org.apache.commons.collections4.Predicate)1 ExtensionId (org.xwiki.extension.ExtensionId)1 InstallException (org.xwiki.extension.InstallException)1 UninstallException (org.xwiki.extension.UninstallException)1 ExtensionJobHistory (org.xwiki.extension.job.history.ExtensionJobHistory)1 ExtensionJobHistoryRecord (org.xwiki.extension.job.history.ExtensionJobHistoryRecord)1 InstallJob (org.xwiki.extension.job.internal.InstallJob)1 UninstallJob (org.xwiki.extension.job.internal.UninstallJob)1 Job (org.xwiki.job.Job)1 LogEvent (org.xwiki.logging.event.LogEvent)1 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)1 AbstractClusterHttpTest (org.xwiki.test.cluster.framework.AbstractClusterHttpTest)1 AbstractTest (org.xwiki.test.ui.AbstractTest)1