Search in sources :

Example 11 with HubNodeAddress

use of alluxio.hub.proto.HubNodeAddress in project alluxio by Alluxio.

the class ManagerProcessContextTest method testListFiles.

@Test
public void testListFiles() {
    AgentListFileResponse r = AgentListFileResponse.newBuilder().addFileInfo(AgentListFileInfo.newBuilder().setFileName("abc123").setProcessType(UploadProcessType.PRESTO).build()).build();
    HubNodeAddress addr = HubTestUtils.generateNodeAddress();
    Map<HubNodeAddress, Pair<AlluxioNodeType, AgentListFileResponse>> resp = new HashMap<>();
    resp.put(addr, new Pair<>(AlluxioNodeType.MASTER, r));
    doReturn(resp).when(mContext).execOnHub(any(), eq(AlluxioNodeType.MASTER), any());
    doReturn(new HashMap<>()).when(mContext).execOnHub(any(), eq(AlluxioNodeType.WORKER), any());
    List<ListFile> s = mContext.listFiles();
    assertNotNull(s);
    assertEquals(1, s.size());
    assertTrue(s.get(0).hasLocation());
    assertTrue(s.get(0).hasName());
    assertTrue(s.get(0).hasProcessType());
    assertEquals(AlluxioNodeType.MASTER, s.get(0).getLocation());
    assertEquals("abc123", s.get(0).getName());
    assertEquals(UploadProcessType.PRESTO, s.get(0).getProcessType());
}
Also used : HubNodeAddress(alluxio.hub.proto.HubNodeAddress) ListFile(alluxio.hub.proto.ListFile) HashMap(java.util.HashMap) AgentListFileResponse(alluxio.hub.proto.AgentListFileResponse) Pair(alluxio.collections.Pair) BaseHubTest(alluxio.hub.test.BaseHubTest) Test(org.junit.Test)

Example 12 with HubNodeAddress

use of alluxio.hub.proto.HubNodeAddress in project alluxio by Alluxio.

the class HubCluster method scanNodes.

/**
 * Scans over the list of nodes in the cluster and marks them as lost if they haven't sent a
 * heartbeat in the expected interval. Otherwise, if the node is in the
 * {@link HubNodeState#LOST} and the time there exceeds a threshold, consider the node gone and
 * remove it from the cluster.
 */
void scanNodes() {
    long now = System.currentTimeMillis();
    long deleteIfBefore = now - mDeleteThreshold;
    long lostIfBefore = now - mLostThreshold;
    Iterator<Map.Entry<HubNodeAddress, Long>> iter = mHeartbeats.entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry<HubNodeAddress, Long> entry = iter.next();
        HubNodeAddress addr = entry.getKey();
        long time = entry.getValue();
        if (time < deleteIfBefore) {
            if (!remove(addr)) {
                LOG.debug("Failed to remove node {} from cluster", addr);
            }
            iter.remove();
            mAlluxioCluster.remove(addr.getHostname());
        } else if (time < lostIfBefore) {
            mNodes.put(addr, HubNodeState.LOST);
        } else {
            mNodes.put(addr, HubNodeState.ALIVE);
        }
    }
}
Also used : HubNodeAddress(alluxio.hub.proto.HubNodeAddress) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 13 with HubNodeAddress

use of alluxio.hub.proto.HubNodeAddress in project alluxio by Alluxio.

the class ManagerAgentServiceTest method agentHeartbeatTest.

@Test
public void agentHeartbeatTest() {
    AlluxioNodeStatus s = AlluxioNodeStatus.newBuilder().setHostname(UUID.randomUUID().toString()).addProcess(AlluxioProcessStatus.newBuilder().setState(ProcessState.RUNNING).setNodeType(AlluxioNodeType.MASTER).build()).build();
    HubNodeAddress addr = HubNodeAddress.newBuilder().setHostname(UUID.randomUUID().toString()).setRpcPort(56565).build();
    AgentHeartbeatRequest request = AgentHeartbeatRequest.newBuilder().setAlluxioStatus(s).setHubNode(addr).build();
    AgentHeartbeatResponse resp = mClient.agentHeartbeat(request);
    assertTrue(resp.hasOk());
    assertTrue(resp.getOk());
    assertEquals(1, mContext.getAlluxioCluster().size());
    AlluxioCluster c = mContext.getAlluxioCluster().toProto();
    AlluxioNodeStatus nodeStatus = c.getNode(0);
    assertEquals(s.getHostname(), nodeStatus.getHostname());
    assertEquals(AlluxioNodeType.MASTER, nodeStatus.getProcess(0).getNodeType());
    assertEquals(ProcessState.RUNNING, nodeStatus.getProcess(0).getState());
}
Also used : HubNodeAddress(alluxio.hub.proto.HubNodeAddress) AlluxioCluster(alluxio.hub.proto.AlluxioCluster) AgentHeartbeatRequest(alluxio.hub.proto.AgentHeartbeatRequest) AlluxioNodeStatus(alluxio.hub.proto.AlluxioNodeStatus) AgentHeartbeatResponse(alluxio.hub.proto.AgentHeartbeatResponse) Test(org.junit.Test) BaseHubTest(alluxio.hub.test.BaseHubTest)

Example 14 with HubNodeAddress

use of alluxio.hub.proto.HubNodeAddress in project alluxio by Alluxio.

the class HubClusterTest method testAddSame.

@Test
public void testAddSame() {
    HubNodeAddress s = HubNodeAddress.newBuilder().setHostname("test-host").setRpcPort(1234).build();
    mCluster.add(s);
    assertEquals(1, mCluster.size());
    HubNodeAddress s2 = HubNodeAddress.newBuilder().setHostname("test-host").setRpcPort(1234).build();
    mCluster.add(s2);
    assertEquals(1, mCluster.size());
}
Also used : HubNodeAddress(alluxio.hub.proto.HubNodeAddress) Test(org.junit.Test) BaseHubTest(alluxio.hub.test.BaseHubTest)

Example 15 with HubNodeAddress

use of alluxio.hub.proto.HubNodeAddress in project alluxio by Alluxio.

the class ManagerProcessContextTest method testRemoveFile.

@Test
public void testRemoveFile() {
    AgentRemoveFileResponse r = AgentRemoveFileResponse.newBuilder().setSuccess(true).build();
    HubNodeAddress addr = HubTestUtils.generateNodeAddress();
    Map<HubNodeAddress, AgentRemoveFileResponse> resp = new HashMap<>();
    resp.put(addr, r);
    RemoveFile req = RemoveFile.newBuilder().setLocation(AlluxioNodeType.WORKER).setProcessType(UploadProcessType.PRESTO).setName("uptime").build();
    doReturn(resp).when(mContext).execOnHub(any(), any(), any());
    boolean addFileResp = mContext.removeFile(Collections.singletonList(req));
    assertTrue(addFileResp);
    resp.put(HubTestUtils.generateNodeAddress(), r.toBuilder().setSuccess(false).build());
    assertFalse(mContext.removeFile(Collections.singletonList(req)));
}
Also used : HubNodeAddress(alluxio.hub.proto.HubNodeAddress) AgentRemoveFileResponse(alluxio.hub.proto.AgentRemoveFileResponse) HashMap(java.util.HashMap) RemoveFile(alluxio.hub.proto.RemoveFile) BaseHubTest(alluxio.hub.test.BaseHubTest) Test(org.junit.Test)

Aggregations

HubNodeAddress (alluxio.hub.proto.HubNodeAddress)17 BaseHubTest (alluxio.hub.test.BaseHubTest)13 Test (org.junit.Test)13 HashMap (java.util.HashMap)6 Map (java.util.Map)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 Pair (alluxio.collections.Pair)2 AgentFileUploadResponse (alluxio.hub.proto.AgentFileUploadResponse)2 AgentListCatalogResponse (alluxio.hub.proto.AgentListCatalogResponse)2 AlluxioConfigurationSet (alluxio.hub.proto.AlluxioConfigurationSet)2 AlluxioNodeType (alluxio.hub.proto.AlluxioNodeType)2 PrestoCatalogListing (alluxio.hub.proto.PrestoCatalogListing)2 UploadFile (alluxio.hub.proto.UploadFile)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Collections (java.util.Collections)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 After (org.junit.After)2 Assert.assertEquals (org.junit.Assert.assertEquals)2