-
Notifications
You must be signed in to change notification settings - Fork 13
/
uuFunctions.r
115 lines (105 loc) · 4 KB
/
uuFunctions.r
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# \file uuFunctions.r
# \brief contains functions used to define queries and return timestamps in iso8601 form
# within iRODS functions are defined differently from rules. A function should have
# no side effects and should always return a value instead of mutating an output parameter
# \author Paul Frederiks
# \copyright Copyright (c) 2015-2023, Utrecht University. All rights reserved.
# \license GPLv3, see LICENSE.
# \function uuiso8601 Return irods style timestamp in iso8601 format
# \param[in] *timestamp irods style timestamp (epoch as string)
# \returnvalue uuiso8601 string with timestamp in iso8601 format
#
uuiso8601(*timestamp) = timestrf(datetime(int(*timestamp)), "%Y%m%dT%H%M%S%z")
# \brief Checks if a collection exists.
# Used to be iicollectionexists from Jan de Mooij.
#
# \param[in] collectionname name of the collection
# \returnvalue boolean, true if collection exists, false if not
#
uuCollectionExists(*collectionname) {
*exists = false;
foreach (*row in SELECT COLL_NAME WHERE COLL_NAME = '*collectionname') {
*exists = true;
break;
}
*exists;
}
# \brief Check if a file exists in the catalog.
#
# \param[in] *path
# \returnvalue boolean, true if collection exists, false if not
#
uuFileExists(*path) {
*exists = false;
uuChopPath(*path, *collName, *dataName);
foreach (*row in SELECT DATA_ID WHERE COLL_NAME = *collName AND DATA_NAME = *dataName) {
*exists = true;
break;
}
*exists;
}
# \brief Return a key-value-pair of metadata associated with a dataobject.
# If a key is defined multiple times, the last found will be returned.
#
# \param[in] data_id Unique DataObject ID. Used because it is Unique
# \param[in] prefix Only include metadata with this prefix
# \param[in,out] kvp key-value-pair to add the metadata to
#
uuObjectMetadataKvp(*data_id, *prefix, *kvp) {
*ContInxOld = 1;
msiMakeGenQuery("META_DATA_ATTR_NAME, META_DATA_ATTR_VALUE", "DATA_ID = '*data_id'", *GenQInp);
if (*prefix != "") {
#| writeLine("stdout", "prefix is *prefix");
msiAddConditionToGenQuery("META_DATA_ATTR_NAME", " like ", "*prefix%%", *GenQInp);
}
msiExecGenQuery(*GenQInp, *GenQOut);
msiGetContInxFromGenQueryOut(*GenQOut, *ContInxNew);
while(*ContInxOld > 0) {
foreach(*meta in *GenQOut) {
*name = *meta.META_DATA_ATTR_NAME;
*val = *meta.META_DATA_ATTR_VALUE;
msiAddKeyVal(*kvp, *name, *val);
}
*ContInxOld = *ContInxNew;
if(*ContInxOld > 0) {
msiGetMoreRows(*GenQInp, *GenQOut, *ContInxNew);
}
}
msiCloseGenQuery(*GenQInp, *GenQOut);
}
# Scheduled replication batch job.
#
# Performs replication for all data objects marked with 'org_replication_scheduled' metadata.
# The metadata value indicates the source and destination resource.
#
# \param[in] verbose Whether to log verbose messages for troubleshooting (1: yes, 0: no)
# \param[in] balance_id_min Minimum balance id for batch jobs (value 1-64)
# \param[in] balance_id_max Maximum balance id for batch jobs (value 1-64)
# \param[in] batch_size_limit Maximum number of items to be processed within one batch
# \param[in] dry_run Whether to do a trial run (1: yes, 0: no)
uuReplicateBatch(*verbose, *balance_id_min, *balance_id_max, *batch_size_limit, *dry_run) {
rule_replicate_batch(*verbose, *balance_id_min, *balance_id_max, *batch_size_limit, *dry_run);
}
# Disable msiSendMail.
msiSendMail(*xtoAddr,*xsubjectLine,*xbody){
writeString('serverLog','WARNING: msiSendMail is disabled');
}
#
# Wrapper of file checksum microservice to handle host delegation
#
wrap_msi_file_checksum(*file, *resc, *sum) {
*host = "";
*result = "";
foreach (*row in select RESC_LOC where RESC_NAME = *resc) {
*host = *row.RESC_LOC;
}
if (*host == "") {
*result = "-1";
writeString("serverLog","Could not find resource location for *resc when invoking file checksum microservice. Resource probably does not exist.");
} else {
remote(*host, "null") {
*result = errorcode(msi_file_checksum(*file, *resc, *sum));
}
}
*result;
}