Search in sources :

Example 1 with WorkerAttemptRegisterEvent

use of com.tencent.angel.master.worker.attempt.WorkerAttemptRegisterEvent in project angel by Tencent.

the class MasterService method workerRegister.

/**
 * worker register to master
 *
 * @param controller rpc controller of protobuf
 * @param request contains worker attempt id, worker location
 */
@SuppressWarnings("unchecked")
@Override
public WorkerRegisterResponse workerRegister(RpcController controller, WorkerRegisterRequest request) throws ServiceException {
    WorkerRegisterResponse.Builder registerResponseBuilder = WorkerRegisterResponse.newBuilder();
    WorkerAttemptId workerAttemptId = ProtobufUtil.convertToId(request.getWorkerAttemptId());
    LOG.info("Worker " + workerAttemptId + " register, location=" + request.getLocation() + ", psagent id=" + request.getPsAgentId());
    // if worker attempt id is not in monitor set, we should shutdown it
    if (!context.getWorkerManager().isAlive(workerAttemptId)) {
        LOG.error("worker attempt " + workerAttemptId + " is not in running worker attempt set now, shutdown it");
        registerResponseBuilder.setCommand(WorkerCommandProto.W_SHUTDOWN);
    } else {
        context.getWorkerManager().alive(workerAttemptId);
        Location location = new Location(request.getLocation().getIp(), request.getLocation().getPort());
        context.getEventHandler().handle(new WorkerAttemptRegisterEvent(workerAttemptId, location));
        registerResponseBuilder.setCommand(WorkerCommandProto.W_SUCCESS);
        LOG.info("worker attempt " + workerAttemptId + " register finished!");
    }
    return registerResponseBuilder.build();
}
Also used : WorkerRegisterResponse(com.tencent.angel.protobuf.generated.WorkerMasterServiceProtos.WorkerRegisterResponse) WorkerAttemptId(com.tencent.angel.worker.WorkerAttemptId) WorkerAttemptRegisterEvent(com.tencent.angel.master.worker.attempt.WorkerAttemptRegisterEvent) PSLocation(com.tencent.angel.ps.server.data.PSLocation) Location(com.tencent.angel.common.location.Location)

Aggregations

Location (com.tencent.angel.common.location.Location)1 WorkerAttemptRegisterEvent (com.tencent.angel.master.worker.attempt.WorkerAttemptRegisterEvent)1 WorkerRegisterResponse (com.tencent.angel.protobuf.generated.WorkerMasterServiceProtos.WorkerRegisterResponse)1 PSLocation (com.tencent.angel.ps.server.data.PSLocation)1 WorkerAttemptId (com.tencent.angel.worker.WorkerAttemptId)1