|
22 | 22 | import com.cloud.user.Account; |
23 | 23 | import com.cloud.user.AccountVO; |
24 | 24 | import com.cloud.user.User; |
25 | | -import com.cloud.user.UserContext; |
26 | 25 | import com.cloud.user.dao.AccountDao; |
27 | 26 | import com.cloud.user.dao.UserDao; |
28 | | -import com.cloud.utils.component.AnnotationInterceptor; |
29 | 27 | import com.cloud.utils.component.ComponentContext; |
30 | | -import net.sf.cglib.proxy.Callback; |
31 | | -import net.sf.cglib.proxy.MethodInterceptor; |
32 | | -import net.sf.cglib.proxy.MethodProxy; |
33 | 28 | import org.apache.cloudstack.framework.events.EventBus; |
34 | 29 | import org.apache.cloudstack.framework.events.EventBusException; |
35 | 30 | import org.apache.log4j.Logger; |
|
38 | 33 |
|
39 | 34 | import javax.annotation.PostConstruct; |
40 | 35 | import javax.inject.Inject; |
41 | | -import java.lang.reflect.AnnotatedElement; |
42 | | -import java.lang.reflect.Method; |
43 | 36 | import java.util.HashMap; |
44 | 37 | import java.util.Map; |
45 | 38 |
|
@@ -185,111 +178,4 @@ private static long getDomainId(long accountId){ |
185 | 178 | AccountVO account = _accountDao.findByIdIncludingRemoved(accountId); |
186 | 179 | return account.getDomainId(); |
187 | 180 | } |
188 | | - |
189 | | - public static class ActionEventCallback implements MethodInterceptor, AnnotationInterceptor<EventVO> { |
190 | | - |
191 | | - @Override |
192 | | - public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { |
193 | | - EventVO event = interceptStart(method); |
194 | | - boolean success = true; |
195 | | - try { |
196 | | - return methodProxy.invokeSuper(object, args); |
197 | | - } catch (Exception e){ |
198 | | - success = false; |
199 | | - interceptException(method, event); |
200 | | - throw e; |
201 | | - } finally { |
202 | | - if(success){ |
203 | | - interceptComplete(method, event); |
204 | | - } |
205 | | - } |
206 | | - } |
207 | | - |
208 | | - @Override |
209 | | - public boolean needToIntercept(AnnotatedElement element) { |
210 | | - if (!(element instanceof Method)) { |
211 | | - return false; |
212 | | - |
213 | | - } |
214 | | - Method method = (Method)element; |
215 | | - ActionEvent actionEvent = method.getAnnotation(ActionEvent.class); |
216 | | - if (actionEvent != null) { |
217 | | - return true; |
218 | | - } |
219 | | - |
220 | | - return false; |
221 | | - } |
222 | | - |
223 | | - @Override |
224 | | - public EventVO interceptStart(AnnotatedElement element) { |
225 | | - EventVO event = null; |
226 | | - Method method = (Method)element; |
227 | | - ActionEvent actionEvent = method.getAnnotation(ActionEvent.class); |
228 | | - if (actionEvent != null) { |
229 | | - boolean async = actionEvent.async(); |
230 | | - if(async){ |
231 | | - UserContext ctx = UserContext.current(); |
232 | | - long userId = ctx.getCallerUserId(); |
233 | | - long accountId = ctx.getAccountId(); |
234 | | - long startEventId = ctx.getStartEventId(); |
235 | | - String eventDescription = actionEvent.eventDescription(); |
236 | | - if(ctx.getEventDetails() != null){ |
237 | | - eventDescription += ". "+ctx.getEventDetails(); |
238 | | - } |
239 | | - ActionEventUtils.onStartedActionEvent(userId, accountId, actionEvent.eventType(), eventDescription, startEventId); |
240 | | - } |
241 | | - } |
242 | | - return event; |
243 | | - } |
244 | | - |
245 | | - @Override |
246 | | - public void interceptComplete(AnnotatedElement element, EventVO event) { |
247 | | - Method method = (Method)element; |
248 | | - ActionEvent actionEvent = method.getAnnotation(ActionEvent.class); |
249 | | - if (actionEvent != null) { |
250 | | - UserContext ctx = UserContext.current(); |
251 | | - long userId = ctx.getCallerUserId(); |
252 | | - long accountId = ctx.getAccountId(); |
253 | | - long startEventId = ctx.getStartEventId(); |
254 | | - String eventDescription = actionEvent.eventDescription(); |
255 | | - if(ctx.getEventDetails() != null){ |
256 | | - eventDescription += ". "+ctx.getEventDetails(); |
257 | | - } |
258 | | - if(actionEvent.create()){ |
259 | | - //This start event has to be used for subsequent events of this action |
260 | | - startEventId = ActionEventUtils.onCreatedActionEvent(userId, accountId, EventVO.LEVEL_INFO, actionEvent.eventType(), "Successfully created entity for " + eventDescription); |
261 | | - ctx.setStartEventId(startEventId); |
262 | | - } else { |
263 | | - ActionEventUtils.onCompletedActionEvent(userId, accountId, EventVO.LEVEL_INFO, actionEvent.eventType(), "Successfully completed " + eventDescription, startEventId); |
264 | | - } |
265 | | - } |
266 | | - } |
267 | | - |
268 | | - @Override |
269 | | - public void interceptException(AnnotatedElement element, EventVO event) { |
270 | | - Method method = (Method)element; |
271 | | - ActionEvent actionEvent = method.getAnnotation(ActionEvent.class); |
272 | | - if (actionEvent != null) { |
273 | | - UserContext ctx = UserContext.current(); |
274 | | - long userId = ctx.getCallerUserId(); |
275 | | - long accountId = ctx.getAccountId(); |
276 | | - long startEventId = ctx.getStartEventId(); |
277 | | - String eventDescription = actionEvent.eventDescription(); |
278 | | - if(ctx.getEventDetails() != null){ |
279 | | - eventDescription += ". "+ctx.getEventDetails(); |
280 | | - } |
281 | | - if(actionEvent.create()){ |
282 | | - long eventId = ActionEventUtils.onCreatedActionEvent(userId, accountId, EventVO.LEVEL_ERROR, actionEvent.eventType(), "Error while creating entity for " + eventDescription); |
283 | | - ctx.setStartEventId(eventId); |
284 | | - } else { |
285 | | - ActionEventUtils.onCompletedActionEvent(userId, accountId, EventVO.LEVEL_ERROR, actionEvent.eventType(), "Error while " + eventDescription, startEventId); |
286 | | - } |
287 | | - } |
288 | | - } |
289 | | - |
290 | | - @Override |
291 | | - public Callback getCallback() { |
292 | | - return this; |
293 | | - } |
294 | | - } |
295 | 181 | } |
0 commit comments