Project

General

Profile

1 8699 walker
# sets the replication policy for all objects in the MN where the calling member node is the  authoritative member node.
2
# This code can easily be changed to replace $identifiers with a custom list of ids
3
# the $xml_path should point to a XML file with the replication policy to apply to all based on xmlns:d1="http://ns.dataone.org/service/types/v1"
4
#
5
# Dependencies:
6
#	xmlstarlet - developed with version 1.0.1
7
#	curl - developed with version 7.19.7
8
9 8698 walker
authoritativeMN="urn:node:mnDemo8"
10
MN_base_URL="https://mn-demo-8.test.dataone.org/knb/d1/mn/v1"
11
CN_base_URL="https://cn-dev.test.dataone.org/cn/v1"
12
cert_path="/var/metacat/certs/urn_node_mnDemo8.pem"
13
xml_path="replicapolicy.xml"
14
15 8700 walker
identifiers=$(curl -s -o - -E $cert_path "$MN_base_URL/object?count=7&replicaStatus=false" | xmlstarlet sel -t -m "//objectInfo" -v "identifier" -n)
16 8698 walker
17 8700 walker
failedIDs=""
18
successCount=0
19
failCount=0
20
skipCount=0
21 8698 walker
22
for id in ${identifiers};
23
do
24 8700 walker
        metadata=$(curl -s -o - -E $cert_path "$CN_base_URL/meta/${id}" | xmlstarlet sel -t -v "concat(//serialVersion,';',//authoritativeMemberNode)" -n)
25 8698 walker
26
        OIFS=$IFS
27
        IFS=";"
28
        arr=($metadata)
29
        if [ ${arr[1]} = $authoritativeMN ]; then
30 8700 walker
#echo "skip"
31
            echo "Updating replica policy for id: $id"
32
           statusCode=$(curl -s -o - -w "%{http_code}" -X PUT -E $cert_path --capath "/etc/ssl/certs" -F "serialVersion=${arr[0]}" -F "policy=@$xml_path" "$CN_base_URL/replicaPolicies/${id}")
33
            if [ $statusCode = "200" ]; then
34
                successCount=$(($successCount + 1))
35
            else
36
                failCount=$(($failCount + 1))
37
            fi
38
39
        else
40 8698 walker
            echo "$authoritativeMN is not the authoritative member node for id: $id. (is ${arr[1]})"
41 8700 walker
            failedIDs=$(printf "$failedIDs\n$id")
42
            skipCount=$(($skipCount + 1))
43 8698 walker
        fi
44
done
45
46 8700 walker
echo -e "\n\nDONE\n----------------------------------"
47
echo -e "\nSUCCESSES: $successCount"
48
echo -e "\nFAILURES: $failCount"
49
echo -e "\n\nSKIPS (objects with a different authoritative member node): $skipCount"
50
echo -e "\nIDs of objects with a different authoritative member node: \n$failedIDs"
51 8698 walker
52 8700 walker