mirror of https://github.com/apache/cloudstack.git
Contrail Event Interceptor fix
When project/domains are created, our plugin code won't get invoked. Our contrail plugin uses Event infrastructure provided by cloudstack to receive these events and handle them accordingly. It is must to create domains/projects before creating a virtual network/vm object in contrail implementation. Hence our plugin must need a way to get notified about project/domain events.
This commit is contained in:
parent
e0de79b170
commit
c1cfaa2d1c
|
|
@ -0,0 +1,41 @@
|
|||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
|
||||
>
|
||||
|
||||
<!--
|
||||
AOP
|
||||
-->
|
||||
<bean id="contrailEventInterceptor" class="org.apache.cloudstack.network.contrail.management.EventUtils.EventInterceptor" />
|
||||
<aop:config>
|
||||
<aop:advisor advice-ref="contrailEventInterceptor"
|
||||
pointcut="execution(* *(..)) && @annotation(com.cloud.event.ActionEvent)" />
|
||||
<aop:advisor advice-ref="contrailEventInterceptor"
|
||||
pointcut="execution(* *(..)) && @annotation(com.cloud.event.ActionEvents)" />
|
||||
</aop:config>
|
||||
|
||||
</beans>
|
||||
|
|
@ -20,6 +20,8 @@ package org.apache.cloudstack.network.contrail.management;
|
|||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
|
|
@ -28,8 +30,11 @@ import org.springframework.stereotype.Component;
|
|||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.framework.messagebus.MessageBus;
|
||||
import org.apache.cloudstack.framework.messagebus.MessageBusBase;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import com.cloud.event.ActionEvent;
|
||||
import com.cloud.event.ActionEvents;
|
||||
import com.cloud.event.Event;
|
||||
import com.cloud.event.EventCategory;
|
||||
import com.cloud.event.EventTypes;
|
||||
|
|
@ -74,7 +79,7 @@ public class EventUtils {
|
|||
|
||||
}
|
||||
|
||||
public static class EventInterceptor implements ComponentMethodInterceptor {
|
||||
public static class EventInterceptor implements ComponentMethodInterceptor, MethodInterceptor {
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(EventInterceptor.class);
|
||||
|
||||
|
|
@ -82,6 +87,55 @@ public class EventUtils {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
Method m = invocation.getMethod();
|
||||
Object target = invocation.getThis();
|
||||
|
||||
if ( getActionEvents(m).size() == 0 ) {
|
||||
/* Look for annotation on impl class */
|
||||
m = target.getClass().getMethod(m.getName(), m.getParameterTypes());
|
||||
}
|
||||
|
||||
Object interceptorData = null;
|
||||
|
||||
boolean success = true;
|
||||
try {
|
||||
interceptorData = interceptStart(m, target);
|
||||
|
||||
Object result = invocation.proceed();
|
||||
success = true;
|
||||
|
||||
return result;
|
||||
} finally {
|
||||
if ( success ) {
|
||||
interceptComplete(m, target, interceptorData);
|
||||
} else {
|
||||
interceptException(m, target, interceptorData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected List<ActionEvent> getActionEvents(Method m) {
|
||||
List<ActionEvent> result = new ArrayList<ActionEvent>();
|
||||
|
||||
ActionEvents events = m.getAnnotation(ActionEvents.class);
|
||||
|
||||
if ( events != null ) {
|
||||
for ( ActionEvent e : events.value() ) {
|
||||
result.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
ActionEvent e = m.getAnnotation(ActionEvent.class);
|
||||
|
||||
if ( e != null ) {
|
||||
result.add(e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object interceptStart(Method method, Object target) {
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue