Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @POST @Consumes(javax.ws.rs.core.MediaType.APPLICATION_JSON) @Path(QUERY_PATH) @SuppressWarnings("unchecked") public javax.ws.rs.core.Response queryBeans(String query)
        public virtual Response QueryBeans(string query)
        {
            try
            {
                MBeanServer server = ManagementFactory.PlatformMBeanServer;

                string json = DodgeStartingUnicodeMarker(query);
                ICollection <object> queries = (ICollection <object>)JsonHelper.readJson(json);

                List <JmxMBeanRepresentation> beans = new List <JmxMBeanRepresentation>();
                foreach (object queryObj in queries)
                {
                    Debug.Assert(queryObj is string);
                    foreach (object objName in server.queryNames(new ObjectName(( string )queryObj), null))
                    {
                        beans.Add(new JmxMBeanRepresentation(( ObjectName )objName));
                    }
                }

                return(_output.ok(new ListRepresentation("jmxBean", beans)));
            }
            catch (Exception e) when(e is JsonParseException || e is MalformedObjectNameException)
            {
                return(_output.badRequest(e));
            }
        }
Beispiel #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.collection.RawIterator<Object[], org.neo4j.internal.kernel.api.exceptions.ProcedureException> apply(org.neo4j.kernel.api.proc.Context ctx, Object[] input, org.neo4j.kernel.api.ResourceTracker resourceTracker) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException
        public override RawIterator <object[], ProcedureException> Apply(Context ctx, object[] input, ResourceTracker resourceTracker)
        {
            string query = input[0].ToString();

            try
            {
                // Find all beans that match the query name pattern
                IEnumerator <ObjectName> names = _jmxServer.queryNames(new ObjectName(query), null).GetEnumerator();

                // Then convert them to a Neo4j type system representation
                return(RawIterator.from(() =>
                {
                    if (!names.hasNext())
                    {
                        return null;
                    }

                    ObjectName name = names.next();
                    try
                    {
                        MBeanInfo beanInfo = _jmxServer.getMBeanInfo(name);
                        return new object[] { name.CanonicalName, beanInfo.Description, ToNeo4jValue(name, beanInfo.Attributes) };
                    }
                    catch (JMException e)
                    {
                        throw new ProcedureException(Status.General.UnknownError, e, "JMX error while accessing `%s`, please report this. Message was: %s", name, e.Message);
                    }
                }));
            }
            catch (MalformedObjectNameException)
            {
                throw new ProcedureException(Org.Neo4j.Kernel.Api.Exceptions.Status_Procedure.ProcedureCallFailed, "'%s' is an invalid JMX name pattern. Valid queries should use" + "the syntax outlined in the javax.management.ObjectName API documentation." + "For instance, try 'org.neo4j:*' to find all JMX beans of the 'org.neo4j' " + "domain, or '*:*' to find every JMX bean.", query);
            }
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Setup()
        {
            _jmxServer     = mock(typeof(MBeanServer));
            _beanName      = new ObjectName("org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference");
            _attributeName = "name";

            when(_jmxServer.queryNames(new ObjectName("*:*"), null)).thenReturn(asSet(_beanName));
            when(_jmxServer.getMBeanInfo(_beanName)).thenReturn(new MBeanInfo("org.neo4j.SomeMBean", "This is a description", new MBeanAttributeInfo[] { new MBeanAttributeInfo(_attributeName, "someType", "This is the attribute desc.", true, false, false) }, null, null, null));
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @GET @Path(BEAN_TEMPLATE) public javax.ws.rs.core.Response getBean(@PathParam("domain") String domainName, @PathParam("objectName") String objectName)
        public virtual Response GetBean(string domainName, string objectName)
        {
            MBeanServer server = ManagementFactory.PlatformMBeanServer;

            List <JmxMBeanRepresentation> beans = new List <JmxMBeanRepresentation>();

            foreach (object objName in server.queryNames(CreateObjectName(domainName, objectName), null))
            {
                beans.Add(new JmxMBeanRepresentation(( ObjectName )objName));
            }

            return(_output.ok(new ListRepresentation("bean", beans)));
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @GET @Path(DOMAIN_TEMPLATE) public javax.ws.rs.core.Response getDomain(@PathParam("domain") String domainName)
        public virtual Response GetDomain(string domainName)
        {
            MBeanServer server = ManagementFactory.PlatformMBeanServer;

            JmxDomainRepresentation domain = new JmxDomainRepresentation(domainName);

            foreach (object objName in server.queryNames(null, null))
            {
                if (objName.ToString().StartsWith(domainName, StringComparison.Ordinal))
                {
                    domain.AddBean(( ObjectName )objName);
                }
            }

            return(_output.ok(domain));
        }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleCompositeAttributes() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleCompositeAttributes()
        {
            // given
            ObjectName beanName = new ObjectName("org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference");

            when(_jmxServer.queryNames(new ObjectName("*:*"), null)).thenReturn(asSet(beanName));
            when(_jmxServer.getMBeanInfo(beanName)).thenReturn(new MBeanInfo("org.neo4j.SomeMBean", "This is a description", new MBeanAttributeInfo[] { new MBeanAttributeInfo("name", "differenceMaker", "Who makes the difference?", true, false, false) }, null, null, null));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: when(jmxServer.getAttribute(beanName, "name")).thenReturn(new javax.management.openmbean.CompositeDataSupport(new javax.management.openmbean.CompositeType("myComposite", "Composite description", new String[]{"key1", "key2"}, new String[]{"Can't be empty", "Also can't be empty"}, new javax.management.openmbean.OpenType<?>[]{javax.management.openmbean.SimpleType.STRING, javax.management.openmbean.SimpleType.INTEGER}), map("key1", "Hello", "key2", 123)));
            when(_jmxServer.getAttribute(beanName, "name")).thenReturn(new CompositeDataSupport(new CompositeType("myComposite", "Composite description", new string[] { "key1", "key2" }, new string[] { "Can't be empty", "Also can't be empty" }, new OpenType <object>[] { SimpleType.STRING, SimpleType.INTEGER }), map("key1", "Hello", "key2", 123)));

            JmxQueryProcedure procedure = new JmxQueryProcedure(ProcedureSignature.procedureName("bob"), _jmxServer);

            // when
            RawIterator <object[], ProcedureException> result = procedure.Apply(null, new object[] { "*:*" }, _resourceTracker);

            // then
            assertThat(asList(result), contains(equalTo(new object[] { "org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference", "This is a description", map(_attributeName, map("description", "Who makes the difference?", "value", map("description", "Composite description", "properties", map("key1", "Hello", "key2", 123)))) })));
        }