Skip to content

Commit

Permalink
[INLONG-1796]DataProxy support monitor indicator with JMX. #1796 (#1797)
Browse files Browse the repository at this point in the history
* [Feature]DataProxy support monitor indicator with JMX. #1796

* [Feature]DataProxy support monitor indicator with JMX. #1796

* [Feature]DataProxy support monitor indicator with JMX. #1796

* [Feature]DataProxy support monitor indicator with JMX. #1796

* fix PR reviews.

* fix PR reviews.

* fix checkstyle problem.

* add more unit test case.

* add apache licenses.

* fix checkstyle problem.

* fix checkstyle problem.
  • Loading branch information
luchunliang committed Nov 18, 2021
1 parent 20aa154 commit e117b3c
Show file tree
Hide file tree
Showing 51 changed files with 4,353 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,28 @@
*/
public abstract class MetricItemSet<T extends MetricItem> implements MetricItemSetMBean {

protected String name;

protected Map<String, T> itemMap = new ConcurrentHashMap<>();

/**
* Constructor
*
* @param name
*/
public MetricItemSet(String name) {
this.name = name;
}

/**
* getName
*
* @return
*/
public String getName() {
return name;
}

/**
* createItem
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public static void register(MetricItem obj) {
public static void register(MetricItemSet<? extends MetricItem> obj) {
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
StringBuilder beanName = new StringBuilder();
beanName.append(MetricUtils.getDomain(obj.getClass())).append(MetricItemMBean.DOMAIN_SEPARATOR).append("type=")
.append(obj.getClass().toString());
beanName.append(MetricUtils.getDomain(obj.getClass())).append(MetricItemMBean.DOMAIN_SEPARATOR).append("name=")
.append(obj.getName());
String strBeanName = beanName.toString();
try {
ObjectName objName = new ObjectName(strBeanName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class DataProxyMetricItemSet extends MetricItemSet<DataProxyMetricItem> {
* Constructor
*/
private DataProxyMetricItemSet() {
super("DataProxy");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public void testResult() throws Exception {
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
StringBuilder beanName = new StringBuilder();
beanName.append(MetricUtils.getDomain(DataProxyMetricItemSet.class)).append(MetricItemMBean.DOMAIN_SEPARATOR)
.append("type=")
.append(DataProxyMetricItemSet.class.toString());
.append("name=")
.append(itemSet.getName());
String strBeanName = beanName.toString();
ObjectName objName = new ObjectName(strBeanName);
{
Expand Down
106 changes: 59 additions & 47 deletions inlong-dataproxy/dataproxy-source/pom.xml
Original file line number Diff line number Diff line change
@@ -1,53 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<!-- 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. -->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache.inlong</groupId>
<artifactId>inlong-dataproxy</artifactId>
<version>0.12.0-incubating-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>Apache InLong - DataProxy Source</name>
<artifactId>dataproxy-source</artifactId>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<guava.version>19.0</guava.version>
</properties>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache.inlong</groupId>
<artifactId>inlong-dataproxy</artifactId>
<version>0.12.0-incubating-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>Apache InLong - DataProxy Source</name>
<artifactId>dataproxy-source</artifactId>

<dependencies>
<dependency>
<groupId>org.apache.inlong</groupId>
<artifactId>tubemq-client</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler.source>1.8</compiler.source>
<compiler.target>1.8</compiler.target>
<junit.version>4.13</junit.version>
<guava.version>19.0</guava.version>
<skipTests>false</skipTests>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.inlong</groupId>
<artifactId>tubemq-client</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
* 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.apache.inlong.dataproxy.config.holder;

import static org.apache.inlong.dataproxy.config.loader.CacheClusterConfigLoader.CACHE_CLUSTER_CONFIG_TYPE;
import static org.apache.inlong.dataproxy.config.loader.ConfigLoader.RELOAD_INTERVAL;

import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import org.apache.commons.lang.ClassUtils;
import org.apache.flume.Context;
import org.apache.flume.conf.Configurable;
import org.apache.inlong.dataproxy.config.loader.CacheClusterConfigLoader;
import org.apache.inlong.dataproxy.config.loader.ContextCacheClusterConfigLoader;
import org.apache.inlong.dataproxy.config.pojo.CacheClusterConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
* CacheClusterConfigHolder
*/
public class CacheClusterConfigHolder implements Configurable {

public static final Logger LOG = LoggerFactory.getLogger(CacheClusterConfigHolder.class);

protected Context context;
private long reloadInterval;
private Timer reloadTimer;
private CacheClusterConfigLoader loader;

private List<CacheClusterConfig> configList;

/**
* configure
*
* @param context
*/
@Override
public void configure(Context context) {
this.context = context;
this.reloadInterval = context.getLong(RELOAD_INTERVAL, 60000L);
String loaderType = context.getString(CACHE_CLUSTER_CONFIG_TYPE,
ContextCacheClusterConfigLoader.class.getName());
try {
Class<?> loaderClass = ClassUtils.getClass(loaderType);
Object loaderObject = loaderClass.getDeclaredConstructor().newInstance();
if (loaderObject instanceof CacheClusterConfigLoader) {
this.loader = (CacheClusterConfigLoader) loaderObject;
}
} catch (Throwable t) {
LOG.error("Fail to init loader,loaderType:{},error:{}", loaderType, t.getMessage());
LOG.error(t.getMessage(), t);
}
if (this.loader == null) {
this.loader = new ContextCacheClusterConfigLoader();
}
this.loader.configure(context);
}

/**
* start
*/
public void start() {
try {
this.reload();
this.setReloadTimer();
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}

/**
* close
*/
public void close() {
try {
this.reloadTimer.cancel();
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}

/**
* setReloadTimer
*/
private void setReloadTimer() {
reloadTimer = new Timer(true);
TimerTask task = new TimerTask() {

/**
* run
*/
public void run() {
reload();
}
};
reloadTimer.schedule(task, new Date(System.currentTimeMillis() + reloadInterval), reloadInterval);
}

/**
* reload
*/
public void reload() {
try {
this.configList = this.loader.load();
} catch (Throwable e) {
LOG.error(e.getMessage(), e);
}
}

/**
* get configList
*
* @return the configList
*/
public List<CacheClusterConfig> getConfigList() {
return configList;
}

}
Loading

0 comments on commit e117b3c

Please sign in to comment.