Skip to content

Commit

Permalink
Adding information about lost workers to REST API.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsimsa committed Dec 29, 2016
1 parent 3c576a0 commit a5dc3ec
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 11 deletions.
28 changes: 24 additions & 4 deletions core/common/src/main/java/alluxio/wire/AlluxioMasterInfo.java
Expand Up @@ -22,6 +22,7 @@
public class AlluxioMasterInfo {
private Capacity mCapacity;
private Map<String, String> mConfiguration;
private List<WorkerInfo> mLostWorkers;
private Map<String, Long> mMetrics;
private Map<String, MountPointInfo> mMountPoints;
private String mRpcAddress;
Expand Down Expand Up @@ -52,6 +53,13 @@ public Map<String, String> getConfiguration() {
return mConfiguration;
}

/**
* @return the list of lost workers
*/
public List<WorkerInfo> getLostWorkers() {
return mLostWorkers;
}

/**
* @return the metrics
*/
Expand Down Expand Up @@ -140,6 +148,15 @@ public AlluxioMasterInfo setConfiguration(Map<String, String> configuration) {
return this;
}

/**
* @param lostWorkers the list of lost workers to use
* @return the Alluxio master information
*/
public AlluxioMasterInfo setLostWorkers(List<WorkerInfo> lostWorkers) {
mLostWorkers = lostWorkers;
return this;
}

/**
* @param metrics the metrics to use
* @return the Alluxio master information
Expand Down Expand Up @@ -241,6 +258,7 @@ public boolean equals(Object o) {
AlluxioMasterInfo that = (AlluxioMasterInfo) o;
return Objects.equal(mCapacity, that.mCapacity)
&& Objects.equal(mConfiguration, that.mConfiguration)
&& Objects.equal(mLostWorkers, that.mLostWorkers)
&& Objects.equal(mMetrics, that.mMetrics)
&& Objects.equal(mMountPoints, that.mMountPoints)
&& Objects.equal(mRpcAddress, that.mRpcAddress)
Expand All @@ -256,16 +274,17 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
return Objects
.hashCode(mCapacity, mConfiguration, mMetrics, mMountPoints, mRpcAddress, mStartTimeMs,
mStartupConsistencyCheck, mTierCapacity, mUfsCapacity, mUptimeMs, mVersion,
mWorkers);
.hashCode(mCapacity, mConfiguration, mLostWorkers, mMetrics, mMountPoints, mRpcAddress,
mStartTimeMs, mStartupConsistencyCheck, mTierCapacity, mUfsCapacity, mUptimeMs,
mVersion, mWorkers);
}

@Override
public String toString() {
return Objects.toStringHelper(this)
.add("capacity", mCapacity)
.add("configuration", mConfiguration)
.add("lost workers", mLostWorkers)
.add("metrics", mMetrics)
.add("mount points", mMountPoints)
.add("rpc address", mRpcAddress)
Expand All @@ -275,6 +294,7 @@ public String toString() {
.add("ufs capacity", mUfsCapacity)
.add("uptime", mUptimeMs)
.add("version", mVersion)
.add("workers", mWorkers).toString();
.add("workers", mWorkers)
.toString();
}
}
Expand Up @@ -43,6 +43,7 @@ public void equals() {
private void checkEquality(AlluxioMasterInfo a, AlluxioMasterInfo b) {
Assert.assertEquals(a.getCapacity(), b.getCapacity());
Assert.assertEquals(a.getConfiguration(), b.getConfiguration());
Assert.assertEquals(a.getLostWorkers(), b.getLostWorkers());
Assert.assertEquals(a.getMetrics(), b.getMetrics());
Assert.assertEquals(a.getRpcAddress(), b.getRpcAddress());
Assert.assertEquals(a.getStartTimeMs(), b.getStartTimeMs());
Expand All @@ -66,6 +67,11 @@ private static AlluxioMasterInfo createRandom() {
configuration.put(CommonUtils.randomAlphaNumString(random.nextInt(10)),
CommonUtils.randomAlphaNumString(random.nextInt(10)));
}
List<WorkerInfo> lostWorkers = new ArrayList<>();
long numLostWorkers = random.nextInt(10);
for (int i = 0; i < numLostWorkers; i++) {
lostWorkers.add(WorkerInfoTest.createRandom());
}
Map<String, Long> metrics = new HashMap<>();
long numMetrics = random.nextInt(10);
for (int i = 0; i < numMetrics; i++) {
Expand Down Expand Up @@ -98,6 +104,7 @@ private static AlluxioMasterInfo createRandom() {

result.setCapacity(capacity);
result.setConfiguration(configuration);
result.setLostWorkers(lostWorkers);
result.setMetrics(metrics);
result.setRpcAddress(rpcAddress);
result.setStartTimeMs(startTimeMs);
Expand Down
Expand Up @@ -126,6 +126,7 @@ public AlluxioMasterInfo call() throws Exception {
new AlluxioMasterInfo()
.setCapacity(getCapacityInternal())
.setConfiguration(getConfigurationInternal(rawConfig))
.setLostWorkers(mBlockMaster.getLostWorkersInfoList())
.setMetrics(getMetricsInternal())
.setMountPoints(getMountPointsInternal())
.setRpcAddress(mMaster.getRpcAddress().toString())
Expand Down
Expand Up @@ -310,8 +310,8 @@ public long getUsedBytes() {
*
* @return a set of worker info
*/
public Set<WorkerInfo> getLostWorkersInfo() {
Set<WorkerInfo> ret = new HashSet<>(mLostWorkers.size());
public List<WorkerInfo> getLostWorkersInfoList() {
List<WorkerInfo> ret = new ArrayList<>(mLostWorkers.size());
for (MasterWorkerInfo worker : mLostWorkers) {
synchronized (worker) {
ret.add(worker.generateClientWorkerInfo());
Expand Down
Expand Up @@ -23,7 +23,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import javax.annotation.concurrent.ThreadSafe;
import javax.servlet.ServletException;
Expand Down Expand Up @@ -223,7 +222,7 @@ private void populateValues(HttpServletRequest request) throws IOException {
NodeInfo[] normalNodeInfos = generateOrderedNodeInfos(workerInfos);
request.setAttribute("normalNodeInfos", normalNodeInfos);

Set<WorkerInfo> lostWorkerInfos = mBlockMaster.getLostWorkersInfo();
List<WorkerInfo> lostWorkerInfos = mBlockMaster.getLostWorkersInfoList();
NodeInfo[] failedNodeInfos = generateOrderedNodeInfos(lostWorkerInfos);
request.setAttribute("failedNodeInfos", failedNodeInfos);
}
Expand Down
Expand Up @@ -41,7 +41,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

Expand Down Expand Up @@ -137,7 +136,7 @@ public void detectLostWorkers() throws Exception {
HeartbeatScheduler.execute(HeartbeatContext.MASTER_LOST_WORKER_DETECTION);

// Make sure the worker is detected as lost.
Set<WorkerInfo> info = mMaster.getLostWorkersInfo();
List<WorkerInfo> info = mMaster.getLostWorkersInfoList();
Assert.assertEquals(worker1, Iterables.getOnlyElement(info).getId());
}

Expand Down Expand Up @@ -167,7 +166,7 @@ public void workerReregisterRemembersLostWorker() throws Exception {

// Check that there are no longer any lost workers and there is a live worker.
Assert.assertEquals(1, mMaster.getWorkerCount());
Assert.assertEquals(0, mMaster.getLostWorkersInfo().size());
Assert.assertEquals(0, mMaster.getLostWorkersInfoList().size());
}

@Test
Expand Down
Expand Up @@ -104,6 +104,12 @@ private void checkConfiguration(PropertyKey key, String expectedValue, Map<Strin
Assert.assertEquals(expectedValue, getInfo(params).getConfiguration().get(key.toString()));
}

@Test
public void getLostWorkers() throws Exception {
List<WorkerInfo> lostWorkersInfo = getInfo(NO_PARAMS).getLostWorkers();
Assert.assertEquals(0, lostWorkersInfo.size());
}

@Test
public void getMetrics() throws Exception {
Assert.assertEquals(Long.valueOf(0), getInfo(NO_PARAMS).getMetrics()
Expand Down

0 comments on commit a5dc3ec

Please sign in to comment.