Search in sources :

Example 1 with MatchWithMsg

use of com.baidu.hugegraph.computer.k8s.operator.common.MatchWithMsg in project hugegraph-computer by hugegraph.

the class ComputerJobController method ownsPredicate.

@Override
protected MatchWithMsg ownsPredicate(HasMetadata ownsResource) {
    MatchWithMsg ownsMatch = super.ownsPredicate(ownsResource);
    if (ownsMatch.isMatch()) {
        return ownsMatch;
    }
    if (ownsResource instanceof Pod) {
        ObjectMeta metadata = ownsResource.getMetadata();
        if (metadata != null && metadata.getLabels() != null) {
            Map<String, String> labels = metadata.getLabels();
            String kind = HasMetadata.getKind(HugeGraphComputerJob.class);
            String crName = KubeUtil.matchKindAndGetCrName(labels, kind);
            if (StringUtils.isNotBlank(crName)) {
                return new MatchWithMsg(true, crName);
            }
        }
    }
    return MatchWithMsg.NO_MATCH;
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Pod(io.fabric8.kubernetes.api.model.Pod) MatchWithMsg(com.baidu.hugegraph.computer.k8s.operator.common.MatchWithMsg)

Example 2 with MatchWithMsg

use of com.baidu.hugegraph.computer.k8s.operator.common.MatchWithMsg in project hugegraph-computer by hugegraph.

the class ComputerJobController method deriveJobStatus.

private ComponentState deriveJobStatus(Job job, List<Pod> pods, ComponentState oldSate, int instances, MutableInt failedComponents, MutableInt succeededComponents, MutableInt runningComponents) {
    if (job != null && job.getStatus() != null) {
        ComponentState newState = new ComponentState();
        newState.setName(job.getMetadata().getName());
        int succeeded = KubeUtil.intVal(job.getStatus().getSucceeded());
        int failed = KubeUtil.intVal(job.getStatus().getFailed());
        MatchWithMsg unSchedulable = this.unSchedulable(pods);
        MatchWithMsg failedPullImage = this.imagePullBackOff(pods);
        if (succeeded >= instances) {
            newState.setState(JobComponentState.SUCCEEDED.name());
            succeededComponents.increment();
        } else if (failed > ALLOW_FAILED_JOBS) {
            newState.setState(JobComponentState.FAILED.name());
            List<JobCondition> conditions = job.getStatus().getConditions();
            if (CollectionUtils.isNotEmpty(conditions)) {
                newState.setMessage(conditions.get(0).getMessage());
            }
            String errorLog = this.getErrorLog(pods);
            if (StringUtils.isNotBlank(errorLog)) {
                newState.setErrorLog(errorLog);
            }
            failedComponents.increment();
        } else if (unSchedulable.isMatch()) {
            newState.setState(JobStatus.FAILED.name());
            newState.setMessage(unSchedulable.msg());
            failedComponents.increment();
        } else if (failedPullImage.isMatch()) {
            newState.setState(JobStatus.FAILED.name());
            newState.setMessage(failedPullImage.msg());
            failedComponents.increment();
        } else {
            int running = pods.stream().filter(PodStatusUtil::isRunning).mapToInt(x -> 1).sum();
            int active = running + succeeded;
            if (active >= instances) {
                newState.setState(JobComponentState.RUNNING.value());
                runningComponents.increment();
            } else {
                newState.setState(JobComponentState.PENDING.value());
            }
        }
        return newState;
    } else if (oldSate != null) {
        oldSate.setState(JobComponentState.CANCELLED.value());
    }
    return oldSate;
}
Also used : MatchWithMsg(com.baidu.hugegraph.computer.k8s.operator.common.MatchWithMsg) List(java.util.List) HugeGraphComputerJobList(com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJobList) 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

MatchWithMsg (com.baidu.hugegraph.computer.k8s.operator.common.MatchWithMsg)2 CommonComponentState (com.baidu.hugegraph.computer.k8s.crd.model.CommonComponentState)1 ComponentState (com.baidu.hugegraph.computer.k8s.crd.model.ComponentState)1 HugeGraphComputerJobList (com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJobList)1 JobComponentState (com.baidu.hugegraph.computer.k8s.crd.model.JobComponentState)1 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 List (java.util.List)1