Search in sources :

Example 1 with JobObserver

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

the class MiniKubeTest method testJobInternalSucceed.

@Test
public void testJobInternalSucceed() {
    Whitebox.setInternalState(this.driver, "enableInternalAlgorithm", true);
    Whitebox.setInternalState(this.driver, "internalAlgorithms", Lists.newArrayList("algorithm123"));
    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("algorithm123", 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)

Example 2 with JobObserver

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

the class MiniKubeTest method testPullImageError.

@Test
public void testPullImageError() {
    Map<String, String> params = new HashMap<>();
    this.updateOptions(KubeDriverOptions.IMAGE_REPOSITORY_URL.name(), "xxx");
    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.FAILED);
    Mockito.verify(jobObserver, Mockito.timeout(30000L).atLeast(1)).onJobStateChanged(Mockito.eq(jobState));
    String diagnostics = this.driver.diagnostics(jobId, params);
    Assert.assertContains("ImagePullBackOff", 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 3 with JobObserver

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

the class MiniKubeTest method testUnSchedulable.

@Test
public void testUnSchedulable() {
    Map<String, String> params = new HashMap<>();
    params.put(KubeSpecOptions.WORKER_INSTANCES.name(), "1");
    params.put(KubeSpecOptions.MASTER_CPU.name(), "10");
    params.put(KubeSpecOptions.MASTER_MEMORY.name(), "10Gi");
    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.FAILED);
    Mockito.verify(jobObserver, Mockito.timeout(30000L).atLeast(1)).onJobStateChanged(Mockito.eq(jobState));
    String diagnostics = this.driver.diagnostics(jobId, params);
    Assert.assertContains("Unschedulable", 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 4 with JobObserver

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

the class MiniKubeTest method testMountConfigMapWithFailed.

@Test
public void testMountConfigMapWithFailed() {
    Map<String, String> params = new HashMap<>();
    params.put(KubeSpecOptions.CONFIG_MAP_PATHS.name(), "[test-config:/opt/configmap123]");
    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(150000L).atLeast(1)).onJobStateChanged(Mockito.eq(jobState));
    DefaultJobState jobState2 = new DefaultJobState();
    jobState2.jobStatus(JobStatus.FAILED);
    Mockito.verify(jobObserver, Mockito.timeout(250000L).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 5 with JobObserver

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

the class MiniKubeTest method testMountConfigMapAndSecret.

@Test
public void testMountConfigMapAndSecret() {
    String dataBase64 = Base64.getEncoder().encodeToString("test123\ntest".getBytes());
    String configMapName = "config-map-test";
    ConfigMap configMap = new ConfigMapBuilder().withNewMetadata().withNamespace(this.namespace).withName(configMapName).endMetadata().addToData("1.txt", "test123\ntest").build();
    this.kubeClient.configMaps().createOrReplace(configMap);
    String secretName = "secret-test";
    Secret secret = new SecretBuilder().withNewMetadata().withNamespace(this.namespace).withName(secretName).endMetadata().withType("Opaque").addToData("2.txt", dataBase64).addToData("3.txt", dataBase64).build();
    this.kubeClient.secrets().createOrReplace(secret);
    ArrayList<String> args = Lists.newArrayList("cat /opt/configmap123/1.txt && " + "cat /opt/secret123/2.txt &&" + "cat /opt/secret123/3.txt");
    super.updateOptions(KubeSpecOptions.MASTER_ARGS.name(), args);
    super.updateOptions(KubeSpecOptions.WORKER_ARGS.name(), args);
    Object defaultSpec = Whitebox.invoke(KubernetesDriver.class, "defaultSpec", this.driver);
    Whitebox.setInternalState(this.driver, "defaultSpec", defaultSpec);
    Map<String, String> params = new HashMap<>();
    params.put(KubeSpecOptions.CONFIG_MAP_PATHS.name(), String.format("[%s:/opt/configmap123]", configMapName));
    params.put(KubeSpecOptions.SECRET_PATHS.name(), String.format("[%s:/opt/secret123]", secretName));
    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(150000L).atLeast(1)).onJobStateChanged(Mockito.eq(jobState));
    DefaultJobState jobState2 = new DefaultJobState();
    jobState2.jobStatus(JobStatus.SUCCEEDED);
    Mockito.verify(jobObserver, Mockito.timeout(150000L).atLeast(1)).onJobStateChanged(Mockito.eq(jobState2));
    future.cancel(true);
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) DefaultJobState(com.baidu.hugegraph.computer.driver.DefaultJobState) Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) JobObserver(com.baidu.hugegraph.computer.driver.JobObserver) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) 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