Search in sources :

Example 6 with ComputerJobSpec

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

the class KubernetesDriver method defaultSpec.

private Map<String, Object> defaultSpec() {
    Map<String, Object> defaultSpec = new HashMap<>();
    Collection<TypedOption<?, ?>> options = KubeSpecOptions.instance().options().values();
    for (TypedOption<?, ?> typeOption : options) {
        Object value = this.conf.get(typeOption);
        if (value != null) {
            String specKey = KubeUtil.covertSpecKey(typeOption.name());
            if (KubeSpecOptions.MAP_TYPE_CONFIGS.contains(typeOption)) {
                if (!Objects.equals(String.valueOf(value), "[]")) {
                    value = this.conf.getMap((ConfigListOption<String>) typeOption);
                    defaultSpec.put(specKey, value);
                }
            } else {
                defaultSpec.put(specKey, value);
            }
        }
    }
    ComputerJobSpec spec = HugeGraphComputerJob.mapToSpec(defaultSpec);
    // Add pullSecrets
    List<String> secretNames = this.conf.get(KubeDriverOptions.PULL_SECRET_NAMES);
    if (CollectionUtils.isNotEmpty(secretNames)) {
        List<LocalObjectReference> secrets = new ArrayList<>();
        for (String name : secretNames) {
            if (StringUtils.isBlank(name)) {
                continue;
            }
            secrets.add(new LocalObjectReference(name));
        }
        if (CollectionUtils.isNotEmpty(secrets)) {
            spec.withPullSecrets(secrets);
        }
    }
    // Add log4j.xml
    String log4jXmlPath = this.conf.get(KubeDriverOptions.LOG4J_XML_PATH);
    if (StringUtils.isNotBlank(log4jXmlPath)) {
        try {
            File file = new File(log4jXmlPath);
            @SuppressWarnings("deprecation") String log4jXml = FileUtils.readFileToString(file);
            spec.withLog4jXml(log4jXml);
        } catch (IOException exception) {
            throw new ComputerDriverException("Failed to read log4j file for computer job", exception);
        }
    }
    Map<String, Object> specMap = HugeGraphComputerJob.specToMap(spec);
    return Collections.unmodifiableMap(specMap);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ConfigListOption(com.baidu.hugegraph.config.ConfigListOption) ComputerJobSpec(com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobSpec) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) ComputerDriverException(com.baidu.hugegraph.computer.driver.ComputerDriverException) TypedOption(com.baidu.hugegraph.config.TypedOption) File(java.io.File)

Example 7 with ComputerJobSpec

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

the class KubernetesDriver method submitJob.

@Override
public String submitJob(String algorithmName, Map<String, String> params) {
    HugeGraphComputerJob computerJob = new HugeGraphComputerJob();
    String jobId = KubeUtil.genJobId(algorithmName);
    String crName = KubeUtil.crName(jobId);
    ObjectMeta meta = new ObjectMetaBuilder().withNamespace(this.namespace).withName(crName).build();
    computerJob.setMetadata(meta);
    ComputerJobSpec spec = this.computerJobSpec(this.defaultSpec, params);
    Map<String, String> computerConf = this.computerConf(this.defaultConf, params);
    this.checkComputerConf(computerConf, spec);
    spec.withAlgorithmName(algorithmName).withJobId(jobId).withComputerConf(computerConf);
    if (this.enableInternalAlgorithm && this.internalAlgorithms.contains(algorithmName)) {
        spec.withImage(this.internalAlgorithmImageUrl);
    } else if (StringUtils.isNotBlank(spec.getRemoteJarUri())) {
        spec.withImage(this.frameworkImageUrl);
    } else {
        String imageUrl = this.buildImageUrl(algorithmName);
        String jarFileDir = this.conf.get(KubeDriverOptions.JAR_FILE_DIR);
        String jarFile = this.buildJarFile(jarFileDir, algorithmName);
        spec.withImage(imageUrl).withJarFile(jarFile);
    }
    computerJob.setSpec(spec);
    this.operation.createOrReplace(computerJob);
    return jobId;
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ComputerJobSpec(com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobSpec) HugeGraphComputerJob(com.baidu.hugegraph.computer.k8s.crd.model.HugeGraphComputerJob) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder)

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