Search in sources :

Example 1 with HugeGraphComputerJob

use of com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob in project hugegraph-computer by hugegraph.

the class ComputerJobDeployer method deploy.

public void deploy(ComputerJobComponent observed) {
    HugeGraphComputerJob computerJob = observed.computerJob();
    Set<ContainerPort> ports = this.handleConfig(computerJob.getSpec());
    ComputerJobComponent desired = new ComputerJobComponent();
    desired.configMap(this.desiredConfigMap(computerJob));
    desired.masterJob(this.desiredMasterJob(computerJob, ports));
    desired.workerJob(this.desiredWorkerJob(computerJob, ports));
    this.reconcileComponent(computerJob.getMetadata().getNamespace(), desired, observed);
}
Also used : ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) HugeGraphComputerJob(com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob)

Example 2 with HugeGraphComputerJob

use of com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob in project hugegraph-computer by hugegraph.

the class ComputerJobController method observeComponent.

private ComputerJobComponent observeComponent(HugeGraphComputerJob computerJob) {
    ComputerJobComponent observed = new ComputerJobComponent();
    observed.computerJob(computerJob);
    String namespace = computerJob.getMetadata().getNamespace();
    String crName = computerJob.getMetadata().getName();
    String masterName = KubeUtil.masterJobName(crName);
    Job master = this.getResourceByName(namespace, masterName, Job.class);
    observed.masterJob(master);
    if (master != null) {
        List<Pod> masterPods = this.getPodsByJob(master);
        observed.masterPods(masterPods);
    }
    String workerName = KubeUtil.workerJobName(crName);
    Job worker = this.getResourceByName(namespace, workerName, Job.class);
    observed.workerJob(worker);
    if (worker != null) {
        List<Pod> workerPods = this.getPodsByJob(worker);
        observed.workerPods(workerPods);
    }
    String configMapName = KubeUtil.configMapName(crName);
    ConfigMap configMap = this.getResourceByName(namespace, configMapName, ConfigMap.class);
    observed.configMap(configMap);
    return observed;
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) HugeGraphComputerJob(com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob)

Example 3 with HugeGraphComputerJob

use of com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob in project hugegraph-computer by hugegraph.

the class ComputerJobController method updateStatus.

private boolean updateStatus(ComputerJobComponent observed) {
    ComputerJobStatus newStatus = this.derivedCRStatus(observed);
    ComputerJobStatus oldStatus = observed.computerJob().getStatus();
    if (!Objects.deepEquals(oldStatus, newStatus)) {
        HugeGraphComputerJob computerJob = observed.computerJob();
        computerJob.setStatus(newStatus);
        this.updateStatus(computerJob);
        return true;
    }
    return false;
}
Also used : HugeGraphComputerJob(com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob) ComputerJobStatus(com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobStatus)

Example 4 with HugeGraphComputerJob

use of com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob in project hugegraph-computer by hugegraph.

the class KubernetesDriverTest method testSubmitJob.

@Test
public void testSubmitJob() {
    Map<String, String> params = new HashMap<>();
    params.put(KubeSpecOptions.WORKER_INSTANCES.name(), "10");
    String jobId = this.driver.submitJob("PageRank", params);
    HugeGraphComputerJob computerJob = this.operation.withName(KubeUtil.crName(jobId)).get();
    Assert.assertNotNull(computerJob);
    Assert.assertEquals(computerJob.getSpec().getAlgorithmName(), "PageRank");
    Assert.assertEquals(computerJob.getSpec().getJobId(), jobId);
}
Also used : HashMap(java.util.HashMap) HugeGraphComputerJob(com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob) Test(org.junit.Test)

Example 5 with HugeGraphComputerJob

use of com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob in project hugegraph-computer by hugegraph.

the class KubernetesDriverTest method testCancelJob.

@Test
public void testCancelJob() {
    Map<String, String> params = new HashMap<>();
    params.put(KubeSpecOptions.WORKER_INSTANCES.name(), "10");
    String jobId = this.driver.submitJob("PageRank2", params);
    String crName = KubeUtil.crName(jobId);
    HugeGraphComputerJob computerJob = this.operation.withName(crName).get();
    Assert.assertNotNull(computerJob);
    UnitTestBase.sleep(1000L);
    this.driver.cancelJob(jobId, params);
    HugeGraphComputerJob canceledComputerJob = this.operation.withName(crName).get();
    Assert.assertNull(canceledComputerJob);
    Assert.assertNull(this.driver.jobState(jobId, params));
}
Also used : HashMap(java.util.HashMap) HugeGraphComputerJob(com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob) Test(org.junit.Test)

Aggregations

HugeGraphComputerJob (com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob)12 Test (org.junit.Test)4 ComputerJobSpec (com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobSpec)3 HashMap (java.util.HashMap)3 ComputerJobStatus (com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobStatus)2 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 Job (io.fabric8.kubernetes.api.model.batch.v1.Job)2 DefaultJobState (com.baidu.hugegraph.computer.driver.DefaultJobState)1 JobObserver (com.baidu.hugegraph.computer.driver.JobObserver)1 CommonComponentState (com.baidu.hugegraph.computer.k8s.crd.model.CommonComponentState)1 ComponentState (com.baidu.hugegraph.computer.k8s.crd.model.ComponentState)1 ComponentStateBuilder (com.baidu.hugegraph.computer.k8s.crd.model.ComponentStateBuilder)1 JobComponentState (com.baidu.hugegraph.computer.k8s.crd.model.JobComponentState)1 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)1 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)1 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 WatcherException (io.fabric8.kubernetes.client.WatcherException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1