Search in sources :

Example 1 with DistributionRequest

use of org.xwiki.extension.distribution.internal.job.DistributionRequest in project xwiki-platform by xwiki.

the class DefaultDistributionManager method startWikiJob.

@Override
public DistributionJob startWikiJob(String wiki) {
    try {
        DistributionJob wikiJob = this.componentManager.getInstance(Job.class, DefaultDistributionJob.HINT);
        this.wikiDistributionJobs.put(wiki, wikiJob);
        final DistributionRequest request = new DistributionRequest();
        request.setId(getWikiJobId(wiki));
        request.setWiki(wiki);
        request.setUserReference(this.xcontextProvider.get().getUserReference());
        request.setInteractive(this.configuration.getProperty("distribution.job.interactive.wiki", true));
        Thread distributionJobThread = new Thread(new Runnable() {

            @Override
            public void run() {
                // Create a clean Execution Context
                ExecutionContext context = new ExecutionContext();
                try {
                    executionContextManager.initialize(context);
                } catch (ExecutionContextException e) {
                    throw new RuntimeException("Failed to initialize wiki distribution job execution context", e);
                }
                DistributionJob job = wikiDistributionJobs.get(request.getWiki());
                job.initialize(request);
                job.run();
            }
        });
        distributionJobThread.setDaemon(true);
        distributionJobThread.setName("Distribution initialization of wiki [" + wiki + "]");
        distributionJobThread.start();
        // Wait until the job is ready (or finished)
        wikiJob.awaitReady();
        return wikiJob;
    } catch (Exception e) {
        this.logger.error("Failed to create distribution job for wiki [" + wiki + "]", e);
    }
    return null;
}
Also used : DistributionRequest(org.xwiki.extension.distribution.internal.job.DistributionRequest) ExecutionContext(org.xwiki.context.ExecutionContext) DistributionJob(org.xwiki.extension.distribution.internal.job.DistributionJob) DefaultDistributionJob(org.xwiki.extension.distribution.internal.job.DefaultDistributionJob) ExecutionContextException(org.xwiki.context.ExecutionContextException) XWikiException(com.xpn.xwiki.XWikiException) InitializationException(org.xwiki.component.phase.InitializationException) ExecutionContextException(org.xwiki.context.ExecutionContextException)

Example 2 with DistributionRequest

use of org.xwiki.extension.distribution.internal.job.DistributionRequest in project xwiki-platform by xwiki.

the class DefaultDistributionManager method copyPreviousWikiJobStatus.

@Override
public void copyPreviousWikiJobStatus(String sourceWiki, String targetWiki) {
    DistributionJobStatus sourceStatus = getPreviousWikiJobStatus(sourceWiki);
    if (sourceStatus != null) {
        DistributionJobStatus targetStatus = new DistributionJobStatus(sourceStatus, this.observationManagerProvider.get(), this.loggerManagerProvider.get());
        DistributionRequest request = targetStatus.getRequest();
        request.setId(getWikiJobId(targetWiki));
        request.setWiki(targetWiki);
        this.jobStatusStorage.store(targetStatus);
    }
}
Also used : DistributionRequest(org.xwiki.extension.distribution.internal.job.DistributionRequest) DistributionJobStatus(org.xwiki.extension.distribution.internal.job.DistributionJobStatus)

Example 3 with DistributionRequest

use of org.xwiki.extension.distribution.internal.job.DistributionRequest in project xwiki-platform by xwiki.

the class DefaultDistributionManager method startFarmJob.

@Override
public DefaultDistributionJob startFarmJob() {
    try {
        this.farmDistributionJob = this.componentManager.getInstance(Job.class, DefaultDistributionJob.HINT);
        XWikiContext xcontext = this.xcontextProvider.get();
        final DistributionRequest request = new DistributionRequest();
        request.setId(getFarmJobId());
        request.setWiki(xcontext.getMainXWiki());
        request.setUserReference(xcontext.getUserReference());
        request.setInteractive(this.configuration.getProperty("distribution.job.interactive", true));
        Thread distributionJobThread = new Thread(new Runnable() {

            @Override
            public void run() {
                // Create a clean Execution Context
                ExecutionContext context = new ExecutionContext();
                try {
                    executionContextManager.initialize(context);
                } catch (ExecutionContextException e) {
                    throw new RuntimeException("Failed to initialize farm distribution job execution context", e);
                }
                farmDistributionJob.initialize(request);
                farmDistributionJob.run();
            }
        });
        distributionJobThread.setDaemon(true);
        distributionJobThread.setName("Farm distribution initialization");
        distributionJobThread.start();
        // Wait until the job is ready (or finished)
        this.farmDistributionJob.awaitReady();
        return this.farmDistributionJob;
    } catch (Exception e) {
        this.logger.error("Failed to create farm distribution job", e);
    }
    return null;
}
Also used : DistributionRequest(org.xwiki.extension.distribution.internal.job.DistributionRequest) ExecutionContext(org.xwiki.context.ExecutionContext) XWikiContext(com.xpn.xwiki.XWikiContext) DistributionJob(org.xwiki.extension.distribution.internal.job.DistributionJob) Job(org.xwiki.job.Job) DefaultDistributionJob(org.xwiki.extension.distribution.internal.job.DefaultDistributionJob) ExecutionContextException(org.xwiki.context.ExecutionContextException) XWikiException(com.xpn.xwiki.XWikiException) InitializationException(org.xwiki.component.phase.InitializationException) ExecutionContextException(org.xwiki.context.ExecutionContextException)

Aggregations

DistributionRequest (org.xwiki.extension.distribution.internal.job.DistributionRequest)3 XWikiException (com.xpn.xwiki.XWikiException)2 InitializationException (org.xwiki.component.phase.InitializationException)2 ExecutionContext (org.xwiki.context.ExecutionContext)2 ExecutionContextException (org.xwiki.context.ExecutionContextException)2 DefaultDistributionJob (org.xwiki.extension.distribution.internal.job.DefaultDistributionJob)2 DistributionJob (org.xwiki.extension.distribution.internal.job.DistributionJob)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 DistributionJobStatus (org.xwiki.extension.distribution.internal.job.DistributionJobStatus)1 Job (org.xwiki.job.Job)1