11 Replies Latest reply: Mar 27, 2012 7:06 AM by 896688 RSS

    Adding rule dynamically to OCEP using JMX

    896688
      I am looking for a way to add rule dynamically to CQL Processor. I tried it using JMX but I get below exception:

      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'control' defined in URL [bundleentry://282.fwk934469/META-INF/spring/eventtypetest-context.xml]: Invocation of init method failed; nested exception is java.lang.ClassCastException: com.bea.core.rmi.RemoteObject cannot be cast to javax.management.remote.mx4j_rmi.RMIConnection
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
           at java.security.AccessController.doPrivileged(Native Method)
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
           at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
           at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
           at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
           at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
           at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)


      I was connecting from a bean within my OCEP application and followed exactly the same steps listed here:

      http://docs.oracle.com/cd/E17904_01/doc.1111/e14300/jmx.htm#autoId4
        • 1. Re: Adding rule dynamically to OCEP using JMX
          665356
          Here is the code we use in our tests to do this. Hope this helps:

          Map<String, Object> environment = new HashMap<String, Object>();
          environment.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER,
          com.bea.core.jmx.remote.provider.msarmi.ServerProvider.class
          .getClassLoader());
          environment.put(JMXConnectorFactory.PROTOCOL_PROVIDER_CLASS_LOADER,
          com.bea.core.jmx.remote.provider.msarmi.ServerProvider.class
          .getClassLoader());

          JMXServiceURL url = new JMXServiceURL("MSARMI", "localhost",
          TestFrameworkBean.getSingleton().getListenPort(), "/jndi/jmxconnector");
          environment.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
          "com.bea.core.jmx.remote.provider");
          System.setProperty("mx4j.remote.resolver.pkgs",
          "com.bea.core.jmx.remote.resolver");

          JMXConnector connector = JMXConnectorFactory.connect(url, environment);
          msc = connector.getMBeanServerConnection();
          • 2. Re: Adding rule dynamically to OCEP using JMX
            896688
            Andy,

            Thanks for the code snippet. I was using exactly the same piece of code to connect. But still am getting the same classcast exception.

            I have declared a bean and used this code in that to connect. Is that the right place or which is the right component to write JMX client within Oracle cep application?
            • 3. Re: Adding rule dynamically to OCEP using JMX
              alexalves
              Hi,

              Could you include your MANIFEST.MF?

              Also, could you confirm you can manage this server remotely from jconsole when you run wlevsjconsole.sh?

              Thanks,
              • 4. Re: Adding rule dynamically to OCEP using JMX
                896688
                Here is the Manifest file:

                Manifest-Version: 1.0
                Bundle-ManifestVersion: 2
                Bundle-Name: %project.name
                Bundle-SymbolicName: CEP_EventTypeTest
                Bundle-Version: 1.0.0
                Bundle-Localization: bundle
                Bundle-Vendor: %project.vendor
                Bundle-RequiredExecutionEnvironment: JavaSE-1.6
                Bundle-ClassPath: .,
                lib/com.bea.wlevs.management_11.1.1.4_0.jar,
                lib/com.bea.wlevs.management.api_11.1.1.4_0.jar,
                lib/com.bea.core.bootbundle_11.0.0.0.jar,
                lib/com.bea.core.jmx_8.0.0.0.jar,
                lib/com.bea.core.jndi.context_8.0.0.0.jar,
                lib/com.bea.core.logging_1.8.0.0.jar,
                lib/com.bea.core.rmi_7.0.0.0.jar
                Import-Package: com.bea.wlevs.configuration;version="11.1.1",
                com.bea.wlevs.ede;version="11.1.1",
                com.bea.wlevs.ede.api;version="11.1.1",
                com.bea.wlevs.ede.impl;version="11.1.1",
                com.bea.wlevs.ede.spi;version="11.1.1",
                com.bea.wlevs.management.spi;version="11.1.1",
                com.bea.wlevs.spring;version="11.1.1",
                com.bea.wlevs.spring.support;version="11.1.1",
                com.bea.wlevs.util;version="11.1.1",
                org.aopalliance.aop;version="1.0.0",
                org.apache.commons.logging;version="1.1.0",
                org.springframework.aop;version="2.5.6",
                org.springframework.aop.framework;version="2.5.6",
                org.springframework.beans;version="2.5.6",
                org.springframework.beans.factory;version="2.5.6",
                org.springframework.beans.factory.config;version="2.5.6",
                org.springframework.core.annotation;version="2.5.6",
                org.springframework.jmx.access;version="2.5.6",
                org.springframework.osgi.context;version="1.2.0",
                org.springframework.osgi.extensions.annotation;version="1.2.0",
                org.springframework.osgi.service;version="1.2.0",
                org.springframework.util;version="2.5.6"


                Yes I able to connect to the server using jconsole by running wlevsjconsole.cmd.

                Service URL used : service:jmx:msarmi://localhost:9002/jndi/jmxconnector
                • 5. Re: Adding rule dynamically to OCEP using JMX
                  665356
                  Remove the Bundle-ClassPath entries - these are already present in the server.
                  • 6. Re: Adding rule dynamically to OCEP using JMX
                    896688
                    Also sharing the code here :

                    public class ProcessorControlBean
                    implements ActivatableBean {

                    private CQLProcessorMBean processor;

                    @Override
                         public void afterConfigurationActive() throws Exception {
                              initConnection("localhost", 9002, "wlevs", new char[] {'w','l','e','v','s','1'});

                    Map<String, String> rules = processor.getAllRules();

                    for ( String key: rules.keySet()) {
                    System.out.println ("rule id-" + key + " rule-" + rules.get (key));
                    }
                         }

                    public void setProcessor(CQLProcessorMBean processor) {
                    this.processor = processor;
                    }

                         public static void initConnection(String hostname, int port, String username, char[] password) throws IOException, NullPointerException, JMException{

                              Map<String, Object> environment = new HashMap<String, Object>();
                              environment.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER,
                                                  com.bea.core.jmx.remote.provider.msarmi.ServerProvider.class
                                                  .getClassLoader());
                              environment.put(JMXConnectorFactory.PROTOCOL_PROVIDER_CLASS_LOADER,
                                                  com.bea.core.jmx.remote.provider.msarmi.ServerProvider.class
                                                  .getClassLoader());

                              environment.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
                                                  "com.bea.core.jmx.remote.provider");
                              System.setProperty("mx4j.remote.resolver.pkgs",
                                                  "com.bea.core.jmx.remote.resolver");

                              environment.put(JMXConnector.CREDENTIALS,
                                                  new Serializable[]{username,password});
                              environment.put("jmx.remote.authenticator",
                                                  "com.bea.core.jmx.server.CEAuthenticator");
                    System.setProperty("jmx.remote.authenticator",
                                        "com.bea.core.jmx.server.CEAuthenticator");

                              JMXServiceURL url = new JMXServiceURL("MSARMI", "localhost", 9002, "/jndi/jmxconnector");
                              JMXConnector connector = JMXConnectorFactory.connect(url, environment);
                              MBeanServerConnection msc = connector.getMBeanServerConnection();

                         ObjectName eplName =
                         ObjectName.getInstance("com.bea.wlevs:Name=xmleventProcessor,Type=CQLProcessor,Application=CEP_EventTypeTest");

                         CQLProcessorMBean eplMBean = (CQLProcessorMBean)
                              MBeanServerInvocationHandler.newProxyInstance(
                                                  msc,
                              ObjectName.getInstance(eplName),
                              CQLProcessorMBean.class,
                              true);
                              
                              Map<String,String> rules = eplMBean.getAllRules();
                         for ( String key: rules.keySet()) {
                         System.out.println ("rule id-" + key + " rule-" + rules.get (key));
                         }
                         }

                    }


                    Part of context XML:
                         <bean id="proxy" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
                         <property name="objectName"
                         value="com.bea.wlevs:Name=xmleventProcessor,Type=CQLProcessor,Application=CEP_EventTypeTest" />
                         <property name="proxyInterface"
                         value="com.bea.wlevs.management.configuration.CQLProcessorMBean" />
                         </bean>

                         <bean id="control" class="com.vz.inms.cep.bean.ProcessorControlBean">
                         <property name="processor" ref="proxy" />
                         </bean>
                    • 7. Re: Adding rule dynamically to OCEP using JMX
                      896688
                      If I don't include bundle classpath, server throws classnotfound exception for MBeanProxyFactoryBean and other classes. Unable to resolve classcastexception.
                      • 8. Re: Adding rule dynamically to OCEP using JMX
                        alexalves
                        Without the Bundle-ClassPath entry, try the following import:

                        Import-Package: com.bea.wlevs.ede,
                        junit.framework;version="3.8.1",
                        org.springframework.util;version="2.5",
                        com.bea.wlevs.util,
                        com.bea.wlevs.ede.api,
                        com.bea.wlevs.server.management,
                        org.apache.commons.logging;version="1.1.0",
                        org.springframework.beans.factory,
                        com.bea.wlevs.spring.support,
                        com.bea.wlevs.monitor,
                        com.bea.core.jmx.remote.provider.msarmi,
                        com.bea.wlevs.management.configuration,
                        org.aopalliance.aop,
                        net.sf.cglib.core,
                        net.sf.cglib.proxy,
                        net.sf.cglib.reflect


                        Thanks
                        • 9. Re: Adding rule dynamically to OCEP using JMX
                          896688
                          Thanks Alex. The below import resolved the issue:

                          Import-Package: com.bea.wlevs.ede,
                          org.springframework.util;version="2.5",
                          com.bea.wlevs.util,
                          com.bea.wlevs.ede.api,
                          com.bea.wlevs.server.management,
                          com.bea.wlevs.management,
                          org.springframework.jmx.access;version="2.5.6",
                          org.apache.commons.logging;version="1.1.0",
                          org.springframework.beans.factory,
                          com.bea.wlevs.spring.support,
                          com.bea.wlevs.monitor,
                          com.bea.core.jmx.remote.provider.msarmi,
                          com.bea.wlevs.management.configuration,
                          org.aopalliance.aop,
                          net.sf.cglib.core,
                          net.sf.cglib.proxy,
                          net.sf.cglib.reflect,
                          org.springframework.aop,
                          org.springframework.aop.framework

                          The intention to access Mbean is to add query dynamically.

                          The line

                               cqlMBean.addQuery("testquery", "select * from helloworldInputChannel[now]");
                          gives below exception:

                          <Exception thrown from prepare method com.oracle.cep.processor.cql.impl.CQLProcessorImpl.prepare.
                          java.lang.IllegalArgumentException: [Assertion failed] - the object argument must be null
                               at org.springframework.util.Assert.isNull(Assert.java:89)
                               at org.springframework.util.Assert.isNull(Assert.java:100)
                               at com.oracle.cep.processor.cql.impl.CQLProcessorImpl.prepare(CQLProcessorImpl.java:934)
                          • 10. Re: Adding rule dynamically to OCEP using JMX
                            alexalves
                            Hi,

                            Are you using PS5? If not, could you move to it?

                            I think you are running into a bug caused when you try to do more than one management action prior to the application being fully started. If that's the case, could you try waiting for the application to be fully started, and only then start adding new queries?

                            Thanks
                            Alex
                            • 11. Re: Adding rule dynamically to OCEP using JMX
                              896688
                              Yes that was the issue. It is resolved now!