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 */ 018package org.apache.oozie.command.coord; 019 020import java.util.Date; 021 022import org.apache.oozie.CoordinatorActionBean; 023import org.apache.oozie.CoordinatorJobBean; 024import org.apache.oozie.AppType; 025import org.apache.oozie.command.XCommand; 026import org.apache.oozie.coord.CoordELFunctions; 027import org.apache.oozie.event.CoordinatorActionEvent; 028import org.apache.oozie.event.CoordinatorJobEvent; 029 030/** 031 * Abstract coordinator command class derived from XCommand 032 */ 033public abstract class CoordinatorXCommand<T> extends XCommand<T> { 034 035 /** 036 * Base class constructor for coordinator commands. 037 * 038 * @param name command name 039 * @param type command type 040 * @param priority command priority 041 */ 042 public CoordinatorXCommand(String name, String type, int priority) { 043 super(name, type, priority); 044 } 045 046 /** 047 * Base class constructor for coordinator commands. 048 * 049 * @param name command name 050 * @param type command type 051 * @param priority command priority 052 * @param dryrun true if rerun is enabled for command 053 */ 054 public CoordinatorXCommand(String name, String type, int priority, boolean dryrun) { 055 super(name, type, priority, dryrun); 056 } 057 058 public static void generateEvent(CoordinatorActionBean coordAction, String user, String appName, Date startTime) { 059 if (eventService.isSupportedApptype(AppType.COORDINATOR_ACTION.name())) { 060 String missDep = coordAction.getMissingDependencies(); 061 if (missDep != null && missDep.length() > 0) { 062 missDep = missDep.split(CoordELFunctions.INSTANCE_SEPARATOR)[0]; 063 } 064 String pushMissDep = coordAction.getPushMissingDependencies(); 065 if (pushMissDep != null && pushMissDep.length() > 0) { 066 pushMissDep = pushMissDep.split(CoordELFunctions.INSTANCE_SEPARATOR)[0]; 067 } 068 String deps = missDep == null ? (pushMissDep == null ? null : pushMissDep) : (pushMissDep == null ? missDep 069 : missDep + CoordELFunctions.INSTANCE_SEPARATOR + pushMissDep); 070 CoordinatorActionEvent event = new CoordinatorActionEvent(coordAction.getId(), coordAction.getJobId(), 071 coordAction.getStatus(), user, appName, coordAction.getNominalTime(), startTime, 072 deps); 073 event.setErrorCode(coordAction.getErrorCode()); 074 event.setErrorMessage(coordAction.getErrorMessage()); 075 eventService.queueEvent(event); 076 } 077 } 078 079 protected void generateEvent(CoordinatorJobBean coordJob) { 080 if (eventService.isSupportedApptype(AppType.COORDINATOR_JOB.name())) { 081 CoordinatorJobEvent event = new CoordinatorJobEvent(coordJob.getId(), coordJob.getBundleId(), 082 coordJob.getStatus(), coordJob.getUser(), coordJob.getAppName(), coordJob.getStartTime(), 083 coordJob.getEndTime()); 084 eventService.queueEvent(event); 085 } 086 } 087 088}