Search in sources :

Example 1 with ComputerJobSpec

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

the class ComputerJobDeployer method desiredConfigMap.

private ConfigMap desiredConfigMap(HugeGraphComputerJob computerJob) {
    String crName = computerJob.getMetadata().getName();
    ComputerJobSpec spec = computerJob.getSpec();
    Map<String, String> computerConf = spec.getComputerConf();
    Map<String, String> data = new HashMap<>();
    data.put(Constants.COMPUTER_CONF_FILE, KubeUtil.asProperties(computerConf));
    String log4jXml = spec.getLog4jXml();
    if (StringUtils.isNotBlank(log4jXml)) {
        data.put(Constants.LOG_XML_FILE, log4jXml);
    }
    String name = KubeUtil.configMapName(crName);
    return new ConfigMapBuilder().withMetadata(this.getMetadata(computerJob, name)).withData(data).build();
}
Also used : ComputerJobSpec(com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobSpec) HashMap(java.util.HashMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder)

Example 2 with ComputerJobSpec

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

the class ComputerJobDeployer method desiredMasterJob.

public Job desiredMasterJob(HugeGraphComputerJob computerJob, Set<ContainerPort> ports) {
    String crName = computerJob.getMetadata().getName();
    String namespace = computerJob.getMetadata().getNamespace();
    ComputerJobSpec spec = computerJob.getSpec();
    List<String> command = spec.getMasterCommand();
    if (CollectionUtils.isEmpty(command)) {
        command = Constants.COMMAND;
    }
    List<String> args = spec.getMasterArgs();
    if (CollectionUtils.isEmpty(args)) {
        args = Constants.MASTER_ARGS;
    }
    String name = KubeUtil.masterJobName(crName);
    ObjectMeta metadata = this.getMetadata(computerJob, name);
    Container container = this.getContainer(name, namespace, spec, ports, command, args);
    List<Container> containers = Lists.newArrayList(container);
    final int instances = Constants.MASTER_INSTANCES;
    return this.getJob(crName, metadata, spec, instances, containers);
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ComputerJobSpec(com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobSpec) Container(io.fabric8.kubernetes.api.model.Container) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint)

Example 3 with ComputerJobSpec

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

the class ComputerJobDeployer method desiredWorkerJob.

public Job desiredWorkerJob(HugeGraphComputerJob computerJob, Set<ContainerPort> ports) {
    String crName = computerJob.getMetadata().getName();
    String namespace = computerJob.getMetadata().getNamespace();
    ComputerJobSpec spec = computerJob.getSpec();
    List<String> command = spec.getWorkerCommand();
    if (CollectionUtils.isEmpty(command)) {
        command = Constants.COMMAND;
    }
    List<String> args = spec.getWorkerArgs();
    if (CollectionUtils.isEmpty(args)) {
        args = Constants.WORKER_ARGS;
    }
    String name = KubeUtil.workerJobName(crName);
    ObjectMeta metadata = this.getMetadata(computerJob, name);
    Container container = this.getContainer(name, namespace, spec, ports, command, args);
    List<Container> containers = Lists.newArrayList(container);
    final int instances = spec.getWorkerInstances();
    return this.getJob(crName, metadata, spec, instances, containers);
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ComputerJobSpec(com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobSpec) Container(io.fabric8.kubernetes.api.model.Container) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint)

Example 4 with ComputerJobSpec

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

the class KubernetesDriverTest method testOnClose.

@Test
public void testOnClose() {
    Map<String, Pair<CompletableFuture<Void>, JobObserver>> waits = Whitebox.getInternalState(this.driver, "waits");
    waits.put("test-123", Pair.of(new CompletableFuture<>(), Mockito.mock(JobObserver.class)));
    AbstractWatchManager<HugeGraphComputerJob> watch = Whitebox.getInternalState(this.driver, "watch");
    Watcher<HugeGraphComputerJob> watcher = Whitebox.getInternalState(watch, "watcher");
    watcher.eventReceived(Watcher.Action.ADDED, null);
    watcher.eventReceived(Watcher.Action.ERROR, new HugeGraphComputerJob());
    HugeGraphComputerJob computerJob = new HugeGraphComputerJob();
    computerJob.setSpec(new ComputerJobSpec());
    watcher.eventReceived(Watcher.Action.MODIFIED, computerJob);
    WatcherException testClose = new WatcherException("test close");
    watcher.onClose(testClose);
    MutableBoolean watchActive = Whitebox.getInternalState(this.driver, "watchActive");
    Assert.assertFalse(watchActive.booleanValue());
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ComputerJobSpec(com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobSpec) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) HugeGraphComputerJob(com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob) Pair(org.apache.commons.lang3.tuple.Pair) WatcherException(io.fabric8.kubernetes.client.WatcherException) Test(org.junit.Test)

Example 5 with ComputerJobSpec

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

the class ComputerJobController method derivedCRStatus.

private ComputerJobStatus derivedCRStatus(ComputerJobComponent observed) {
    HugeGraphComputerJob computerJob = observed.computerJob();
    ComputerJobSpec spec = computerJob.getSpec();
    MutableInt failedComponents = new MutableInt(0);
    MutableInt succeededComponents = new MutableInt(0);
    MutableInt runningComponents = new MutableInt(0);
    ComputerJobStatus status = Serialization.clone(computerJob.getStatus());
    // ConfigMap
    ConfigMap configMap = observed.configMap();
    if (configMap != null) {
        ComponentState configMapState = new ComponentStateBuilder().withName(configMap.getMetadata().getName()).withState(CommonComponentState.READY.value()).build();
        status.getComponentStates().setConfigMap(configMapState);
    } else if (status.getComponentStates().getConfigMap() != null) {
        status.getComponentStates().getConfigMap().setState(CommonComponentState.DELETED.value());
    }
    // MasterJob
    Job masterJob = observed.masterJob();
    ComponentState masterJobState = this.deriveJobStatus(masterJob, observed.masterPods(), status.getComponentStates().getMasterJob(), Constants.MASTER_INSTANCES, failedComponents, succeededComponents, runningComponents);
    status.getComponentStates().setMasterJob(masterJobState);
    // WorkerJob
    Job workerJob = observed.workerJob();
    ComponentState workerJobState = this.deriveJobStatus(workerJob, observed.workerPods(), status.getComponentStates().getWorkerJob(), spec.getWorkerInstances(), failedComponents, succeededComponents, runningComponents);
    status.getComponentStates().setWorkerJob(workerJobState);
    if (failedComponents.intValue() > ALLOW_FAILED_COMPONENTS) {
        status.setJobStatus(JobStatus.FAILED.name());
        this.recordFailedEvent(computerJob, masterJobState, workerJobState);
        return status;
    } else if (succeededComponents.intValue() == TOTAL_COMPONENTS) {
        status.setJobStatus(JobStatus.SUCCEEDED.name());
        String crName = computerJob.getMetadata().getName();
        long cost = this.calculateJobCost(computerJob);
        this.recordEvent(computerJob, EventType.NORMAL, KubeUtil.succeedEventName(crName), "ComputerJobSucceed", String.format("Job %s run successfully, took %ss", crName, cost));
        return status;
    }
    int activeComponents = runningComponents.intValue() + succeededComponents.intValue();
    if (activeComponents == TOTAL_COMPONENTS) {
        status.setJobStatus(JobStatus.RUNNING.name());
    } else {
        status.setJobStatus(JobStatus.INITIALIZING.name());
    }
    return status;
}
Also used : ComponentStateBuilder(com.baidu.hugegraph.computer.k8s.crd.model.ComponentStateBuilder) ComputerJobSpec(com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobSpec) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) MutableInt(org.apache.commons.lang3.mutable.MutableInt) HugeGraphComputerJob(com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob) ComputerJobStatus(com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobStatus) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) HugeGraphComputerJob(com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob) CommonComponentState(com.baidu.hugegraph.computer.k8s.crd.model.CommonComponentState) ComponentState(com.baidu.hugegraph.computer.k8s.crd.model.ComponentState) JobComponentState(com.baidu.hugegraph.computer.k8s.crd.model.JobComponentState)

Aggregations

ComputerJobSpec (com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobSpec)7 HugeGraphComputerJob (com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob)3 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)3 Container (io.fabric8.kubernetes.api.model.Container)2 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)2 HashMap (java.util.HashMap)2 ComputerDriverException (com.baidu.hugegraph.computer.driver.ComputerDriverException)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 ComputerJobStatus (com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobStatus)1 JobComponentState (com.baidu.hugegraph.computer.k8s.crd.model.JobComponentState)1 ConfigListOption (com.baidu.hugegraph.config.ConfigListOption)1 TypedOption (com.baidu.hugegraph.config.TypedOption)1 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)1 LocalObjectReference (io.fabric8.kubernetes.api.model.LocalObjectReference)1 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)1 Job (io.fabric8.kubernetes.api.model.batch.v1.Job)1 WatcherException (io.fabric8.kubernetes.client.WatcherException)1