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    
019    package org.apache.oozie.sla;
020    
021    import java.util.Date;
022    import org.apache.oozie.AppType;
023    import org.apache.oozie.client.event.SLAEvent;
024    
025    /**
026     * Class used by SLAService to store SLA objects and perform calculations and
027     * sla decisions
028     */
029    public class SLACalcStatus extends SLAEvent {
030    
031        private SLARegistrationBean regBean;
032        private String jobStatus;
033        private SLAStatus slaStatus;
034        private EventStatus eventStatus;
035        private Date actualStart;
036        private Date actualEnd;
037        private long actualDuration = -1;
038        private Date lastModifiedTime;
039        private byte eventProcessed;
040    
041        public SLACalcStatus(SLARegistrationBean reg) {
042            this();
043            setSLARegistrationBean(reg);
044        }
045    
046        public SLACalcStatus(SLASummaryBean summary, SLARegistrationBean regBean) {
047            this();
048            SLARegistrationBean reg = new SLARegistrationBean();
049            reg.setNotificationMsg(regBean.getNotificationMsg());
050            reg.setUpstreamApps(regBean.getUpstreamApps());
051            reg.setAlertContact(regBean.getAlertContact());
052            reg.setAlertEvents(regBean.getAlertEvents());
053            reg.setJobData(regBean.getJobData());
054            reg.setId(summary.getId());
055            reg.setAppType(summary.getAppType());
056            reg.setUser(summary.getUser());
057            reg.setAppName(summary.getAppName());
058            reg.setParentId(summary.getParentId());
059            reg.setNominalTime(summary.getNominalTime());
060            reg.setExpectedStart(summary.getExpectedStart());
061            reg.setExpectedEnd(summary.getExpectedEnd());
062            reg.setExpectedDuration(summary.getExpectedDuration());
063            setSLARegistrationBean(reg);
064            setActualStart(summary.getActualStart());
065            setActualEnd(summary.getActualEnd());
066            setActualDuration(summary.getActualDuration());
067            setSLAStatus(summary.getSLAStatus());
068            setJobStatus(summary.getJobStatus());
069            setEventStatus(summary.getEventStatus());
070            setLastModifiedTime(summary.getLastModifiedTime());
071            setEventProcessed(summary.getEventProcessed());
072        }
073    
074        /**
075         * copy constructor
076         * @return SLACalcStatus
077         */
078        public SLACalcStatus(SLACalcStatus a) {
079            this();
080            setSLARegistrationBean(a.getSLARegistrationBean());
081            setJobStatus(a.getJobStatus());
082            setSLAStatus(a.getSLAStatus());
083            setEventStatus(a.getEventStatus());
084            setActualStart(a.getActualStart());
085            setActualEnd(a.getActualEnd());
086            setActualDuration(a.getActualDuration());
087            setEventProcessed(a.getEventProcessed());
088        }
089    
090        public SLACalcStatus() {
091            setMsgType(MessageType.SLA);
092            setLastModifiedTime(new Date());
093        }
094    
095        public SLARegistrationBean getSLARegistrationBean() {
096            return regBean;
097        }
098    
099        public void setSLARegistrationBean(SLARegistrationBean slaBean) {
100            this.regBean = slaBean;
101        }
102    
103        @Override
104        public String getId() {
105            return regBean.getId();
106        }
107    
108        public void setId(String id) {
109            regBean.setId(id);
110        }
111    
112        @Override
113        public Date getActualStart() {
114            return actualStart;
115        }
116    
117        public void setActualStart(Date actualStart) {
118            this.actualStart = actualStart;
119        }
120    
121        @Override
122        public Date getActualEnd() {
123            return actualEnd;
124        }
125    
126        public void setActualEnd(Date actualEnd) {
127            this.actualEnd = actualEnd;
128        }
129    
130        @Override
131        public long getActualDuration() {
132            return actualDuration;
133        }
134    
135        public void setActualDuration(long actualDuration) {
136            this.actualDuration = actualDuration;
137        }
138    
139        @Override
140        public String getJobStatus() {
141            return jobStatus;
142        }
143    
144        public void setJobStatus(String status) {
145            this.jobStatus = status;
146        }
147    
148        @Override
149        public SLAStatus getSLAStatus() {
150            return slaStatus;
151        }
152    
153        public void setSLAStatus(SLAStatus slaStatus) {
154            this.slaStatus = slaStatus;
155        }
156    
157        @Override
158        public EventStatus getEventStatus() {
159            return eventStatus;
160        }
161    
162        public void setEventStatus(EventStatus es) {
163            this.eventStatus = es;
164        }
165    
166        public void setLastModifiedTime(Date lastModifiedTime) {
167            this.lastModifiedTime = lastModifiedTime;
168        }
169    
170        /**
171         * Get which type of sla event has been processed needed when calculator
172         * periodically loops to update all jobs' sla
173         *
174         * @return byte 1st bit set (from LSB) = start processed
175         * 2nd bit set = duration processed
176         * 3rd bit set = end processed
177         * only 4th bit set = everything processed
178         */
179        public byte getEventProcessed() {
180            return eventProcessed;
181        }
182    
183        public void setEventProcessed(int eventProcessed) {
184            this.eventProcessed = (byte) eventProcessed;
185        }
186    
187        @Override
188        public String getParentId() {
189            return regBean.getParentId();
190        }
191    
192        @Override
193        public AppType getAppType() {
194            return regBean.getAppType();
195        }
196    
197        @Override
198        public String getAppName() {
199            return regBean.getAppName();
200        }
201    
202        @Override
203        public Date getNominalTime() {
204            return regBean.getNominalTime();
205        }
206    
207        @Override
208        public Date getExpectedStart() {
209            return regBean.getExpectedStart();
210        }
211    
212        @Override
213        public Date getExpectedEnd() {
214            return regBean.getExpectedEnd();
215        }
216    
217        @Override
218        public long getExpectedDuration() {
219            return regBean.getExpectedDuration();
220        }
221    
222        @Override
223        public String getNotificationMsg() {
224            return regBean.getNotificationMsg();
225        }
226    
227        @Override
228        public String getAlertEvents() {
229            return regBean.getAlertEvents();
230        }
231    
232        @Override
233        public String getAlertContact() {
234            return regBean.getAlertContact();
235        }
236    
237        @Override
238        public String getUpstreamApps() {
239            return regBean.getUpstreamApps();
240        }
241    
242        @Override
243        public String getJobData() {
244            return regBean.getJobData();
245        }
246    
247        @Override
248        public String getUser() {
249            return regBean.getUser();
250        }
251    
252        @Override
253        public String getSlaConfig() {
254            return regBean.getSlaConfig();
255        }
256    
257        @Override
258        public MessageType getMsgType() {
259            return regBean.getMsgType();
260        }
261    
262        @Override
263        public Date getLastModifiedTime() {
264            return lastModifiedTime;
265        }
266    
267    }