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.command.coord; 020 021import java.util.List; 022import java.util.Map; 023 024import org.apache.oozie.ErrorCode; 025import org.apache.oozie.SLAEventBean; 026import org.apache.oozie.XException; 027import org.apache.oozie.command.CommandException; 028import org.apache.oozie.command.PreconditionException; 029import org.apache.oozie.command.XCommand; 030import org.apache.oozie.executor.jpa.SLAEventsGetForFilterJPAExecutor; 031import org.apache.oozie.service.JPAService; 032import org.apache.oozie.service.Service; 033import org.apache.oozie.service.Services; 034 035/** 036 * The command to get a list of SLAEvents which are greater than given seqId. 037 * 038 */ 039@SuppressWarnings("deprecation") 040public class SLAEventsXCommand extends XCommand<List<SLAEventBean>> { 041 042 private long seqId = 0; 043 private int maxNoEvents = 100; // Default 044 private long lastSeqId = -1; 045 private final Map<String, List<String>> filter; 046 047 public static final String SLA_DEFAULT_MAXEVENTS = Service.CONF_PREFIX + "sla.default.maxevents"; 048 049 public SLAEventsXCommand(long seqId, int maxNoEvnts, Map<String, List<String>> filter) { 050 super("SLAEventsXCommand", "SLAEventsXCommand", 1); 051 this.seqId = seqId; 052 int sysMax = Services.get().getConf().getInt(SLA_DEFAULT_MAXEVENTS, 1000); 053 this.maxNoEvents = maxNoEvnts > sysMax ? sysMax : maxNoEvnts; 054 this.filter = filter; 055 } 056 057 @Override 058 protected boolean isLockRequired() { 059 return false; 060 } 061 062 @Override 063 public String getEntityKey() { 064 return Long.toString(seqId); 065 } 066 067 @Override 068 protected void loadState() throws CommandException { 069 } 070 071 @Override 072 protected void verifyPrecondition() throws CommandException, PreconditionException { 073 } 074 075 @Override 076 protected List<SLAEventBean> execute() throws CommandException { 077 try { 078 JPAService jpaService = Services.get().get(JPAService.class); 079 List<SLAEventBean> slaEventList = null; 080 long lastSeqId[] = new long[1]; 081 if (jpaService != null) { 082 slaEventList = jpaService.execute(new SLAEventsGetForFilterJPAExecutor(seqId, maxNoEvents, filter, lastSeqId)); 083 } 084 else { 085 LOG.error(ErrorCode.E0610); 086 } 087 setLastSeqId(lastSeqId[0]); 088 return slaEventList; 089 } 090 catch (XException ex) { 091 throw new CommandException(ex); 092 } 093 } 094 095 /** 096 * Set lastSeqId 097 * 098 * @param lastSeqId 099 */ 100 public void setLastSeqId(long lastSeqId) { 101 this.lastSeqId = lastSeqId; 102 } 103 104 /** 105 * Get lastSeqId 106 * 107 * @return lastSeqId 108 */ 109 public long getLastSeqId() { 110 return lastSeqId; 111 } 112 113}