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.sla.listener; 020 021import java.util.Date; 022 023import org.apache.hadoop.conf.Configuration; 024import org.apache.oozie.client.CoordinatorAction; 025import org.apache.oozie.client.event.JobEvent; 026import org.apache.oozie.event.BundleJobEvent; 027import org.apache.oozie.event.CoordinatorActionEvent; 028import org.apache.oozie.event.CoordinatorJobEvent; 029import org.apache.oozie.event.WorkflowActionEvent; 030import org.apache.oozie.event.WorkflowJobEvent; 031import org.apache.oozie.event.listener.JobEventListener; 032import org.apache.oozie.service.ServiceException; 033import org.apache.oozie.service.Services; 034import org.apache.oozie.sla.service.SLAService; 035import org.apache.oozie.util.XLog; 036 037public class SLAJobEventListener extends JobEventListener { 038 039 @Override 040 public void init(Configuration conf) { 041 } 042 043 @Override 044 public void destroy() { 045 } 046 047 @Override 048 public void onWorkflowJobEvent(WorkflowJobEvent event) { 049 sendEventToSLAService(event, event.getStatus().toString()); 050 } 051 052 @Override 053 public void onWorkflowActionEvent(WorkflowActionEvent event) { 054 sendEventToSLAService(event, event.getStatus().toString()); 055 } 056 057 @Override 058 public void onCoordinatorJobEvent(CoordinatorJobEvent event) { 059 sendEventToSLAService(event, event.getStatus().toString()); 060 } 061 062 @Override 063 public void onCoordinatorActionEvent(CoordinatorActionEvent event) { 064 sendEventToSLAService(event, event.getStatus().toString()); 065 } 066 067 @Override 068 public void onBundleJobEvent(BundleJobEvent wje) { 069 } 070 071 private void sendEventToSLAService(JobEvent event, String status) { 072 Date startTime = event.getStartTime(); 073 Date endTime = event.getEndTime(); 074 try { 075 Services.get().get(SLAService.class) 076 .addStatusEvent(event.getId(), status, event.getEventStatus(), startTime, endTime); 077 } 078 catch (ServiceException se) { 079 XLog.getLog(SLAService.class).error("Exception happened while sending Job-Status event for SLA", se); 080 } 081 } 082 083}