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