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
019
020package org.apache.oozie.event;
021
022import java.util.Date;
023
024import org.apache.oozie.AppType;
025import org.apache.oozie.client.WorkflowJob;
026import org.apache.oozie.client.event.JobEvent;
027import org.apache.oozie.service.EventHandlerService;
028import org.apache.oozie.util.XLog;
029
030/**
031 * Class implementing JobEvent for events generated by Workflow Jobs
032 */
033@SuppressWarnings("serial")
034public class WorkflowJobEvent extends JobEvent {
035
036    private WorkflowJob.Status status;
037    private String errorCode;
038    private String errorMessage;
039    // TODO more attributes - run, coordName, bundleId
040    // for some advanced processing and linking using events
041
042    public WorkflowJobEvent(String id, String parentId, WorkflowJob.Status status, String user, String appName,
043            Date startTime, Date endTime) {
044        super(id, parentId, user, AppType.WORKFLOW_JOB, appName);
045        setStatus(status);
046        setStartTime(startTime);
047        setEndTime(endTime);
048        XLog.getLog(EventHandlerService.class).trace("Event generated - " + this.toString());
049    }
050
051    public String getCoordJobId() {
052        return null; // TODO extract prefix from coordActionId before '@'
053    }
054
055    public WorkflowJob.Status getStatus() {
056        return status;
057    }
058
059    public String getErrorCode() {
060        return errorCode;
061    }
062
063    public void setErrorCode(String code) {
064        errorCode = code;
065    }
066
067    public String getErrorMessage() {
068        return errorMessage;
069    }
070
071    public void setErrorMessage(String msg) {
072        errorMessage = msg;
073    }
074
075    public void setStatus(WorkflowJob.Status wfstatus) {
076        status = wfstatus;
077        // set high-level status for event based on low-level actual job status
078        // this is to ease filtering on the consumer side
079        switch (status) {
080            case SUCCEEDED:
081                setEventStatus(EventStatus.SUCCESS);
082                break;
083            case RUNNING:
084                setEventStatus(EventStatus.STARTED);
085                break;
086            case SUSPENDED:
087                setEventStatus(EventStatus.SUSPEND);
088                break;
089            case KILLED:
090            case FAILED:
091                setEventStatus(EventStatus.FAILURE);
092        }
093    }
094
095}