use of com.tencent.angel.psagent.client.MasterClient in project angel by Tencent.
the class PSAgentTest method testMasterClient.
@Test
public void testMasterClient() throws Exception {
try {
AngelApplicationMaster angelAppMaster = LocalClusterContext.get().getMaster().getAppMaster();
assertTrue(angelAppMaster != null);
AMTaskManager taskManager = angelAppMaster.getAppContext().getTaskManager();
assertTrue(taskManager != null);
WorkerManager workerManager = angelAppMaster.getAppContext().getWorkerManager();
assertTrue(workerManager != null);
Worker worker = LocalClusterContext.get().getWorker(worker0Attempt0Id).getWorker();
PSAgentMatrixMetaManager matrixMetaManager = worker.getPSAgent().getMatrixMetaManager();
int w1Id = matrixMetaManager.getMatrixId("w1");
int w2Id = matrixMetaManager.getMatrixId("w2");
MasterClient masterClient = worker.getPSAgent().getMasterClient();
assertTrue(masterClient != null);
Location location = masterClient.getPSLocation(psId);
String ipRegex = "(2[5][0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})";
Pattern pattern = Pattern.compile(ipRegex);
Matcher matcher = pattern.matcher(location.getIp());
assertTrue(matcher.matches());
assertTrue(location.getPort() >= 1 && location.getPort() <= 65535);
Map<ParameterServerId, Location> psLocations = masterClient.getPSLocations();
assertEquals(psLocations.size(), 1);
} catch (Exception x) {
LOG.error("run testMasterClient failed ", x);
throw x;
}
}
use of com.tencent.angel.psagent.client.MasterClient in project angel by Tencent.
the class PSAgentTest method testPSClient.
@Test
public void testPSClient() throws Exception {
try {
AngelApplicationMaster angelAppMaster = LocalClusterContext.get().getMaster().getAppMaster();
assertTrue(angelAppMaster != null);
AMTaskManager taskManager = angelAppMaster.getAppContext().getTaskManager();
assertTrue(taskManager != null);
WorkerManager workerManager = angelAppMaster.getAppContext().getWorkerManager();
assertTrue(workerManager != null);
Worker worker = LocalClusterContext.get().getWorker(worker0Attempt0Id).getWorker();
assertTrue(worker != null);
PSAgent psAgent = worker.getPSAgent();
assertTrue(psAgent != null);
// psAgent.initAndStart();
// test conf
Configuration conf = psAgent.getConf();
assertTrue(conf != null);
assertEquals(conf.get(AngelConf.ANGEL_DEPLOY_MODE), "LOCAL");
// test master location
Location masterLoc = psAgent.getMasterLocation();
String ipRegex = "(2[5][0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})";
Pattern pattern = Pattern.compile(ipRegex);
Matcher matcher = pattern.matcher(masterLoc.getIp());
assertTrue(matcher.matches());
assertTrue(masterLoc.getPort() >= 1 && masterLoc.getPort() <= 65535);
// test app id
ApplicationId appId = psAgent.getAppId();
// test user
String user = psAgent.getUser();
// test ps agent attempt id
int psAgentId = psAgent.getId();
assertEquals(psAgentId, 1);
// test connection
TConnection conn = psAgent.getConnection();
assertTrue(conn != null);
// test master client
MasterClient masterClient = psAgent.getMasterClient();
assertTrue(masterClient != null);
// test ip
String ip = psAgent.getIp();
matcher = pattern.matcher(ip);
assertTrue(matcher.matches());
// test loc
Location loc = psAgent.getLocation();
assertTrue(loc != null);
matcher = pattern.matcher(loc.getIp());
assertTrue(matcher.matches());
assertTrue(loc.getPort() >= 1 && loc.getPort() <= 65535);
} catch (Exception x) {
LOG.error("run testPSClient failed ", x);
throw x;
}
}
use of com.tencent.angel.psagent.client.MasterClient in project angel by Tencent.
the class TaskContext method releaseMatrix.
/**
* Release matrix.
*
* @param matrix the matrix
* @return the matrix meta
* @throws ServiceException
* @throws InterruptedException
*/
public MatrixMeta releaseMatrix(MatrixMeta matrix) throws Exception {
MasterClient masterClient = WorkerContext.get().getPSAgent().getMasterClient();
masterClient.releaseMatrix(matrix.getName());
return matrix;
}
use of com.tencent.angel.psagent.client.MasterClient in project angel by Tencent.
the class TaskManagerTest method testTaskIteration.
@Test
public void testTaskIteration() throws Exception {
try {
LOG.info("===========================testTaskIteration===============================");
AngelApplicationMaster angelAppMaster = LocalClusterContext.get().getMaster().getAppMaster();
assertTrue(angelAppMaster != null);
AMTaskManager taskManager = angelAppMaster.getAppContext().getTaskManager();
WorkerManager workerManager = angelAppMaster.getAppContext().getWorkerManager();
assertTrue(workerManager != null);
AMWorkerGroup workerGroup0 = workerManager.getWorkGroup(worker0Id);
AMWorker worker0 = workerGroup0.getWorker(worker0Id);
WorkerAttempt worker0Attempt0 = worker0.getWorkerAttempt(worker0Attempt0Id);
Worker worker = LocalClusterContext.get().getWorker(worker0Attempt0Id).getWorker();
MasterClient masterClient = worker.getPSAgent().getMasterClient();
masterClient.taskIteration(task0Id.getIndex(), 1);
AMTask task0 = taskManager.getTask(task0Id);
AMTask task1 = taskManager.getTask(task1Id);
assertEquals(task0.getIteration(), 1);
assertEquals(task1.getIteration(), 0);
assertEquals(worker0Attempt0.getMinIteration(), 0);
assertEquals(worker0.getMinIteration(), 0);
assertEquals(workerGroup0.getMinIteration(), 0);
masterClient.taskIteration(task1Id.getIndex(), 1);
assertEquals(task0.getIteration(), 1);
assertEquals(task1.getIteration(), 1);
assertEquals(worker0Attempt0.getMinIteration(), 1);
assertEquals(worker0.getMinIteration(), 1);
assertEquals(workerGroup0.getMinIteration(), 1);
} catch (Exception x) {
LOG.error("run testTaskIteration failed ", x);
throw x;
}
}
Aggregations