use of com.tencent.angel.common.location.Location in project angel by Tencent.
the class PSAgent method main.
public static void main(String[] args) {
// get configuration from config file
Configuration conf = new Configuration();
conf.addResource(AngelConf.ANGEL_JOB_CONF_FILE);
String containerIdStr = System.getenv(Environment.CONTAINER_ID.name());
ContainerId containerId = ConverterUtils.toContainerId(containerIdStr);
ApplicationAttemptId applicationAttemptId = containerId.getApplicationAttemptId();
ApplicationId appId = applicationAttemptId.getApplicationId();
String user = System.getenv(Environment.USER.name());
// set localDir with enviroment set by nm.
String[] localSysDirs = StringUtils.getTrimmedStrings(System.getenv(Environment.LOCAL_DIRS.name()));
conf.setStrings(AngelConf.LOCAL_DIR, localSysDirs);
LOG.info(AngelConf.LOCAL_DIR + " for child: " + conf.get(AngelConf.LOCAL_DIR));
String psAgentindex = System.getenv(AngelEnvironment.PSAGENT_ID.name());
String psAgentAttemptIndex = System.getenv(AngelEnvironment.PSAGENT_ATTEMPT_ID.name());
String masterAddr = System.getenv(AngelEnvironment.LISTEN_ADDR.name());
String portStr = System.getenv(AngelEnvironment.LISTEN_PORT.name());
Location masterLocation = new Location(masterAddr, Integer.valueOf(portStr));
LOG.info("psAgentindex=" + psAgentindex);
LOG.info("psAgentAttemptIndex=" + psAgentAttemptIndex);
LOG.info("masterLocation=" + masterLocation);
LOG.info("user=" + user);
LOG.info("appId=" + appId);
PSAgentId psAgentId = new PSAgentId(Integer.valueOf(psAgentindex));
PSAgentAttemptId psAgentAttemptId = new PSAgentAttemptId(psAgentId, Integer.valueOf(psAgentAttemptIndex));
try {
PSAgent psAgent = new PSAgent(conf, appId, user, psAgentAttemptId, masterAddr, Integer.valueOf(portStr), true, null);
psAgent.initAndStart();
} catch (Exception e) {
LOG.fatal("Failed to start worker.", e);
}
}
use of com.tencent.angel.common.location.Location in project angel by Tencent.
the class MasterClient method init.
/**
* Init protobuf rpc client to master
*
* @throws IOException connect to master failed
*/
public void init() throws IOException {
TConnection connection = TConnectionManager.getConnection(PSAgentContext.get().getConf());
Location masterLoc = PSAgentContext.get().getPsAgent().getMasterLocation();
this.master = connection.getMasterService(masterLoc.getIp(), masterLoc.getPort());
}
use of com.tencent.angel.common.location.Location 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;
}
}
use of com.tencent.angel.common.location.Location in project angel by Tencent.
the class WorkerTest method testMaster.
@Test
public void testMaster() throws Exception {
try {
localWorker = LocalClusterContext.get().getWorker(worker0Attempt0Id);
worker = localWorker.getWorker();
localMaster = LocalClusterContext.get().getMaster();
master = localMaster.getAppMaster();
assertTrue(master != null);
// master location
Location masterLoc = LocalClusterContext.get().getMaster().getAppMaster().getAppContext().getMasterService().getLocation();
assertEquals(masterLoc, worker.getMasterLocation());
// masterClient
MasterClient masterClient = worker.getPSAgent().getMasterClient();
WorkerMasterServiceProtos.WorkerRegisterResponse response = masterClient.workerRegister();
assertTrue(response != null);
assertEquals(WorkerMasterServiceProtos.WorkerCommandProto.W_SUCCESS, response.getCommand());
} catch (Exception x) {
LOG.error("run testMaster failed ", x);
throw x;
}
}
use of com.tencent.angel.common.location.Location in project angel by Tencent.
the class MatrixTransportClient method refreshServerLocation.
/**
* refresh the server location use async mode
*
* @param serverId server id
*/
private void refreshServerLocation(final ParameterServerId serverId) {
Thread psLocRefresher = new Thread() {
@Override
public void run() {
Location location = null;
try {
while (location == null) {
Thread.sleep(PSAgentContext.get().getRequestSleepTimeMS());
location = PSAgentContext.get().getMasterClient().getPSLocation(serverId);
LOG.info("Get PS " + serverId + " location = " + location);
if (location != null) {
Location oldLocation = PSAgentContext.get().getLocationManager().getPsLocation(serverId);
PSAgentContext.get().getLocationManager().setPsLocation(serverId, location);
if (oldLocation != null && location.equals(oldLocation)) {
refreshServerLocationSuccess(serverId, false);
} else {
refreshServerLocationSuccess(serverId, true);
}
return;
}
}
} catch (Exception x) {
refreshServerLocationFailed(serverId);
}
}
};
psLocRefresher.setName("ps-location-getter");
psLocRefresher.start();
}
Aggregations