Search in sources :

Example 1 with LocalWorker

use of com.tencent.angel.localcluster.LocalWorker in project angel by Tencent.

the class WorkerTest method testWorkerContext.

@Test
public void testWorkerContext() throws IOException {
    try {
        localWorker = LocalClusterContext.get().getWorker(worker0Attempt0Id);
        worker = localWorker.getWorker();
        WorkerContext context = WorkerContext.get();
        assertTrue(context != null);
        // application
        ApplicationId appid = context.getAppId();
        assertTrue(appid != null);
        assertEquals(LocalClusterContext.get().getAppId(), appid);
        assertEquals(worker.getUser(), context.getUser());
        assertEquals(AngelDeployMode.LOCAL, context.getDeployMode());
        assertEquals(conf, context.getConf());
        assertEquals(0, context.getInitMinClock());
        // lcation
        String localIp = NetUtils.getRealLocalIP();
        Location location = context.getLocation();
        assertEquals(localIp, location.getIp());
        int port = location.getPort();
        assertTrue(port > 0 && port < 655355);
        // workerGroup info
        assertEquals(group0Id, context.getWorkerGroupId());
        // worker info
        Worker w = context.getWorker();
        assertTrue(w != null);
        assertTrue(w.equals(worker));
        WorkerId wid = context.getWorkerId();
        assertEquals(worker0Id, wid);
        assertEquals(worker0Attempt0Id, context.getWorkerAttemptId());
        assertEquals(ProtobufUtil.convertToIdProto(worker0Attempt0Id), context.getWorkerAttemptIdProto());
        Map<String, String> workerMetrics = context.getWorkerMetrics();
        assertTrue(workerMetrics != null);
        assertEquals(worker, context.getWorker());
        assertEquals(worker.getDataBlockManager(), context.getDataBlockManager());
        assertEquals(worker.getPSAgent(), context.getPSAgent());
        // task
        assertEquals(2, context.getActiveTaskNum());
        assertEquals(worker.getTaskManager(), context.getTaskManager());
    } catch (Exception x) {
        LOG.error("run testWorkerContext failed ", x);
        throw x;
    }
}
Also used : LocalWorker(com.tencent.angel.localcluster.LocalWorker) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) IOException(java.io.IOException) Location(com.tencent.angel.common.location.Location) MasterServiceTest(com.tencent.angel.master.MasterServiceTest)

Example 2 with LocalWorker

use of com.tencent.angel.localcluster.LocalWorker in project angel by Tencent.

the class LocalContainerLauncher method launch.

@SuppressWarnings("unchecked")
private void launch(ContainerLauncherEvent event) {
    Id id = event.getId();
    if (id instanceof PSAttemptId) {
        LocalPS ps = new LocalPS((PSAttemptId) id, context.getMasterService().getLocation(), context.getConf());
        context.getEventHandler().handle(new PSAttemptEvent(PSAttemptEventType.PA_CONTAINER_LAUNCHED, (PSAttemptId) id));
        try {
            ps.start();
            LocalClusterContext.get().addPS((PSAttemptId) id, ps);
        } catch (Exception e) {
            LOG.error("launch ps failed.", e);
            context.getEventHandler().handle(new PSAttemptEvent(PSAttemptEventType.PA_CONTAINER_LAUNCH_FAILED, (PSAttemptId) id));
        }
    } else if (id instanceof WorkerAttemptId) {
        LocalWorker worker = new LocalWorker(context.getConf(), context.getApplicationId(), context.getUser(), (WorkerAttemptId) id, context.getMasterService().getLocation(), 0, false);
        context.getEventHandler().handle(new WorkerAttemptEvent(WorkerAttemptEventType.CONTAINER_LAUNCHED, (WorkerAttemptId) id));
        try {
            worker.start();
            LocalClusterContext.get().addWorker((WorkerAttemptId) id, worker);
        } catch (Exception e) {
            LOG.error("launch worker failed.", e);
            context.getEventHandler().handle(new WorkerAttemptEvent(WorkerAttemptEventType.CONTAINER_LAUNCH_FAILED, (WorkerAttemptId) id));
        }
    }
}
Also used : PSAttemptId(com.tencent.angel.ps.PSAttemptId) WorkerAttemptId(com.tencent.angel.worker.WorkerAttemptId) LocalWorker(com.tencent.angel.localcluster.LocalWorker) LocalPS(com.tencent.angel.localcluster.LocalPS) WorkerAttemptEvent(com.tencent.angel.master.worker.attempt.WorkerAttemptEvent) PSAttemptId(com.tencent.angel.ps.PSAttemptId) WorkerAttemptId(com.tencent.angel.worker.WorkerAttemptId) Id(com.tencent.angel.common.Id) PSAttemptEvent(com.tencent.angel.master.ps.attempt.PSAttemptEvent)

Aggregations

LocalWorker (com.tencent.angel.localcluster.LocalWorker)2 Id (com.tencent.angel.common.Id)1 Location (com.tencent.angel.common.location.Location)1 LocalPS (com.tencent.angel.localcluster.LocalPS)1 MasterServiceTest (com.tencent.angel.master.MasterServiceTest)1 PSAttemptEvent (com.tencent.angel.master.ps.attempt.PSAttemptEvent)1 WorkerAttemptEvent (com.tencent.angel.master.worker.attempt.WorkerAttemptEvent)1 PSAttemptId (com.tencent.angel.ps.PSAttemptId)1 WorkerAttemptId (com.tencent.angel.worker.WorkerAttemptId)1 IOException (java.io.IOException)1 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)1