001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *      http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.oozie.command;
020
021/**
022 * Transition command for materialize the job. The derived class has to override these following functions:
023 * <p>
024 * loadState() : load the job's and/or actions' state
025 * updateJob() : update job status and attributes
026 * StartChildren() : submit or queue commands to start children
027 * notifyParent() : update the status to upstream if any
028 */
029public abstract class MaterializeTransitionXCommand extends TransitionXCommand<Void> {
030
031    /**
032     * The constructor for abstract class {@link MaterializeTransitionXCommand}
033     *
034     * @param name the command name
035     * @param type the command type
036     * @param priority the command priority
037     */
038    public MaterializeTransitionXCommand(String name, String type, int priority) {
039        super(name, type, priority);
040    }
041
042    /**
043     * The constructor for abstract class {@link MaterializeTransitionXCommand}
044     *
045     * @param name the command name
046     * @param type the command type
047     * @param priority the command priority
048     * @param dryrun true if dryrun is enable
049     */
050    public MaterializeTransitionXCommand(String name, String type, int priority, boolean dryrun) {
051        super(name, type, priority, dryrun);
052    }
053
054    /* (non-Javadoc)
055     * @see org.apache.oozie.command.TransitionXCommand#transitToNext()
056     */
057    @Override
058    public void transitToNext() throws CommandException {
059    }
060
061    /**
062     * Materialize the actions for current job
063     * @throws CommandException thrown if failed to materialize
064     */
065    protected abstract void materialize() throws CommandException;
066
067    /* (non-Javadoc)
068     * @see org.apache.oozie.command.TransitionXCommand#execute()
069     */
070    @Override
071    protected Void execute() throws CommandException {
072        try {
073            materialize();
074            updateJob();
075            performWrites();
076        } finally {
077            notifyParent();
078        }
079        return null;
080    }
081
082}