Search in sources :

Example 1 with AlluxioMasterInfo

use of alluxio.wire.AlluxioMasterInfo in project alluxio by Alluxio.

the class AlluxioMasterRestApiTest method getInfo.

private AlluxioMasterInfo getInfo(Map<String, String> params) throws Exception {
    String result = new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_INFO), params, HttpMethod.GET, null).call();
    AlluxioMasterInfo info = new ObjectMapper().readValue(result, AlluxioMasterInfo.class);
    return info;
}
Also used : TestCase(alluxio.rest.TestCase) AlluxioMasterInfo(alluxio.wire.AlluxioMasterInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with AlluxioMasterInfo

use of alluxio.wire.AlluxioMasterInfo in project alluxio by Alluxio.

the class AlluxioMasterRestServiceHandlerTest method getMasterInfo.

@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();
    }
}
Also used : HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) WorkerInfo(alluxio.wire.WorkerInfo) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MetricSet(com.codahale.metrics.MetricSet) Response(javax.ws.rs.core.Response) Capacity(alluxio.wire.Capacity) AlluxioMasterInfo(alluxio.wire.AlluxioMasterInfo) Metric(com.codahale.metrics.Metric) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with AlluxioMasterInfo

use of alluxio.wire.AlluxioMasterInfo in project alluxio by Alluxio.

the class AlluxioMasterRestApiTest method getInfo.

private AlluxioMasterInfo getInfo(Map<String, String> params) throws Exception {
    String result = new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_INFO), params, HttpMethod.GET, null).call();
    AlluxioMasterInfo info = new ObjectMapper().readValue(result, AlluxioMasterInfo.class);
    return info;
}
Also used : AlluxioMasterInfo(alluxio.wire.AlluxioMasterInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

AlluxioMasterInfo (alluxio.wire.AlluxioMasterInfo)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 TestCase (alluxio.rest.TestCase)1 Capacity (alluxio.wire.Capacity)1 WorkerInfo (alluxio.wire.WorkerInfo)1 Metric (com.codahale.metrics.Metric)1 MetricSet (com.codahale.metrics.MetricSet)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 InetSocketAddress (java.net.InetSocketAddress)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1