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