use of com.tencent.angel.common.location.Location in project angel by Tencent.
the class MasterClient method register.
/**
* Register to Master
*
* @throws IOException
* @throws ServiceException
*/
public void register() throws IOException, ServiceException {
PSRegisterRequest.Builder regBuilder = PSRegisterRequest.newBuilder();
regBuilder.setPsAttemptId(ProtobufUtil.convertToIdProto(context.getPSAttemptId()));
try {
Location location = new Location(InetAddress.getLocalHost().getHostAddress(), context.getPsService().getPort());
regBuilder.setLocation(ProtobufUtil.convertLocation(location));
} catch (UnknownHostException eop) {
LOG.error("UnknownHostException: " + eop);
throw new IOException(eop);
}
masterProxy.psRegister(null, regBuilder.build());
}
use of com.tencent.angel.common.location.Location in project angel by Tencent.
the class MasterService method psRegister.
/**
* response for parameter server register.
*
* @param controller rpc controller of protobuf
* @param request register request
*/
@SuppressWarnings("unchecked")
@Override
public PSRegisterResponse psRegister(RpcController controller, PSRegisterRequest request) throws ServiceException {
if (LOG.isDebugEnabled()) {
LOG.debug("receive ps register request. request=" + request);
}
PSAttemptId psAttemptId = ProtobufUtil.convertToId(request.getPsAttemptId());
PSRegisterResponse.Builder resBuilder = PSRegisterResponse.newBuilder();
// if psAttemptId is not in monitor set, just return a PSCOMMAND_SHUTDOWN command.
if (!context.getParameterServerManager().isAlive(psAttemptId)) {
LOG.info(psAttemptId + " doesn't exists!");
resBuilder.setPsCommand(PSCommandProto.PSCOMMAND_SHUTDOWN);
} else {
context.getParameterServerManager().alive(psAttemptId);
context.getEventHandler().handle(new PSAttemptRegisterEvent(psAttemptId, new Location(request.getLocation().getIp(), request.getLocation().getPort())));
LOG.info(psAttemptId + " is registered now!");
resBuilder.setPsCommand(PSCommandProto.PSCOMMAND_OK);
}
LOG.info(psAttemptId + " register finished!");
return resBuilder.build();
}
use of com.tencent.angel.common.location.Location in project angel by Tencent.
the class MasterService method getPartLocation.
/**
* Get locations for a partition
*/
@Override
public GetPartLocationResponse getPartLocation(RpcController controller, GetPartLocationRequest request) throws ServiceException {
GetPartLocationResponse.Builder builder = GetPartLocationResponse.newBuilder();
List<ParameterServerId> psIds = context.getMatrixMetaManager().getPss(request.getMatrixId(), request.getPartId());
if (psIds != null) {
int size = psIds.size();
for (int i = 0; i < size; i++) {
Location psLocation = context.getLocationManager().getPsLocation(psIds.get(i));
if (psLocation == null) {
builder.addLocations((PSLocationProto.newBuilder().setPsId(ProtobufUtil.convertToIdProto(psIds.get(i))).setPsStatus(PSStatus.PS_NOTREADY).build()));
} else {
builder.addLocations(ProtobufUtil.convertToPSLocProto(psIds.get(i), psLocation));
}
}
}
return builder.build();
}
use of com.tencent.angel.common.location.Location in project angel by Tencent.
the class MasterService method getPSLocation.
/**
* get a specific parameter server location.
*
* @param controller rpc controller of protobuf
* @param request parameter server id
*/
@Override
public GetPSLocationReponse getPSLocation(RpcController controller, GetPSLocationRequest request) throws ServiceException {
GetPSLocationReponse.Builder resBuilder = GetPSLocationReponse.newBuilder();
ParameterServerId psId = ProtobufUtil.convertToId(request.getPsId());
Location psLocation = context.getLocationManager().getPsLocation(psId);
if (psLocation == null) {
resBuilder.setPsLocation(PSLocationProto.newBuilder().setPsId(request.getPsId()).setPsStatus(PSStatus.PS_NOTREADY).build());
} else {
resBuilder.setPsLocation(ProtobufUtil.convertToPSLocProto(psId, psLocation));
}
return resBuilder.build();
}
use of com.tencent.angel.common.location.Location in project angel by Tencent.
the class MasterService method serviceInit.
@Override
protected void serviceInit(Configuration conf) throws Exception {
String ip;
int servicePort;
if (conf.get(AngelConf.ANGEL_DEPLOY_MODE, AngelConf.DEFAULT_ANGEL_DEPLOY_MODE).equals("KUBERNETES")) {
ip = conf.get(AngelConf.ANGEL_KUBERNETES_MASTER_POD_IP);
servicePort = conf.getInt(AngelConf.ANGEL_KUBERNETES_MASTER_PORT, AngelConf.DEFAULT_ANGEL_KUBERNETES_MASTER_PORT);
} else {
ip = NetUtils.getRealLocalIP();
// choose a unused port
servicePort = NetUtils.chooseAListenPort(conf);
}
LOG.info("listen ip:" + ip + ", port:" + servicePort);
location = new Location(ip, servicePort);
// start RPC server
this.rpcServer = MLRPC.getServer(MasterService.class, this, new Class<?>[] { MasterProtocol.class }, ip, servicePort, conf);
rpcServer.openServer();
super.serviceInit(conf);
}
Aggregations