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.BundleJob;
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 Bundle Jobs
032 *
033 */
034@SuppressWarnings("serial")
035public class BundleJobEvent extends JobEvent {
036
037    private BundleJob.Status status;
038
039    public BundleJobEvent(String id, BundleJob.Status status, String user, String appName, Date startTime, Date endTime) {
040        super(id, null, user, AppType.BUNDLE_JOB, appName); // parentId is null
041        setStatus(status);
042        setStartTime(startTime);
043        setEndTime(endTime);
044        XLog.getLog(EventHandlerService.class).trace("Event generated - " + this.toString());
045    }
046
047    public BundleJob.Status getStatus() {
048        return status;
049    }
050
051    public void setStatus(BundleJob.Status bstatus) {
052        status = bstatus;
053        // set high-level status for event based on low-level actual job status
054        // this is to ease filtering on the consumer side
055        switch (status) {
056            case SUCCEEDED:
057                setEventStatus(EventStatus.SUCCESS);
058                break;
059            case RUNNING:
060                setEventStatus(EventStatus.STARTED);
061                break;
062            case SUSPENDED:
063            case SUSPENDEDWITHERROR:
064                setEventStatus(EventStatus.SUSPEND);
065                break;
066            case KILLED:
067            case FAILED:
068            case DONEWITHERROR:
069                setEventStatus(EventStatus.FAILURE);
070        }
071    }
072
073}