You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by zz...@apache.org on 2014/09/02 22:45:18 UTC
git commit: [HELIX-512] add back
HelixManager#getHealthReportCollector() interface to 0.6.x
Repository: helix
Updated Branches:
refs/heads/helix-0.6.x 315ffa9b6 -> 5ae03d975
[HELIX-512] add back HelixManager#getHealthReportCollector() interface to 0.6.x
Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/5ae03d97
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/5ae03d97
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/5ae03d97
Branch: refs/heads/helix-0.6.x
Commit: 5ae03d9755b77a06e6b966b699c4fd63dc163735
Parents: 315ffa9
Author: zzhang <zz...@apache.org>
Authored: Tue Sep 2 13:44:32 2014 -0700
Committer: zzhang <zz...@apache.org>
Committed: Tue Sep 2 13:44:32 2014 -0700
----------------------------------------------------------------------
.../java/org/apache/helix/HelixManager.java | 8 +
.../main/java/org/apache/helix/PropertyKey.java | 20 +++
.../ParticipantHealthReportCollector.java | 32 ++++
.../ParticipantHealthReportCollectorImpl.java | 109 ++++++++++++++
.../ParticipantHealthReportTask.java | 71 +++++++++
.../apache/helix/manager/zk/ZKHelixManager.java | 19 +++
.../java/org/apache/helix/model/HealthStat.java | 147 +++++++++++++++++++
.../src/test/java/org/apache/helix/Mocks.java | 7 +
.../controller/stages/DummyClusterManager.java | 7 +
...estParticipantHealthReportCollectorImpl.java | 86 +++++++++++
.../helix/participant/MockZKHelixManager.java | 7 +
11 files changed, 513 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/helix/blob/5ae03d97/helix-core/src/main/java/org/apache/helix/HelixManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/HelixManager.java b/helix-core/src/main/java/org/apache/helix/HelixManager.java
index b4d918b..25c29e6 100644
--- a/helix-core/src/main/java/org/apache/helix/HelixManager.java
+++ b/helix-core/src/main/java/org/apache/helix/HelixManager.java
@@ -22,6 +22,7 @@ package org.apache.helix;
import java.util.List;
import org.apache.helix.controller.GenericHelixController;
+import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
import org.apache.helix.manager.zk.ZKHelixManager;
import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
import org.apache.helix.participant.HelixStateMachineEngine;
@@ -287,4 +288,11 @@ public interface HelixManager {
* @param liveInstanceInfoProvider
*/
void setLiveInstanceInfoProvider(LiveInstanceInfoProvider liveInstanceInfoProvider);
+
+ /**
+ * Participant only component that periodically update participant health
+ * report to cluster manager server.
+ * @return ParticipantHealthReportCollector
+ */
+ ParticipantHealthReportCollector getHealthReportCollector();
}
http://git-wip-us.apache.org/repos/asf/helix/blob/5ae03d97/helix-core/src/main/java/org/apache/helix/PropertyKey.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/PropertyKey.java b/helix-core/src/main/java/org/apache/helix/PropertyKey.java
index f4e47a0..a394b50 100644
--- a/helix-core/src/main/java/org/apache/helix/PropertyKey.java
+++ b/helix-core/src/main/java/org/apache/helix/PropertyKey.java
@@ -42,6 +42,7 @@ import org.apache.helix.model.ClusterConstraints;
import org.apache.helix.model.CurrentState;
import org.apache.helix.model.Error;
import org.apache.helix.model.ExternalView;
+import org.apache.helix.model.HealthStat;
import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.InstanceConfig;
@@ -592,6 +593,25 @@ public class PropertyKey {
public PropertyKey pause() {
return new PropertyKey(PAUSE, PauseSignal.class, _clusterName);
}
+
+ /**
+ * Get a property key associated with a {@link HealthStat} for an instance
+ * @param instanceName
+ * @param id identifies the statistics
+ * @return {@link PropertyKey}
+ */
+ public PropertyKey healthReport(String instanceName, String id) {
+ return new PropertyKey(PropertyType.HEALTHREPORT, HealthStat.class, _clusterName, instanceName, id);
+ }
+
+ /**
+ * Get a property key associated with {@link HealthStat}s for an instance
+ * @param instanceName
+ * @return {@link PropertyKey}
+ */
+ public PropertyKey healthReports(String instanceName) {
+ return new PropertyKey(PropertyType.HEALTHREPORT, HealthStat.class, _clusterName, instanceName);
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/helix/blob/5ae03d97/helix-core/src/main/java/org/apache/helix/healthcheck/ParticipantHealthReportCollector.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/healthcheck/ParticipantHealthReportCollector.java b/helix-core/src/main/java/org/apache/helix/healthcheck/ParticipantHealthReportCollector.java
new file mode 100644
index 0000000..5ba6cb4
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/healthcheck/ParticipantHealthReportCollector.java
@@ -0,0 +1,32 @@
+package org.apache.helix.healthcheck;
+
+/*
+ * 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.
+ */
+
+import org.apache.helix.ZNRecord;
+
+public interface ParticipantHealthReportCollector {
+ void addHealthReportProvider(HealthReportProvider provider);
+
+ void removeHealthReportProvider(HealthReportProvider provider);
+
+ void reportHealthReportMessage(ZNRecord healthReport);
+
+ void transmitHealthReports();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/helix/blob/5ae03d97/helix-core/src/main/java/org/apache/helix/healthcheck/ParticipantHealthReportCollectorImpl.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/healthcheck/ParticipantHealthReportCollectorImpl.java b/helix-core/src/main/java/org/apache/helix/healthcheck/ParticipantHealthReportCollectorImpl.java
new file mode 100644
index 0000000..16a2ea8
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/healthcheck/ParticipantHealthReportCollectorImpl.java
@@ -0,0 +1,109 @@
+package org.apache.helix.healthcheck;
+
+/*
+ * 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.
+ */
+
+import java.util.LinkedList;
+import java.util.Map;
+
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixManager;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.PropertyKey.Builder;
+import org.apache.helix.model.HealthStat;
+import org.apache.log4j.Logger;
+
+public class ParticipantHealthReportCollectorImpl implements ParticipantHealthReportCollector {
+ private final LinkedList<HealthReportProvider> _healthReportProviderList =
+ new LinkedList<HealthReportProvider>();
+ private static final Logger _logger = Logger
+ .getLogger(ParticipantHealthReportCollectorImpl.class);
+ private final HelixManager _helixManager;
+ String _instanceName;
+
+ public ParticipantHealthReportCollectorImpl(HelixManager helixManager, String instanceName) {
+ _helixManager = helixManager;
+ _instanceName = instanceName;
+ }
+
+ @Override
+ public void addHealthReportProvider(HealthReportProvider provider) {
+ try {
+ synchronized (_healthReportProviderList) {
+ if (!_healthReportProviderList.contains(provider)) {
+ _healthReportProviderList.add(provider);
+ } else {
+ _logger.warn("Skipping a duplicated HealthCheckInfoProvider");
+ }
+ }
+ } catch (Exception e) {
+ _logger.error(e);
+ }
+ }
+
+ @Override
+ public void removeHealthReportProvider(HealthReportProvider provider) {
+ synchronized (_healthReportProviderList) {
+ if (_healthReportProviderList.contains(provider)) {
+ _healthReportProviderList.remove(provider);
+ } else {
+ _logger.warn("Skip removing a non-exist HealthCheckInfoProvider");
+ }
+ }
+ }
+
+ @Override
+ public void reportHealthReportMessage(ZNRecord healthCheckInfoUpdate) {
+ HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
+ Builder keyBuilder = accessor.keyBuilder();
+ accessor.setProperty(keyBuilder.healthReport(_instanceName, healthCheckInfoUpdate.getId()),
+ new HealthStat(healthCheckInfoUpdate));
+
+ }
+
+ @Override
+ public synchronized void transmitHealthReports() {
+ synchronized (_healthReportProviderList) {
+ for (HealthReportProvider provider : _healthReportProviderList) {
+ try {
+ Map<String, String> report = provider.getRecentHealthReport();
+ Map<String, Map<String, String>> partitionReport =
+ provider.getRecentPartitionHealthReport();
+ ZNRecord record = new ZNRecord(provider.getReportName());
+ if (report != null) {
+ record.setSimpleFields(report);
+ }
+ if (partitionReport != null) {
+ record.setMapFields(partitionReport);
+ }
+ record.setSimpleField(HealthStat.TIMESTAMP_NAME, "" + System.currentTimeMillis());
+
+ HelixDataAccessor accessor = _helixManager.getHelixDataAccessor();
+ Builder keyBuilder = accessor.keyBuilder();
+ accessor.setProperty(keyBuilder.healthReport(_instanceName, record.getId()),
+ new HealthStat(record));
+
+ provider.resetStats();
+ } catch (Exception e) {
+ _logger.error("fail to transmit health report", e);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/helix/blob/5ae03d97/helix-core/src/main/java/org/apache/helix/healthcheck/ParticipantHealthReportTask.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/healthcheck/ParticipantHealthReportTask.java b/helix-core/src/main/java/org/apache/helix/healthcheck/ParticipantHealthReportTask.java
new file mode 100644
index 0000000..f1c4c24
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/healthcheck/ParticipantHealthReportTask.java
@@ -0,0 +1,71 @@
+package org.apache.helix.healthcheck;
+
+/*
+ * 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.
+ */
+
+import java.util.Random;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.apache.helix.HelixTimerTask;
+import org.apache.log4j.Logger;
+
+public class ParticipantHealthReportTask extends HelixTimerTask {
+ private static final Logger LOG = Logger.getLogger(ParticipantHealthReportTask.class);
+ public final static int DEFAULT_REPORT_LATENCY = 60 * 1000;
+
+ Timer _timer;
+ final ParticipantHealthReportCollectorImpl _healthReportCollector;
+
+ class ParticipantHealthReportTimerTask extends TimerTask {
+
+ @Override
+ public void run() {
+ _healthReportCollector.transmitHealthReports();
+ }
+ }
+
+ public ParticipantHealthReportTask(ParticipantHealthReportCollectorImpl healthReportCollector) {
+ _healthReportCollector = healthReportCollector;
+ }
+
+ @Override
+ public void start() {
+ if (_timer == null) {
+ LOG.info("Start HealthCheckInfoReportingTask");
+ _timer = new Timer("ParticipantHealthReportTimerTask", true);
+ _timer.scheduleAtFixedRate(new ParticipantHealthReportTimerTask(),
+ new Random().nextInt(DEFAULT_REPORT_LATENCY), DEFAULT_REPORT_LATENCY);
+ } else {
+ LOG.warn("ParticipantHealthReportTimerTask already started");
+ }
+ }
+
+ @Override
+ public void stop() {
+ if (_timer != null) {
+ LOG.info("Stop ParticipantHealthReportTimerTask");
+ _timer.cancel();
+ _timer = null;
+ } else {
+ LOG.warn("ParticipantHealthReportTimerTask already stopped");
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/helix/blob/5ae03d97/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
index cc24656..6c3923a 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
@@ -56,6 +56,9 @@ import org.apache.helix.PropertyType;
import org.apache.helix.ScopedConfigChangeListener;
import org.apache.helix.ZNRecord;
import org.apache.helix.controller.GenericHelixController;
+import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
+import org.apache.helix.healthcheck.ParticipantHealthReportCollectorImpl;
+import org.apache.helix.healthcheck.ParticipantHealthReportTask;
import org.apache.helix.messaging.DefaultMessagingService;
import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
import org.apache.helix.model.LiveInstance;
@@ -117,6 +120,8 @@ public class ZKHelixManager implements HelixManager, IZkStateListener {
private final StateMachineEngine _stateMachineEngine;
private final List<HelixTimerTask> _timerTasks = new ArrayList<HelixTimerTask>();
+ private final ParticipantHealthReportCollectorImpl _participantHealthInfoCollector;
+
/**
* controller fields
*/
@@ -212,19 +217,28 @@ public class ZKHelixManager implements HelixManager, IZkStateListener {
switch (instanceType) {
case PARTICIPANT:
_stateMachineEngine = new HelixStateMachineEngine(this);
+ _participantHealthInfoCollector =
+ new ParticipantHealthReportCollectorImpl(this, _instanceName);
+ _timerTasks.add(new ParticipantHealthReportTask(_participantHealthInfoCollector));
break;
case CONTROLLER:
_stateMachineEngine = null;
+ _participantHealthInfoCollector = null;
_controllerTimerTasks.add(new StatusDumpTask(this));
break;
case CONTROLLER_PARTICIPANT:
_stateMachineEngine = new HelixStateMachineEngine(this);
+ _participantHealthInfoCollector =
+ new ParticipantHealthReportCollectorImpl(this, _instanceName);
+
+ _timerTasks.add(new ParticipantHealthReportTask(_participantHealthInfoCollector));
_controllerTimerTasks.add(new StatusDumpTask(this));
break;
case ADMINISTRATOR:
case SPECTATOR:
_stateMachineEngine = null;
+ _participantHealthInfoCollector = null;
break;
default:
throw new IllegalArgumentException("unrecognized type: " + instanceType);
@@ -857,4 +871,9 @@ public class ZKHelixManager implements HelixManager, IZkStateListener {
}
}
+ @Override
+ public ParticipantHealthReportCollector getHealthReportCollector() {
+ checkConnected();
+ return _participantHealthInfoCollector;
+ }
}
http://git-wip-us.apache.org/repos/asf/helix/blob/5ae03d97/helix-core/src/main/java/org/apache/helix/model/HealthStat.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/model/HealthStat.java b/helix-core/src/main/java/org/apache/helix/model/HealthStat.java
new file mode 100644
index 0000000..715927f
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/model/HealthStat.java
@@ -0,0 +1,147 @@
+package org.apache.helix.model;
+
+/*
+ * 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.
+ */
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.helix.HelixProperty;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.model.Message.Attributes;
+import org.apache.log4j.Logger;
+
+/**
+ * Represents a set of properties that can be queried to determine the health of instances on a
+ * Helix-managed cluster
+ */
+public class HealthStat extends HelixProperty {
+ public static final String VALUE_NAME = "value";
+ public static final String TIMESTAMP_NAME = "TimeStamp";
+ public static final String statFieldDelim = ".";
+
+ /**
+ * Queryable health statistic properties
+ */
+ public enum HealthStatProperty {
+ FIELDS
+ }
+
+ /**
+ * Instantiate with an identifier
+ * @param id the name of these statistics
+ */
+ public HealthStat(String id) {
+ super(id);
+ }
+
+ /**
+ * Instantiate with a pre-populated record
+ * @param record a ZNRecord corresponding to health statistics
+ */
+ public HealthStat(ZNRecord record) {
+ super(record);
+ if (getCreateTimeStamp() == 0) {
+ _record.setLongField(Attributes.CREATE_TIMESTAMP.toString(), new Date().getTime());
+ }
+ }
+
+ /**
+ * Get when these statistics were last modified
+ * @return a UNIX timestamp
+ */
+ public long getLastModifiedTimeStamp() {
+ return _record.getModifiedTime();
+ }
+
+ /**
+ * Get when these statistics were created
+ * @return a UNIX timestamp
+ */
+ public long getCreateTimeStamp() {
+ return _record.getLongField(Attributes.CREATE_TIMESTAMP.toString(), 0L);
+ }
+
+ /**
+ * Get the value of a test field corresponding to a request count
+ * @return the number of requests
+ */
+ public String getTestField() {
+ return _record.getSimpleField("requestCountStat");
+ }
+
+ /**
+ * Set a group of heath statistics, grouped by the statistic
+ * @param healthFields a map of statistic name, the corresponding entity, and the value
+ */
+ public void setHealthFields(Map<String, Map<String, String>> healthFields) {
+ _record.setMapFields(healthFields);
+ }
+
+ /**
+ * Create a key based on a parent key, instance, and statistic
+ * @param instance the instance for which these statistics exist
+ * @param parentKey the originating key
+ * @param statName the statistic
+ * @return a unified key
+ */
+ public String buildCompositeKey(String instance, String parentKey, String statName) {
+ String delim = statFieldDelim;
+ return instance + delim + parentKey + delim + statName;
+ }
+
+ /**
+ * Get all the health statistics for a given instance
+ * @param instanceName the instance for which to get health statistics
+ * @return a map of (instance and statistic, value or timestamp, value) triples
+ */
+ public Map<String, Map<String, String>> getHealthFields(String instanceName) // ,
+ // String
+ // timestamp)
+ {
+ // XXX: need to do some conversion of input format to the format that stats
+ // computation wants
+ Map<String, Map<String, String>> currMapFields = _record.getMapFields();
+ Map<String, Map<String, String>> convertedMapFields =
+ new HashMap<String, Map<String, String>>();
+ for (String key : currMapFields.keySet()) {
+ Map<String, String> currMap = currMapFields.get(key);
+ String timestamp = _record.getStringField(TIMESTAMP_NAME, "-1");
+ for (String subKey : currMap.keySet()) {
+ if (subKey.equals("StatsHolder.TIMESTAMP_NAME")) { // don't want to get timestamp again
+ continue;
+ }
+ String compositeKey = buildCompositeKey(instanceName, key, subKey);
+ String value = currMap.get(subKey);
+ Map<String, String> convertedMap = new HashMap<String, String>();
+ convertedMap.put(VALUE_NAME, value);
+ convertedMap.put(TIMESTAMP_NAME, timestamp);
+ convertedMapFields.put(compositeKey, convertedMap);
+ }
+ }
+ return convertedMapFields;
+ }
+
+ @Override
+ public boolean isValid() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/helix/blob/5ae03d97/helix-core/src/test/java/org/apache/helix/Mocks.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/Mocks.java b/helix-core/src/test/java/org/apache/helix/Mocks.java
index e6582e0..6a27402 100644
--- a/helix-core/src/test/java/org/apache/helix/Mocks.java
+++ b/helix-core/src/test/java/org/apache/helix/Mocks.java
@@ -31,6 +31,7 @@ import org.I0Itec.zkclient.DataUpdater;
import org.I0Itec.zkclient.IZkChildListener;
import org.I0Itec.zkclient.IZkDataListener;
import org.apache.helix.PropertyKey.Builder;
+import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
import org.apache.helix.messaging.AsyncCallback;
import org.apache.helix.messaging.handling.HelixTaskExecutor;
import org.apache.helix.messaging.handling.HelixTaskResult;
@@ -445,6 +446,12 @@ public class Mocks {
// TODO Auto-generated method stub
}
+ @Override
+ public ParticipantHealthReportCollector getHealthReportCollector() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
public static class MockAccessor implements HelixDataAccessor {
http://git-wip-us.apache.org/repos/asf/helix/blob/5ae03d97/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java b/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java
index 73ba122..b54ddcc 100644
--- a/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java
+++ b/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java
@@ -39,6 +39,7 @@ import org.apache.helix.PreConnectCallback;
import org.apache.helix.PropertyKey;
import org.apache.helix.ScopedConfigChangeListener;
import org.apache.helix.ZNRecord;
+import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
import org.apache.helix.participant.StateMachineEngine;
import org.apache.helix.store.zk.ZkHelixPropertyStore;
@@ -245,4 +246,10 @@ public class DummyClusterManager implements HelixManager {
// TODO Auto-generated method stub
}
+
+ @Override
+ public ParticipantHealthReportCollector getHealthReportCollector() {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/helix/blob/5ae03d97/helix-core/src/test/java/org/apache/helix/healthcheck/TestParticipantHealthReportCollectorImpl.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestParticipantHealthReportCollectorImpl.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestParticipantHealthReportCollectorImpl.java
new file mode 100644
index 0000000..d760f32
--- /dev/null
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestParticipantHealthReportCollectorImpl.java
@@ -0,0 +1,86 @@
+package org.apache.helix.healthcheck;
+
+/*
+ * 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.
+ */
+
+import java.util.Map;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.Mocks.MockManager;
+import org.apache.helix.healthcheck.ParticipantHealthReportCollectorImpl;
+import org.apache.helix.healthcheck.ParticipantHealthReportTask;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class TestParticipantHealthReportCollectorImpl {
+
+ protected ParticipantHealthReportCollectorImpl _providerImpl;
+ protected ParticipantHealthReportTask _providerTask;
+ protected HelixManager _manager;
+ protected MockHealthReportProvider _mockProvider;
+
+ public static class MockHealthReportProvider extends HealthReportProvider {
+
+ @Override
+ public Map<String, String> getRecentHealthReport() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void resetStats() {
+ // TODO Auto-generated method stub
+
+ }
+
+ }
+
+ @BeforeMethod()
+ public void setup() {
+ _providerImpl = new ParticipantHealthReportCollectorImpl(new MockManager(), "instance_123");
+ _providerTask = new ParticipantHealthReportTask(_providerImpl);
+ _mockProvider = new MockHealthReportProvider();
+ }
+
+ @Test()
+ public void testStart() throws Exception {
+ _providerTask.start();
+ _providerTask.start();
+ }
+
+ @Test()
+ public void testStop() throws Exception {
+ _providerTask.stop();
+ _providerTask.stop();
+ }
+
+ @Test()
+ public void testAddProvider() throws Exception {
+ _providerImpl.removeHealthReportProvider(_mockProvider);
+ _providerImpl.addHealthReportProvider(_mockProvider);
+ _providerImpl.addHealthReportProvider(_mockProvider);
+ }
+
+ @Test()
+ public void testRemoveProvider() throws Exception {
+ _providerImpl.addHealthReportProvider(_mockProvider);
+ _providerImpl.removeHealthReportProvider(_mockProvider);
+ _providerImpl.removeHealthReportProvider(_mockProvider);
+ }
+}
http://git-wip-us.apache.org/repos/asf/helix/blob/5ae03d97/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java b/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
index 11cdd34..2b6f757 100644
--- a/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
+++ b/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
@@ -41,6 +41,7 @@ import org.apache.helix.PreConnectCallback;
import org.apache.helix.PropertyKey;
import org.apache.helix.ScopedConfigChangeListener;
import org.apache.helix.ZNRecord;
+import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.manager.zk.ZkClient;
@@ -252,4 +253,10 @@ public class MockZKHelixManager implements HelixManager {
}
+ @Override
+ public ParticipantHealthReportCollector getHealthReportCollector() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}