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