本节介绍用于管理HDC图和HDC算法的方法。请注意,这些方法要求数据库部署HDC服务器。
HDC图
ShowHDCGraph()
获取从图创建的全部HDC图。
参数
config: *configuration.RequestConfig
(可选):请求配置。
返回值
[]*structs.HDCGraph
:获取的HDC图的指针切片。error
:包含操作过程中遇到的任何问题的错误对象;如果操作成功,则返回nil
。
// Retrieves all HDC graphs of the graph 'miniCircle'
requestConfig := &configuration.RequestConfig{
Graph: "miniCircle",
}
hdcGraphs, _ := driver.ShowHDCGraph(requestConfig)
for _, hdcGraph := range hdcGraphs {
fmt.Println(hdcGraph.Name, "on", hdcGraph.HDCServerName)
}
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: *configuration.RequestConfig
(可选):请求配置。
返回值
JobResponse
:请求结果。error
:包含操作过程中遇到的任何问题的错误对象;如果操作成功,则返回nil
。
// Creates an HDC graph named 'test_hdc_graph' for the graph 'miniCircle'
requestConfig := &configuration.RequestConfig{
Graph: "miniCircle",
}
response, _ := driver.CreateHDCGraphBySchema(api.HDCBuilder{
HDCGraphName: "test_hdc_graph",
HDCServerName: "hdc-server-1",
NodeSchema: map[string][]string{"*": {"*"}},
EdgeSchema: map[string][]string{"direct": {"*"}, "review": {"value", "content"}},
SyncType: api.STATIC,
}, requestConfig)
jobID := response.JobId
time.Sleep(3 * time.Second)
jobs, _ := driver.ShowJob(jobID, requestConfig)
for _, job := range jobs {
fmt.Println(job.Id, "-", job.Status)
}
28 - FINISHED
28_1 - FINISHED
DropHDCGraph()
删除指定的HDC图。
参数
hdcGraphName: string
:HDC图名称。config: *configuration.RequestConfig
(可选):请求配置。
返回值
Response
:请求结果。error
:包含操作过程中遇到的任何问题的错误对象;如果操作成功,则返回nil
。
// Drops the HDC graph 'miniCircle_hdc_graph2' of the graph 'miniCircle'
requestConfig := &configuration.RequestConfig{
Graph: "miniCircle",
}
response, _ := driver.DropHDCGraph("miniCircle_hdc_graph2", requestConfig)
fmt.Println(response.Status.Code)
SUCCESS
HDC算法
ShowHDCAlgo()
获取安装在一台HDC服务器上的全部HDC算法。
参数
hdcServerName: string
:HDC服务器名称。config: *configuration.RequestConfig
(可选):请求配置。
返回值
[]*structs.Algo
:获取的HDC算法的指针切片。error
:包含操作过程中遇到的任何问题的错误对象;如果操作成功,则返回nil
。
// Retrieves all HDC algorithms installed on the HDC server 'hdc-server-1'
algos, _ := driver.ShowHDCAlgo("hdc-server-1", nil)
for _, algo := range algos {
fmt.Print(algo.Name, " supports writeback type(s): ")
if algo.WriteSupportType != "" {
fmt.Print(algo.WriteSupportType)
} else {
fmt.Print("None")
}
fmt.Println()
}
fastRP supports writeback type(s): DB,FILE
schema_overview supports writeback type(s): None
InstallHDCAlgo()
在一台HDC服务器上安装一个HDC算法。
参数
files: []string
:安装文件路径列表,算法包文件(.so)必须,配置文件(.yml)可选。hdcServerName: string
:HDC服务器名称。config: *configuration.RequestConfig
(可选):请求配置。
返回值
Response
:请求结果。error
:包含操作过程中遇到的任何问题的错误对象;如果操作成功,则返回nil
。
// Installs the HDC algorithm LPA on the HDC server 'hdc-server-1'
// The files 'libplugin_lpa.so' and 'lpa.yml' are located in the 'algo' folder that is placed in the same directory as the file you executed
response, _ := driver.InstallHDCAlgo([]string{"algo/libplugin_lpa.so", "algo/lpa.yml"}, "hdc-server-1", nil)
fmt.Println(response.Status.Code)
SUCCESS
UninstallHDCAlgo()
从一台HDC服务器上卸载一个HDC算法。
参数
algoName: string
:算法名称。hdcServerName: string
:服务器名称。config: *configuration.RequestConfig
(可选):请求配置。
返回值
Response
:请求结果。error
:包含操作过程中遇到的任何问题的错误对象;如果操作成功,则返回nil
。
// Uninstalls the HDC algorithm LPA from the HDC server 'hdc-server-1'
response, _ := driver.UninstallHDCAlgo("lpa", "hdc-server-1", nil)
fmt.Println(response.Status.Code)
SUCCESS
RollbackHDCAlgo()
将一台HDC服务器上的一个指定HDC算法回退到上一个版本。
参数
algoName: string
:算法名称。hdcServerName: string
:HDC服务器名称。config: *configuration.RequestConfig
(可选):请求配置。
返回值
Response
:请求结果。error
:包含操作过程中遇到的任何问题的错误对象;如果操作成功,则返回nil
。
// Rolls back the HDC algorithms LPA on the HDC server 'hdc-server-1'
response, _ := driver.RollbackHDCAlgo("lpa", "hdc-server-1", nil)
fmt.Println(response.Status.Code)
SUCCESS
完整示例
package main
import (
"fmt"
"log"
"github.com/ultipa/ultipa-go-driver/v5/sdk"
"github.com/ultipa/ultipa-go-driver/v5/sdk/configuration"
)
func main() {
config := &configuration.UltipaConfig{
// URI example: Hosts: []string{"mqj4zouys.us-east-1.cloud.ultipa.com:60010"},
Hosts: []string{"192.168.1.85:60061", "192.168.1.87:60061", "192.168.1.88:60061"},
Username: "<usernmae>",
Password: "<password>",
}
driver, err := sdk.NewUltipaDriver(config)
if err != nil {
log.Fatalln("Failed to connect to Ultipa:", err)
}
// Installs the HDC algorithm LPA on the HDC server 'hdc-server-1'
// The files 'libplugin_lpa.so' and 'lpa.yml' are located in the 'algo' folder that is placed in the same directory as the file you executed
response, _ := driver.InstallHDCAlgo([]string{"algo/libplugin_lpa.so", "algo/lpa.yml"}, "hdc-server-1", nil)
fmt.Println(response.Status.Code)
}