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.CoordinatorAction; 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 Actions 032 */ 033@SuppressWarnings("serial") 034public class CoordinatorActionEvent extends JobEvent { 035 036 private CoordinatorAction.Status status; 037 private Date nominalTime; 038 private String missingDeps; 039 private String errorCode; 040 private String errorMessage; 041 // TODO more attributes - frequency, timeunit, bundleName 042 // for some advanced processing and linking using events 043 044 public CoordinatorActionEvent(String id, String parentId, CoordinatorAction.Status status, String user, 045 String appName, Date nomTime, Date startTime, String missDeps) { 046 super(id, parentId, user, AppType.COORDINATOR_ACTION, appName); 047 setStatus(status); 048 setNominalTime(nomTime); 049 setStartTime(startTime); 050 setMissingDeps(missDeps); 051 XLog.getLog(EventHandlerService.class).trace("Event generated - " + this.toString()); 052 } 053 054 public String getBundleJobId() { 055 return null; // TODO extract prefix from bundleActionId before '@' 056 } 057 058 public CoordinatorAction.Status getStatus() { 059 return status; 060 } 061 062 public void setStatus(CoordinatorAction.Status castatus) { 063 status = castatus; 064 // set high-level status for event based on low-level actual job status 065 // this is to ease filtering on the consumer side 066 switch (status) { 067 case WAITING: 068 setEventStatus(EventStatus.WAITING); 069 break; 070 case SUCCEEDED: 071 setEventStatus(EventStatus.SUCCESS); 072 setEndTime(new Date()); 073 break; 074 case RUNNING: 075 setEventStatus(EventStatus.STARTED); 076 break; 077 case SUSPENDED: 078 setEventStatus(EventStatus.SUSPEND); 079 break; 080 case KILLED: 081 case FAILED: 082 case TIMEDOUT: 083 setEventStatus(EventStatus.FAILURE); 084 setEndTime(new Date()); 085 } 086 } 087 088 public Date getNominalTime() { 089 return nominalTime; 090 } 091 092 public void setNominalTime(Date time) { 093 nominalTime = time; 094 } 095 096 public String getMissingDeps() { 097 return missingDeps; 098 } 099 100 public void setMissingDeps(String dependencies) { 101 missingDeps = dependencies; 102 } 103 104 public String getErrorCode() { 105 return errorCode; 106 } 107 108 public void setErrorCode(String code) { 109 errorCode = code; 110 } 111 112 public String getErrorMessage() { 113 return errorMessage; 114 } 115 116 public void setErrorMessage(String msg) { 117 errorMessage = msg; 118 } 119 120}