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 */
018package org.apache.oozie.command.wf;
019
020import org.apache.oozie.AppType;
021import org.apache.oozie.WorkflowActionBean;
022import org.apache.oozie.WorkflowJobBean;
023import org.apache.oozie.command.XCommand;
024import org.apache.oozie.event.WorkflowActionEvent;
025import org.apache.oozie.event.WorkflowJobEvent;
026
027/**
028 * Abstract coordinator command class derived from XCommand
029 *
030 * @param <T>
031 */
032public abstract class WorkflowXCommand<T> extends XCommand<T> {
033    /**
034     * Base class constructor for workflow commands.
035     *
036     * @param name command name
037     * @param type command type
038     * @param priority command priority
039     */
040    public WorkflowXCommand(String name, String type, int priority) {
041        super(name, type, priority);
042    }
043
044    /**
045     * Base class constructor for workflow commands.
046     *
047     * @param name command name
048     * @param type command type
049     * @param priority command priority
050     * @param dryrun true if rerun is enabled for command
051     */
052    public WorkflowXCommand(String name, String type, int priority, boolean dryrun) {
053        super(name, type, priority, dryrun);
054    }
055
056    protected static void generateEvent(WorkflowJobBean wfJob, String errorCode, String errorMsg) {
057        if (eventService.isSupportedApptype(AppType.WORKFLOW_JOB.name())) {
058            WorkflowJobEvent event = new WorkflowJobEvent(wfJob.getId(), wfJob.getParentId(), wfJob.getStatus(),
059                    wfJob.getUser(), wfJob.getAppName(), wfJob.getStartTime(), wfJob.getEndTime());
060            event.setErrorCode(errorCode);
061            event.setErrorMessage(errorMsg);
062            eventService.queueEvent(event);
063        }
064    }
065
066    protected static void generateEvent(WorkflowJobBean wfJob) {
067        generateEvent(wfJob, null, null);
068    }
069
070    protected void generateEvent(WorkflowActionBean wfAction, String wfUser) {
071        if (eventService.isSupportedApptype(AppType.WORKFLOW_ACTION.name())) {
072            WorkflowActionEvent event = new WorkflowActionEvent(wfAction.getId(), wfAction.getJobId(),
073                    wfAction.getStatus(), wfUser, wfAction.getName(), wfAction.getStartTime(), wfAction.getEndTime());
074            event.setErrorCode(wfAction.getErrorCode());
075            event.setErrorMessage(wfAction.getErrorMessage());
076            eventService.queueEvent(event);
077        }
078    }
079
080}