Search in sources :

Example 1 with TypedOption

use of com.baidu.hugegraph.config.TypedOption in project hugegraph-computer by hugegraph.

the class ComputerOptionsTest method testOptions.

@Test
public void testOptions() {
    MapConfiguration mapConfig = new MapConfiguration(options);
    HugeConfig config = new HugeConfig(mapConfig);
    Map<String, TypedOption<?, ?>> allOptions = ComputerOptions.instance().options();
    Collection<TypedOption<?, ?>> typedOptions = allOptions.values();
    for (TypedOption<?, ?> typedOption : typedOptions) {
        Object value = config.get(typedOption);
        String key = typedOption.name();
        if (options.containsKey(key)) {
            Assert.assertEquals(String.valueOf(value), options.get(key));
        } else {
            Assert.assertNull(value);
        }
    }
}
Also used : MapConfiguration(org.apache.commons.configuration.MapConfiguration) TypedOption(com.baidu.hugegraph.config.TypedOption) HugeConfig(com.baidu.hugegraph.config.HugeConfig) Test(org.junit.Test)

Example 2 with TypedOption

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

TypedOption (com.baidu.hugegraph.config.TypedOption)2 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 HugeConfig (com.baidu.hugegraph.config.HugeConfig)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 MapConfiguration (org.apache.commons.configuration.MapConfiguration)1 Test (org.junit.Test)1