83 lines
2.1 KiB
Bash
Executable file
83 lines
2.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
TMPDIR="${TMPDIR:-/tmp}"
|
|
mkdir -p "${TMPDIR}"
|
|
|
|
# shellcheck source=/dev/null
|
|
source "${ROOT_DIR}/scripts/graph_client_helpers.sh"
|
|
graph_helpers_init "${ROOT_DIR}"
|
|
|
|
AMDUATD_BIN="${ROOT_DIR}/build/amduatd"
|
|
ASL_BIN="${ROOT_DIR}/vendor/amduat/build/amduat-asl"
|
|
if [[ ! -x "${AMDUATD_BIN}" || ! -x "${ASL_BIN}" ]]; then
|
|
echo "missing binaries; build amduatd and amduat-asl first" >&2
|
|
exit 1
|
|
fi
|
|
|
|
tmp_root="$(mktemp -d -p "${TMPDIR}" amduatd-graph-index-XXXXXX)"
|
|
root="${tmp_root}/root"
|
|
sock="${tmp_root}/amduatd.sock"
|
|
space_id="graphindex"
|
|
log_file="${tmp_root}/amduatd.log"
|
|
|
|
cleanup() {
|
|
if [[ -n "${pid:-}" ]]; then
|
|
kill "${pid}" >/dev/null 2>&1 || true
|
|
wait "${pid}" >/dev/null 2>&1 || true
|
|
fi
|
|
rm -rf "${tmp_root}"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
mkdir -p "${root}"
|
|
"${ASL_BIN}" index init --root "${root}" >/dev/null
|
|
|
|
"${AMDUATD_BIN}" --root "${root}" --sock "${sock}" --store-backend index --space "${space_id}" \
|
|
>"${log_file}" 2>&1 &
|
|
pid=$!
|
|
|
|
ready_rc=0
|
|
graph_wait_for_ready "${sock}" "${pid}" "${log_file}" || ready_rc=$?
|
|
if [[ ${ready_rc} -eq 77 ]]; then
|
|
exit 77
|
|
fi
|
|
if [[ ${ready_rc} -ne 0 ]]; then
|
|
echo "daemon not ready" >&2
|
|
exit 1
|
|
fi
|
|
|
|
node_a="$(
|
|
graph_http_post "${sock}" "/v2/graph/nodes" '{"name":"idx-a"}' \
|
|
--header "Content-Type: application/json" \
|
|
--header "X-Amduat-Space: ${space_id}"
|
|
)"
|
|
echo "${node_a}" | grep -q '"name":"idx-a"' || {
|
|
echo "first node create failed: ${node_a}" >&2
|
|
exit 1
|
|
}
|
|
|
|
node_b="$(
|
|
graph_http_post "${sock}" "/v2/graph/nodes" '{"name":"idx-b"}' \
|
|
--header "Content-Type: application/json" \
|
|
--header "X-Amduat-Space: ${space_id}"
|
|
)"
|
|
echo "${node_b}" | grep -q '"name":"idx-b"' || {
|
|
echo "second node create failed: ${node_b}" >&2
|
|
exit 1
|
|
}
|
|
|
|
edge="$(
|
|
graph_http_post "${sock}" "/v2/graph/edges" \
|
|
'{"subject":"idx-a","predicate":"ms.within_domain","object":"idx-b"}' \
|
|
--header "Content-Type: application/json" \
|
|
--header "X-Amduat-Space: ${space_id}"
|
|
)"
|
|
echo "${edge}" | grep -q '"edge_ref":"' || {
|
|
echo "edge create failed: ${edge}" >&2
|
|
exit 1
|
|
}
|
|
|
|
echo "ok: index append sequence passed"
|