Package org.rhq.plugins.jmx.util

Examples of org.rhq.plugins.jmx.util.ObjectNameQueryUtility


    Set<DiscoveredResourceDetails> resources = new HashSet<DiscoveredResourceDetails>();

    Pattern pattern = Pattern.compile(REGEX);

        ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(
                defaultPluginConfig.getSimple(JBossCacheComponent.CACHE_SEARCH_STRING).getStringValue());

        List<EmsBean> cacheBeans = connection.queryBeans(queryUtility
                .getTranslatedQuery());

        HashSet<String> beanNames = new HashSet<String>();

        for (EmsBean bean : cacheBeans) {
View Full Code Here


        String query = baseObjectName + ",";
        if (isTreeCache)
            query += "tree";
        query += "cache-interceptor=%name%";
        ObjectNameQueryUtility util = new ObjectNameQueryUtility(query);
        query = util.getTranslatedQuery();
        EmsConnection connection = parentServer.getEmsConnection();
        if (connection != null)
            interceptors = connection.queryBeans(query);

    }
View Full Code Here

import org.rhq.core.domain.configuration.PropertySimple;

public class ObjectNameQueryUtilityTest {
    @Test
    public void testObjectNameQueryUtility() throws MalformedObjectNameException {
        ObjectNameQueryUtility onqu = null;
        onqu = new ObjectNameQueryUtility("java.lang:type=MemoryPool,name=Code Cache");
        assert onqu.getQueryTemplate().equals("java.lang:type=MemoryPool,name=Code Cache");

        onqu = new ObjectNameQueryUtility("java.lang:type=MemoryPool,name=%name%");
        assert onqu.getTranslatedQuery().equals("java.lang:type=MemoryPool,*");
        assert onqu.getVariableProperties().size() == 1;
        assert onqu.getVariableProperties().get("name").equals("name");

        onqu = new ObjectNameQueryUtility("java.lang:type=Threading");

        onqu = new ObjectNameQueryUtility("java.lang:type=%foo%");
        assert onqu.getTranslatedQuery().equals("java.lang:*");
        assert onqu.getVariableProperties().size() == 1;
        assert onqu.getVariableProperties().get("type").equals("foo");

        onqu = new ObjectNameQueryUtility("jboss.esb.*:service=Queue,name=%name%");
        assert onqu.getTranslatedQuery().equals("jboss.esb.*:service=Queue,*");
        assert onqu.getVariableProperties().size() == 1;
        assert onqu.getVariableProperties().get("name").equals("name");
        ObjectName testON = new ObjectName(
            "jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_gw");
        onqu.setMatchedKeyValues(testON.getKeyPropertyList());
        String formulatedMessageTemplate = "Name of queue: {name}";
        assert onqu.formatMessage(formulatedMessageTemplate).equals("Name of queue: quickstart_helloworld_Request_gw");

        onqu = new ObjectNameQueryUtility("java.lang:type=%MyType%,name=%MyName%,app=%MyApp%,foo=%MyFoo%");
        assert onqu.getTranslatedQuery().equals("java.lang:*");
        assert onqu.getVariableProperties().size() == 4;
        testON = new ObjectName("java.lang:type=A,name=B,app=C,foo=D");
        onqu.setMatchedKeyValues(testON.getKeyPropertyList());
        formulatedMessageTemplate = "Type: {MyType}, Name: {MyName}, App: {MyApp}, Foo: {MyFoo}";
        assert onqu.formatMessage(formulatedMessageTemplate).equals("Type: A, Name: B, App: C, Foo: D");

        Configuration c = new Configuration();
        c.put(new PropertySimple("e", "foo"));
        c.put(new PropertySimple("g", "bar"));
        onqu = new ObjectNameQueryUtility("a:b=c,d={e},f={g}", c);
        System.out.println("Template: " + onqu.getQueryTemplate());
        assert onqu.getQueryTemplate().equals("a:b=c,d=foo,f=bar");

        // Test some very long replacement tokens inspired by BZ 828596
        onqu = new ObjectNameQueryUtility("*:type=HttpMetricInspector,name=%name%");
        assert onqu.getQueryTemplate().equals("*:type=HttpMetricInspector,name=%name%");
        assert onqu.getVariableProperties().size() == 1;
        assert onqu.getVariableProperties().get("name").equals("name");
        testON = new ObjectName("FooBarABCDEFGHIJKLMNOPQRSTUVWXYZ:type=HttpMetricInspector,name=ABCDEFGHIJKLMNOPQRSTUVWXYZ�ABCDEFGHIJKLMNOPQRSTUVWXYZ");
        onqu.setMatchedKeyValues(testON.getKeyPropertyList());
        formulatedMessageTemplate = "Http metrics for endpoint {name}";
        String res = onqu.formatMessage(formulatedMessageTemplate);
        assert res.equals("Http metrics for endpoint ABCDEFGHIJKLMNOPQRSTUVWXYZ�ABCDEFGHIJKLMNOPQRSTUVWXYZ") : res;


    }
View Full Code Here

    }

    @Test
    public void testObjectNameQueryUtilityFiltering() throws MalformedObjectNameException {
        ObjectNameQueryUtility onqu = null;

        onqu = new ObjectNameQueryUtility("java.lang:type=MemoryPool,name=%foo%");
        assert !onqu.isContainsExtraKeyProperties(Collections.singleton("type"));
        assert !onqu.isContainsExtraKeyProperties(Collections.singleton("name"));
        assert onqu.isContainsExtraKeyProperties(Collections.singleton("splat"));

    }
View Full Code Here

     */
    protected Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<JMXComponent<?>> context, String objectName, String resourceName, String resourceDescription, String versionSource) {

        Set<DiscoveredResourceDetails> result = new HashSet<DiscoveredResourceDetails>();

        ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(objectName);
        JMXComponent parentResourceComponent = context.getParentResourceComponent();
        EmsConnection connection = parentResourceComponent.getEmsConnection();

        Configuration pluginConfig = context.getDefaultPluginConfiguration();

        List<EmsBean> beans = connection.queryBeans(queryUtility.getTranslatedQuery());
        if (beans.size() == 1) {
            String version = getVersionFromSource(connection, versionSource);
            DiscoveredResourceDetails detail = new DiscoveredResourceDetails(context.getResourceType(), objectName, resourceName, version, resourceDescription, pluginConfig, null);
            result.add(detail);
        }
View Full Code Here

        String beanName = versionSource.substring(0, pos);
        String attribs = versionSource.substring(pos + 1);
        String[] attrs = attribs.split(",");

        try {
            ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(beanName);
            List<EmsBean> beans = connection.queryBeans(queryUtility.getTranslatedQuery());
            if (beans.size() == 1) {
                EmsBean bean = beans.get(0);
                bean.refreshAttributes(Arrays.asList(attrs));
                StringBuilder ret = new StringBuilder();
                Iterator<String> iter = Arrays.asList(attrs).iterator();
View Full Code Here

        EmsConnection jmxConnection = getEmsConnection();

        String servletMBeanNames = QUERY_TEMPLATE_SERVLET;
        Configuration config = getResourceContext().getPluginConfiguration();
        servletMBeanNames = servletMBeanNames.replace("%WEBMODULE%", config.getSimpleValue(PROPERTY_NAME, ""));
        ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(servletMBeanNames);
        List<EmsBean> mBeans = jmxConnection.queryBeans(queryUtility.getTranslatedQuery());

        long min = Long.MAX_VALUE;
        long max = 0;
        long processingTime = 0;
        int requestCount = 0;
View Full Code Here

        EmsBean result = null;

        if (null != webModuleMBeanName) {
            EmsConnection conn = getEmsConnection();
            if (null != conn) {
                ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(webModuleMBeanName);
                List<EmsBean> mBeans = conn.queryBeans(queryUtility.getTranslatedQuery());
                // There should only be one mBean for this match.
                if (mBeans.size() == 1) {
                    result = mBeans.get(0);
                }
            }
View Full Code Here

    private List<EmsBean> getVHosts() {
        EmsConnection emsConnection = getEmsConnection();
        String query = QUERY_TEMPLATE_HOST;
        query = query.replace("%PATH%",
            getResourceContext().getPluginConfiguration().getSimpleValue(PROPERTY_CONTEXT_ROOT, ""));
        ObjectNameQueryUtility queryUtil = new ObjectNameQueryUtility(query);
        List<EmsBean> mBeans = emsConnection.queryBeans(queryUtil.getTranslatedQuery());
        return mBeans;
    }
View Full Code Here

        if (AvailabilityType.UP == result) {
            // When the connector is stopped its associated GlobalRequestProcessor will not exist. We test
            // for availability by checking the existence of objectName Catalina:type=GlobalRequestProcessor,name=%handler%[%address%]-%port%.
            String objectName = getGlobalRequestProcessorName();
            EmsConnection connection = getEmsConnection();
            ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(objectName);
            List<EmsBean> beans = connection.queryBeans(queryUtility.getTranslatedQuery());

            result = (beans.isEmpty()) ? AvailabilityType.DOWN : AvailabilityType.UP;
        }

        return result;
View Full Code Here

TOP

Related Classes of org.rhq.plugins.jmx.util.ObjectNameQueryUtility

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.