001 /** 002 * Copyright (c) 2010 Yahoo! Inc. All rights reserved. 003 * Licensed under the Apache License, Version 2.0 (the "License"); 004 * you may not use this file except in compliance with the License. 005 * You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software 010 * distributed under the License is distributed on an "AS IS" BASIS, 011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 * See the License for the specific language governing permissions and 013 * limitations under the License. See accompanying LICENSE file. 014 */ 015 package org.apache.oozie.command.coord; 016 017 import java.util.List; 018 019 import org.apache.oozie.ErrorCode; 020 import org.apache.oozie.SLAEventBean; 021 import org.apache.oozie.XException; 022 import org.apache.oozie.command.CommandException; 023 import org.apache.oozie.command.PreconditionException; 024 import org.apache.oozie.command.XCommand; 025 import org.apache.oozie.executor.jpa.SLAEventsGetForSeqIdJPAExecutor; 026 import org.apache.oozie.service.JPAService; 027 import org.apache.oozie.service.Services; 028 029 /** 030 * The command to get a list of SLAEvents which are greater than given seqId. 031 * 032 */ 033 public class SLAEventsXCommand extends XCommand<List<SLAEventBean>> { 034 035 private long seqId = 0; 036 private int maxNoEvents = 100; // Default 037 private long lastSeqId = -1; 038 039 public SLAEventsXCommand(long seqId, int maxNoEvnts) { 040 super("SLAEventsXCommand", "SLAEventsXCommand", 1); 041 this.seqId = seqId; 042 this.maxNoEvents = maxNoEvnts; 043 } 044 045 /* (non-Javadoc) 046 * @see org.apache.oozie.command.XCommand#isLockRequired() 047 */ 048 @Override 049 protected boolean isLockRequired() { 050 return false; 051 } 052 053 /* (non-Javadoc) 054 * @see org.apache.oozie.command.XCommand#getEntityKey() 055 */ 056 @Override 057 protected String getEntityKey() { 058 return Long.toString(seqId); 059 } 060 061 /* (non-Javadoc) 062 * @see org.apache.oozie.command.XCommand#loadState() 063 */ 064 @Override 065 protected void loadState() throws CommandException { 066 } 067 068 /* (non-Javadoc) 069 * @see org.apache.oozie.command.XCommand#verifyPrecondition() 070 */ 071 @Override 072 protected void verifyPrecondition() throws CommandException, PreconditionException { 073 } 074 075 /* (non-Javadoc) 076 * @see org.apache.oozie.command.XCommand#execute() 077 */ 078 @Override 079 protected List<SLAEventBean> execute() throws CommandException { 080 try { 081 JPAService jpaService = Services.get().get(JPAService.class); 082 List<SLAEventBean> slaEventList = null; 083 long lastSeqId[] = new long[1]; 084 if (jpaService != null) { 085 slaEventList = jpaService.execute(new SLAEventsGetForSeqIdJPAExecutor(seqId, maxNoEvents, lastSeqId)); 086 } 087 else { 088 LOG.error(ErrorCode.E0610); 089 } 090 setLastSeqId(lastSeqId[0]); 091 return slaEventList; 092 } 093 catch (XException ex) { 094 throw new CommandException(ex); 095 } 096 } 097 098 /** 099 * Set lastSeqId 100 * 101 * @param lastSeqId 102 */ 103 public void setLastSeqId(long lastSeqId) { 104 this.lastSeqId = lastSeqId; 105 } 106 107 /** 108 * Get lastSeqId 109 * 110 * @return lastSeqId 111 */ 112 public long getLastSeqId() { 113 return lastSeqId; 114 } 115 116 }