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