本节介绍用于管理HDC图和HDC算法的方法。请注意,这些方法要求数据库部署HDC服务器。
HDC图
showHDCGraph()
获取从图创建的全部HDC图。
参数
config: RequestConfig
(可选):请求配置。
返回
List[HDCGraph]
:获取的HDC图列表。
// Retrieves all HDC graphs of the graph 'miniCircle'
RequestConfig requestConfig = new RequestConfig();
requestConfig.setGraph("miniCircle");
List<HDCGraph> hdcGraphs = driver.showHDCGraph(requestConfig);
for (HDCGraph hdcGraph : hdcGraphs) {
System.out.println(hdcGraph.getName() + " on " + hdcGraph.getHdcServerName());
}
miniCircle_hdc_graph on hdc-server-1
miniCircle_hdc_graph2 on hdc-server-2
createHDCGraphBySchema()
为图创建一个HDC图。
参数
builder: HDCBuilder
: 要创建的HDC图;属性hdcGraphName
和hdcServerName
必填,nodeSchema
、edgeSchema
、syncType
、direction
、loadId
和isDefault
可选。config: RequestConfig
(可选):请求配置。
返回
JobResponse
:请求结果。
// Creates an HDC graph named 'test_hdc_graph' for the graph 'miniCircle'
RequestConfig requestConfig = new RequestConfig();
requestConfig.setGraph("miniCircle");
Map<String, List<String>> nodeSchema = new HashMap<>();
nodeSchema.put("*", Lists.newArrayList("*"));
Map<String, List<String>> edgeSchema = new HashMap<>();
edgeSchema.put("direct", Lists.newArrayList("*"));
edgeSchema.put("review", Lists.newArrayList("value", "content"));
HDCAPI.HDCBuilder hdcBuilder = new HDCAPI.HDCBuilder()
.setHdcGraphName("test_hdc_graph")
.setHdcServerName("hdc-server-1")
.setNodeSchema(nodeSchema)
.setEdgeSchema(edgeSchema);
JobResponse response = driver.createHDCGraphBySchema(hdcBuilder, requestConfig);
String jobId = response.getJobId();
Thread.sleep(3000);
List<Job> jobs = driver.showJob(jobId, requestConfig);
for (Job job : jobs) {
System.out.println(job.getId() + " - " + job.getStatus());
}
61 - FINISHED
61_1 - FINISHED
dropHDCGraph()
删除指定的HDC图。
参数
hdcGraphName: String
:HDC图名称。config: RequestConfig
(可选):请求配置。
返回
Response
:请求结果。
// Drops the HDC graph 'miniCircle_hdc_graph2' of the graph 'miniCircle'
RequestConfig requestConfig = new RequestConfig();
requestConfig.setGraph("miniCircle");
Response response = driver.dropHDCGraph("miniCircle_hdc_graph2", requestConfig);
System.out.println(response.getStatus().getCode());
SUCCESS
HDC算法
showAlgo()
获取安装在一台HDC服务器上的全部HDC算法。
参数
hdcServerName: String
:HDC服务器名称。config: RequestConfig
(可选):请求配置。
返回值
List[Algo]
:获取的HDC算法列表。
// Retrieves all HDC algorithms installed on the HDC server 'hdc-server-1'
List<Algo> algos = driver.showHDCAlgo("hdc-server-1");
for (Algo algo : algos) {
System.out.println(algo.getName() + " supports writeback types: " + algo.getWriteSupportType());
}
fastRP supports writeback types: DB,FILE
struc2vec supports writeback types: DB,FILE
installAlgo()
在一台HDC服务器上安装一个HDC算法。
参数
files: List<String>
:安装文件路径列表,算法包文件(.so)必须,配置文件(.yml)可选。hdcServerName: String
:HDC服务器名称。config: RequestConfig
(可选):请求配置。
返回值
Response
:请求结果。
// Installs the HDC algorithm LPA on the HDC server 'hdc-server-1'
Response response = driver.installHDCAlgo(Arrays.asList("src/main/resources/algo/libplugin_lpa.so", "src/main/resources/algo/lpa.yml"), "hdc-server-1");
System.out.println(response.getStatus().getCode());
SUCCESS
uninstallAlgo()
从一台HDC服务器上卸载一个HDC算法。
参数
algoName: String
:算法名称。hdcServerName: String
:HDC服务器名称。config: RequestConfig
(可选):请求配置。
返回值
Response
:请求结果。
// Uninstalls the HDC algorithm LPA from the HDC server 'hdc-server-1'
Response response = driver.uninstallHDCAlgo("lpa", "hdc-server-1");
System.out.println(response.getStatus().getCode());
SUCCESS
rollbackHDCAlgo()
将一台HDC服务器上的一个指定HDC算法回退到上一个版本。
参数
algoName: String
:算法名称。hdcServerName: String
:HDC服务器名称。config: RequestConfig
(可选):请求配置。
返回值
Response
:请求结果。
// Uninstalls the HDC algorithm LPA from the HDC server 'hdc-server-1'
Response response = driver.uninstallHDCAlgo("lpa", "hdc-server-1");
System.out.println(response.getStatus().getCode());
SUCCESS
完整示例
package com.ultipa.www.sdk.api;
import com.ultipa.sdk.UltipaDriver;
import com.ultipa.sdk.connect.conf.UltipaConfig;
import com.ultipa.sdk.operate.response.Response;
import org.assertj.core.util.Lists;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
UltipaConfig ultipaConfig = UltipaConfig.config()
// URI example: .hosts(Lists.newArrayList("d3026ac361964633986849ec43b84877s.eu-south-1.cloud.ultipa.com:8443"))
.hosts(Lists.newArrayList("192.168.1.85:60061","192.168.1.88:60061","192.168.1.87:60061"))
.username("<username>")
.password("<password>");
UltipaDriver driver = null;
try {
driver = new UltipaDriver(ultipaConfig);
// Installs the HDC algorithm LPA on the HDC server 'hdc-server-1'
Response response = driver.installHDCAlgo(Arrays.asList("src/main/resources/algo/libplugin_lpa.so", "src/main/resources/algo/lpa.yml"), "hdc-server-1");
System.out.println(response.getStatus().getCode());
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
if (driver != null) {
driver.close();
}
}
}
}