diff --git a/app/src/main/java/org/astraea/app/performance/Report.java b/app/src/main/java/org/astraea/app/performance/Report.java index bca1d01095..84df178a11 100644 --- a/app/src/main/java/org/astraea/app/performance/Report.java +++ b/app/src/main/java/org/astraea/app/performance/Report.java @@ -20,7 +20,7 @@ import java.util.Optional; import java.util.stream.Collectors; import org.astraea.common.metrics.BeanQuery; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.client.consumer.ConsumerMetrics; import org.astraea.common.metrics.client.consumer.HasConsumerFetchMetrics; import org.astraea.common.metrics.client.producer.ProducerMetrics; @@ -28,7 +28,7 @@ public interface Report { static long recordsConsumedTotal() { - var client = MBeanClient.local(); + var client = JndiClient.local(); return (long) ConsumerMetrics.fetch(client).stream() .mapToDouble(HasConsumerFetchMetrics::recordsConsumedTotal) @@ -37,7 +37,7 @@ static long recordsConsumedTotal() { static List consumers() { - return ConsumerMetrics.fetch(MBeanClient.local()).stream() + return ConsumerMetrics.fetch(JndiClient.local()).stream() .map( m -> new Report() { @@ -74,7 +74,7 @@ public String clientId() { @Override public Optional e2eLatency() { return Optional.ofNullable( - MBeanClient.local() + JndiClient.local() .bean( BeanQuery.builder() .domainName(ConsumerThread.DOMAIN_NAME) @@ -91,7 +91,7 @@ public Optional e2eLatency() { } static List producers() { - return ProducerMetrics.producer(MBeanClient.local()).stream() + return ProducerMetrics.producer(JndiClient.local()).stream() .map( m -> new Report() { @@ -113,7 +113,7 @@ public double avgLatency() { @Override public Optional e2eLatency() { return Optional.ofNullable( - MBeanClient.local() + JndiClient.local() .bean( BeanQuery.builder() .domainName(ProducerThread.DOMAIN_NAME) diff --git a/app/src/main/java/org/astraea/app/performance/TrackerThread.java b/app/src/main/java/org/astraea/app/performance/TrackerThread.java index 0b15d329fb..294c29b2ba 100644 --- a/app/src/main/java/org/astraea/app/performance/TrackerThread.java +++ b/app/src/main/java/org/astraea/app/performance/TrackerThread.java @@ -27,7 +27,7 @@ import org.astraea.common.DataSize; import org.astraea.common.Utils; import org.astraea.common.metrics.HasBeanObject; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.client.consumer.ConsumerMetrics; import org.astraea.common.metrics.client.consumer.HasConsumerCoordinatorMetrics; import org.astraea.common.metrics.client.producer.HasProducerTopicMetrics; @@ -37,7 +37,7 @@ public interface TrackerThread extends AbstractThread { class ProducerPrinter { - private final MBeanClient mBeanClient = MBeanClient.local(); + private final JndiClient mBeanClient = JndiClient.local(); private final Supplier> reportSupplier; private long lastRecords = 0; @@ -97,7 +97,7 @@ boolean tryToPrint(Duration duration) { } class ConsumerPrinter { - private final MBeanClient mBeanClient = MBeanClient.local(); + private final JndiClient mBeanClient = JndiClient.local(); private final Supplier> reportSupplier; private long lastRecords = 0; diff --git a/app/src/main/java/org/astraea/app/publisher/MetricPublisher.java b/app/src/main/java/org/astraea/app/publisher/MetricPublisher.java index 976ca23bb9..d99c040995 100644 --- a/app/src/main/java/org/astraea/app/publisher/MetricPublisher.java +++ b/app/src/main/java/org/astraea/app/publisher/MetricPublisher.java @@ -26,7 +26,7 @@ import org.astraea.common.Utils; import org.astraea.common.admin.Admin; import org.astraea.common.admin.NodeInfo; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.collector.MetricFetcher; /** Keep fetching all kinds of metrics and publish to inner topics. */ @@ -58,7 +58,7 @@ static void execute(Arguments arguments) { Collectors.toUnmodifiableMap( NodeInfo::id, node -> - MBeanClient.jndi( + JndiClient.of( node.host(), arguments.idToJmxPort().apply(node.id())))))) .fetchBeanDelay(arguments.period) diff --git a/app/src/main/java/org/astraea/app/web/BeanHandler.java b/app/src/main/java/org/astraea/app/web/BeanHandler.java index 7a7308aed2..ed88814c60 100644 --- a/app/src/main/java/org/astraea/app/web/BeanHandler.java +++ b/app/src/main/java/org/astraea/app/web/BeanHandler.java @@ -23,7 +23,7 @@ import org.astraea.common.admin.Admin; import org.astraea.common.metrics.BeanObject; import org.astraea.common.metrics.BeanQuery; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; public class BeanHandler implements Handler { private final Admin admin; @@ -45,8 +45,7 @@ public CompletionStage get(Channel channel) { brokers.stream() .map( b -> { - try (var client = - MBeanClient.jndi(b.host(), jmxPorts.apply(b.id()))) { + try (var client = JndiClient.of(b.host(), jmxPorts.apply(b.id()))) { return new NodeBean( b.host(), client.beans(builder.build()).stream() diff --git a/app/src/main/java/org/astraea/app/web/WebService.java b/app/src/main/java/org/astraea/app/web/WebService.java index acbeddeb9a..521a8fc0e4 100644 --- a/app/src/main/java/org/astraea/app/web/WebService.java +++ b/app/src/main/java/org/astraea/app/web/WebService.java @@ -35,6 +35,7 @@ import org.astraea.common.Utils; import org.astraea.common.admin.Admin; import org.astraea.common.admin.NodeInfo; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MBeanClient; import org.astraea.common.metrics.collector.MetricSensor; import org.astraea.common.metrics.collector.MetricStore; @@ -62,8 +63,7 @@ public WebService( Collectors.toUnmodifiableMap( NodeInfo::id, b -> - MBeanClient.jndi( - b.host(), brokerIdToJmxPort.apply(b.id()))))); + JndiClient.of(b.host(), brokerIdToJmxPort.apply(b.id()))))); var metricStore = MetricStore.builder() .beanExpiration(beanExpiration) diff --git a/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java b/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java index cfa1eef4df..01ae8544fe 100644 --- a/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java +++ b/app/src/test/java/org/astraea/app/web/BalancerHandlerTest.java @@ -76,6 +76,7 @@ import org.astraea.common.json.JsonConverter; import org.astraea.common.json.TypeRef; import org.astraea.common.metrics.ClusterBean; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MBeanClient; import org.astraea.common.metrics.collector.MetricSensor; import org.astraea.common.metrics.collector.MetricStore; @@ -1355,8 +1356,7 @@ private MetricStore metricStore(Admin admin, List costWeights) { Collectors.toUnmodifiableMap( NodeInfo::id, b -> - MBeanClient.jndi( - b.host(), brokerIdToJmxPort.apply(b.id()))))); + JndiClient.of(b.host(), brokerIdToJmxPort.apply(b.id()))))); var cw = costWeights.stream().map(x -> x.cost).collect(Collectors.toSet()); var cf = Utils.costFunctions(cw, HasClusterCost.class, Configuration.EMPTY); var metricSensors = cf.stream().map(c -> c.metricSensor().get()).collect(Collectors.toList()); diff --git a/common/src/main/java/org/astraea/common/assignor/Assignor.java b/common/src/main/java/org/astraea/common/assignor/Assignor.java index a1c063a1e7..7f83bfc21d 100644 --- a/common/src/main/java/org/astraea/common/assignor/Assignor.java +++ b/common/src/main/java/org/astraea/common/assignor/Assignor.java @@ -39,6 +39,7 @@ import org.astraea.common.consumer.ConsumerConfigs; import org.astraea.common.cost.HasPartitionCost; import org.astraea.common.cost.ReplicaLeaderSizeCost; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MBeanClient; import org.astraea.common.metrics.collector.MetricStore; import org.astraea.common.partitioner.PartitionerUtils; @@ -159,13 +160,13 @@ public final void configure(Map configs) { .brokers() .thenApply( brokers -> { - var map = new HashMap(); + var map = new HashMap(); brokers.forEach( b -> map.put( - b.id(), MBeanClient.jndi(b.host(), jmxPortGetter.apply(b.id())))); + b.id(), JndiClient.of(b.host(), jmxPortGetter.apply(b.id())))); // add local client to fetch consumer metrics - map.put(-1, MBeanClient.local()); + map.put(-1, JndiClient.local()); return Collections.unmodifiableMap(map); }); metricStore = diff --git a/common/src/main/java/org/astraea/common/metrics/JndiClient.java b/common/src/main/java/org/astraea/common/metrics/JndiClient.java new file mode 100644 index 0000000000..d8fc407a59 --- /dev/null +++ b/common/src/main/java/org/astraea/common/metrics/JndiClient.java @@ -0,0 +1,184 @@ +/* + * 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. + */ +package org.astraea.common.metrics; + +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.net.MalformedURLException; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.management.AttributeNotFoundException; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanException; +import javax.management.MBeanFeatureInfo; +import javax.management.MBeanServerConnection; +import javax.management.ObjectInstance; +import javax.management.ReflectionException; +import javax.management.RuntimeMBeanException; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; +import org.astraea.common.Utils; + +/** A MBeanClient used to retrieve mbean value from remote Jmx server. */ +public interface JndiClient extends MBeanClient, AutoCloseable { + + /** + * @param host the address of jmx server + * @param port the port of jmx server + * @return a mbean client using JNDI to lookup metrics. + */ + static JndiClient of(String host, int port) { + try { + return of( + new JMXServiceURL( + String.format( + "service:jmx:rmi://%s:%s/jndi/rmi://%s:%s/jmxrmi", host, port, host, port))); + } catch (MalformedURLException e) { + throw new IllegalArgumentException(e); + } + } + + static JndiClient of(JMXServiceURL jmxServiceURL) { + return Utils.packException( + () -> { + var jmxConnector = JMXConnectorFactory.connect(jmxServiceURL); + return new BasicMBeanClient( + jmxConnector.getMBeanServerConnection(), + jmxServiceURL.getHost(), + jmxServiceURL.getPort()) { + @Override + public void close() { + Utils.close(jmxConnector); + } + }; + }); + } + + static JndiClient local() { + return new BasicMBeanClient(ManagementFactory.getPlatformMBeanServer(), Utils.hostname(), -1); + } + + @Override + default void close() {} + + class BasicMBeanClient implements JndiClient { + + private final MBeanServerConnection connection; + final String host; + + final int port; + + BasicMBeanClient(MBeanServerConnection connection, String host, int port) { + this.connection = connection; + this.host = host; + this.port = port; + } + + @Override + public BeanObject bean(BeanQuery beanQuery) { + return Utils.packException( + () -> { + // ask for MBeanInfo + var mBeanInfo = connection.getMBeanInfo(beanQuery.objectName()); + + // create a list builder all available attributes name + var attributeName = + Arrays.stream(mBeanInfo.getAttributes()) + .map(MBeanFeatureInfo::getName) + .collect(Collectors.toList()); + + // query the result + return queryBean(beanQuery, attributeName); + }); + } + + BeanObject queryBean(BeanQuery beanQuery, Collection attributeNameCollection) + throws ReflectionException, + InstanceNotFoundException, + IOException, + AttributeNotFoundException, + MBeanException { + // fetch attribute value from mbean server + var attributeNameArray = attributeNameCollection.toArray(new String[0]); + var attributeList = + connection.getAttributes(beanQuery.objectName(), attributeNameArray).asList(); + + // collect attribute name & value into a map + var attributes = new HashMap(); + attributeList.forEach(attribute -> attributes.put(attribute.getName(), attribute.getValue())); + + // according to the javadoc of MBeanServerConnection#getAttributes, the API will + // ignore any error occurring during the fetch process (for example, attribute not + // exists). Below code check for such condition and try to figure out what exactly + // the error is. put it into attributes return result. + for (var str : attributeNameArray) { + if (attributes.containsKey(str)) continue; + try { + attributes.put(str, connection.getAttribute(beanQuery.objectName(), str)); + } catch (RuntimeMBeanException e) { + if (!(e.getCause() instanceof UnsupportedOperationException)) + throw new IllegalStateException(e); + // the UnsupportedOperationException is thrown when we query unacceptable + // attribute. we just skip it as it is normal case to + // return "acceptable" attribute only + } + } + + // collect result, and build a new BeanObject as return result + return new BeanObject(beanQuery.domainName(), beanQuery.properties(), attributes); + } + + @Override + public Collection beans( + BeanQuery beanQuery, Consumer errorHandle) { + return Utils.packException( + () -> + connection.queryMBeans(beanQuery.objectName(), null).stream() + // Parallelize the sampling of bean objects. The underlying RMI is thread-safe. + // https://github.com/skiptests/astraea/issues/1553#issuecomment-1461143723 + .parallel() + .map(ObjectInstance::getObjectName) + .map(BeanQuery::fromObjectName) + .flatMap( + query -> { + try { + return Stream.of(bean(query)); + } catch (RuntimeException e) { + errorHandle.accept(e); + return Stream.empty(); + } + }) + .collect(Collectors.toUnmodifiableList())); + } + + /** + * Returns the list of domains in which any MBean is currently registered. + * + *

The order of strings within the returned array is not defined. + * + * @return a {@link List} of domain name {@link String} + */ + List domains() { + return Utils.packException(() -> Arrays.asList(connection.getDomains())); + } + } +} diff --git a/common/src/main/java/org/astraea/common/metrics/MBeanClient.java b/common/src/main/java/org/astraea/common/metrics/MBeanClient.java index 819ea2c053..35bf73509b 100644 --- a/common/src/main/java/org/astraea/common/metrics/MBeanClient.java +++ b/common/src/main/java/org/astraea/common/metrics/MBeanClient.java @@ -16,46 +16,16 @@ */ package org.astraea.common.metrics; -import java.io.IOException; -import java.lang.management.ManagementFactory; -import java.net.MalformedURLException; -import java.util.Arrays; import java.util.Collection; -import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; import java.util.function.Consumer; import java.util.regex.Pattern; import java.util.stream.Collectors; -import java.util.stream.Stream; -import javax.management.AttributeNotFoundException; -import javax.management.InstanceNotFoundException; -import javax.management.MBeanException; -import javax.management.MBeanFeatureInfo; -import javax.management.MBeanServerConnection; -import javax.management.ObjectInstance; import javax.management.ObjectName; -import javax.management.ReflectionException; -import javax.management.RuntimeMBeanException; -import javax.management.remote.JMXConnectorFactory; -import javax.management.remote.JMXServiceURL; -import org.astraea.common.Utils; -/** - * A MBeanClient used to retrieve mbean value from remote Jmx server. - * - *

{@code
- * try(var client = new MBeanClient(jmxConnectorServer.getAddress())) {
- *   var bean = client.bean(BeanQuery.builder("java.lang")
- *            .property("type", "MemoryManager")
- *            .property("name", "CodeCacheManager")
- *            .build());
- *   System.out.println(bean.getAttributes());
- * }
- */ -public interface MBeanClient extends AutoCloseable { +public interface MBeanClient { static MBeanClient of(Collection objs) { return new MBeanClient() { @@ -98,42 +68,6 @@ public Collection beans( }; } - /** - * @param host the address of jmx server - * @param port the port of jmx server - * @return a mbean client using JNDI to lookup metrics. - */ - static MBeanClient jndi(String host, int port) { - try { - return of( - new JMXServiceURL( - String.format( - "service:jmx:rmi://%s:%s/jndi/rmi://%s:%s/jmxrmi", host, port, host, port))); - } catch (MalformedURLException e) { - throw new IllegalArgumentException(e); - } - } - - static MBeanClient of(JMXServiceURL jmxServiceURL) { - return Utils.packException( - () -> { - var jmxConnector = JMXConnectorFactory.connect(jmxServiceURL); - return new BasicMBeanClient( - jmxConnector.getMBeanServerConnection(), - jmxServiceURL.getHost(), - jmxServiceURL.getPort()) { - @Override - public void close() { - Utils.close(jmxConnector); - } - }; - }); - } - - static MBeanClient local() { - return new BasicMBeanClient(ManagementFactory.getPlatformMBeanServer(), Utils.hostname(), -1); - } - /** * Fetch all attributes of target mbean. * @@ -167,109 +101,4 @@ default Collection beans(BeanQuery beanQuery) { * @return A {@link Set} of {@link BeanObject}, all BeanObject has its own attributes resolved. */ Collection beans(BeanQuery beanQuery, Consumer errorHandle); - - @Override - default void close() {} - - class BasicMBeanClient implements MBeanClient { - - private final MBeanServerConnection connection; - final String host; - - final int port; - - BasicMBeanClient(MBeanServerConnection connection, String host, int port) { - this.connection = connection; - this.host = host; - this.port = port; - } - - @Override - public BeanObject bean(BeanQuery beanQuery) { - return Utils.packException( - () -> { - // ask for MBeanInfo - var mBeanInfo = connection.getMBeanInfo(beanQuery.objectName()); - - // create a list builder all available attributes name - var attributeName = - Arrays.stream(mBeanInfo.getAttributes()) - .map(MBeanFeatureInfo::getName) - .collect(Collectors.toList()); - - // query the result - return queryBean(beanQuery, attributeName); - }); - } - - BeanObject queryBean(BeanQuery beanQuery, Collection attributeNameCollection) - throws ReflectionException, - InstanceNotFoundException, - IOException, - AttributeNotFoundException, - MBeanException { - // fetch attribute value from mbean server - var attributeNameArray = attributeNameCollection.toArray(new String[0]); - var attributeList = - connection.getAttributes(beanQuery.objectName(), attributeNameArray).asList(); - - // collect attribute name & value into a map - var attributes = new HashMap(); - attributeList.forEach(attribute -> attributes.put(attribute.getName(), attribute.getValue())); - - // according to the javadoc of MBeanServerConnection#getAttributes, the API will - // ignore any error occurring during the fetch process (for example, attribute not - // exists). Below code check for such condition and try to figure out what exactly - // the error is. put it into attributes return result. - for (var str : attributeNameArray) { - if (attributes.containsKey(str)) continue; - try { - attributes.put(str, connection.getAttribute(beanQuery.objectName(), str)); - } catch (RuntimeMBeanException e) { - if (!(e.getCause() instanceof UnsupportedOperationException)) - throw new IllegalStateException(e); - // the UnsupportedOperationException is thrown when we query unacceptable - // attribute. we just skip it as it is normal case to - // return "acceptable" attribute only - } - } - - // collect result, and build a new BeanObject as return result - return new BeanObject(beanQuery.domainName(), beanQuery.properties(), attributes); - } - - @Override - public Collection beans( - BeanQuery beanQuery, Consumer errorHandle) { - return Utils.packException( - () -> - connection.queryMBeans(beanQuery.objectName(), null).stream() - // Parallelize the sampling of bean objects. The underlying RMI is thread-safe. - // https://github.com/skiptests/astraea/issues/1553#issuecomment-1461143723 - .parallel() - .map(ObjectInstance::getObjectName) - .map(BeanQuery::fromObjectName) - .flatMap( - query -> { - try { - return Stream.of(bean(query)); - } catch (RuntimeException e) { - errorHandle.accept(e); - return Stream.empty(); - } - }) - .collect(Collectors.toUnmodifiableList())); - } - - /** - * Returns the list of domains in which any MBean is currently registered. - * - *

The order of strings within the returned array is not defined. - * - * @return a {@link List} of domain name {@link String} - */ - List domains() { - return Utils.packException(() -> Arrays.asList(connection.getDomains())); - } - } } diff --git a/common/src/main/java/org/astraea/common/partitioner/SmoothWeightRoundRobinPartitioner.java b/common/src/main/java/org/astraea/common/partitioner/SmoothWeightRoundRobinPartitioner.java index 3bf7f44e8c..2fd0b2853a 100644 --- a/common/src/main/java/org/astraea/common/partitioner/SmoothWeightRoundRobinPartitioner.java +++ b/common/src/main/java/org/astraea/common/partitioner/SmoothWeightRoundRobinPartitioner.java @@ -33,6 +33,7 @@ import org.astraea.common.admin.BrokerTopic; import org.astraea.common.admin.ClusterInfo; import org.astraea.common.cost.NeutralIntegratedCost; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MBeanClient; import org.astraea.common.metrics.collector.MetricStore; @@ -124,13 +125,13 @@ void configure( .brokers() .thenApply( brokers -> { - var map = new HashMap(); + var map = new HashMap(); brokers.forEach( b -> map.put( - b.id(), MBeanClient.jndi(b.host(), jmxPortGetter.apply(b.id())))); + b.id(), JndiClient.of(b.host(), jmxPortGetter.apply(b.id())))); // add local client to fetch consumer metrics - map.put(-1, MBeanClient.local()); + map.put(-1, JndiClient.local()); return Collections.unmodifiableMap(map); }); diff --git a/common/src/main/java/org/astraea/common/partitioner/StrictCostPartitioner.java b/common/src/main/java/org/astraea/common/partitioner/StrictCostPartitioner.java index 8792ac6d04..5d12b00e61 100644 --- a/common/src/main/java/org/astraea/common/partitioner/StrictCostPartitioner.java +++ b/common/src/main/java/org/astraea/common/partitioner/StrictCostPartitioner.java @@ -35,6 +35,7 @@ import org.astraea.common.cost.HasBrokerCost; import org.astraea.common.cost.NoSufficientMetricsException; import org.astraea.common.cost.NodeLatencyCost; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MBeanClient; import org.astraea.common.metrics.collector.MetricStore; @@ -145,13 +146,13 @@ public void configure(Configuration config) { .brokers() .thenApply( brokers -> { - var map = new HashMap(); + var map = new HashMap(); brokers.forEach( b -> map.put( - b.id(), MBeanClient.jndi(b.host(), jmxPortGetter.apply(b.id())))); + b.id(), JndiClient.of(b.host(), jmxPortGetter.apply(b.id())))); // add local client to fetch consumer metrics - map.put(-1, MBeanClient.local()); + map.put(-1, JndiClient.local()); return Collections.unmodifiableMap(map); }); diff --git a/common/src/test/java/org/astraea/common/balancer/algorithms/GreedyBalancerTest.java b/common/src/test/java/org/astraea/common/balancer/algorithms/GreedyBalancerTest.java index a30d2c4674..90affa56c9 100644 --- a/common/src/test/java/org/astraea/common/balancer/algorithms/GreedyBalancerTest.java +++ b/common/src/test/java/org/astraea/common/balancer/algorithms/GreedyBalancerTest.java @@ -28,7 +28,7 @@ import org.astraea.common.cost.DecreasingCost; import org.astraea.common.metrics.BeanQuery; import org.astraea.common.metrics.ClusterBean; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -65,7 +65,7 @@ void testJmx() { Utils.construct( GreedyBalancer.class, Configuration.of(Map.of(GreedyBalancer.ITERATION_CONFIG, "100"))); - try (MBeanClient client = MBeanClient.local()) { + try (JndiClient client = JndiClient.local()) { IntStream.range(0, 10) .forEach( run -> { diff --git a/common/src/test/java/org/astraea/common/cost/BrokerInputCostTest.java b/common/src/test/java/org/astraea/common/cost/BrokerInputCostTest.java index 3f51078eff..26b7e8f0c4 100644 --- a/common/src/test/java/org/astraea/common/cost/BrokerInputCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/BrokerInputCostTest.java @@ -21,7 +21,7 @@ import org.astraea.common.admin.ClusterInfo; import org.astraea.common.metrics.BeanObject; import org.astraea.common.metrics.ClusterBean; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MetricsTestUtils; import org.astraea.common.metrics.broker.ServerMetrics; import org.astraea.common.producer.Producer; @@ -66,7 +66,7 @@ void testSensor() { var f = new BrokerInputCost(); var clusterBean = MetricsTestUtils.clusterBean( - Map.of(0, MBeanClient.of(SERVICE.jmxServiceURL())), f.metricSensor().get()); + Map.of(0, JndiClient.of(SERVICE.jmxServiceURL())), f.metricSensor().get()); Assertions.assertNotEquals( 0, clusterBean.brokerMetrics(0, ServerMetrics.BrokerTopic.Meter.class).count()); diff --git a/common/src/test/java/org/astraea/common/cost/BrokerOutputCostTest.java b/common/src/test/java/org/astraea/common/cost/BrokerOutputCostTest.java index 7128a1e6ba..04e7290e95 100644 --- a/common/src/test/java/org/astraea/common/cost/BrokerOutputCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/BrokerOutputCostTest.java @@ -26,7 +26,7 @@ import org.astraea.common.consumer.ConsumerConfigs; import org.astraea.common.metrics.BeanObject; import org.astraea.common.metrics.ClusterBean; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MetricsTestUtils; import org.astraea.common.metrics.broker.ServerMetrics; import org.astraea.common.producer.Producer; @@ -81,7 +81,7 @@ void testSensor() { var f = new BrokerOutputCost(); var clusterBean = - MetricsTestUtils.clusterBean(Map.of(0, MBeanClient.local()), f.metricSensor().get()); + MetricsTestUtils.clusterBean(Map.of(0, JndiClient.local()), f.metricSensor().get()); Assertions.assertNotEquals( 0, clusterBean.brokerMetrics(0, ServerMetrics.BrokerTopic.Meter.class).count()); diff --git a/common/src/test/java/org/astraea/common/cost/ClusterCostTest.java b/common/src/test/java/org/astraea/common/cost/ClusterCostTest.java index 8997fbfb60..628a6efa6f 100644 --- a/common/src/test/java/org/astraea/common/cost/ClusterCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/ClusterCostTest.java @@ -22,7 +22,7 @@ import org.astraea.common.admin.Admin; import org.astraea.common.admin.ClusterInfo; import org.astraea.common.metrics.ClusterBean; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.broker.ServerMetrics; import org.astraea.it.Service; import org.junit.jupiter.api.AfterAll; @@ -63,7 +63,7 @@ void testSensor() { var mergeCost = HasClusterCost.of(Map.of(cost1, 1.0, cost2, 1.0)); var metrics = mergeCost.metricSensor().stream() - .map(x -> x.fetch(MBeanClient.of(SERVICE.jmxServiceURL()), ClusterBean.EMPTY)) + .map(x -> x.fetch(JndiClient.of(SERVICE.jmxServiceURL()), ClusterBean.EMPTY)) .collect(Collectors.toSet()); Assertions.assertTrue( metrics.iterator().next().stream() diff --git a/common/src/test/java/org/astraea/common/cost/CpuCostTest.java b/common/src/test/java/org/astraea/common/cost/CpuCostTest.java index 35d064a180..310b415788 100644 --- a/common/src/test/java/org/astraea/common/cost/CpuCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/CpuCostTest.java @@ -21,7 +21,7 @@ import java.util.Objects; import org.astraea.common.admin.ClusterInfo; import org.astraea.common.metrics.ClusterBean; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MetricsTestUtils; import org.astraea.common.metrics.platform.OperatingSystemInfo; import org.junit.jupiter.api.Assertions; @@ -55,7 +55,7 @@ void testCost() { void testSensor() { var f = new CpuCost(); var clusterBean = - MetricsTestUtils.clusterBean(Map.of(0, MBeanClient.local()), f.metricSensor().get()); + MetricsTestUtils.clusterBean(Map.of(0, JndiClient.local()), f.metricSensor().get()); Assertions.assertFalse( clusterBean.brokerMetrics(0, OperatingSystemInfo.class).findAny().isEmpty()); Assertions.assertTrue( diff --git a/common/src/test/java/org/astraea/common/cost/MemoryCostTest.java b/common/src/test/java/org/astraea/common/cost/MemoryCostTest.java index 383fe40553..4be9d630c2 100644 --- a/common/src/test/java/org/astraea/common/cost/MemoryCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/MemoryCostTest.java @@ -22,7 +22,7 @@ import java.util.Objects; import org.astraea.common.admin.ClusterInfo; import org.astraea.common.metrics.ClusterBean; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MetricsTestUtils; import org.astraea.common.metrics.platform.HasJvmMemory; import org.astraea.common.metrics.platform.JvmMemory; @@ -54,7 +54,7 @@ void testCost() { void testSensor() { var f = new MemoryCost(); var clusterBean = - MetricsTestUtils.clusterBean(Map.of(0, MBeanClient.local()), f.metricSensor().get()); + MetricsTestUtils.clusterBean(Map.of(0, JndiClient.local()), f.metricSensor().get()); Assertions.assertTrue(clusterBean.brokerMetrics(0, JvmMemory.class).allMatch(Objects::nonNull)); // Test if we can get "used memory" and "max memory". diff --git a/common/src/test/java/org/astraea/common/cost/MoveCostTest.java b/common/src/test/java/org/astraea/common/cost/MoveCostTest.java index 3507ba020c..88246e799f 100644 --- a/common/src/test/java/org/astraea/common/cost/MoveCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/MoveCostTest.java @@ -22,7 +22,7 @@ import org.astraea.common.admin.Admin; import org.astraea.common.admin.ClusterInfo; import org.astraea.common.metrics.ClusterBean; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.broker.ServerMetrics; import org.astraea.common.metrics.collector.MetricSensor; import org.astraea.it.Service; @@ -49,7 +49,7 @@ void testSensor() { var mergeCost = HasMoveCost.of(List.of(cost1, cost2)); var metrics = mergeCost.metricSensor().stream() - .map(x -> x.fetch(MBeanClient.of(SERVICE.jmxServiceURL()), ClusterBean.EMPTY)) + .map(x -> x.fetch(JndiClient.of(SERVICE.jmxServiceURL()), ClusterBean.EMPTY)) .collect(Collectors.toSet()); Assertions.assertEquals(3, metrics.iterator().next().size()); Assertions.assertTrue( diff --git a/common/src/test/java/org/astraea/common/cost/NodeLatencyCostTest.java b/common/src/test/java/org/astraea/common/cost/NodeLatencyCostTest.java index 09af3937ba..d9628857bc 100644 --- a/common/src/test/java/org/astraea/common/cost/NodeLatencyCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/NodeLatencyCostTest.java @@ -26,7 +26,7 @@ import org.astraea.common.metrics.BeanObject; import org.astraea.common.metrics.ClusterBean; import org.astraea.common.metrics.HasBeanObject; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.client.HasNodeMetrics; import org.astraea.common.metrics.client.producer.ProducerMetrics; import org.astraea.common.producer.Producer; @@ -90,7 +90,7 @@ void testCost() { ClusterBean.of( Map.of( -1, - ProducerMetrics.node(MBeanClient.local()).stream() + ProducerMetrics.node(JndiClient.local()).stream() .map(b -> (HasBeanObject) b) .collect(Collectors.toUnmodifiableList())))) .value() @@ -102,7 +102,7 @@ void testCost() { @Test void testSensor() { var function = new NodeLatencyCost(); - var client = Mockito.mock(MBeanClient.class); + var client = Mockito.mock(JndiClient.class); Mockito.when(client.beans(Mockito.any())) .thenReturn( List.of( diff --git a/common/src/test/java/org/astraea/common/cost/NodeMetricsCostTest.java b/common/src/test/java/org/astraea/common/cost/NodeMetricsCostTest.java index 40e1968b7d..e494d3ebd8 100644 --- a/common/src/test/java/org/astraea/common/cost/NodeMetricsCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/NodeMetricsCostTest.java @@ -21,7 +21,7 @@ import org.astraea.common.Utils; import org.astraea.common.admin.Admin; import org.astraea.common.metrics.ClusterBean; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.client.HasNodeMetrics; import org.astraea.common.metrics.client.producer.ProducerMetrics; import org.astraea.common.producer.Producer; @@ -64,7 +64,7 @@ void testAllBrokersHaveCost() { .toCompletableFuture() .join(), ClusterBean.of( - ProducerMetrics.node(MBeanClient.local()).stream() + ProducerMetrics.node(JndiClient.local()).stream() .collect(Collectors.groupingBy(HasNodeMetrics::brokerId)))); Assertions.assertEquals(3, cost.value().size()); // only 1 node has latency metrics, so all costs are equal @@ -86,7 +86,7 @@ void testAllBrokersHaveCost() { .toCompletableFuture() .join(), ClusterBean.of( - ProducerMetrics.node(MBeanClient.local()).stream() + ProducerMetrics.node(JndiClient.local()).stream() .collect(Collectors.groupingBy(HasNodeMetrics::brokerId)))); Assertions.assertEquals(3, cost2.value().size()); // only 2 node has latency metrics. The other cost is equal to "max cost" diff --git a/common/src/test/java/org/astraea/common/cost/NodeThroughputCostTest.java b/common/src/test/java/org/astraea/common/cost/NodeThroughputCostTest.java index 318931d605..51ebd4ac1f 100644 --- a/common/src/test/java/org/astraea/common/cost/NodeThroughputCostTest.java +++ b/common/src/test/java/org/astraea/common/cost/NodeThroughputCostTest.java @@ -21,7 +21,7 @@ import org.astraea.common.admin.ClusterInfo; import org.astraea.common.metrics.BeanObject; import org.astraea.common.metrics.ClusterBean; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.client.HasNodeMetrics; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -76,7 +76,7 @@ void testSensor() { var throughputCost = new NodeThroughputCost(); var sensor = throughputCost.metricSensor().get(); var bean = new BeanObject("aaa", Map.of("node-id", "node-1"), Map.of()); - var client = Mockito.mock(MBeanClient.class); + var client = Mockito.mock(JndiClient.class); Mockito.when(client.beans(Mockito.any())).thenReturn(List.of(bean)); var result = sensor.fetch(client, ClusterBean.EMPTY); Assertions.assertEquals(1, result.size()); diff --git a/common/src/test/java/org/astraea/common/cost/utils/ClusterInfoSensorTest.java b/common/src/test/java/org/astraea/common/cost/utils/ClusterInfoSensorTest.java index c5ed84f467..be39d52cca 100644 --- a/common/src/test/java/org/astraea/common/cost/utils/ClusterInfoSensorTest.java +++ b/common/src/test/java/org/astraea/common/cost/utils/ClusterInfoSensorTest.java @@ -29,7 +29,7 @@ import org.astraea.common.metrics.BeanObject; import org.astraea.common.metrics.ClusterBean; import org.astraea.common.metrics.HasBeanObject; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MetricFactory; import org.astraea.common.metrics.MetricsTestUtils; import org.astraea.common.metrics.broker.ClusterMetrics; @@ -74,7 +74,7 @@ void testClusterInfoSensor() { .forEach(i -> i.toCompletableFuture().join()); } - var cb = MetricsTestUtils.clusterBean(Map.of(aBroker.id(), MBeanClient.local()), sensor); + var cb = MetricsTestUtils.clusterBean(Map.of(aBroker.id(), JndiClient.local()), sensor); // assert contains that metrics cb.all() diff --git a/common/src/test/java/org/astraea/common/metrics/BeanQueryIntegratedTest.java b/common/src/test/java/org/astraea/common/metrics/BeanQueryIntegratedTest.java index ba67cae671..f3aa0f202c 100644 --- a/common/src/test/java/org/astraea/common/metrics/BeanQueryIntegratedTest.java +++ b/common/src/test/java/org/astraea/common/metrics/BeanQueryIntegratedTest.java @@ -35,7 +35,7 @@ static void closeService() { @Test void testAllBuiltInQueries() { - try (var client = MBeanClient.of(SERVICE.jmxServiceURL())) { + try (var client = JndiClient.of(SERVICE.jmxServiceURL())) { var exist = new HashSet>(); MetricFetcher.QUERIES.forEach( q -> diff --git a/common/src/test/java/org/astraea/common/metrics/MBeanClientTest.java b/common/src/test/java/org/astraea/common/metrics/MBeanClientTest.java index dd3486575d..d158b00eae 100644 --- a/common/src/test/java/org/astraea/common/metrics/MBeanClientTest.java +++ b/common/src/test/java/org/astraea/common/metrics/MBeanClientTest.java @@ -109,7 +109,7 @@ void tearDown() throws IOException { @Test void testFetchAttributes() { // arrange - try (var client = MBeanClient.of(jmxServer.getAddress())) { + try (var client = JndiClient.of(jmxServer.getAddress())) { BeanQuery beanQuery = BeanQuery.builder().domainName("java.lang").property("type", "Memory").build(); @@ -126,7 +126,7 @@ void testFetchAttributes() { @Test void testFetchMbeanWithMultipleProperties() { // arrange - try (var client = MBeanClient.of(jmxServer.getAddress())) { + try (var client = JndiClient.of(jmxServer.getAddress())) { BeanQuery query1 = BeanQuery.builder() .domainName("java.lang") @@ -168,7 +168,7 @@ void testFetchSelectedAttributes() AttributeNotFoundException, MBeanException { // arrange - try (var client = (MBeanClient.BasicMBeanClient) MBeanClient.of(jmxServer.getAddress())) { + try (var client = (JndiClient.BasicMBeanClient) JndiClient.of(jmxServer.getAddress())) { BeanQuery beanQuery = BeanQuery.builder().domainName("java.lang").property("type", "Memory").build(); List selectedAttribute = List.of("HeapMemoryUsage"); @@ -186,7 +186,7 @@ void testFetchSelectedAttributes() @Test void testQueryBeans() { // arrange 1 query beans - try (var client = MBeanClient.of(jmxServer.getAddress())) { + try (var client = JndiClient.of(jmxServer.getAddress())) { BeanQuery beanQuery = BeanQuery.builder().domainName("java.lang").property("type", "C*").build(); @@ -224,7 +224,7 @@ void testQueryBeans() { @Test void testQueryNonExistsBeans() { // arrange - try (var client = MBeanClient.of(jmxServer.getAddress())) { + try (var client = JndiClient.of(jmxServer.getAddress())) { BeanQuery beanQuery = BeanQuery.builder().domainName("java.lang").property("type", "Something").build(); @@ -239,7 +239,7 @@ void testQueryNonExistsBeans() { @Test void testFetchNonExistsBeans() { // arrange - try (var client = (MBeanClient.BasicMBeanClient) MBeanClient.of(jmxServer.getAddress())) { + try (var client = (JndiClient.BasicMBeanClient) JndiClient.of(jmxServer.getAddress())) { BeanQuery beanQuery = BeanQuery.builder().domainName("java.lang").property("type", "Something").build(); @@ -254,7 +254,7 @@ void testFetchNonExistsBeans() { @Test void testCloseOnceMore() { // arrange - var client = MBeanClient.of(jmxServer.getAddress()); + var client = JndiClient.of(jmxServer.getAddress()); // act client.close(); @@ -270,7 +270,7 @@ void testCloseOnceMore() { @Test void testGetAllMBeans() { // arrange - try (var client = MBeanClient.of(jmxServer.getAddress())) { + try (var client = JndiClient.of(jmxServer.getAddress())) { // act Collection beanObjects = client.beans(BeanQuery.all()); @@ -284,7 +284,7 @@ void testGetAllMBeans() { @Test void testGetAllMBeansUnderSpecificDomainName() { // arrange - try (var client = MBeanClient.of(jmxServer.getAddress())) { + try (var client = JndiClient.of(jmxServer.getAddress())) { // act Collection beanObjects = client.beans(BeanQuery.all("java.lang")); @@ -298,7 +298,7 @@ void testGetAllMBeansUnderSpecificDomainName() { @Test void testGetAllMBeansUnderSpecificDomainNamePattern() { // arrange - try (var client = MBeanClient.of(jmxServer.getAddress())) { + try (var client = JndiClient.of(jmxServer.getAddress())) { // act Collection beanObjects = client.beans(BeanQuery.all("java.*")); @@ -311,15 +311,15 @@ void testGetAllMBeansUnderSpecificDomainNamePattern() { @Test void testUsePropertyListPatternForRemote() { - testUsePropertyListPattern(MBeanClient.of(jmxServer.getAddress())); + testUsePropertyListPattern(JndiClient.of(jmxServer.getAddress())); } @Test void testUsePropertyListPatternForLocal() { - testUsePropertyListPattern(MBeanClient.local()); + testUsePropertyListPattern(JndiClient.local()); } - private void testUsePropertyListPattern(MBeanClient client) { + private void testUsePropertyListPattern(JndiClient client) { // arrange try (client) { BeanQuery patternQuery = @@ -374,7 +374,7 @@ private void testUsePropertyListPattern(MBeanClient client) { @Test void testListDomains() { // arrange - try (var client = (MBeanClient.BasicMBeanClient) MBeanClient.of(jmxServer.getAddress())) { + try (var client = (JndiClient.BasicMBeanClient) JndiClient.of(jmxServer.getAddress())) { // act List domains = client.domains(); @@ -388,7 +388,7 @@ void testListDomains() { @Test void testHostAndPort() { // arrange - try (var client = (MBeanClient.BasicMBeanClient) MBeanClient.of(jmxServer.getAddress())) { + try (var client = (JndiClient.BasicMBeanClient) JndiClient.of(jmxServer.getAddress())) { assertEquals(jmxServer.getAddress().getHost(), client.host); assertEquals(jmxServer.getAddress().getPort(), client.port); } @@ -404,7 +404,7 @@ void testCustomMBeanWith500Attributes() throws Exception { register(objectName0, customMBean0); - try (var client = MBeanClient.of(jmxServer.getAddress())) { + try (var client = JndiClient.of(jmxServer.getAddress())) { // act Collection all = @@ -431,7 +431,7 @@ void testWith100CustomMBeans() throws Exception { register(objectName, mbean); } - try (var client = MBeanClient.of(jmxServer.getAddress())) { + try (var client = JndiClient.of(jmxServer.getAddress())) { // act Collection all = @@ -469,7 +469,7 @@ void testWith100CustomMBeans() throws Exception { @Test void testLocal() { - var client = MBeanClient.local(); + var client = JndiClient.local(); Assertions.assertNotEquals(0, client.beans(BeanQuery.all()).size()); } diff --git a/common/src/test/java/org/astraea/common/metrics/MBeanRegisterTest.java b/common/src/test/java/org/astraea/common/metrics/MBeanRegisterTest.java index 10b1c0782e..bce26c0b9d 100644 --- a/common/src/test/java/org/astraea/common/metrics/MBeanRegisterTest.java +++ b/common/src/test/java/org/astraea/common/metrics/MBeanRegisterTest.java @@ -35,14 +35,14 @@ void testNodeMetrics() { .attribute("incoming-byte-rate", Double.class, () -> 10D) .register(); - var metrics = ProducerMetrics.node(MBeanClient.local()); + var metrics = ProducerMetrics.node(JndiClient.local()); Assertions.assertEquals(1, metrics.size()); Assertions.assertEquals(10D, metrics.iterator().next().incomingByteRate()); } @Test void testBuilder() { - try (MBeanClient client = MBeanClient.local()) { + try (JndiClient client = JndiClient.local()) { var domainName = MBeanRegisterTest.class.getPackageName(); var id = UUID.randomUUID().toString(); Supplier bean = diff --git a/common/src/test/java/org/astraea/common/metrics/MetricsTestUtils.java b/common/src/test/java/org/astraea/common/metrics/MetricsTestUtils.java index 7c5d0bb2a0..ea324c4af7 100644 --- a/common/src/test/java/org/astraea/common/metrics/MetricsTestUtils.java +++ b/common/src/test/java/org/astraea/common/metrics/MetricsTestUtils.java @@ -43,7 +43,7 @@ private MetricsTestUtils() {} * @param sensor to generate object * @return cluster bean */ - public static ClusterBean clusterBean(Map clients, MetricSensor sensor) { + public static ClusterBean clusterBean(Map clients, MetricSensor sensor) { return ClusterBean.of( clients.entrySet().stream() .collect( diff --git a/common/src/test/java/org/astraea/common/metrics/broker/ControllerMetricsTest.java b/common/src/test/java/org/astraea/common/metrics/broker/ControllerMetricsTest.java index af134c7da6..38898c8a53 100644 --- a/common/src/test/java/org/astraea/common/metrics/broker/ControllerMetricsTest.java +++ b/common/src/test/java/org/astraea/common/metrics/broker/ControllerMetricsTest.java @@ -20,7 +20,7 @@ import java.util.Arrays; import java.util.Locale; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MetricsTestUtils; import org.astraea.it.Service; import org.junit.jupiter.api.AfterAll; @@ -47,7 +47,7 @@ static void closeService() { @ParameterizedTest @EnumSource(ControllerMetrics.Controller.class) void testController(ControllerMetrics.Controller controller) { - var gauge = controller.fetch(MBeanClient.local()); + var gauge = controller.fetch(JndiClient.local()); MetricsTestUtils.validate(gauge); Assertions.assertEquals(controller, gauge.type()); } diff --git a/common/src/test/java/org/astraea/common/metrics/broker/LogMetricsTest.java b/common/src/test/java/org/astraea/common/metrics/broker/LogMetricsTest.java index c9c857aa8b..452764d624 100644 --- a/common/src/test/java/org/astraea/common/metrics/broker/LogMetricsTest.java +++ b/common/src/test/java/org/astraea/common/metrics/broker/LogMetricsTest.java @@ -25,7 +25,7 @@ import org.astraea.common.Utils; import org.astraea.common.admin.Admin; import org.astraea.common.metrics.HasBeanObject; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MetricsTestUtils; import org.astraea.it.Service; import org.junit.jupiter.api.AfterAll; @@ -56,7 +56,7 @@ void testLogCleanerManager(LogMetrics.LogCleanerManager log) { var topicName = Utils.randomString(10); try (var admin = Admin.of(SERVICE.bootstrapServers())) { var beans = - log.fetch(MBeanClient.local()).stream() + log.fetch(JndiClient.local()).stream() .collect(Collectors.groupingBy(LogMetrics.LogCleanerManager.Gauge::path)); Assertions.assertEquals( SERVICE.dataFolders().values().stream().flatMap(Collection::stream).distinct().count(), @@ -79,7 +79,7 @@ void testMetrics(LogMetrics.Log log) { admin.creator().topic(topicName).numberOfPartitions(2).run().toCompletableFuture().join(); Utils.sleep(Duration.ofSeconds(2)); var beans = - log.fetch(MBeanClient.local()).stream() + log.fetch(JndiClient.local()).stream() .filter(m -> m.topic().equals(topicName)) .collect(Collectors.toUnmodifiableList()); Assertions.assertEquals(2, beans.size()); @@ -93,7 +93,7 @@ void testMetrics(LogMetrics.Log log) { @ParameterizedTest @EnumSource(LogMetrics.Log.class) void testValue(LogMetrics.Log log) { - log.fetch(MBeanClient.local()) + log.fetch(JndiClient.local()) .forEach( m -> { MetricsTestUtils.validate(m); @@ -130,7 +130,7 @@ void testTopicPartitionMetrics(LogMetrics.Log request) { // wait for topic creation Utils.sleep(Duration.ofSeconds(2)); - var beans = request.fetch(MBeanClient.local()); + var beans = request.fetch(JndiClient.local()); assertNotEquals(0, beans.size()); } diff --git a/common/src/test/java/org/astraea/common/metrics/broker/NetworkMetricsTest.java b/common/src/test/java/org/astraea/common/metrics/broker/NetworkMetricsTest.java index ca0564cb8b..27fc7366ab 100644 --- a/common/src/test/java/org/astraea/common/metrics/broker/NetworkMetricsTest.java +++ b/common/src/test/java/org/astraea/common/metrics/broker/NetworkMetricsTest.java @@ -16,7 +16,7 @@ */ package org.astraea.common.metrics.broker; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MetricsTestUtils; import org.astraea.it.Service; import org.junit.jupiter.api.AfterAll; @@ -44,7 +44,7 @@ static void closeService() { @ParameterizedTest() @EnumSource(value = NetworkMetrics.Request.class) void testRequestTotalTimeMs(NetworkMetrics.Request request) { - var histogram = request.fetch(MBeanClient.local()); + var histogram = request.fetch(JndiClient.local()); MetricsTestUtils.validate(histogram); } diff --git a/common/src/test/java/org/astraea/common/metrics/broker/ReplicaManagerMetricsTest.java b/common/src/test/java/org/astraea/common/metrics/broker/ReplicaManagerMetricsTest.java index 11ef797338..7de252d222 100644 --- a/common/src/test/java/org/astraea/common/metrics/broker/ReplicaManagerMetricsTest.java +++ b/common/src/test/java/org/astraea/common/metrics/broker/ReplicaManagerMetricsTest.java @@ -16,7 +16,7 @@ */ package org.astraea.common.metrics.broker; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MetricsTestUtils; import org.astraea.it.Service; import org.junit.jupiter.api.AfterAll; @@ -44,7 +44,7 @@ static void closeService() { @ParameterizedTest @EnumSource(ServerMetrics.ReplicaManager.class) void testBrokerTopic(ServerMetrics.ReplicaManager rm) { - var gauge = rm.fetch(MBeanClient.local()); + var gauge = rm.fetch(JndiClient.local()); Assertions.assertEquals(0, gauge.value()); MetricsTestUtils.validate(gauge); Assertions.assertEquals(rm, gauge.type()); diff --git a/common/src/test/java/org/astraea/common/metrics/broker/ServerMetricsTest.java b/common/src/test/java/org/astraea/common/metrics/broker/ServerMetricsTest.java index ff6c05f94f..cdd3d728a7 100644 --- a/common/src/test/java/org/astraea/common/metrics/broker/ServerMetricsTest.java +++ b/common/src/test/java/org/astraea/common/metrics/broker/ServerMetricsTest.java @@ -31,7 +31,7 @@ import org.astraea.common.consumer.Consumer; import org.astraea.common.consumer.ConsumerConfigs; import org.astraea.common.metrics.BeanObject; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MetricsTestUtils; import org.astraea.common.producer.Producer; import org.astraea.common.producer.Record; @@ -60,13 +60,13 @@ static void closeService() { @Test void testAppInfo() { - ServerMetrics.appInfo(MBeanClient.local()).forEach(MetricsTestUtils::validate); + ServerMetrics.appInfo(JndiClient.local()).forEach(MetricsTestUtils::validate); } @ParameterizedTest() @EnumSource(value = ServerMetrics.DelayedOperationPurgatory.class) void testPurgatorySize(ServerMetrics.DelayedOperationPurgatory request) { - var m = request.fetch(MBeanClient.local()); + var m = request.fetch(JndiClient.local()); Assertions.assertDoesNotThrow(m::value); MetricsTestUtils.validate(m); } @@ -74,17 +74,17 @@ void testPurgatorySize(ServerMetrics.DelayedOperationPurgatory request) { @ParameterizedTest() @EnumSource(value = ServerMetrics.KafkaServer.class) void testKafkaServer(ServerMetrics.KafkaServer request) { - MetricsTestUtils.validate(request.fetch(MBeanClient.local())); + MetricsTestUtils.validate(request.fetch(JndiClient.local())); } @Test void testKafkaServerOtherMetrics() { - MetricsTestUtils.validate(ServerMetrics.KafkaServer.CLUSTER_ID.fetch(MBeanClient.local())); + MetricsTestUtils.validate(ServerMetrics.KafkaServer.CLUSTER_ID.fetch(JndiClient.local())); } @Test void testSocketMetrics() { - var socketMetric = ServerMetrics.Socket.socket(MBeanClient.local()); + var socketMetric = ServerMetrics.Socket.socket(JndiClient.local()); assertDoesNotThrow(socketMetric::brokerConnectionAcceptRate); assertDoesNotThrow(socketMetric::memoryPoolAvgDepletedPercent); @@ -93,7 +93,7 @@ void testSocketMetrics() { @Test void testSocketListenerMetrics() { - var socketListenerMetrics = ServerMetrics.Socket.socketListener(MBeanClient.local()); + var socketListenerMetrics = ServerMetrics.Socket.socketListener(JndiClient.local()); assertTrue(socketListenerMetrics.size() > 0); socketListenerMetrics.forEach( x -> { @@ -108,7 +108,7 @@ void testSocketListenerMetrics() { @Test void testSocketNetworkProcessorMetrics() { var socketNetworkProcessorMetrics = - ServerMetrics.Socket.socketNetworkProcessor(MBeanClient.local()); + ServerMetrics.Socket.socketNetworkProcessor(JndiClient.local()); assertTrue(socketNetworkProcessorMetrics.size() > 0); socketNetworkProcessorMetrics.forEach( x -> { @@ -160,7 +160,7 @@ void testSocketNetworkProcessorMetrics() { @Test void testSocketClientMetrics() { - var clientMetrics = ServerMetrics.Socket.client(MBeanClient.local()); + var clientMetrics = ServerMetrics.Socket.client(JndiClient.local()); assertTrue(clientMetrics.size() > 0); clientMetrics.forEach( x -> { @@ -228,7 +228,7 @@ void testTopic(ServerMetrics.Topic topic) { var records = consumer.poll(Duration.ofSeconds(5)); Assertions.assertEquals(1, records.size()); } - var meters = topic.fetch(MBeanClient.local()); + var meters = topic.fetch(JndiClient.local()); Assertions.assertNotEquals(0, meters.size()); Assertions.assertNotEquals(0, meters.stream().filter(m -> m.topic().equals(name)).count()); meters.forEach( diff --git a/common/src/test/java/org/astraea/common/metrics/broker/ServerTopicMetricsTest.java b/common/src/test/java/org/astraea/common/metrics/broker/ServerTopicMetricsTest.java index 0b679c35a6..4e74c0c966 100644 --- a/common/src/test/java/org/astraea/common/metrics/broker/ServerTopicMetricsTest.java +++ b/common/src/test/java/org/astraea/common/metrics/broker/ServerTopicMetricsTest.java @@ -16,7 +16,7 @@ */ package org.astraea.common.metrics.broker; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MetricsTestUtils; import org.astraea.it.Service; import org.junit.jupiter.api.AfterAll; @@ -43,7 +43,7 @@ static void closeService() { @ParameterizedTest @EnumSource(value = ServerMetrics.BrokerTopic.class) void testRequestBrokerTopicMetrics(ServerMetrics.BrokerTopic metric) { - var meter = metric.fetch(MBeanClient.local()); + var meter = metric.fetch(JndiClient.local()); MetricsTestUtils.validate(meter); } } diff --git a/common/src/test/java/org/astraea/common/metrics/client/admin/AdminMetricsTest.java b/common/src/test/java/org/astraea/common/metrics/client/admin/AdminMetricsTest.java index 20ffea7cda..7336cc46f0 100644 --- a/common/src/test/java/org/astraea/common/metrics/client/admin/AdminMetricsTest.java +++ b/common/src/test/java/org/astraea/common/metrics/client/admin/AdminMetricsTest.java @@ -19,7 +19,7 @@ import java.time.Duration; import org.astraea.common.Utils; import org.astraea.common.admin.Admin; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.client.HasNodeMetrics; import org.astraea.it.Service; import org.junit.jupiter.api.AfterAll; @@ -41,7 +41,7 @@ void testMultiBrokers() { try (var admin = Admin.of(SERVICE.bootstrapServers())) { admin.creator().topic(topic).numberOfPartitions(3).run().toCompletableFuture().join(); Utils.sleep(Duration.ofSeconds(3)); - var metrics = AdminMetrics.node(MBeanClient.local()); + var metrics = AdminMetrics.node(JndiClient.local()); Assertions.assertNotEquals(1, metrics.size()); Assertions.assertTrue( metrics.stream() @@ -73,7 +73,7 @@ void testMetrics() { admin.creator().topic(topic).numberOfPartitions(3).run().toCompletableFuture().join(); Utils.sleep(Duration.ofSeconds(3)); var metrics = - AdminMetrics.admin(MBeanClient.local()).stream() + AdminMetrics.admin(JndiClient.local()).stream() .filter(m -> m.clientId().equals(admin.clientId())) .findFirst() .get(); diff --git a/common/src/test/java/org/astraea/common/metrics/client/consumer/ConsumerMetricsTest.java b/common/src/test/java/org/astraea/common/metrics/client/consumer/ConsumerMetricsTest.java index 4f69230ce9..59deccff13 100644 --- a/common/src/test/java/org/astraea/common/metrics/client/consumer/ConsumerMetricsTest.java +++ b/common/src/test/java/org/astraea/common/metrics/client/consumer/ConsumerMetricsTest.java @@ -22,7 +22,7 @@ import org.astraea.common.Utils; import org.astraea.common.admin.Admin; import org.astraea.common.consumer.Consumer; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MetricsTestUtils; import org.astraea.common.metrics.client.HasNodeMetrics; import org.astraea.it.Service; @@ -50,7 +50,7 @@ void testAppInfo() { admin.creator().topic(topic).numberOfPartitions(3).run().toCompletableFuture().join(); Utils.sleep(Duration.ofSeconds(3)); consumer.poll(Duration.ofSeconds(5)); - ConsumerMetrics.appInfo(MBeanClient.local()).forEach(MetricsTestUtils::validate); + ConsumerMetrics.appInfo(JndiClient.local()).forEach(MetricsTestUtils::validate); } } @@ -65,7 +65,7 @@ void testMultiBrokers() { admin.creator().topic(topic).numberOfPartitions(3).run().toCompletableFuture().join(); Utils.sleep(Duration.ofSeconds(3)); consumer.poll(Duration.ofSeconds(5)); - var metrics = ConsumerMetrics.node(MBeanClient.local()); + var metrics = ConsumerMetrics.node(JndiClient.local()); Assertions.assertNotEquals(1, metrics.size()); Assertions.assertTrue( metrics.stream() diff --git a/common/src/test/java/org/astraea/common/metrics/client/consumer/HasConsumerCoordinatorMetricsTest.java b/common/src/test/java/org/astraea/common/metrics/client/consumer/HasConsumerCoordinatorMetricsTest.java index 0008cdc179..111fb0459e 100644 --- a/common/src/test/java/org/astraea/common/metrics/client/consumer/HasConsumerCoordinatorMetricsTest.java +++ b/common/src/test/java/org/astraea/common/metrics/client/consumer/HasConsumerCoordinatorMetricsTest.java @@ -23,7 +23,7 @@ import org.astraea.common.Utils; import org.astraea.common.consumer.Consumer; import org.astraea.common.consumer.ConsumerConfigs; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.producer.Producer; import org.astraea.common.producer.Record; import org.astraea.it.Service; @@ -63,7 +63,7 @@ void testClientId() { .build()) { Assertions.assertEquals(10, consumer.poll(Duration.ofSeconds(5)).size()); consumer.commitOffsets(Duration.ofSeconds(2)); - var metrics = ConsumerMetrics.coordinator(MBeanClient.local()); + var metrics = ConsumerMetrics.coordinator(JndiClient.local()); Assertions.assertEquals(1, metrics.size()); var m = metrics.iterator().next(); Assertions.assertNotNull(m.clientId()); diff --git a/common/src/test/java/org/astraea/common/metrics/client/consumer/HasConsumerFetchMetricsTest.java b/common/src/test/java/org/astraea/common/metrics/client/consumer/HasConsumerFetchMetricsTest.java index 8efe4cbede..ecdc696f37 100644 --- a/common/src/test/java/org/astraea/common/metrics/client/consumer/HasConsumerFetchMetricsTest.java +++ b/common/src/test/java/org/astraea/common/metrics/client/consumer/HasConsumerFetchMetricsTest.java @@ -23,7 +23,7 @@ import org.astraea.common.Utils; import org.astraea.common.consumer.Consumer; import org.astraea.common.consumer.ConsumerConfigs; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.producer.Producer; import org.astraea.common.producer.Record; import org.astraea.it.Service; @@ -63,7 +63,7 @@ void testClientId() { .build()) { Assertions.assertEquals(10, consumer.poll(Duration.ofSeconds(5)).size()); consumer.commitOffsets(Duration.ofSeconds(2)); - var metrics = ConsumerMetrics.fetch(MBeanClient.local()); + var metrics = ConsumerMetrics.fetch(JndiClient.local()); Assertions.assertEquals(1, metrics.size()); var m = metrics.iterator().next(); Assertions.assertNotNull(m.clientId()); diff --git a/common/src/test/java/org/astraea/common/metrics/client/consumer/HasConsumerMetricsTest.java b/common/src/test/java/org/astraea/common/metrics/client/consumer/HasConsumerMetricsTest.java index 18014450e6..a423f5946b 100644 --- a/common/src/test/java/org/astraea/common/metrics/client/consumer/HasConsumerMetricsTest.java +++ b/common/src/test/java/org/astraea/common/metrics/client/consumer/HasConsumerMetricsTest.java @@ -23,7 +23,7 @@ import org.astraea.common.Utils; import org.astraea.common.consumer.Consumer; import org.astraea.common.consumer.ConsumerConfigs; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.producer.Producer; import org.astraea.common.producer.Record; import org.astraea.it.Service; @@ -63,7 +63,7 @@ void testClientId() { .build()) { Assertions.assertEquals(10, consumer.poll(Duration.ofSeconds(5)).size()); consumer.commitOffsets(Duration.ofSeconds(2)); - var metrics = ConsumerMetrics.consumer(MBeanClient.local()); + var metrics = ConsumerMetrics.consumer(JndiClient.local()); Assertions.assertEquals(1, metrics.size()); var m = metrics.iterator().next(); Assertions.assertNotNull(m.clientId()); diff --git a/common/src/test/java/org/astraea/common/metrics/client/producer/ProducerMetricsTest.java b/common/src/test/java/org/astraea/common/metrics/client/producer/ProducerMetricsTest.java index c4814c2bff..114c7f2d55 100644 --- a/common/src/test/java/org/astraea/common/metrics/client/producer/ProducerMetricsTest.java +++ b/common/src/test/java/org/astraea/common/metrics/client/producer/ProducerMetricsTest.java @@ -20,7 +20,7 @@ import java.util.stream.Collectors; import org.astraea.common.Utils; import org.astraea.common.admin.Admin; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MetricsTestUtils; import org.astraea.common.metrics.client.HasNodeMetrics; import org.astraea.common.producer.Producer; @@ -44,7 +44,7 @@ void testAppInfo() { var topic = Utils.randomString(10); try (var producer = Producer.of(SERVICE.bootstrapServers())) { producer.send(Record.builder().topic(topic).build()).toCompletableFuture().join(); - ProducerMetrics.appInfo(MBeanClient.local()).forEach(MetricsTestUtils::validate); + ProducerMetrics.appInfo(JndiClient.local()).forEach(MetricsTestUtils::validate); } } @@ -54,7 +54,7 @@ void testMetrics() { try (var producer = Producer.of(SERVICE.bootstrapServers())) { producer.send(Record.builder().topic(topic).build()).toCompletableFuture().join(); var metrics = - ProducerMetrics.producer(MBeanClient.local()).stream() + ProducerMetrics.producer(JndiClient.local()).stream() .filter(m -> m.clientId().equals(producer.clientId())) .findFirst() .get(); @@ -135,7 +135,7 @@ void testTopicMetrics() { var topic = Utils.randomString(10); try (var producer = Producer.of(SERVICE.bootstrapServers())) { producer.send(Record.builder().topic(topic).build()).toCompletableFuture().join(); - var metrics = ProducerMetrics.topic(MBeanClient.local()); + var metrics = ProducerMetrics.topic(JndiClient.local()); Assertions.assertNotEquals(0, metrics.stream().filter(m -> m.topic().equals(topic)).count()); var producerTopicMetrics = metrics.stream().filter(m -> m.clientId().equals(producer.clientId())).findFirst().get(); @@ -173,7 +173,7 @@ void testNodeMetrics() { .toCompletableFuture() .join(); - var metrics = ProducerMetrics.node(MBeanClient.local()); + var metrics = ProducerMetrics.node(JndiClient.local()); Assertions.assertNotEquals(1, metrics.size()); Assertions.assertTrue( metrics.stream() diff --git a/common/src/test/java/org/astraea/common/metrics/collector/LocalMetricsTest.java b/common/src/test/java/org/astraea/common/metrics/collector/LocalMetricsTest.java index cc7c79210d..0f561d57ef 100644 --- a/common/src/test/java/org/astraea/common/metrics/collector/LocalMetricsTest.java +++ b/common/src/test/java/org/astraea/common/metrics/collector/LocalMetricsTest.java @@ -21,7 +21,7 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; import org.astraea.common.Utils; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.it.Service; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; @@ -42,7 +42,7 @@ void test() { try (var store = MetricStore.builder() .beanExpiration(Duration.ofSeconds(1)) - .localReceiver(() -> CompletableFuture.completedStage(Map.of(-1, MBeanClient.local()))) + .localReceiver(() -> CompletableFuture.completedStage(Map.of(-1, JndiClient.local()))) .build()) { Utils.sleep(Duration.ofSeconds(3)); Assertions.assertNotEquals(0, store.clusterBean().all().size()); diff --git a/common/src/test/java/org/astraea/common/metrics/collector/MetricFetcherTest.java b/common/src/test/java/org/astraea/common/metrics/collector/MetricFetcherTest.java index 74e5cdb260..af04f030ad 100644 --- a/common/src/test/java/org/astraea/common/metrics/collector/MetricFetcherTest.java +++ b/common/src/test/java/org/astraea/common/metrics/collector/MetricFetcherTest.java @@ -33,6 +33,7 @@ import org.astraea.common.consumer.Deserializer; import org.astraea.common.consumer.SeekStrategy; import org.astraea.common.metrics.BeanObject; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.MBeanClient; import org.astraea.it.Service; import org.junit.jupiter.api.AfterAll; @@ -51,7 +52,7 @@ static void close() { @Test void testPublishAndClose() { var beans = List.of(new BeanObject(Utils.randomString(), Map.of(), Map.of())); - var client = Mockito.mock(MBeanClient.class); + var client = Mockito.mock(JndiClient.class); Mockito.when(client.beans(Mockito.any(), Mockito.any())).thenReturn(beans); var sender = Mockito.mock(MetricFetcher.Sender.class); var queue = new ConcurrentHashMap>(); @@ -105,7 +106,7 @@ void testNullCheck() { @Test void testFetchBeanDelay() { - var client = Mockito.mock(MBeanClient.class); + var client = Mockito.mock(JndiClient.class); try (var fetcher = MetricFetcher.builder() .sender(MetricFetcher.Sender.local()) diff --git a/common/src/test/java/org/astraea/common/metrics/collector/MetricSensorTest.java b/common/src/test/java/org/astraea/common/metrics/collector/MetricSensorTest.java index a2114c1157..75b9da83c7 100644 --- a/common/src/test/java/org/astraea/common/metrics/collector/MetricSensorTest.java +++ b/common/src/test/java/org/astraea/common/metrics/collector/MetricSensorTest.java @@ -21,7 +21,7 @@ import java.util.Optional; import org.astraea.common.metrics.ClusterBean; import org.astraea.common.metrics.HasBeanObject; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -37,7 +37,7 @@ void testMultipleSensors() { var sensor = MetricSensor.of(List.of(metricSensor0, metricSensor1)).get(); - var result = sensor.fetch(Mockito.mock(MBeanClient.class), ClusterBean.EMPTY); + var result = sensor.fetch(Mockito.mock(JndiClient.class), ClusterBean.EMPTY); Assertions.assertEquals(2, result.size()); Assertions.assertTrue(result.contains(mbean0)); @@ -68,7 +68,7 @@ void testNoSwallowException() { .get(); Assertions.assertThrows( RuntimeException.class, - () -> sensor.fetch(Mockito.mock(MBeanClient.class), ClusterBean.EMPTY)); + () -> sensor.fetch(Mockito.mock(JndiClient.class), ClusterBean.EMPTY)); } @Test @@ -86,15 +86,15 @@ void testSensorsWithExceptionHandler() { var sensor = MetricSensor.of(List.of(metricSensor0, metricSensor1)).get(); Assertions.assertDoesNotThrow( - () -> sensor.fetch(Mockito.mock(MBeanClient.class), ClusterBean.EMPTY)); + () -> sensor.fetch(Mockito.mock(JndiClient.class), ClusterBean.EMPTY)); Assertions.assertEquals( - 1, sensor.fetch(Mockito.mock(MBeanClient.class), ClusterBean.EMPTY).size()); + 1, sensor.fetch(Mockito.mock(JndiClient.class), ClusterBean.EMPTY).size()); Assertions.assertDoesNotThrow( () -> MetricSensor.of(List.of(metricSensor0, metricSensor2)) .get() - .fetch(Mockito.mock(MBeanClient.class), ClusterBean.EMPTY)); + .fetch(Mockito.mock(JndiClient.class), ClusterBean.EMPTY)); Assertions.assertThrows( NoSuchElementException.class, () -> @@ -104,6 +104,6 @@ void testSensorsWithExceptionHandler() { if (e instanceof NoSuchElementException) throw new NoSuchElementException(); }) .get() - .fetch(Mockito.mock(MBeanClient.class), ClusterBean.EMPTY)); + .fetch(Mockito.mock(JndiClient.class), ClusterBean.EMPTY)); } } diff --git a/common/src/test/java/org/astraea/common/metrics/connector/ConnectorMetricsTest.java b/common/src/test/java/org/astraea/common/metrics/connector/ConnectorMetricsTest.java index 67ce636855..164ed2b435 100644 --- a/common/src/test/java/org/astraea/common/metrics/connector/ConnectorMetricsTest.java +++ b/common/src/test/java/org/astraea/common/metrics/connector/ConnectorMetricsTest.java @@ -17,7 +17,7 @@ package org.astraea.common.metrics.connector; import org.astraea.common.connector.ConnectorClient; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.it.Service; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; @@ -36,7 +36,7 @@ static void closeService() { void testMetrics() { ConnectorClient.builder().url(SERVICE.workerUrl()).build(); - var m0 = ConnectorMetrics.appInfo(MBeanClient.local()); + var m0 = ConnectorMetrics.appInfo(JndiClient.local()); Assertions.assertNotEquals(0, m0.size()); m0.forEach( m -> { @@ -45,7 +45,7 @@ void testMetrics() { Assertions.assertDoesNotThrow(m::version); }); - var m1 = ConnectorMetrics.coordinatorInfo(MBeanClient.local()); + var m1 = ConnectorMetrics.coordinatorInfo(JndiClient.local()); Assertions.assertNotEquals(0, m1.size()); m1.forEach( m -> { @@ -73,7 +73,7 @@ void testMetrics() { Assertions.assertDoesNotThrow(m::assignedTasks); }); - var m2 = ConnectorMetrics.connector(MBeanClient.local()); + var m2 = ConnectorMetrics.connector(JndiClient.local()); Assertions.assertNotEquals(0, m2.size()); m2.forEach( m -> { @@ -115,7 +115,7 @@ void testMetrics() { Assertions.assertDoesNotThrow(m::successfulReauthenticationTotal); }); - var m3 = ConnectorMetrics.nodeInfo(MBeanClient.local()); + var m3 = ConnectorMetrics.nodeInfo(JndiClient.local()); Assertions.assertNotEquals(0, m3.size()); m3.forEach( m -> { @@ -133,7 +133,7 @@ void testMetrics() { Assertions.assertDoesNotThrow(m::responseTotal); }); - var m4 = ConnectorMetrics.workerInfo(MBeanClient.local()); + var m4 = ConnectorMetrics.workerInfo(JndiClient.local()); Assertions.assertNotEquals(0, m4.size()); m4.forEach( m -> { @@ -151,7 +151,7 @@ void testMetrics() { Assertions.assertDoesNotThrow(m::taskStartupSuccessTotal); }); - var m5 = ConnectorMetrics.workerRebalanceInfo(MBeanClient.local()); + var m5 = ConnectorMetrics.workerRebalanceInfo(JndiClient.local()); Assertions.assertNotEquals(0, m5.size()); m5.forEach( m -> { diff --git a/common/src/test/java/org/astraea/common/metrics/platform/HostMetricsTest.java b/common/src/test/java/org/astraea/common/metrics/platform/HostMetricsTest.java index da6028790c..76bdb0990e 100644 --- a/common/src/test/java/org/astraea/common/metrics/platform/HostMetricsTest.java +++ b/common/src/test/java/org/astraea/common/metrics/platform/HostMetricsTest.java @@ -19,7 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.condition.OS.WINDOWS; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledOnOs; @@ -27,7 +27,7 @@ public class HostMetricsTest { @Test void operatingSystem() { - var operatingSystemInfo = HostMetrics.operatingSystem(MBeanClient.local()); + var operatingSystemInfo = HostMetrics.operatingSystem(JndiClient.local()); assertDoesNotThrow(operatingSystemInfo::arch); assertDoesNotThrow(operatingSystemInfo::availableProcessors); assertDoesNotThrow(operatingSystemInfo::committedVirtualMemorySize); @@ -46,20 +46,20 @@ void operatingSystem() { @Test @DisabledOnOs(WINDOWS) void maxFileDescriptorCount() { - OperatingSystemInfo operatingSystemInfo = HostMetrics.operatingSystem(MBeanClient.local()); + OperatingSystemInfo operatingSystemInfo = HostMetrics.operatingSystem(JndiClient.local()); assertDoesNotThrow(operatingSystemInfo::maxFileDescriptorCount); } @Test @DisabledOnOs(WINDOWS) void openFileDescriptorCount() { - OperatingSystemInfo operatingSystemInfo = HostMetrics.operatingSystem(MBeanClient.local()); + OperatingSystemInfo operatingSystemInfo = HostMetrics.operatingSystem(JndiClient.local()); assertDoesNotThrow(operatingSystemInfo::openFileDescriptorCount); } @Test void testJvmMemory() { - JvmMemory jvmMemory = HostMetrics.jvmMemory(MBeanClient.local()); + JvmMemory jvmMemory = HostMetrics.jvmMemory(JndiClient.local()); assertDoesNotThrow(() -> jvmMemory.heapMemoryUsage().getCommitted()); assertDoesNotThrow(() -> jvmMemory.heapMemoryUsage().getMax()); assertDoesNotThrow(() -> jvmMemory.heapMemoryUsage().getUsed()); diff --git a/connector/src/test/java/org/astraea/connector/perf/PerfSinkTest.java b/connector/src/test/java/org/astraea/connector/perf/PerfSinkTest.java index 23a2ac4919..9cca7d93ec 100644 --- a/connector/src/test/java/org/astraea/connector/perf/PerfSinkTest.java +++ b/connector/src/test/java/org/astraea/connector/perf/PerfSinkTest.java @@ -25,7 +25,7 @@ import org.astraea.common.connector.ConnectorClient; import org.astraea.common.connector.ConnectorConfigs; import org.astraea.common.consumer.Record; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.connector.ConnectorMetrics; import org.astraea.it.Service; import org.junit.jupiter.api.AfterAll; @@ -132,7 +132,7 @@ void testMetrics() { Utils.sleep(Duration.ofSeconds(3)); var m0 = - ConnectorMetrics.sinkTaskInfo(MBeanClient.local()).stream() + ConnectorMetrics.sinkTaskInfo(JndiClient.local()).stream() .filter(m -> m.connectorName().equals(name)) .collect(Collectors.toList()); Assertions.assertNotEquals(0, m0.size()); @@ -158,7 +158,7 @@ void testMetrics() { }); var m1 = - ConnectorMetrics.taskError(MBeanClient.local()).stream() + ConnectorMetrics.taskError(JndiClient.local()).stream() .filter(m -> m.connectorName().equals(name)) .collect(Collectors.toList()); Assertions.assertNotEquals(0, m1.size()); @@ -175,7 +175,7 @@ void testMetrics() { }); var m2 = - ConnectorMetrics.connectorTaskInfo(MBeanClient.local()).stream() + ConnectorMetrics.connectorTaskInfo(JndiClient.local()).stream() .filter(m -> m.connectorName().equals(name)) .collect(Collectors.toList()); Assertions.assertEquals(1, m2.size()); @@ -195,7 +195,7 @@ void testMetrics() { }); var m3 = - ConnectorMetrics.workerConnectorInfo(MBeanClient.local()).stream() + ConnectorMetrics.workerConnectorInfo(JndiClient.local()).stream() .filter(m -> m.connectorName().equals(name)) .collect(Collectors.toList()); Assertions.assertEquals(1, m3.size()); @@ -211,7 +211,7 @@ void testMetrics() { }); var m4 = - ConnectorMetrics.connectorInfo(MBeanClient.local()).stream() + ConnectorMetrics.connectorInfo(JndiClient.local()).stream() .filter(m -> m.connectorName().equals(name)) .collect(Collectors.toList()); Assertions.assertEquals(1, m4.size()); diff --git a/connector/src/test/java/org/astraea/connector/perf/PerfSourceTest.java b/connector/src/test/java/org/astraea/connector/perf/PerfSourceTest.java index 6808d72c5b..27c0f57b67 100644 --- a/connector/src/test/java/org/astraea/connector/perf/PerfSourceTest.java +++ b/connector/src/test/java/org/astraea/connector/perf/PerfSourceTest.java @@ -28,7 +28,7 @@ import org.astraea.common.admin.TopicPartition; import org.astraea.common.connector.ConnectorClient; import org.astraea.common.connector.ConnectorConfigs; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.connector.ConnectorMetrics; import org.astraea.connector.MetadataStorage; import org.astraea.connector.SourceConnector; @@ -241,7 +241,7 @@ void testMetrics() { Utils.sleep(Duration.ofSeconds(3)); var m0 = - ConnectorMetrics.sourceTaskInfo(MBeanClient.local()).stream() + ConnectorMetrics.sourceTaskInfo(JndiClient.local()).stream() .filter(m -> m.connectorName().equals(name)) .collect(Collectors.toList()); Assertions.assertNotEquals(0, m0.size()); @@ -262,7 +262,7 @@ void testMetrics() { }); var m1 = - ConnectorMetrics.taskError(MBeanClient.local()).stream() + ConnectorMetrics.taskError(JndiClient.local()).stream() .filter(m -> m.connectorName().equals(name)) .collect(Collectors.toList()); Assertions.assertNotEquals(0, m1.size()); @@ -279,7 +279,7 @@ void testMetrics() { }); var m2 = - ConnectorMetrics.connectorTaskInfo(MBeanClient.local()).stream() + ConnectorMetrics.connectorTaskInfo(JndiClient.local()).stream() .filter(m -> m.connectorName().equals(name)) .collect(Collectors.toList()); Assertions.assertEquals(1, m2.size()); @@ -299,7 +299,7 @@ void testMetrics() { }); var m3 = - ConnectorMetrics.workerConnectorInfo(MBeanClient.local()).stream() + ConnectorMetrics.workerConnectorInfo(JndiClient.local()).stream() .filter(m -> m.connectorName().equals(name)) .collect(Collectors.toList()); Assertions.assertEquals(1, m3.size()); @@ -315,7 +315,7 @@ void testMetrics() { }); var m4 = - ConnectorMetrics.connectorInfo(MBeanClient.local()).stream() + ConnectorMetrics.connectorInfo(JndiClient.local()).stream() .filter(m -> m.connectorName().equals(name)) .collect(Collectors.toList()); Assertions.assertEquals(1, m4.size()); diff --git a/gui/src/main/java/org/astraea/gui/Context.java b/gui/src/main/java/org/astraea/gui/Context.java index ead99959c9..ecf305b7a3 100644 --- a/gui/src/main/java/org/astraea/gui/Context.java +++ b/gui/src/main/java/org/astraea/gui/Context.java @@ -26,7 +26,7 @@ import org.astraea.common.admin.Admin; import org.astraea.common.admin.NodeInfo; import org.astraea.common.connector.ConnectorClient; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; public class Context { private final AtomicReference adminReference = new AtomicReference<>(); @@ -63,32 +63,32 @@ public void replace(ConnectorClient connectorClient) { } public void brokerJmxPort(int brokerJmxPort) { - if (brokerClients != null) brokerClients.clients.values().forEach(MBeanClient::close); + if (brokerClients != null) brokerClients.clients.values().forEach(JndiClient::close); brokerClients = new Clients<>(brokerJmxPort); } public void workerJmxPort(int workerJmxPort) { - if (workerClients != null) workerClients.clients.values().forEach(MBeanClient::close); + if (workerClients != null) workerClients.clients.values().forEach(JndiClient::close); workerClients = new Clients<>(workerJmxPort); } @SuppressWarnings("resource") - public Map addBrokerClients(List nodeInfos) { + public Map addBrokerClients(List nodeInfos) { if (brokerClients == null) return Map.of(); nodeInfos.forEach( n -> brokerClients.clients.computeIfAbsent( - n.id(), ignored -> MBeanClient.jndi(n.host(), brokerClients.jmxPort))); + n.id(), ignored -> JndiClient.of(n.host(), brokerClients.jmxPort))); return Map.copyOf(brokerClients.clients); } @SuppressWarnings("resource") - public Map addWorkerClients(Set hostnames) { + public Map addWorkerClients(Set hostnames) { if (workerClients == null) return Map.of(); hostnames.forEach( n -> workerClients.clients.computeIfAbsent( - n, ignored -> MBeanClient.jndi(n, workerClients.jmxPort))); + n, ignored -> JndiClient.of(n, workerClients.jmxPort))); return Map.copyOf(workerClients.clients); } @@ -104,19 +104,19 @@ public ConnectorClient connectorClient() { return connectorClient; } - public Map brokerClients() { + public Map brokerClients() { if (brokerClients == null) return Map.of(); return Map.copyOf(brokerClients.clients); } - public Map workerClients() { + public Map workerClients() { if (workerClients == null) return Map.of(); return Map.copyOf(workerClients.clients); } private static class Clients> { private final int jmxPort; - private final Map clients = new ConcurrentHashMap<>(); + private final Map clients = new ConcurrentHashMap<>(); Clients(int jmxPort) { this.jmxPort = jmxPort; diff --git a/gui/src/main/java/org/astraea/gui/tab/BrokerNode.java b/gui/src/main/java/org/astraea/gui/tab/BrokerNode.java index a47e7fd2a7..d66ac07ae0 100644 --- a/gui/src/main/java/org/astraea/gui/tab/BrokerNode.java +++ b/gui/src/main/java/org/astraea/gui/tab/BrokerNode.java @@ -40,7 +40,7 @@ import org.astraea.common.admin.BrokerConfigs; import org.astraea.common.admin.NodeInfo; import org.astraea.common.admin.TopicPartition; -import org.astraea.common.metrics.MBeanClient; +import org.astraea.common.metrics.JndiClient; import org.astraea.common.metrics.broker.ControllerMetrics; import org.astraea.common.metrics.broker.HasGauge; import org.astraea.common.metrics.broker.HasStatistics; @@ -196,10 +196,10 @@ private enum MetricType { } }))); - private final Function> fetcher; + private final Function> fetcher; private final String display; - MetricType(String display, Function> fetcher) { + MetricType(String display, Function> fetcher) { this.display = display; this.fetcher = fetcher; }