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 019package org.apache.oozie.client.event.message; 020 021import java.util.Date; 022 023import javax.jms.JMSException; 024import javax.jms.Message; 025 026import org.apache.oozie.AppType; 027import org.apache.oozie.client.event.Event.MessageType; 028import org.apache.oozie.client.event.SLAEvent; 029import org.apache.oozie.client.event.jms.JMSHeaderConstants; 030import org.apache.oozie.client.event.message.EventMessage; 031import org.codehaus.jackson.annotate.JsonIgnore; 032import org.codehaus.jackson.annotate.JsonProperty; 033import org.codehaus.jackson.map.annotate.JsonSerialize; 034 035@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) 036public class SLAMessage extends EventMessage { 037 038 @JsonProperty 039 private String id; 040 @JsonProperty 041 private String parentId; 042 @JsonProperty 043 private Date nominalTime; 044 @JsonProperty 045 private Date expectedStartTime; 046 @JsonProperty 047 private Date actualStartTime; 048 @JsonProperty 049 private Date expectedEndTime; 050 @JsonProperty 051 private Date actualEndTime; 052 @JsonProperty 053 private long expectedDuration; 054 @JsonProperty 055 private long actualDuration; 056 @JsonProperty 057 private String notificationMessage; 058 @JsonProperty 059 private String upstreamApps; 060 061 private String user; 062 private String appName; 063 private SLAEvent.EventStatus eventStatus; 064 private SLAEvent.SLAStatus slaStatus; 065 066 public SLAMessage(){ 067 // Dummy constructor for JSON 068 } 069 070 public SLAMessage(SLAEvent.EventStatus eventStatus, SLAEvent.SLAStatus slaStatus, AppType appType, String appName, 071 String user, String jobId, String parentJobId, Date nominalTime, Date expectedStartTime, 072 Date actualStartTime, Date expectedEndTime, Date actualEndTime, long expectedDuration, long actualDuration, 073 String notificationMessage, String upstreamApps) { 074 075 super(MessageType.SLA, appType); 076 this.eventStatus = eventStatus; 077 this.slaStatus = slaStatus; 078 this.appName = appName; 079 this.user = user; 080 this.id = jobId; 081 this.parentId = parentJobId; 082 this.nominalTime = nominalTime; 083 this.expectedStartTime = expectedStartTime; 084 this.actualStartTime = actualStartTime; 085 this.expectedEndTime = expectedEndTime; 086 this.actualEndTime = actualEndTime; 087 this.expectedDuration = expectedDuration; 088 this.actualDuration = actualDuration; 089 this.notificationMessage = notificationMessage; 090 this.upstreamApps = upstreamApps; 091 } 092 093 /** 094 * Get the job Id 095 * 096 * @return id the job id 097 */ 098 public String getId() { 099 return id; 100 } 101 102 /** 103 * Set the job Id for message 104 * 105 * @param id the job id 106 */ 107 public void setId(String id) { 108 this.id = id; 109 } 110 111 /** 112 * Gets the parent job id 113 * 114 * @return the parent job Id 115 */ 116 public String getParentId() { 117 return parentId; 118 } 119 120 /** 121 * Set the parent job Id for message 122 * 123 * @param parentId the parent job Id 124 */ 125 public void setParentId(String parentId) { 126 this.parentId = parentId; 127 } 128 129 /** 130 * Get nominal time 131 * 132 * @return nominal time 133 */ 134 public Date getNominalTime() { 135 return nominalTime; 136 } 137 138 /** 139 * Set nominal time for message 140 * 141 * @param nominalTime 142 */ 143 public void setNominalTime(Date nominalTime) { 144 this.nominalTime = nominalTime; 145 } 146 147 /** 148 * Get expected start time 149 * 150 * @return the expected start time 151 */ 152 public Date getExpectedStartTime() { 153 return expectedStartTime; 154 } 155 156 /** 157 * Set expected start time for message 158 * 159 * @param expectedStartTime 160 */ 161 public void setExpectedStartTime(Date expectedStartTime) { 162 this.expectedStartTime = expectedStartTime; 163 } 164 165 /** 166 * Get actual start time 167 * 168 * @return actual start time 169 */ 170 public Date getActualStartTime() { 171 return actualStartTime; 172 } 173 174 /** 175 * Set actual start time for message 176 * 177 * @param actualStartTime 178 */ 179 public void setActualStartTime(Date actualStartTime) { 180 this.actualStartTime = actualStartTime; 181 } 182 183 /** 184 * Get expected end time 185 * 186 * @return expectedEndTime 187 */ 188 public Date getExpectedEndTime() { 189 return expectedEndTime; 190 } 191 192 /** 193 * Set expected end time for message 194 * 195 * @param expectedEndTime 196 */ 197 public void setExpectedEndTime(Date expectedEndTime) { 198 this.expectedEndTime = expectedEndTime; 199 } 200 201 /** 202 * Get actual end time 203 * 204 * @return actual end time 205 */ 206 public Date getActualEndTime() { 207 return actualEndTime; 208 } 209 210 /** 211 * Set actual end time for message 212 * 213 * @param actualEndTime 214 */ 215 public void setActualEndTime(Date actualEndTime) { 216 this.actualEndTime = actualEndTime; 217 } 218 219 /** 220 * Get expected duration time (in milliseconds) 221 * 222 * @return expectedDuration (in milliseconds) 223 */ 224 public long getExpectedDuration() { 225 return expectedDuration; 226 } 227 228 /** 229 * Set expected duration (in milliseconds) for message 230 * 231 * @param expectedDuration (in milliseconds) 232 */ 233 public void setExpectedDuration(long expectedDuration) { 234 this.expectedDuration = expectedDuration; 235 } 236 237 /** 238 * Get actual duration (in milliseconds) 239 * 240 * @return actual duration (in milliseconds) 241 */ 242 public long getActualDuration() { 243 return actualDuration; 244 } 245 246 /** 247 * Set actual duration (in milliseconds) for message 248 * 249 * @param actualDuration (in milliseconds) 250 */ 251 public void setActualDuration(long actualDuration) { 252 this.actualDuration = actualDuration; 253 } 254 255 /** 256 * Get notification message 257 * 258 * @return notification message 259 */ 260 public String getNotificationMessage() { 261 return notificationMessage; 262 } 263 264 /** 265 * Set notification message 266 * 267 * @param notificationMessage 268 */ 269 public void setNotificationMessage(String notificationMessage) { 270 this.notificationMessage = notificationMessage; 271 } 272 273 /** 274 * Get upstream app names 275 * 276 * @return upstreamApps 277 */ 278 public String getUpstreamApps() { 279 return upstreamApps; 280 } 281 282 /** 283 * Set upstream app names 284 * 285 * @param upstreamApps 286 */ 287 public void setUpstreamApps(String upstreamApps) { 288 this.upstreamApps = upstreamApps; 289 } 290 291 /** 292 * Get user name 293 * 294 * @return user name 295 */ 296 @JsonIgnore 297 public String getUser() { 298 return user; 299 } 300 301 /** 302 * Set user name for message 303 * 304 * @param user 305 */ 306 public void setUser(String user) { 307 this.user = user; 308 } 309 310 /** 311 * Get application name 312 * 313 * @return application name 314 */ 315 @JsonIgnore 316 public String getAppName() { 317 return appName; 318 } 319 320 /** 321 * Set application name for message 322 * 323 * @param appName 324 */ 325 public void setAppName(String appName) { 326 this.appName = appName; 327 } 328 329 /** 330 * Get event status 331 * 332 * @return event status 333 */ 334 @JsonIgnore 335 public SLAEvent.EventStatus getEventStatus() { 336 return eventStatus; 337 } 338 339 /** 340 * Set event status 341 * 342 * @param eventStatus 343 */ 344 public void setEventStatus(SLAEvent.EventStatus eventStatus){ 345 this.eventStatus = eventStatus; 346 } 347 348 /** 349 * Get SLA status 350 * 351 * @return sla status 352 */ 353 @JsonIgnore 354 public SLAEvent.SLAStatus getSLAStatus() { 355 return slaStatus; 356 } 357 358 /** 359 * Set SLA status for message 360 * 361 * @param slaStatus 362 */ 363 public void setSLAStatus(SLAEvent.SLAStatus slaStatus) { 364 this.slaStatus = slaStatus; 365 } 366 367 /** 368 * Set the JMS properties for SLA message 369 * 370 * @param message the JMS message 371 * @throws JMSException 372 */ 373 @Override 374 @JsonIgnore 375 public void setProperties(Message message) throws JMSException { 376 super.setProperties(message); 377 setEventStatus(SLAEvent.EventStatus.valueOf(message.getStringProperty(JMSHeaderConstants.EVENT_STATUS))); 378 setSLAStatus(SLAEvent.SLAStatus.valueOf(message.getStringProperty(JMSHeaderConstants.SLA_STATUS))); 379 setAppName(message.getStringProperty(JMSHeaderConstants.APP_NAME)); 380 setUser(message.getStringProperty(JMSHeaderConstants.USER)); 381 } 382}