Search in sources :

Example 1 with ComputerJobStatus

use of com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobStatus 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 2 with ComputerJobStatus

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

the class ComputerJobController method finalizer.

private boolean finalizer(HugeGraphComputerJob computerJob) {
    if (computerJob.addFinalizer(FINALIZER_NAME)) {
        this.replaceCR(computerJob);
        return true;
    }
    ComputerJobStatus status = computerJob.getStatus();
    if (computerJob.isMarkedForDeletion()) {
        if (!JobStatus.finished(status.getJobStatus())) {
            status.setJobStatus(JobStatus.CANCELLED.name());
            this.updateStatus(computerJob);
        } else {
            if (computerJob.removeFinalizer(FINALIZER_NAME)) {
                this.replaceCR(computerJob);
            }
        }
        return true;
    } else {
        if (JobStatus.finished(status.getJobStatus())) {
            if (this.autoDestroyPod) {
                this.deleteCR(computerJob);
            }
            return true;
        }
    }
    return false;
}
Also used : ComputerJobStatus(com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobStatus)

Example 3 with ComputerJobStatus

use of com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobStatus 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)

Example 4 with ComputerJobStatus

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

the class ComputerJobController method fillCRStatus.

private void fillCRStatus(HugeGraphComputerJob computerJob) {
    ComputerJobStatus status = computerJob.getStatus() == null ? new ComputerJobStatus() : computerJob.getStatus();
    status = new ComputerJobStatusBuilder(status).editOrNewComponentStates().endComponentStates().editOrNewJobState().endJobState().build();
    computerJob.setStatus(status);
}
Also used : ComputerJobStatus(com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobStatus) ComputerJobStatusBuilder(com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobStatusBuilder)

Example 5 with ComputerJobStatus

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

the class KubernetesDriver method buildJobState.

private JobState buildJobState(HugeGraphComputerJob computerJob) {
    E.checkNotNull(computerJob, "computerJob");
    ComputerJobStatus status = computerJob.getStatus();
    if (status == null || status.getJobStatus() == null) {
        return new DefaultJobState().jobStatus(JobStatus.INITIALIZING);
    }
    JobStatus jobStatus = JobStatus.valueOf(status.getJobStatus());
    return new DefaultJobState().jobStatus(jobStatus);
}
Also used : ComputerJobStatus(com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobStatus) JobStatus(com.baidu.hugegraph.computer.driver.JobStatus) DefaultJobState(com.baidu.hugegraph.computer.driver.DefaultJobState) ComputerJobStatus(com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobStatus)

Aggregations

ComputerJobStatus (com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobStatus)5 HugeGraphComputerJob (com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob)2 DefaultJobState (com.baidu.hugegraph.computer.driver.DefaultJobState)1 JobStatus (com.baidu.hugegraph.computer.driver.JobStatus)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 ComputerJobSpec (com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobSpec)1 ComputerJobStatusBuilder (com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobStatusBuilder)1 JobComponentState (com.baidu.hugegraph.computer.k8s.crd.model.JobComponentState)1 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 Job (io.fabric8.kubernetes.api.model.batch.v1.Job)1 MutableInt (org.apache.commons.lang3.mutable.MutableInt)1