public void requestAndLaunchContainers ( ) throws Exception { if ( masterExists ( ) ) { InetAddress address = InetAddress . getByName ( mMasterAddress ) ; mMasterContainerNetAddress = address . getHostAddress ( ) ; LOG . info ( "Found master already running on " + mMasterAddress ) ; } else { LOG . info ( "Configuring master container request." ) ; Resource masterResource = Records . newRecord ( Resource . class ) ; masterResource . setMemory ( mMasterMemInMB ) ; masterResource . setVirtualCores ( mMasterCpu ) ; mContainerAllocator = new ContainerAllocator ( "master" , 1 , 1 , masterResource , mYarnClient , mRMClient , mMasterAddress ) ; List < Container > masterContainers = mContainerAllocator . allocateContainers ( ) ; launchMasterContainer ( Iterables . getOnlyElement ( masterContainers ) ) ; } Resource workerResource = Records . newRecord ( Resource . class ) ; workerResource . setMemory ( mWorkerMemInMB + mRamdiskMemInMB ) ; workerResource . setVirtualCores ( mWorkerCpu ) ; mContainerAllocator = new ContainerAllocator ( "worker" , mNumWorkers , mMaxWorkersPerHost , workerResource , mYarnClient , mRMClient ) ; List < Container > workerContainers = mContainerAllocator . allocateContainers ( ) ; for ( Container container : workerContainers ) { launchWorkerContainer ( container ) ; } LOG . info ( "Master and workers are launched" ) ; }
Submits requests for containers until the master and all workers are launched .