@GET
  @Path(GET_INFO)
  @ApiOperation(value = "Get general Alluxio Master service information",
      response = alluxio.wire.AlluxioMasterInfo.class)
  public Response getInfo(@QueryParam(QUERY_RAW_CONFIGURATION) final Boolean rawConfiguration) {
    // TODO(jiri): Add a mechanism for retrieving only a subset of the fields.
    return RestUtils.call(() -> {
      boolean rawConfig = false;
      if (rawConfiguration != null) {
        rawConfig = rawConfiguration;
      }
      return new AlluxioMasterInfo().setCapacity(getCapacityInternal())
          .setConfiguration(getConfigurationInternal(rawConfig))
          .setLostWorkers(mBlockMaster.getLostWorkersInfoList()).setMetrics(getMetricsInternal())
          .setMountPoints(getMountPointsInternal())
          .setRpcAddress(mMasterProcess.getRpcAddress().toString())
          .setStartTimeMs(mMasterProcess.getStartTimeMs())
          .setTierCapacity(getTierCapacityInternal()).setUfsCapacity(getUfsCapacityInternal())
          .setUptimeMs(mMasterProcess.getUptimeMs())
          .setVersion(RuntimeConstants.VERSION).setRevision(ProjectConstants.REVISION)
          .setWorkers(mBlockMaster.getWorkerInfoList());
    }, Configuration.global());
  }
@Test
  public void getMasterInfo() {
    // Mock for rpc address
    when(mMasterProcess.getRpcAddress()).thenReturn(new InetSocketAddress("localhost", 8080));
    // Mock for metrics
    final int FILES_PINNED_TEST_VALUE = 100;
    String filesPinnedProperty = MetricKey.MASTER_FILES_PINNED.getName();
    Gauge<Integer> filesPinnedGauge = () -> FILES_PINNED_TEST_VALUE;
    MetricSet mockMetricsSet = mock(MetricSet.class);
    Map<String, Metric> map = new HashMap<>();
    map.put(filesPinnedProperty, filesPinnedGauge);
    when(mockMetricsSet.getMetrics()).thenReturn(map);
    MetricsSystem.METRIC_REGISTRY.registerAll(mockMetricsSet);
    // Mock for start time
    when(mMasterProcess.getStartTimeMs()).thenReturn(101L);
    // Mock for up time
    when(mMasterProcess.getUptimeMs()).thenReturn(102L);

    Response response = mHandler.getInfo(false);
    try {
      assertNotNull("Response must be not null!", response);
      assertNotNull("Response must have a entry!", response.getEntity());
      assertTrue("Entry must be an AlluxioMasterInfo!",
              (response.getEntity() instanceof AlluxioMasterInfo));
      AlluxioMasterInfo info = (AlluxioMasterInfo) response.getEntity();

      // Validate configuration
      assertNotNull("Configuration must be not null", info.getConfiguration());
      assertFalse("Properties Map must be not empty!", (info.getConfiguration().isEmpty()));
      // Validate rpc address
      assertEquals("localhost/127.0.0.1:8080", info.getRpcAddress());
      // Validate metrics
      Map<String, Long> metricsMap = info.getMetrics();
      assertFalse("Metrics Map must be not empty!", (metricsMap.isEmpty()));
      assertTrue("Map must contain key " + filesPinnedProperty + "!",
          metricsMap.containsKey(filesPinnedProperty));
      assertEquals(FILES_PINNED_TEST_VALUE, metricsMap.get(filesPinnedProperty).longValue());
      // Validate StartTimeMs
      assertEquals(101L, info.getStartTimeMs());
      // Validate UptimeMs
      assertEquals(102L, info.getUptimeMs());
      // Validate version
      assertEquals(RuntimeConstants.VERSION, info.getVersion());
      // Validate capacity bytes
      Capacity cap = info.getCapacity();
      long sumCapacityBytes = 0;
      for (Map.Entry<String, Long> entry1 : WORKER1_TOTAL_BYTES_ON_TIERS.entrySet()) {
        Long totalBytes = entry1.getValue();
        sumCapacityBytes += totalBytes;
      }
      for (Map.Entry<String, Long> entry1 : WORKER2_TOTAL_BYTES_ON_TIERS.entrySet()) {
        Long totalBytes = entry1.getValue();
        sumCapacityBytes += totalBytes;
      }
      assertEquals(sumCapacityBytes, cap.getTotal());
      // Validate used bytes
      long sumUsedBytes = 0;
      for (Map.Entry<String, Long> entry1 : WORKER1_USED_BYTES_ON_TIERS.entrySet()) {
        Long totalBytes = entry1.getValue();
        sumUsedBytes += totalBytes;
      }
      for (Map.Entry<String, Long> entry1 : WORKER2_USED_BYTES_ON_TIERS.entrySet()) {
        Long totalBytes = entry1.getValue();
        sumUsedBytes += totalBytes;
      }
      assertEquals(sumUsedBytes, cap.getUsed());
      // Validate UFS capacity
      Capacity ufsCapacity = info.getUfsCapacity();
      assertEquals(UFS_SPACE_TOTAL, ufsCapacity.getTotal());
      assertEquals(UFS_SPACE_USED, ufsCapacity.getUsed());
      // Validate workers
      List<WorkerInfo> workers = info.getWorkers();
      assertEquals(2, workers.size());
      long worker1 = mBlockMaster.getWorkerId(NET_ADDRESS_1);
      long worker2 = mBlockMaster.getWorkerId(NET_ADDRESS_2);
      Set<Long> expectedWorkers = new HashSet<>();
      expectedWorkers.add(worker1);
      expectedWorkers.add(worker2);
      Set<Long> actualWorkers = new HashSet<>();
      for (WorkerInfo w : workers) {
        actualWorkers.add(w.getId());
      }
      assertEquals(expectedWorkers, actualWorkers);
    } finally {
      response.close();
    }
  }