Search in sources :

Example 1 with ConfigListOption

use of com.baidu.hugegraph.config.ConfigListOption 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)

Aggregations

ComputerDriverException (com.baidu.hugegraph.computer.driver.ComputerDriverException)1 ComputerJobSpec (com.baidu.hugegraph.computer.k8s.crd.model.ComputerJobSpec)1 ConfigListOption (com.baidu.hugegraph.config.ConfigListOption)1 TypedOption (com.baidu.hugegraph.config.TypedOption)1 LocalObjectReference (io.fabric8.kubernetes.api.model.LocalObjectReference)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1