Search in sources :

Example 1 with ContainerInfo

use of com.baidu.hugegraph.computer.core.common.ContainerInfo in project hugegraph-computer by hugegraph.

the class Bsp4Worker method waitMasterInitDone.

/**
 * Wait master registered, get master's information includes hostname
 * and port.
 */
public ContainerInfo waitMasterInitDone() {
    LOG.info("Worker({}) is waiting for master init-done", this.workerInfo.uniqueName());
    String path = this.constructPath(BspEvent.BSP_MASTER_INIT_DONE);
    byte[] bytes = this.bspClient().get(path, this.registerTimeout(), this.logInterval());
    ContainerInfo masterInfo = new ContainerInfo();
    SerializeUtil.fromBytes(bytes, masterInfo);
    LOG.info("Worker({}) waited master init-done: {}", this.workerInfo.uniqueName(), masterInfo);
    return masterInfo;
}
Also used : ContainerInfo(com.baidu.hugegraph.computer.core.common.ContainerInfo)

Example 2 with ContainerInfo

use of com.baidu.hugegraph.computer.core.common.ContainerInfo in project hugegraph-computer by hugegraph.

the class EtcdBspTest method testInit.

@Test
public void testInit() throws InterruptedException {
    // If both two threads reach countDown, it means no exception is thrown.
    CountDownLatch countDownLatch = new CountDownLatch(2);
    this.executorService.submit(() -> {
        this.bsp4Master.masterInitDone(this.masterInfo);
        List<ContainerInfo> workers = this.bsp4Master.waitWorkersInitDone();
        Assert.assertEquals(1, workers.size());
        countDownLatch.countDown();
    });
    this.executorService.submit(() -> {
        this.bsp4Worker.workerInitDone();
        ContainerInfo master = this.bsp4Worker.waitMasterInitDone();
        Assert.assertEquals(this.masterInfo, master);
        List<ContainerInfo> workers = this.bsp4Worker.waitMasterAllInitDone();
        Assert.assertEquals(1, workers.size());
        Assert.assertEquals(this.workerInfo, workers.get(0));
        countDownLatch.countDown();
    });
    countDownLatch.await();
}
Also used : ContainerInfo(com.baidu.hugegraph.computer.core.common.ContainerInfo) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with ContainerInfo

use of com.baidu.hugegraph.computer.core.common.ContainerInfo in project hugegraph-computer by hugegraph.

the class MasterService method init.

/**
 * Init master service, create the managers used by master.
 */
public void init(Config config) {
    E.checkArgument(!this.inited, "The %s has been initialized", this);
    LOG.info("{} Start to initialize master", this);
    this.serviceThread = Thread.currentThread();
    this.registerShutdownHook();
    this.config = config;
    this.maxSuperStep = this.config.get(ComputerOptions.BSP_MAX_SUPER_STEP);
    InetSocketAddress rpcAddress = this.initManagers();
    this.masterInfo = new ContainerInfo(ContainerInfo.MASTER_ID, TransportUtil.host(rpcAddress), rpcAddress.getPort());
    /*
         * Connect to BSP server and clean the old data may be left by the
         * previous job with same job id.
         */
    this.bsp4Master = new Bsp4Master(this.config);
    this.bsp4Master.clean();
    this.masterComputation = this.config.createObject(ComputerOptions.MASTER_COMPUTATION_CLASS);
    this.masterComputation.init(new DefaultMasterContext());
    this.managers.initedAll(config);
    LOG.info("{} register MasterService", this);
    this.bsp4Master.masterInitDone(this.masterInfo);
    this.workers = this.bsp4Master.waitWorkersInitDone();
    LOG.info("{} waited all workers registered, workers count: {}", this, this.workers.size());
    LOG.info("{} MasterService initialized", this);
    this.inited = true;
}
Also used : Bsp4Master(com.baidu.hugegraph.computer.core.bsp.Bsp4Master) InetSocketAddress(java.net.InetSocketAddress) ContainerInfo(com.baidu.hugegraph.computer.core.common.ContainerInfo)

Example 4 with ContainerInfo

use of com.baidu.hugegraph.computer.core.common.ContainerInfo in project hugegraph-computer by hugegraph.

the class WorkerService method init.

/**
 * Init worker service, create the managers used by worker service.
 */
public void init(Config config) {
    E.checkArgument(!this.inited, "The %s has been initialized", this);
    this.serviceThread = Thread.currentThread();
    this.registerShutdownHook();
    this.config = config;
    this.workerInfo = new ContainerInfo();
    LOG.info("{} Start to initialize worker", this);
    this.bsp4Worker = new Bsp4Worker(this.config, this.workerInfo);
    /*
         * Keep the waitMasterInitDone() called before initManagers(),
         * in order to ensure master init() before worker managers init()
         */
    this.masterInfo = this.bsp4Worker.waitMasterInitDone();
    InetSocketAddress address = this.initManagers(this.masterInfo);
    this.workerInfo.updateAddress(address);
    Computation<?> computation = this.config.createObject(ComputerOptions.WORKER_COMPUTATION_CLASS);
    LOG.info("Loading computation '{}' in category '{}'", computation.name(), computation.category());
    this.combiner = this.config.createObject(ComputerOptions.WORKER_COMBINER_CLASS, false);
    if (this.combiner == null) {
        LOG.info("None combiner is provided for computation '{}'", computation.name());
    } else {
        LOG.info("Combiner '{}' is provided for computation '{}'", this.combiner.name(), computation.name());
    }
    LOG.info("{} register WorkerService", this);
    this.bsp4Worker.workerInitDone();
    List<ContainerInfo> workers = this.bsp4Worker.waitMasterAllInitDone();
    DataClientManager dm = this.managers.get(DataClientManager.NAME);
    for (ContainerInfo worker : workers) {
        this.workers.put(worker.id(), worker);
        dm.connect(worker.id(), worker.hostname(), worker.dataPort());
    }
    this.computeManager = new ComputeManager(this.context, this.managers);
    this.managers.initedAll(this.config);
    LOG.info("{} WorkerService initialized", this);
    this.inited = true;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DataClientManager(com.baidu.hugegraph.computer.core.network.DataClientManager) ContainerInfo(com.baidu.hugegraph.computer.core.common.ContainerInfo) Bsp4Worker(com.baidu.hugegraph.computer.core.bsp.Bsp4Worker) ComputeManager(com.baidu.hugegraph.computer.core.compute.ComputeManager)

Example 5 with ContainerInfo

use of com.baidu.hugegraph.computer.core.common.ContainerInfo in project hugegraph-computer by hugegraph.

the class EtcdBspTest method setup.

@Before
public void setup() {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.JOB_ID, "local_001", ComputerOptions.JOB_WORKERS_COUNT, "1", ComputerOptions.BSP_LOG_INTERVAL, "30000", ComputerOptions.BSP_MAX_SUPER_STEP, "2");
    this.bsp4Master = new Bsp4Master(config);
    this.bsp4Master.clean();
    this.masterInfo = new ContainerInfo(-1, "localhost", 8001, 8002);
    this.workerInfo = new ContainerInfo(0, "localhost", 8003, 8004);
    this.bsp4Worker = new Bsp4Worker(config, this.workerInfo);
    this.maxSuperStep = config.get(ComputerOptions.BSP_MAX_SUPER_STEP);
}
Also used : Config(com.baidu.hugegraph.computer.core.config.Config) ContainerInfo(com.baidu.hugegraph.computer.core.common.ContainerInfo) Before(org.junit.Before)

Aggregations

ContainerInfo (com.baidu.hugegraph.computer.core.common.ContainerInfo)7 InetSocketAddress (java.net.InetSocketAddress)2 Bsp4Master (com.baidu.hugegraph.computer.core.bsp.Bsp4Master)1 Bsp4Worker (com.baidu.hugegraph.computer.core.bsp.Bsp4Worker)1 ComputeManager (com.baidu.hugegraph.computer.core.compute.ComputeManager)1 Config (com.baidu.hugegraph.computer.core.config.Config)1 DataClientManager (com.baidu.hugegraph.computer.core.network.DataClientManager)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Before (org.junit.Before)1 Test (org.junit.Test)1