diff --git a/core/common/src/main/java/alluxio/wire/AlluxioMasterInfo.java b/core/common/src/main/java/alluxio/wire/AlluxioMasterInfo.java new file mode 100644 index 000000000000..a1dbd2d5100f --- /dev/null +++ b/core/common/src/main/java/alluxio/wire/AlluxioMasterInfo.java @@ -0,0 +1,230 @@ +/* + * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 + * (the "License"). You may not use this work except in compliance with the License, which is + * available at www.apache.org/licenses/LICENSE-2.0 + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied, as more fully set forth in the License. + * + * See the NOTICE file distributed with this work for information regarding copyright ownership. + */ + +package alluxio.wire; + +import com.google.common.base.Objects; + +import java.util.List; +import java.util.Map; + +/** + * Alluxio master descriptor. + */ +public class AlluxioMasterInfo { + private Capacity mCapacity; + private Map mConfiguration; + private Map mMetrics; + private String mRpcAddress; + private long mStartTimeMs; + private Map mTierCapacity; + private Capacity mUfsCapacity; + private long mUptimeMs; + private String mVersion; + private List mWorkers; + + /** + * Creates a new instance of {@link AlluxioMasterInfo}. + */ + public AlluxioMasterInfo() {} + + /** + * @return the capacity + */ + public Capacity getCapacity() { + return mCapacity; + } + + /** + * @return the configuration + */ + public Map getConfiguration() { + return mConfiguration; + } + + /** + * @return the metrics + */ + public Map getMetrics() { + return mMetrics; + } + + /** + * @return the RPC address + */ + public String getRpcAddress() { + return mRpcAddress; + } + + /** + * @return the start time (in milliseconds) + */ + public long getStartTimeMs() { + return mStartTimeMs; + } + + /** + * @return the capacity per tier + */ + public Map getTierCapacity() { + return mTierCapacity; + } + + /** + * @return the UFS capacity + */ + public Capacity getUfsCapacity() { + return mCapacity; + } + + /** + * @return the uptime (in milliseconds) + */ + public long getUptimeMs() { + return mUptimeMs; + } + + /** + * @return the version + */ + public String getVersion() { + return mVersion; + } + + /** + * @return the list of workers + */ + public List getWorkers() { + return mWorkers; + } + + /** + * @param capacity the capacity to use + * @return the Alluxio master descriptor + */ + public AlluxioMasterInfo setCapacity(Capacity capacity) { + mCapacity = capacity; + return this; + } + + /** + * @param configuration the configuration to use + * @return the Alluxio master descriptor + */ + public AlluxioMasterInfo setConfiguration(Map configuration) { + mConfiguration = configuration; + return this; + } + + /** + * @param metrics the metrics to use + * @return the Alluxio master descriptor + */ + public AlluxioMasterInfo setMetrics(Map metrics) { + mMetrics = metrics; + return this; + } + + /** + * @param rpcAddress the RPC address to use + * @return the Alluxio master descriptor + */ + public AlluxioMasterInfo setRpcAddress(String rpcAddress) { + mRpcAddress = rpcAddress; + return this; + } + + /** + * @param startTimeMs the start time to use (in milliseconds) + * @return the Alluxio master descriptor + */ + public AlluxioMasterInfo setStartTimeMs(long startTimeMs) { + mStartTimeMs = startTimeMs; + return this; + } + + /** + * @param tierCapacity the capacity per tier to use + * @return the Alluxio master descriptor + */ + public AlluxioMasterInfo setTierCapacity(Map tierCapacity) { + mTierCapacity = tierCapacity; + return this; + } + + /** + * @param ufsCapacity the UFS capacity to use + * @return the Alluxio master descriptor + */ + public AlluxioMasterInfo setUfsCapacity(Capacity ufsCapacity) { + mUfsCapacity = ufsCapacity; + return this; + } + + /** + * @param uptimeMs the uptime to use (in milliseconds) + * @return the Alluxio master descriptor + */ + public AlluxioMasterInfo setUptimeMs(long uptimeMs) { + mUptimeMs = uptimeMs; + return this; + } + + /** + * @param version the version to use + * @return the Alluxio master descriptor + */ + public AlluxioMasterInfo setVersion(String version) { + mVersion = version; + return this; + } + + /** + * @param workers the list of workers to use + * @return the Alluxio master descriptor + */ + public AlluxioMasterInfo setWorkers(List workers) { + mWorkers = workers; + return this; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof AlluxioMasterInfo)) { + return false; + } + AlluxioMasterInfo that = (AlluxioMasterInfo) o; + return mCapacity.equals(that.mCapacity) && mConfiguration.equals(that.mConfiguration) + && mMetrics.equals(that.mMetrics) && mRpcAddress.equals(that.mRpcAddress) + && mStartTimeMs == that.mStartTimeMs && mTierCapacity.equals(that.mTierCapacity) + && mUfsCapacity.equals(that.mUfsCapacity) && mUptimeMs == that.mUptimeMs && mVersion + .equals(that.mVersion) && mWorkers.equals(that.mWorkers); + } + + @Override + public int hashCode() { + return Objects + .hashCode(mCapacity, mConfiguration, mMetrics, mRpcAddress, mStartTimeMs, mTierCapacity, + mUfsCapacity, mUptimeMs, mVersion, mWorkers); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).add("capacity", mCapacity) + .add("configuration", mConfiguration).add("metrics", mMetrics) + .add("rpc address", mRpcAddress).add("start time", mStartTimeMs) + .add("tier capacity", mTierCapacity).add("ufs capacity", mUfsCapacity) + .add("uptime", mUptimeMs).add("version", mVersion).add("workers", mWorkers).toString(); + } +} diff --git a/core/common/src/main/java/alluxio/wire/AlluxioWorkerInfo.java b/core/common/src/main/java/alluxio/wire/AlluxioWorkerInfo.java new file mode 100644 index 000000000000..14efc085bd01 --- /dev/null +++ b/core/common/src/main/java/alluxio/wire/AlluxioWorkerInfo.java @@ -0,0 +1,24 @@ +/* + * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 + * (the "License"). You may not use this work except in compliance with the License, which is + * available at www.apache.org/licenses/LICENSE-2.0 + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied, as more fully set forth in the License. + * + * See the NOTICE file distributed with this work for information regarding copyright ownership. + */ + +package alluxio.wire; + +/** + * Alluxio worker descriptor. + */ +public class AlluxioWorkerInfo { + + /** + * Creates a new instance of {@link AlluxioWorkerInfo}. + */ + public AlluxioWorkerInfo() {} + +} diff --git a/core/common/src/main/java/alluxio/wire/Capacity.java b/core/common/src/main/java/alluxio/wire/Capacity.java new file mode 100644 index 000000000000..228ecffa6559 --- /dev/null +++ b/core/common/src/main/java/alluxio/wire/Capacity.java @@ -0,0 +1,81 @@ +/* + * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 + * (the "License"). You may not use this work except in compliance with the License, which is + * available at www.apache.org/licenses/LICENSE-2.0 + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied, as more fully set forth in the License. + * + * See the NOTICE file distributed with this work for information regarding copyright ownership. + */ + +package alluxio.wire; + +import com.google.common.base.Objects; + +/** + * Class that represents the available, free, and total capacity. + */ +public class Capacity { + private long mTotal; + private long mUsed; + + /** + * Creates a new instance of {@link Capacity}. + */ + public Capacity() {} + + /** + * @return the total capacity + */ + public long getTotal() { + return mTotal; + } + + /** + * @return the used capacity + */ + public long getUsed() { + return mUsed; + } + + /** + * @param total the total capacity to use + * @return the capacity + */ + public Capacity setTotal(long total) { + mTotal = total; + return this; + } + + /** + * @param used the used capacity to use + * @return the capacity + */ + public Capacity setUsed(long used) { + mUsed = used; + return this; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Capacity)) { + return false; + } + Capacity that = (Capacity) o; + return mTotal == that.mTotal && mUsed == that.mUsed; + } + + @Override + public int hashCode() { + return Objects.hashCode(mTotal, mUsed); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).add("total", mTotal).add("used", mUsed).toString(); + } +} diff --git a/core/server/src/main/java/alluxio/master/AlluxioMasterRestServiceHandler.java b/core/server/src/main/java/alluxio/master/AlluxioMasterRestServiceHandler.java index 548b404c7e63..dd2de38ce3ef 100644 --- a/core/server/src/main/java/alluxio/master/AlluxioMasterRestServiceHandler.java +++ b/core/server/src/main/java/alluxio/master/AlluxioMasterRestServiceHandler.java @@ -13,7 +13,6 @@ import alluxio.Configuration; import alluxio.Constants; -import alluxio.MasterStorageTierAssoc; import alluxio.PropertyKey; import alluxio.RestUtils; import alluxio.RuntimeConstants; @@ -21,16 +20,16 @@ import alluxio.underfs.UnderFileSystem; import alluxio.util.CommonUtils; import alluxio.web.MasterUIWebServer; +import alluxio.wire.AlluxioMasterInfo; +import alluxio.wire.Capacity; import com.codahale.metrics.Counter; import com.codahale.metrics.Gauge; import com.codahale.metrics.MetricRegistry; -import com.qmino.miredot.annotations.ReturnType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import java.util.Comparator; import java.util.Map; import java.util.Set; import java.util.SortedMap; @@ -53,25 +52,9 @@ @Produces(MediaType.APPLICATION_JSON) public final class AlluxioMasterRestServiceHandler { private static final Logger LOG = LoggerFactory.getLogger(Constants.LOGGER_TYPE); - private static final String ALLUXIO_CONF_PREFIX = "alluxio"; public static final String SERVICE_PREFIX = "master"; - public static final String GET_RPC_ADDRESS = "rpc_address"; - public static final String GET_CONFIGURATION = "configuration"; - public static final String GET_CAPACITY_BYTES = "capacity_bytes"; - public static final String GET_USED_BYTES = "used_bytes"; - public static final String GET_FREE_BYTES = "free_bytes"; - public static final String GET_CAPACITY_BYTES_ON_TIERS = "capacity_bytes_on_tiers"; - public static final String GET_USED_BYTES_ON_TIERS = "used_bytes_on_tiers"; - public static final String GET_UFS_CAPACITY_BYTES = "ufs_capacity_bytes"; - public static final String GET_UFS_USED_BYTES = "ufs_used_bytes"; - public static final String GET_UFS_FREE_BYTES = "ufs_free_bytes"; - public static final String GET_METRICS = "metrics"; - public static final String GET_START_TIME_MS = "start_time_ms"; - public static final String GET_UPTIME_MS = "uptime_ms"; - public static final String GET_VERSION = "version"; - public static final String GET_WORKER_COUNT = "worker_count"; - public static final String GET_WORKER_INFO_LIST = "worker_info_list"; + public static final String GET_INFO = "info"; private final AlluxioMaster mMaster; private final BlockMaster mBlockMaster; @@ -91,13 +74,32 @@ public AlluxioMasterRestServiceHandler(@Context ServletContext context) { } /** - * @summary get the configuration map, the keys are ordered alphabetically. + * @summary get the Alluxio master information * @return the response object */ @GET - @Path(GET_CONFIGURATION) - @ReturnType("java.util.SortedMap") - public Response getConfiguration() { + @Path(GET_INFO) + public Response getInfo() { + try { + AlluxioMasterInfo result = + new AlluxioMasterInfo().setCapacity(getCapacity()).setConfiguration(getConfiguration()) + .setMetrics(getMetrics()).setRpcAddress(mMaster.getMasterAddress().toString()) + .setStartTimeMs(mMaster.getStartTimeMs()).setTierCapacity(getTierCapacity()) + .setUfsCapacity(getUfsCapacity()).setUptimeMs(mMaster.getUptimeMs()) + .setVersion(RuntimeConstants.VERSION).setWorkers(mBlockMaster.getWorkerInfoList()); + return RestUtils.createResponse(result); + } catch (IOException e) { + LOG.warn(e.getMessage()); + return RestUtils.createErrorResponse(e.getMessage()); + } + } + + private Capacity getCapacity() { + return new Capacity().setTotal(mBlockMaster.getCapacityBytes()) + .setUsed(mBlockMaster.getUsedBytes()); + } + + private Map getConfiguration() { Set> properties = Configuration.toMap().entrySet(); SortedMap configuration = new TreeMap<>(); for (Map.Entry entry : properties) { @@ -106,28 +108,10 @@ public Response getConfiguration() { configuration.put(key, entry.getValue()); } } - return RestUtils.createResponse(configuration); - } - - /** - * @summary get the master rpc address - * @return the response object - */ - @GET - @Path(GET_RPC_ADDRESS) - @ReturnType("java.lang.String") - public Response getRpcAddress() { - return RestUtils.createResponse(mMaster.getMasterAddress().toString()); + return configuration; } - /** - * @summary get the master metrics, the keys are ordered alphabetically. - * @return the response object - */ - @GET - @Path(GET_METRICS) - @ReturnType("java.util.SortedMap") - public Response getMetrics() { + private Map getMetrics() { MetricRegistry metricRegistry = mMaster.getMasterMetricsSystem().getMetricRegistry(); // Get all counters. @@ -148,196 +132,23 @@ public Response getMetrics() { } metrics.put(filesPinnedProperty, filesPinned.getValue().longValue()); - return RestUtils.createResponse(metrics); - } - - /** - * @summary get the start time of the master - * @return the response object - */ - @GET - @Path(GET_START_TIME_MS) - @ReturnType("java.lang.Long") - public Response getStartTimeMs() { - return RestUtils.createResponse(mMaster.getStartTimeMs()); + return metrics; } - /** - * @summary get the uptime of the master - * @return the response object - */ - @GET - @Path(GET_UPTIME_MS) - @ReturnType("java.lang.Long") - public Response getUptimeMs() { - return RestUtils.createResponse(mMaster.getUptimeMs()); - } - - /** - * @summary get the version of the master - * @return the response object - */ - @GET - @Path(GET_VERSION) - @ReturnType("java.lang.String") - public Response getVersion() { - return RestUtils.createResponse(RuntimeConstants.VERSION); - } - - /** - * @summary get the total capacity of all workers in bytes - * @return the response object - */ - @GET - @Path(GET_CAPACITY_BYTES) - @ReturnType("java.lang.Long") - public Response getCapacityBytes() { - return RestUtils.createResponse(mBlockMaster.getCapacityBytes()); - } - - /** - * @summary get the used capacity - * @return the response object - */ - @GET - @Path(GET_USED_BYTES) - @ReturnType("java.lang.Long") - public Response getUsedBytes() { - return RestUtils.createResponse(mBlockMaster.getUsedBytes()); - } - - /** - * @summary get the free capacity - * @return the response object - */ - @GET - @Path(GET_FREE_BYTES) - @ReturnType("java.lang.Long") - public Response getFreeBytes() { - return RestUtils.createResponse(mBlockMaster.getCapacityBytes() - mBlockMaster.getUsedBytes()); - } - - /** - * @summary get the total ufs capacity in bytes, a negative value means the capacity is unknown. - * @return the response object - */ - @GET - @Path(GET_UFS_CAPACITY_BYTES) - @ReturnType("java.lang.Long") - public Response getUfsCapacityBytes() { - try { - return RestUtils - .createResponse(mUfs.getSpace(mUfsRoot, UnderFileSystem.SpaceType.SPACE_TOTAL)); - } catch (IOException e) { - LOG.warn(e.getMessage()); - return RestUtils.createErrorResponse(e.getMessage()); - } - } - - /** - * @summary get the used disk capacity, a negative value means the capacity is unknown. - * @return the response object - */ - @GET - @Path(GET_UFS_USED_BYTES) - @ReturnType("java.lang.Long") - public Response getUfsUsedBytes() { - try { - return RestUtils - .createResponse(mUfs.getSpace(mUfsRoot, UnderFileSystem.SpaceType.SPACE_USED)); - } catch (IOException e) { - LOG.warn(e.getMessage()); - return RestUtils.createErrorResponse(e.getMessage()); - } - } - - /** - * @summary get the free ufs capacity in bytes, a negative value means the capacity is unknown. - * @return the response object - */ - @GET - @Path(GET_UFS_FREE_BYTES) - @ReturnType("java.lang.Long") - public Response getUfsFreeBytes() { - try { - return RestUtils - .createResponse(mUfs.getSpace(mUfsRoot, UnderFileSystem.SpaceType.SPACE_FREE)); - } catch (IOException e) { - LOG.warn(e.getMessage()); - return RestUtils.createErrorResponse(e.getMessage()); + private Map getTierCapacity() { + SortedMap tierCapacity = new TreeMap<>(); + Map totalTierCapacity = mBlockMaster.getTotalBytesOnTiers(); + Map usedTierCapacity = mBlockMaster.getUsedBytesOnTiers(); + for (String tierAlias : mBlockMaster.getGlobalStorageTierAssoc().getOrderedStorageAliases()) { + long total = totalTierCapacity.containsKey(tierAlias) ? totalTierCapacity.get(tierAlias) : 0; + long used = usedTierCapacity.containsKey(tierAlias) ? usedTierCapacity.get(tierAlias) : 0; + tierCapacity.put(tierAlias, new Capacity().setTotal(total).setUsed(used)); } + return tierCapacity; } - private Comparator getTierAliasComparator() { - return new Comparator() { - private MasterStorageTierAssoc mTierAssoc = new MasterStorageTierAssoc(); - - @Override - public int compare(String tier1, String tier2) { - int ordinal1 = mTierAssoc.getOrdinal(tier1); - int ordinal2 = mTierAssoc.getOrdinal(tier2); - if (ordinal1 < ordinal2) { - return -1; - } - if (ordinal1 == ordinal2) { - return 0; - } - return 1; - } - }; - } - - /** - * @summary get the mapping from tier alias to total capacity of the tier in bytes, keys are in - * the order from tier alias with smaller ordinal to those with larger ones. - * @return the response object - */ - @GET - @Path(GET_CAPACITY_BYTES_ON_TIERS) - @ReturnType("java.util.SortedMap") - public Response getCapacityBytesOnTiers() { - SortedMap capacityBytesOnTiers = new TreeMap<>(getTierAliasComparator()); - for (Map.Entry tierBytes : mBlockMaster.getTotalBytesOnTiers().entrySet()) { - capacityBytesOnTiers.put(tierBytes.getKey(), tierBytes.getValue()); - } - return RestUtils.createResponse(capacityBytesOnTiers); - } - - /** - * @summary get the mapping from tier alias to the used bytes of the tier, keys are in the order - * from tier alias with smaller ordinal to those with larger ones. - * @return the response object - */ - @GET - @Path(GET_USED_BYTES_ON_TIERS) - @ReturnType("java.util.SortedMap") - public Response getUsedBytesOnTiers() { - SortedMap usedBytesOnTiers = new TreeMap<>(getTierAliasComparator()); - for (Map.Entry tierBytes : mBlockMaster.getUsedBytesOnTiers().entrySet()) { - usedBytesOnTiers.put(tierBytes.getKey(), tierBytes.getValue()); - } - return RestUtils.createResponse(usedBytesOnTiers); - } - - /** - * @summary get the count of workers - * @return the response object - */ - @GET - @Path(GET_WORKER_COUNT) - @ReturnType("java.lang.Integer") - public Response getWorkerCount() { - return RestUtils.createResponse(mBlockMaster.getWorkerCount()); - } - - /** - * @summary get the list of worker descriptors - * @return the response object - */ - @GET - @Path(GET_WORKER_INFO_LIST) - @ReturnType("java.util.List") - public Response getWorkerInfoList() { - return RestUtils.createResponse(mBlockMaster.getWorkerInfoList()); + private Capacity getUfsCapacity() throws IOException { + return new Capacity().setTotal(mUfs.getSpace(mUfsRoot, UnderFileSystem.SpaceType.SPACE_TOTAL)) + .setUsed(mUfs.getSpace(mUfsRoot, UnderFileSystem.SpaceType.SPACE_USED)); } } diff --git a/tests/src/test/java/alluxio/master/AlluxioMasterRestApiTest.java b/tests/src/test/java/alluxio/master/AlluxioMasterRestApiTest.java index 04f669f52ba1..93eef0ff739f 100644 --- a/tests/src/test/java/alluxio/master/AlluxioMasterRestApiTest.java +++ b/tests/src/test/java/alluxio/master/AlluxioMasterRestApiTest.java @@ -16,18 +16,18 @@ import alluxio.RuntimeConstants; import alluxio.rest.RestApiTest; import alluxio.rest.TestCase; -import alluxio.thrift.WorkerInfo; import alluxio.util.network.NetworkAddressUtils; import alluxio.util.network.NetworkAddressUtils.ServiceType; +import alluxio.wire.AlluxioMasterInfo; +import alluxio.wire.Capacity; +import alluxio.wire.WorkerInfo; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.ImmutableMap; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import java.util.Map; +import java.util.List; import javax.ws.rs.HttpMethod; @@ -43,40 +43,28 @@ public void before() { mServicePrefix = AlluxioMasterRestServiceHandler.SERVICE_PREFIX; } - @Test - public void getCapacityBytes() throws Exception { - long memorySize = Configuration.getBytes(PropertyKey.WORKER_MEMORY_SIZE); - new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_CAPACITY_BYTES), - NO_PARAMS, HttpMethod.GET, memorySize).run(); - } - - @Test - public void getUsedBytes() throws Exception { - new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_USED_BYTES), - NO_PARAMS, HttpMethod.GET, 0).run(); + private AlluxioMasterInfo getInfo() throws Exception { + String result = + new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_INFO), + NO_PARAMS, HttpMethod.GET, null).call(); + AlluxioMasterInfo info = new ObjectMapper().readValue(result, AlluxioMasterInfo.class); + return info; } @Test - public void getFreeBytes() throws Exception { - long freeBytes = Configuration.getBytes(PropertyKey.WORKER_MEMORY_SIZE); - new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_FREE_BYTES), - NO_PARAMS, HttpMethod.GET, freeBytes).run(); + public void getCapacity() throws Exception { + long total = Configuration.getBytes(PropertyKey.WORKER_MEMORY_SIZE); + Capacity capacity = getInfo().getCapacity(); + Assert.assertEquals(total, capacity.getTotal()); + Assert.assertEquals(0, capacity.getUsed()); } @Test - public void getWorkerCount() throws Exception { - new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_WORKER_COUNT), - NO_PARAMS, HttpMethod.GET, 1).run(); - } + public void getWorkers() throws Exception { + List workerInfos = getInfo().getWorkers(); - @Test - public void getWorkerInfoList() throws Exception { - String result = new TestCase(mHostname, mPort, - getEndpoint(AlluxioMasterRestServiceHandler.GET_WORKER_INFO_LIST), NO_PARAMS, - HttpMethod.GET, null).call(); - WorkerInfo[] workerInfos = new ObjectMapper().readValue(result, WorkerInfo[].class); - Assert.assertEquals(1, workerInfos.length); - WorkerInfo workerInfo = workerInfos[0]; + Assert.assertEquals(1, workerInfos.size()); + WorkerInfo workerInfo = workerInfos.get(0); Assert.assertEquals(0, workerInfo.getUsedBytes()); long bytes = Configuration.getBytes(PropertyKey.WORKER_MEMORY_SIZE); Assert.assertEquals(bytes, workerInfo.getCapacityBytes()); @@ -85,97 +73,47 @@ public void getWorkerInfoList() throws Exception { @Test public void getConfiguration() throws Exception { Configuration.set(PropertyKey.METRICS_CONF_FILE, "abc"); - String result = new TestCase(mHostname, mPort, - getEndpoint(AlluxioMasterRestServiceHandler.GET_CONFIGURATION), NO_PARAMS, HttpMethod.GET, - null).call(); - @SuppressWarnings("unchecked") - Map config = - (Map) new ObjectMapper().readValue(result, Map.class); - Assert.assertEquals("abc", config.get(PropertyKey.METRICS_CONF_FILE.toString())); + Assert.assertEquals("abc", + getInfo().getConfiguration().get(PropertyKey.METRICS_CONF_FILE.toString())); } @Test public void getRpcAddress() throws Exception { - // Don't check the exact value, which could differ between systems. - String result = - new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_RPC_ADDRESS), - NO_PARAMS, HttpMethod.GET, null).call(); - Assert.assertTrue( - result.contains(String.valueOf(NetworkAddressUtils.getPort(ServiceType.MASTER_RPC)))); + Assert.assertTrue(getInfo().getRpcAddress() + .contains(String.valueOf(NetworkAddressUtils.getPort(ServiceType.MASTER_RPC)))); } @Test public void getMetrics() throws Exception { - String result = - new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_METRICS), - NO_PARAMS, HttpMethod.GET, null).call(); - @SuppressWarnings("unchecked") - Map metrics = new ObjectMapper().readValue(result, - new TypeReference>() {}); - - Assert.assertEquals(Long.valueOf(0), metrics.get("master.CompleteFileOps")); + Assert.assertEquals(Long.valueOf(0), getInfo().getMetrics().get("master.CompleteFileOps")); } @Test public void getStartTimeMs() throws Exception { - String startTime = new TestCase(mHostname, mPort, - getEndpoint(AlluxioMasterRestServiceHandler.GET_START_TIME_MS), NO_PARAMS, HttpMethod.GET, - null).call(); - Assert.assertTrue(Long.valueOf(startTime) > 0); + Assert.assertTrue(getInfo().getStartTimeMs() > 0); } @Test public void getUptimeMs() throws Exception { - String uptime = - new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_UPTIME_MS), - NO_PARAMS, HttpMethod.GET, null).call(); - - Assert.assertTrue(Long.valueOf(uptime) > 0); + Assert.assertTrue(getInfo().getUptimeMs() > 0); } @Test public void getVersion() throws Exception { - new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_VERSION), - NO_PARAMS, HttpMethod.GET, RuntimeConstants.VERSION).run(); - } - - @Test - public void getUfsCapacityBytes() throws Exception { - String ufsCapacity = new TestCase(mHostname, mPort, - getEndpoint(AlluxioMasterRestServiceHandler.GET_UFS_CAPACITY_BYTES), NO_PARAMS, - HttpMethod.GET, null).call(); - - Assert.assertTrue(Long.valueOf(ufsCapacity) > 0); - } - - @Test - public void getUfsUsedBytes() throws Exception { - // Don't check the exact value, which could differ between systems. - new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_UFS_USED_BYTES), - NO_PARAMS, HttpMethod.GET, null).call(); - } - - @Test - public void getUfsFreeBytes() throws Exception { - String ufsFreeBytes = new TestCase(mHostname, mPort, - getEndpoint(AlluxioMasterRestServiceHandler.GET_UFS_FREE_BYTES), NO_PARAMS, HttpMethod.GET, - null).call(); - - Assert.assertTrue(Long.valueOf(ufsFreeBytes) > 0); + Assert.assertEquals(RuntimeConstants.VERSION, getInfo().getVersion()); } @Test - public void getCapacityBytesOnTiers() throws Exception { - Long memorySize = Configuration.getLong(PropertyKey.WORKER_MEMORY_SIZE); - new TestCase(mHostname, mPort, - getEndpoint(AlluxioMasterRestServiceHandler.GET_CAPACITY_BYTES_ON_TIERS), NO_PARAMS, - HttpMethod.GET, ImmutableMap.of("MEM", memorySize)).run(); + public void getUfsCapacity() throws Exception { + Capacity ufsCapacity = getInfo().getUfsCapacity(); + Assert.assertTrue(ufsCapacity.getTotal() > 0); } @Test - public void getUsedBytesOnTiers() throws Exception { - new TestCase(mHostname, mPort, - getEndpoint(AlluxioMasterRestServiceHandler.GET_USED_BYTES_ON_TIERS), NO_PARAMS, - HttpMethod.GET, ImmutableMap.of("MEM", 0)).run(); + public void getTierCapacity() throws Exception { + long total = Configuration.getLong(PropertyKey.WORKER_MEMORY_SIZE); + Capacity capacity = getInfo().getTierCapacity().get("MEM"); + Assert.assertEquals(total, capacity.getTotal()); + Assert.assertEquals(0, capacity.getUsed()); } }