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);
}
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;
}
Aggregations