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.CoordinatorJob; 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 Coordinator Jobs 032 */ 033@SuppressWarnings("serial") 034public class CoordinatorJobEvent extends JobEvent { 035 036 private CoordinatorJob.Status status; 037 038 public CoordinatorJobEvent(String id, String parentId, CoordinatorJob.Status status, String user, String appName, 039 Date startTime, Date endTime) { 040 super(id, parentId, user, AppType.COORDINATOR_JOB, appName); 041 setStatus(status); 042 setStartTime(startTime); 043 setEndTime(endTime); 044 XLog.getLog(EventHandlerService.class).trace("Event generated - " + this.toString()); 045 } 046 047 public CoordinatorJob.Status getStatus() { 048 return status; 049 } 050 051 public void setStatus(CoordinatorJob.Status coordStatus) { 052 status = coordStatus; 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 PREPSUSPENDED: 064 case SUSPENDEDWITHERROR: 065 setEventStatus(EventStatus.SUSPEND); 066 break; 067 case KILLED: 068 case FAILED: 069 case DONEWITHERROR: 070 setEventStatus(EventStatus.FAILURE); 071 } 072 } 073 074}