{"action":"created","issue":{"url":"https://api.github.com/repos/apache/cloudstack/issues/1157","repository_url":"https://api.github.com/repos/apache/cloudstack","labels_url":"https://api.github.com/repos/apache/cloudstack/issues/1157/labels{/name}","comments_url":"https://api.github.com/repos/apache/cloudstack/issues/1157/comments","events_url":"https://api.github.com/repos/apache/cloudstack/issues/1157/events","html_url":"https://github.com/apache/cloudstack/pull/1157","id":120152827,"number":1157,"title":"CLOUDSTACK-9100: ISO.CREATE/TEMPLATE.CREATE event missing for usage_e…","user":{"login":"SudharmaJain","id":12229259,"avatar_url":"https://avatars.githubusercontent.com/u/12229259?v=3","gravatar_id":"","url":"https://api.github.com/users/SudharmaJain","html_url":"https://github.com/SudharmaJain","followers_url":"https://api.github.com/users/SudharmaJain/followers","following_url":"https://api.github.com/users/SudharmaJain/following{/other_user}","gists_url":"https://api.github.com/users/SudharmaJain/gists{/gist_id}","starred_url":"https://api.github.com/users/SudharmaJain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SudharmaJain/subscriptions","organizations_url":"https://api.github.com/users/SudharmaJain/orgs","repos_url":"https://api.github.com/users/SudharmaJain/repos","events_url":"https://api.github.com/users/SudharmaJain/events{/privacy}","received_events_url":"https://api.github.com/users/SudharmaJain/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-12-03T11:48:26Z","updated_at":"2016-04-20T10:00:20Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/cloudstack/pulls/1157","html_url":"https://github.com/apache/cloudstack/pull/1157","diff_url":"https://github.com/apache/cloudstack/pull/1157.diff","patch_url":"https://github.com/apache/cloudstack/pull/1157.patch"},"body":"…vent by template sync thread\r\n\r\nIf there is a Management server restart while template is in downloading or installing state. Template Sync does not push event into usage_event table. \r\n\r\nI have verified the fix manually. Here is a snapshot.\r\n![image](https://cloud.githubusercontent.com/assets/12229259/11559714/0989748c-99e1-11e5-88e0-48b4dbec0224.png)\r\n\r\n I have registered 4 templates. template id 207 and 208(ISO.CREATE event is missing) before applying the fix. and template id 209 and 210 after applying the fix.\r\n\r\nRepro Steps (3 cases)\r\n==========\r\nCase - 1 (private template)\r\n-------------\r\n1. register a private template/iso.\r\n2. restart management server when template is in downloading state.\r\n3. After management server restart, template_store_ref entry is removed if  download was not yet completed.\r\n4. on next management server restart, if download would have completed, template_store_ref entry will get populated, but TEMPLATE.CREATE event is missing in usage_event.\r\n\r\nCase - 2 (Public template)\r\n--------------------------------\r\n1.  register public template.\r\n2. restart management server when in downloading state.\r\n3. after restart template download reinitiates.\r\n4. template goes to ready state, but there is no usage event.\r\n\r\ncase -3 (public/private template)\r\n--------------------------------- \r\n1. register a template \r\n2. restart management server when template is in installing state.\r\n3. after restart template goes to ready, but there is no usage event.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/apache/cloudstack/issues/comments/212360074","html_url":"https://github.com/apache/cloudstack/pull/1157#issuecomment-212360074","issue_url":"https://api.github.com/repos/apache/cloudstack/issues/1157","id":212360074,"user":{"login":"SudharmaJain","id":12229259,"avatar_url":"https://avatars.githubusercontent.com/u/12229259?v=3","gravatar_id":"","url":"https://api.github.com/users/SudharmaJain","html_url":"https://github.com/SudharmaJain","followers_url":"https://api.github.com/users/SudharmaJain/followers","following_url":"https://api.github.com/users/SudharmaJain/following{/other_user}","gists_url":"https://api.github.com/users/SudharmaJain/gists{/gist_id}","starred_url":"https://api.github.com/users/SudharmaJain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SudharmaJain/subscriptions","organizations_url":"https://api.github.com/users/SudharmaJain/orgs","repos_url":"https://api.github.com/users/SudharmaJain/repos","events_url":"https://api.github.com/users/SudharmaJain/events{/privacy}","received_events_url":"https://api.github.com/users/SudharmaJain/received_events","type":"User","site_admin":false},"created_at":"2016-04-20T10:00:20Z","updated_at":"2016-04-20T10:00:20Z","body":"@pedro-martins On line 503, It is not a function but It is a way to define callback method. It has been used all over the cloudstack code.  On line 504, context was set and will be available in callback method 'createTemplateAsyncCallBack'. So there are no chances of null pointer exception on line 598. If there was any chance of null pointer exception, it would have happened in my test setup."}}