001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2013-2015 ForgeRock AS.
015 */
016
017package org.opends.server.tools.upgrade;
018
019import com.forgerock.opendj.cli.ClientException;
020
021/**
022 * An upgrade task.
023 */
024public interface UpgradeTask
025{
026
027  /**
028   * Defines the different types of upgrade tasks.
029   */
030  public enum TaskType {
031    /**
032     * Defines a standard task.
033     */
034    NORMAL,
035    /**
036     * Defines a task which require a standard user interaction.
037     */
038    NEED_USER_INTERACTION,
039    /**
040     * Defines a critical task which require an imperative user interaction.
041     */
042    MANDATORY_USER_INTERACTION,
043    /**
044     * Defines a task which take a long time to complete.
045     */
046    TAKE_LONG_TIME_TO_COMPLETE,
047    /**
048     * Defines a task which cannot be reverted once started.
049     */
050    CANNOT_BE_REVERTED
051  }
052
053  /**
054   * Performs any preparation work required before performing the upgrade task, including
055   * interacting with the user where needed (e.g. in order to ask for confirmation), and throw a
056   * {@code ClientException} if the upgrade cannot proceed.
057   *
058   * @param context
059   *          Context through which tasks can interact with the server installation.
060   * @throws ClientException
061   *           If the upgrade cannot proceed.
062   */
063  void prepare(UpgradeContext context) throws ClientException;
064
065  /**
066   * Performs this upgrade task.
067   *
068   * @param context
069   *          Context through which tasks can interact with the server installation.
070   * @throws ClientException
071   *           If an error occurred while performing the task.
072   */
073  void perform(UpgradeContext context) throws ClientException;
074
075  /**
076   * This method will be invoked after all upgrade tasks have completed
077   * successfully The post upgrade tasks are processes which should be launched
078   * after a successful upgrade.
079   *
080   * @param context
081   *          Context through which tasks can interact with the server
082   *          installation.
083   * @throws ClientException
084   *           If the task cannot proceed.
085   */
086  void postUpgrade(UpgradeContext context) throws ClientException;
087
088  /**
089   * This method will be invoked only if one of the previous post upgrade task
090   * has failed.
091   *
092   * @param context
093   *          Context through which tasks can interact with the server
094   *          installation.
095   * @throws ClientException
096   *           If the task cannot proceed.
097   */
098  void postponePostUpgrade(UpgradeContext context) throws ClientException;
099}