-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathboundwiths-create
More file actions
executable file
·103 lines (72 loc) · 3.09 KB
/
boundwiths-create
File metadata and controls
executable file
·103 lines (72 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/bash
auth 2>/dev/null || authn 2>/dev/null
tenant=$(cat tenant)
okapi_url=$(cat okapi.url)
okapi_token=$(cat okapi.token)
infile="bw_parent_child.tsv"
logfile="boundwiths.log"
numrecs=$(wc -l ${infile} |cut -d " " -f1)
namespace="8405ae4d-b315-42e1-918a-d1919900cf3f"
instanceRelationshipTypeId=$(curl -s -w '\n' -X GET -H "Accept: application/json" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" "${okapi_url}/instance-relationship-types" |jq -r '.instanceRelationshipTypes[] |select(.name == "bound-with") | .id')
rm -f ${logfile}
##################################################
refresh_record() {
local uuid="${1}"
local apicall=""
apicall=$(curl -s -w '\n' -X GET -H "Accept: application/json" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" "${okapi_url}/instance-storage/instances/${uuid}")
if [[ ${apicall} =~ \"id\": ]];then
apicall=$(curl --http1.1 -s -w '\n' -X PUT -H "Content-type: application/json" -H "Accept: text/plain" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" -d "${apicall}" "${okapi_url}/inventory/instances/${uuid}")
fi
}
############################################
create_boundwith() {
local boundwith=""
local bw_uuid=$(uuid -v 5 ${namespace} "${okapi_url}:boundwiths:${1}${2}")
local parent_uuid=$(uuid -v 5 ${namespace} "${okapi_url}:instances:${1}")
local child_uuid=$(uuid -v 5 ${namespace} "${okapi_url}:instances:${2}")
IFS='' read -r -d '' boundwith << EndOfJSON
{
"id": "${bw_uuid}",
"superInstanceId": "${parent_uuid}",
"subInstanceId": "${child_uuid}",
"instanceRelationshipTypeId": "${instanceRelationshipTypeId}"
}
EndOfJSON
apicall=$(curl --http1.1 -s -w '\n' -X POST -H "Content-type: application/json" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" -d "${boundwith}" "${okapi_url}/instance-storage/instance-relationships")
echo "${apicall}" | tr "\n" ' ' |sed 's/$/\n/' > "tmp_records.${seq}"
}
#######################################
counter=0
while mapfile -t -n 6 lines && ((${#lines[@]})); do
seq=0
echo -en "Processing record $counter of ${numrecs}. \r"
for line in "${lines[@]}";do
IFS=$'\t' read -r parent_id child_id <<< "${line}"
create_boundwith $parent_id $child_id ${seq} &
counter=$(($counter + 1))
seq=$(($seq + 1))
printf "Processing record %s of %s\r" $counter $numrecs
done
wait
cat tmp_records.* >> ${logfile}
rm tmp_records.*
done < ${infile}
echo "${numrecs} boundwiths have been created. API output has been directed to ${logfile}"
echo "Reindexing instances. Please be patient -- this is slow"
cut -f1 ${infile} |sort -u > tmp_reindex
infile=tmp_reindex
SECONDS=1
numrecs=$(wc -l ${infile} |cut -d " " -f1)
counter=0
while mapfile -t -n 6 uuids && ((${#uuids[@]})); do
for uuid in ${uuids[@]};do
refresh_record "${uuid}" &
counter=$(($counter + 1))
done
wait
recsPerSec=$(bc <<< "scale=1;$counter/$SECONDS")
echo -en "Reindexed $counter records of $numrecs at $recsPerSec records/sec\r"
done < ${infile}
rm -f ${infile}
echo "Reindexed $counter unique records. "
echo "Done building boundwiths"