CLOUDSTACK-6970: Protect event interpretion from causing NPE exception

(cherry picked from commit 06d8d3a03f)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Kelven Yang 2014-05-29 09:35:03 -07:00 committed by Rohit Yadav
parent b716444b84
commit 839ef94ce9
1 changed files with 11 additions and 6 deletions

View File

@ -239,15 +239,20 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
// Get the event type from the cmdInfo json string
String info = job.getCmdInfo();
String cmdEventType;
if (info == null) {
cmdEventType = "unknown";
} else {
String cmdEventType = "unknown";
if (info != null) {
String marker = "\"cmdEventType\"";
int begin = info.indexOf(marker);
cmdEventType = info.substring(begin + marker.length() + 2, info.indexOf(",", begin) - 1);
}
if (begin >= 0) {
cmdEventType = info.substring(begin + marker.length() + 2, info.indexOf(",", begin) - 1);
if (s_logger.isDebugEnabled())
s_logger.debug("Retrieved cmdEventType from job info: " + cmdEventType);
} else {
if (s_logger.isDebugEnabled())
s_logger.debug("Unable to locate cmdEventType marker in job info. publish as unknown event");
}
}
// For some reason, the instanceType / instanceId are not abstract, which means we may get null values.
org.apache.cloudstack.framework.events.Event event = new org.apache.cloudstack.framework.events.Event(
"management-server",