@Test public void getMasterInfo() { when(mMasterProcess.getRpcAddress()).thenReturn(new InetSocketAddress("localhost", 8080)); 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); when(mMasterProcess.getStartTimeMs()).thenReturn(101L); 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(); assertNotNull("Configuration must be not null", info.getConfiguration()); assertFalse("Properties Map must be not empty!", (info.getConfiguration().isEmpty())); assertEquals("localhost/127.0.0.1:8080", info.getRpcAddress()); 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()); assertEquals(101L, info.getStartTimeMs()); assertEquals(102L, info.getUptimeMs()); assertEquals(RuntimeConstants.VERSION, info.getVersion()); 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()); 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()); Capacity ufsCapacity = info.getUfsCapacity(); assertEquals(UFS_SPACE_TOTAL, ufsCapacity.getTotal()); assertEquals(UFS_SPACE_USED, ufsCapacity.getUsed()); 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(); } }
@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) { 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) .setWorkers(mBlockMaster.getWorkerInfoList()); }, ServerConfiguration.global()); }
AlluxioMasterRestServiceHandler { @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) { 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) .setWorkers(mBlockMaster.getWorkerInfoList()); }, ServerConfiguration.global()); } }
AlluxioMasterRestServiceHandler { @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) { 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) .setWorkers(mBlockMaster.getWorkerInfoList()); }, ServerConfiguration.global()); } AlluxioMasterRestServiceHandler(@Context ServletContext context); }
AlluxioMasterRestServiceHandler { @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) { 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) .setWorkers(mBlockMaster.getWorkerInfoList()); }, ServerConfiguration.global()); } AlluxioMasterRestServiceHandler(@Context ServletContext context); @GET @Path(GET_INFO) @ApiOperation(value = "Get general Alluxio Master service information", response = alluxio.wire.AlluxioMasterInfo.class) Response getInfo(@QueryParam(QUERY_RAW_CONFIGURATION) final Boolean rawConfiguration); @GET @Path(WEBUI_INIT) Response getWebUIInit(); @GET @Path(WEBUI_OVERVIEW) Response getWebUIOverview(); @GET @Path(WEBUI_BROWSE) Response getWebUIBrowse(@DefaultValue("/") @QueryParam("path") String requestPath,
      @DefaultValue("0") @QueryParam("offset") String requestOffset,
      @DefaultValue("") @QueryParam("end") String requestEnd,
      @DefaultValue("20") @QueryParam("limit") String requestLimit); @GET @Path(WEBUI_DATA) Response getWebUIData(@DefaultValue("0") @QueryParam("offset") String requestOffset,
      @DefaultValue("20") @QueryParam("limit") String requestLimit); @GET @Path(WEBUI_LOGS) Response getWebUILogs(@DefaultValue("") @QueryParam("path") String requestPath,
      @DefaultValue("0") @QueryParam("offset") String requestOffset,
      @DefaultValue("") @QueryParam("end") String requestEnd,
      @DefaultValue("20") @QueryParam("limit") String requestLimit); @GET @Path(WEBUI_CONFIG) Response getWebUIConfiguration(); @GET @Path(WEBUI_WORKERS) Response getWebUIWorkers(); @GET @Path(WEBUI_METRICS) Response getWebUIMetrics(); @POST @Path(LOG_LEVEL) Response logLevel(@QueryParam(LOG_ARGUMENT_NAME) final String logName,
      @QueryParam(LOG_ARGUMENT_LEVEL) final String level); }
AlluxioMasterRestServiceHandler { @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) { 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) .setWorkers(mBlockMaster.getWorkerInfoList()); }, ServerConfiguration.global()); } AlluxioMasterRestServiceHandler(@Context ServletContext context); @GET @Path(GET_INFO) @ApiOperation(value = "Get general Alluxio Master service information", response = alluxio.wire.AlluxioMasterInfo.class) Response getInfo(@QueryParam(QUERY_RAW_CONFIGURATION) final Boolean rawConfiguration); @GET @Path(WEBUI_INIT) Response getWebUIInit(); @GET @Path(WEBUI_OVERVIEW) Response getWebUIOverview(); @GET @Path(WEBUI_BROWSE) Response getWebUIBrowse(@DefaultValue("/") @QueryParam("path") String requestPath,
      @DefaultValue("0") @QueryParam("offset") String requestOffset,
      @DefaultValue("") @QueryParam("end") String requestEnd,
      @DefaultValue("20") @QueryParam("limit") String requestLimit); @GET @Path(WEBUI_DATA) Response getWebUIData(@DefaultValue("0") @QueryParam("offset") String requestOffset,
      @DefaultValue("20") @QueryParam("limit") String requestLimit); @GET @Path(WEBUI_LOGS) Response getWebUILogs(@DefaultValue("") @QueryParam("path") String requestPath,
      @DefaultValue("0") @QueryParam("offset") String requestOffset,
      @DefaultValue("") @QueryParam("end") String requestEnd,
      @DefaultValue("20") @QueryParam("limit") String requestLimit); @GET @Path(WEBUI_CONFIG) Response getWebUIConfiguration(); @GET @Path(WEBUI_WORKERS) Response getWebUIWorkers(); @GET @Path(WEBUI_METRICS) Response getWebUIMetrics(); @POST @Path(LOG_LEVEL) Response logLevel(@QueryParam(LOG_ARGUMENT_NAME) final String logName,
      @QueryParam(LOG_ARGUMENT_LEVEL) final String level); static final String SERVICE_PREFIX; static final String GET_INFO; static final String WEBUI_INIT; static final String WEBUI_OVERVIEW; static final String WEBUI_BROWSE; static final String WEBUI_DATA; static final String WEBUI_LOGS; static final String WEBUI_CONFIG; static final String WEBUI_WORKERS; static final String WEBUI_METRICS; static final String QUERY_RAW_CONFIGURATION; static final String LOG_LEVEL; static final String LOG_ARGUMENT_NAME; static final String LOG_ARGUMENT_LEVEL; }