Search in sources :

Example 6 with JobObserver

use of com.baidu.hugegraph.computer.driver.JobObserver in project hugegraph-computer by hugegraph.

the class KubernetesDriverTest method testWatchJobAndCancel.

@Test
public void testWatchJobAndCancel() {
    Map<String, String> params = new HashMap<>();
    params.put(KubeSpecOptions.WORKER_INSTANCES.name(), "10");
    String jobId = this.driver.submitJob("PageRank3", params);
    JobObserver jobObserver = Mockito.mock(JobObserver.class);
    CompletableFuture<Void> future = this.driver.waitJobAsync(jobId, params, jobObserver);
    Mockito.verify(jobObserver, Mockito.timeout(5000L).atLeast(1)).onJobStateChanged(Mockito.any(DefaultJobState.class));
    future.getNow(null);
    MutableBoolean watchActive = Whitebox.getInternalState(this.driver, "watchActive");
    watchActive.setFalse();
    this.driver.waitJobAsync(jobId, params, jobObserver);
    this.driver.cancelJob(jobId, params);
    UnitTestBase.sleep(1000L);
    CompletableFuture<Void> future2 = this.driver.waitJobAsync(jobId, params, jobObserver);
    Assert.assertNull(future2);
}
Also used : JobObserver(com.baidu.hugegraph.computer.driver.JobObserver) HashMap(java.util.HashMap) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) DefaultJobState(com.baidu.hugegraph.computer.driver.DefaultJobState) Test(org.junit.Test)

Example 7 with JobObserver

use of com.baidu.hugegraph.computer.driver.JobObserver in project hugegraph-computer by hugegraph.

the class MiniKubeTest method testTwiceCreate.

@Test
public void testTwiceCreate() {
    super.updateOptions(KubeSpecOptions.MASTER_ARGS.name(), Lists.newArrayList("pwd && sleep 60"));
    super.updateOptions(KubeSpecOptions.WORKER_ARGS.name(), Lists.newArrayList("pwd && sleep 60"));
    Object defaultSpec = Whitebox.invoke(KubernetesDriver.class, "defaultSpec", this.driver);
    Whitebox.setInternalState(this.driver, "defaultSpec", defaultSpec);
    Map<String, String> params = new HashMap<>();
    params.put(KubeSpecOptions.WORKER_INSTANCES.name(), "1");
    String jobId = this.driver.submitJob(ALGORITHM_NAME, params);
    JobObserver jobObserver = Mockito.mock(JobObserver.class);
    CompletableFuture<Void> future = this.driver.waitJobAsync(jobId, params, jobObserver);
    DefaultJobState jobState = new DefaultJobState();
    jobState.jobStatus(JobStatus.RUNNING);
    Mockito.verify(jobObserver, Mockito.timeout(20000L).atLeast(1)).onJobStateChanged(Mockito.eq(jobState));
    HugeGraphComputerJob computerJob = this.operation.withName(KubeUtil.crName(jobId)).get();
    computerJob.getSpec().setMasterCpu(Quantity.parse("2"));
    this.operation.createOrReplace(computerJob);
    UnitTestBase.sleep(1000L);
    this.driver.cancelJob(jobId, params);
    UnitTestBase.sleep(1000L);
    future.cancel(true);
}
Also used : JobObserver(com.baidu.hugegraph.computer.driver.JobObserver) HashMap(java.util.HashMap) DefaultJobState(com.baidu.hugegraph.computer.driver.DefaultJobState) HugeGraphComputerJob(com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob) Test(org.junit.Test)

Example 8 with JobObserver

use of com.baidu.hugegraph.computer.driver.JobObserver in project hugegraph-computer by hugegraph.

the class MiniKubeTest method testJobFailed.

@Test
public void testJobFailed() {
    super.updateOptions(KubeSpecOptions.MASTER_ARGS.name(), Lists.newArrayList("cat xxx"));
    super.updateOptions(KubeSpecOptions.WORKER_ARGS.name(), Lists.newArrayList("cat xxx"));
    Object defaultSpec = Whitebox.invoke(KubernetesDriver.class, "defaultSpec", this.driver);
    Whitebox.setInternalState(this.driver, "defaultSpec", defaultSpec);
    Map<String, String> params = new HashMap<>();
    params.put(KubeSpecOptions.WORKER_INSTANCES.name(), "1");
    String jobId = this.driver.submitJob(ALGORITHM_NAME, params);
    JobObserver jobObserver = Mockito.mock(JobObserver.class);
    CompletableFuture<Void> future = this.driver.waitJobAsync(jobId, params, jobObserver);
    DefaultJobState jobState = new DefaultJobState();
    jobState.jobStatus(JobStatus.INITIALIZING);
    Mockito.verify(jobObserver, Mockito.timeout(15000L).atLeast(1)).onJobStateChanged(Mockito.eq(jobState));
    DefaultJobState jobState2 = new DefaultJobState();
    jobState2.jobStatus(JobStatus.FAILED);
    Mockito.verify(jobObserver, Mockito.timeout(150000L).atLeast(1)).onJobStateChanged(Mockito.eq(jobState2));
    UnitTestBase.sleep(500L);
    String diagnostics = this.driver.diagnostics(jobId, params);
    Assert.assertContains("No such file or directory", diagnostics);
    future.cancel(true);
}
Also used : JobObserver(com.baidu.hugegraph.computer.driver.JobObserver) HashMap(java.util.HashMap) DefaultJobState(com.baidu.hugegraph.computer.driver.DefaultJobState) Test(org.junit.Test)

Example 9 with JobObserver

use of com.baidu.hugegraph.computer.driver.JobObserver in project hugegraph-computer by hugegraph.

the class MiniKubeTest method testJobCancelled.

@Test
public void testJobCancelled() {
    super.updateOptions(KubeSpecOptions.MASTER_ARGS.name(), Lists.newArrayList("pwd && sleep 60"));
    super.updateOptions(KubeSpecOptions.WORKER_ARGS.name(), Lists.newArrayList("pwd && sleep 60"));
    Object defaultSpec = Whitebox.invoke(KubernetesDriver.class, "defaultSpec", this.driver);
    Whitebox.setInternalState(this.driver, "defaultSpec", defaultSpec);
    Map<String, String> params = new HashMap<>();
    params.put(KubeSpecOptions.WORKER_INSTANCES.name(), "1");
    String jobId = this.driver.submitJob(ALGORITHM_NAME, params);
    JobObserver jobObserver = Mockito.mock(JobObserver.class);
    CompletableFuture<Void> future = this.driver.waitJobAsync(jobId, params, jobObserver);
    DefaultJobState jobState = new DefaultJobState();
    jobState.jobStatus(JobStatus.INITIALIZING);
    Mockito.verify(jobObserver, Mockito.timeout(15000L).atLeast(1)).onJobStateChanged(Mockito.eq(jobState));
    this.driver.cancelJob(jobId, params);
    DefaultJobState jobState2 = new DefaultJobState();
    jobState2.jobStatus(JobStatus.CANCELLED);
    Mockito.verify(jobObserver, Mockito.timeout(15000L).atLeast(1)).onJobStateChanged(Mockito.eq(jobState2));
    future.cancel(true);
}
Also used : JobObserver(com.baidu.hugegraph.computer.driver.JobObserver) HashMap(java.util.HashMap) DefaultJobState(com.baidu.hugegraph.computer.driver.DefaultJobState) Test(org.junit.Test)

Example 10 with JobObserver

use of com.baidu.hugegraph.computer.driver.JobObserver in project hugegraph-computer by hugegraph.

the class MiniKubeTest method testJobSucceed.

@Test
public void testJobSucceed() {
    Map<String, String> params = new HashMap<>();
    params.put(KubeSpecOptions.WORKER_INSTANCES.name(), "1");
    params.put(ComputerOptions.TRANSPORT_SERVER_PORT.name(), "0");
    params.put(ComputerOptions.RPC_SERVER_PORT.name(), "0");
    String jobId = this.driver.submitJob(ALGORITHM_NAME, params);
    JobObserver jobObserver = Mockito.mock(JobObserver.class);
    CompletableFuture<Void> future = this.driver.waitJobAsync(jobId, params, jobObserver);
    DefaultJobState jobState = new DefaultJobState();
    jobState.jobStatus(JobStatus.INITIALIZING);
    Mockito.verify(jobObserver, Mockito.timeout(15000L).atLeast(1)).onJobStateChanged(Mockito.eq(jobState));
    DefaultJobState jobState2 = new DefaultJobState();
    jobState2.jobStatus(JobStatus.SUCCEEDED);
    Mockito.verify(jobObserver, Mockito.timeout(15000L).atLeast(1)).onJobStateChanged(Mockito.eq(jobState2));
    future.cancel(true);
}
Also used : JobObserver(com.baidu.hugegraph.computer.driver.JobObserver) HashMap(java.util.HashMap) DefaultJobState(com.baidu.hugegraph.computer.driver.DefaultJobState) Test(org.junit.Test)

Aggregations

DefaultJobState (com.baidu.hugegraph.computer.driver.DefaultJobState)11 JobObserver (com.baidu.hugegraph.computer.driver.JobObserver)11 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 HugeGraphComputerJob (com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob)1 AbstractController (com.baidu.hugegraph.computer.k8s.operator.common.AbstractController)1 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 Secret (io.fabric8.kubernetes.api.model.Secret)1 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1