use of com.tencent.angel.master.deploy.yarn.YarnContainerAllocator in project angel by Tencent.
the class AngelApplicationMaster method initAndStart.
/**
* init and start all service modules for angel applicaiton master.
*/
public void initAndStart() throws Exception {
addIfService(angelApp);
// init app state storage
String tmpOutPath = conf.get(AngelConf.ANGEL_JOB_TMP_OUTPUT_PATH);
Path appStatePath = new Path(tmpOutPath, "app");
LOG.info("app state output path = " + appStatePath.toUri().toString());
FileSystem fs = appStatePath.getFileSystem(conf);
appStateStorage = new AppStateStorage(appContext, appStatePath.toUri().toString(), fs);
addIfService(appStateStorage);
LOG.info("build app state storage success");
// init event dispacher
dispatcher = new AsyncDispatcher();
addIfService(dispatcher);
LOG.info("build event dispacher");
// init location manager
locationManager = new LocationManager();
// init container allocator
AngelDeployMode deployMode = appContext.getDeployMode();
LOG.info("deploy mode=" + deployMode);
if (deployMode == AngelDeployMode.LOCAL) {
containerAllocator = new LocalContainerAllocator(appContext);
containerLauncher = new LocalContainerLauncher(appContext);
} else {
containerAllocator = new YarnContainerAllocator(appContext);
containerLauncher = new YarnContainerLauncher(appContext);
}
addIfService(containerAllocator);
dispatcher.register(ContainerAllocatorEventType.class, containerAllocator);
LOG.info("build containerAllocator success");
addIfService(containerLauncher);
dispatcher.register(ContainerLauncherEventType.class, containerLauncher);
LOG.info("build containerLauncher success");
// init a rpc service
masterService = new MasterService(appContext);
LOG.info("build master service success");
// recover matrix meta if needed
recoverMatrixMeta();
// recover ps attempt information if need
Map<ParameterServerId, Integer> psIdToAttemptIndexMap = recoverPSAttemptIndex();
if (psIdToAttemptIndexMap == null) {
LOG.info("recoverPSAttemptIndex return is null");
} else {
for (Entry<ParameterServerId, Integer> entry : psIdToAttemptIndexMap.entrySet()) {
LOG.info("psId=" + entry.getKey() + ",attemptIndex=" + entry.getValue());
}
}
// init parameter server manager
psManager = new ParameterServerManager(appContext, psIdToAttemptIndexMap);
addIfService(psManager);
psManager.init();
List<ParameterServerId> psIds = new ArrayList<>(psManager.getParameterServerMap().keySet());
Collections.sort(psIds, new Comparator<ParameterServerId>() {
@Override
public int compare(ParameterServerId s1, ParameterServerId s2) {
return s1.getIndex() - s2.getIndex();
}
});
locationManager.setPsIds(psIds.toArray(new ParameterServerId[0]));
dispatcher.register(ParameterServerManagerEventType.class, psManager);
dispatcher.register(AMParameterServerEventType.class, new ParameterServerEventHandler());
dispatcher.register(PSAttemptEventType.class, new PSAttemptEventDispatcher());
LOG.info("build PSManager success");
// recover task information if needed
recoverTaskState();
RunningMode mode = appContext.getRunningMode();
LOG.info("running mode=" + mode);
switch(mode) {
case ANGEL_PS_PSAGENT:
{
// init psagent manager and register psagent manager event
psAgentManager = new PSAgentManager(appContext);
addIfService(psAgentManager);
dispatcher.register(PSAgentManagerEventType.class, psAgentManager);
dispatcher.register(AMPSAgentEventType.class, new PSAgentEventHandler());
dispatcher.register(PSAgentAttemptEventType.class, new PSAgentAttemptEventHandler());
LOG.info("build PSAgentManager success");
break;
}
case ANGEL_PS_WORKER:
{
// a dummy data spliter is just for test now
boolean useDummyDataSpliter = conf.getBoolean(AngelConf.ANGEL_AM_USE_DUMMY_DATASPLITER, AngelConf.DEFAULT_ANGEL_AM_USE_DUMMY_DATASPLITER);
if (useDummyDataSpliter) {
dataSpliter = new DummyDataSpliter(appContext);
} else {
// recover data splits information if needed
recoveryDataSplits();
}
// init worker manager and register worker manager event
workerManager = new WorkerManager(appContext);
workerManager.adjustTaskNumber(dataSpliter.getSplitNum());
addIfService(workerManager);
dispatcher.register(WorkerManagerEventType.class, workerManager);
dispatcher.register(AMWorkerGroupEventType.class, new WorkerGroupEventHandler());
dispatcher.register(AMWorkerEventType.class, new WorkerEventHandler());
dispatcher.register(WorkerAttemptEventType.class, new WorkerAttemptEventHandler());
LOG.info("build WorkerManager success");
break;
}
case ANGEL_PS:
break;
}
// register slow worker/ps checker
addIfService(new SlowChecker(appContext));
algoMetricsService = new MetricsService(appContext);
addIfService(algoMetricsService);
dispatcher.register(MetricsEventType.class, algoMetricsService);
// register app manager event and finish event
dispatcher.register(AppEventType.class, angelApp);
dispatcher.register(AppFinishEventType.class, new AppFinishEventHandler());
masterService.init(conf);
super.init(conf);
// start a web service if use yarn deploy mode
if (deployMode == AngelDeployMode.YARN) {
try {
webApp = WebApps.$for("angel", AMContext.class, appContext).with(conf).start(new AngelWebApp());
LOG.info("start webapp server success");
LOG.info("webApp.port()=" + webApp.port());
} catch (Exception e) {
LOG.error("Webapps failed to start. Ignoring for now:", e);
}
}
masterService.start();
locationManager.setMasterLocation(masterService.getLocation());
super.serviceStart();
psManager.startAllPS();
AngelServiceLoader.startServiceIfNeed(this, getConfig());
LOG.info("appAttemptId.getAttemptId()=" + appAttemptId.getAttemptId());
if (appAttemptId.getAttemptId() > 1) {
waitForAllPsRegisted();
waitForAllMetricsInited();
angelApp.startExecute();
}
}
Aggregations