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