Search in sources :

Example 1 with DistributionStep

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

the class AbstractDistributionJob method runInternal.

@Override
protected void runInternal() throws Exception {
    List<DistributionStep> steps = getStatus().getSteps();
    this.progressManager.pushLevelProgress(steps.size(), this);
    // Initialize steps
    WelcomeDistributionStep welcomeStep = (WelcomeDistributionStep) getStep(steps, WelcomeDistributionStep.ID);
    ReportDistributionStep reportStep = (ReportDistributionStep) getStep(steps, ReportDistributionStep.ID);
    for (DistributionStep step : steps) {
        step.initialize(this);
        // Enable Welcome step if one of the steps is enabled
        if (step.getState() == null) {
            if (welcomeStep != null) {
                welcomeStep.setState(null);
            }
            if (reportStep != null) {
                reportStep.setState(null);
            }
        }
    }
    // Execute steps
    try {
        for (int index = 0; index < steps.size(); ++index) {
            this.progressManager.startStep(this);
            getStatus().setCurrentStateIndex(index);
            DistributionStep step = steps.get(index);
            // Prepare step
            step.prepare();
            // Execute step
            if (step.getState() == null) {
                if (getRequest().isInteractive()) {
                    DistributionQuestion question = new DistributionQuestion(step);
                    // Waiting to start
                    signalReady();
                    getStatus().ask(question);
                    if (question.getAction() != null) {
                        switch(question.getAction()) {
                            case CANCEL:
                                for (; index < steps.size(); ++index) {
                                    steps.get(index).setState(DistributionStep.State.CANCELED);
                                }
                            case SKIP:
                                index = steps.size() - 1;
                                break;
                            default:
                                break;
                        }
                    }
                    // Save the status so that we remember the answer even if the DW is stopped before the end
                    this.store.storeAsync(this.status);
                } else {
                    step.executeNonInteractive();
                }
            }
            this.progressManager.endStep(this);
        }
    } finally {
        this.progressManager.popLevelProgress(this);
    }
}
Also used : WelcomeDistributionStep(org.xwiki.extension.distribution.internal.job.step.WelcomeDistributionStep) DistributionStep(org.xwiki.extension.distribution.internal.job.step.DistributionStep) ReportDistributionStep(org.xwiki.extension.distribution.internal.job.step.ReportDistributionStep) ReportDistributionStep(org.xwiki.extension.distribution.internal.job.step.ReportDistributionStep) WelcomeDistributionStep(org.xwiki.extension.distribution.internal.job.step.WelcomeDistributionStep)

Example 2 with DistributionStep

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

the class DefaultDistributionJob method createSteps.

@Override
protected List<DistributionStep> createSteps() {
    List<DistributionStep> steps = new ArrayList<>();
    boolean isMainWiki = isMainWiki();
    // Create admin user if needed
    if (isMainWiki) {
        try {
            steps.add(this.componentManager.<DistributionStep>getInstance(DistributionStep.class, FirstAdminUserStep.ID));
        } catch (ComponentLookupException e) {
            this.logger.error("Failed to get first admin step instance", e);
        }
    }
    // Install/upgrade main wiki UI
    addDefaultUIStep(steps, isMainWiki);
    // Upgrade other wikis
    if (isMainWiki) {
        ExtensionId wikiUI = this.distributionManager.getWikiUIExtensionId();
        if (wikiUI != null && StringUtils.isNotBlank(wikiUI.getId())) {
            // ... but only if the wiki extension ID is defined
            try {
                steps.add(this.componentManager.<DistributionStep>getInstance(DistributionStep.class, WikisDefaultUIDistributionStep.ID));
            } catch (ComponentLookupException e) {
                this.logger.error("Failed to get all in one default UI step instance", e);
            }
        } else {
        // TODO: Display the wikis flavor step
        }
    }
    // Upgrade outdated extensions
    try {
        steps.add(this.componentManager.<DistributionStep>getInstance(DistributionStep.class, OutdatedExtensionsDistributionStep.ID));
    } catch (ComponentLookupException e) {
        this.logger.error("Failed to get outdated extensions step instance", e);
    }
    return steps;
}
Also used : DistributionStep(org.xwiki.extension.distribution.internal.job.step.DistributionStep) WikisDefaultUIDistributionStep(org.xwiki.extension.distribution.internal.job.step.WikisDefaultUIDistributionStep) DefaultUIDistributionStep(org.xwiki.extension.distribution.internal.job.step.DefaultUIDistributionStep) FlavorDistributionStep(org.xwiki.extension.distribution.internal.job.step.FlavorDistributionStep) OutdatedExtensionsDistributionStep(org.xwiki.extension.distribution.internal.job.step.OutdatedExtensionsDistributionStep) ArrayList(java.util.ArrayList) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ExtensionId(org.xwiki.extension.ExtensionId)

Example 3 with DistributionStep

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

the class AbstractDistributionJob method createNewStatus.

@Override
protected DistributionJobStatus createNewStatus(R request) {
    List<DistributionStep> steps = createSteps();
    if (getRequest().isInteractive()) {
        // Add Welcome step
        try {
            DistributionStep welcomeStep = this.componentManager.<DistributionStep>getInstance(DistributionStep.class, WelcomeDistributionStep.ID);
            welcomeStep.setState(State.COMPLETED);
            steps.add(0, welcomeStep);
        } catch (ComponentLookupException e1) {
            this.logger.error("Failed to get step instance for id [{}]", WelcomeDistributionStep.ID);
        }
        // Add Report step
        try {
            DistributionStep welcomeStep = this.componentManager.<DistributionStep>getInstance(DistributionStep.class, ReportDistributionStep.ID);
            welcomeStep.setState(State.COMPLETED);
            steps.add(welcomeStep);
        } catch (ComponentLookupException e1) {
            this.logger.error("Failed to get step instance for id [{}]", ReportDistributionStep.ID);
        }
    }
    // Create status
    DistributionJobStatus status = createNewDistributionStatus(request, steps);
    if (this.distributionManager.getDistributionExtension() != null) {
        DistributionJobStatus previousStatus = getPreviousStatus();
        if (previousStatus != null && previousStatus.getDistributionExtension() != null && !Objects.equals(previousStatus.getDistributionExtension(), this.distributionManager.getDistributionExtension().getId())) {
            status.setPreviousDistributionExtension(previousStatus.getDistributionExtension());
            status.setPreviousDistributionExtensionUI(previousStatus.getDistributionExtensionUI());
        }
        status.setDistributionExtension(this.distributionManager.getDistributionExtension().getId());
        status.setDistributionExtensionUI(getUIExtensionId());
    }
    return status;
}
Also used : WelcomeDistributionStep(org.xwiki.extension.distribution.internal.job.step.WelcomeDistributionStep) DistributionStep(org.xwiki.extension.distribution.internal.job.step.DistributionStep) ReportDistributionStep(org.xwiki.extension.distribution.internal.job.step.ReportDistributionStep) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Aggregations

DistributionStep (org.xwiki.extension.distribution.internal.job.step.DistributionStep)3 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)2 ReportDistributionStep (org.xwiki.extension.distribution.internal.job.step.ReportDistributionStep)2 WelcomeDistributionStep (org.xwiki.extension.distribution.internal.job.step.WelcomeDistributionStep)2 ArrayList (java.util.ArrayList)1 ExtensionId (org.xwiki.extension.ExtensionId)1 DefaultUIDistributionStep (org.xwiki.extension.distribution.internal.job.step.DefaultUIDistributionStep)1 FlavorDistributionStep (org.xwiki.extension.distribution.internal.job.step.FlavorDistributionStep)1 OutdatedExtensionsDistributionStep (org.xwiki.extension.distribution.internal.job.step.OutdatedExtensionsDistributionStep)1 WikisDefaultUIDistributionStep (org.xwiki.extension.distribution.internal.job.step.WikisDefaultUIDistributionStep)1