mirror of
https://github.com/wassname/ray.git
synced 2026-07-02 18:48:35 +08:00
[Streaming] Add configuration with owner config. (#6687)
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
package org.ray.streaming.runtime.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.accessibility.Accessible;
|
||||
|
||||
/**
|
||||
* Basic config interface.
|
||||
*/
|
||||
public interface Config extends org.aeonbits.owner.Config, Accessible, Serializable {
|
||||
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package org.ray.streaming.runtime.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Streaming config including general, master and worker part.
|
||||
*/
|
||||
public class StreamingConfig implements Serializable {
|
||||
|
||||
public StreamingMasterConfig masterConfig;
|
||||
public StreamingWorkerConfig workerConfigTemplate;
|
||||
|
||||
public StreamingConfig(final Map<String, String> conf) {
|
||||
masterConfig = new StreamingMasterConfig(conf);
|
||||
workerConfigTemplate = new StreamingWorkerConfig(conf);
|
||||
}
|
||||
|
||||
public Map<String, String> getMap() {
|
||||
Map<String, String> wholeConfigMap = masterConfig.configMap;
|
||||
wholeConfigMap.putAll(workerConfigTemplate.configMap);
|
||||
return wholeConfigMap;
|
||||
}
|
||||
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package org.ray.streaming.runtime.config;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.aeonbits.owner.Config.DefaultValue;
|
||||
import org.aeonbits.owner.Config.Key;
|
||||
import org.aeonbits.owner.ConfigFactory;
|
||||
import org.ray.streaming.runtime.config.global.CommonConfig;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Streaming general config. May used by both JobMaster and JobWorker.
|
||||
*/
|
||||
public class StreamingGlobalConfig implements Serializable {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(StreamingGlobalConfig.class);
|
||||
|
||||
public final CommonConfig commonConfig;
|
||||
|
||||
public final Map<String, String> configMap;
|
||||
|
||||
public StreamingGlobalConfig(final Map<String, String> conf) {
|
||||
configMap = new HashMap<>(conf);
|
||||
|
||||
commonConfig = ConfigFactory.create(CommonConfig.class, conf);
|
||||
globalConfig2Map();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return configMap.toString();
|
||||
}
|
||||
|
||||
private void globalConfig2Map() {
|
||||
try {
|
||||
configMap.putAll(config2Map(this.commonConfig));
|
||||
} catch (Exception e) {
|
||||
LOG.error("Couldn't convert global config to a map.", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected Map<String, String> config2Map(org.aeonbits.owner.Config config)
|
||||
throws ClassNotFoundException {
|
||||
Map<String, String> result = new HashMap<>();
|
||||
|
||||
Class<?> proxyClazz = Class.forName(config.getClass().getName());
|
||||
Class<?>[] proxyInterfaces = proxyClazz.getInterfaces();
|
||||
|
||||
Class<?> configInterface = null;
|
||||
for (Class<?> proxyInterface : proxyInterfaces) {
|
||||
if (Config.class.isAssignableFrom(proxyInterface)) {
|
||||
configInterface = proxyInterface;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Preconditions.checkArgument(configInterface != null,
|
||||
"Can not get config interface.");
|
||||
Method[] methods = configInterface.getMethods();
|
||||
|
||||
for (Method method : methods) {
|
||||
Key ownerKeyAnnotation = method.getAnnotation(Key.class);
|
||||
String ownerKeyAnnotationValue;
|
||||
if (ownerKeyAnnotation != null) {
|
||||
ownerKeyAnnotationValue = ownerKeyAnnotation.value();
|
||||
Object value;
|
||||
try {
|
||||
value = method.invoke(config);
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Can not get value by method invoking for config key: {}. "
|
||||
+ "So use default value instead.", ownerKeyAnnotationValue);
|
||||
String defaultValue = method.getAnnotation(DefaultValue.class).value();
|
||||
value = defaultValue;
|
||||
}
|
||||
result.put(ownerKeyAnnotationValue, value + "");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package org.ray.streaming.runtime.config;
|
||||
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Streaming job master config.
|
||||
*/
|
||||
public class StreamingMasterConfig extends StreamingGlobalConfig {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(StreamingMasterConfig.class);
|
||||
|
||||
public StreamingMasterConfig(final Map<String, String> conf) {
|
||||
super(conf);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package org.ray.streaming.runtime.config;
|
||||
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Streaming job worker specified config.
|
||||
*/
|
||||
public class StreamingWorkerConfig extends StreamingGlobalConfig {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(StreamingWorkerConfig.class);
|
||||
|
||||
public StreamingWorkerConfig(final Map<String, String> conf) {
|
||||
super(conf);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package org.ray.streaming.runtime.config.global;
|
||||
|
||||
import org.ray.streaming.runtime.config.Config;
|
||||
|
||||
/**
|
||||
* Job common config.
|
||||
*/
|
||||
public interface CommonConfig extends Config {
|
||||
|
||||
String JOB_ID = "streaming.job.id";
|
||||
String JOB_NAME = "streaming.job.name";
|
||||
|
||||
/**
|
||||
* Ray streaming job id. Non-custom.
|
||||
* @return Job id with string type.
|
||||
*/
|
||||
@DefaultValue(value = "default-job-id")
|
||||
@Key(value = JOB_ID)
|
||||
String jobId();
|
||||
|
||||
/**
|
||||
* Ray streaming job name. Non-custom.
|
||||
* @return Job name with string type.
|
||||
*/
|
||||
@DefaultValue(value = "default-job-name")
|
||||
@Key(value = JOB_NAME)
|
||||
String jobName();
|
||||
}
|
||||
Reference in New Issue
Block a user