All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
aerospike_udf.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2008-2013 by Aerospike.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  *****************************************************************************/
22 
23 /**
24  * @defgroup udf_operations UDF Operations (3.0 only)
25  * @ingroup client_operations
26  *
27  * The UDF API provides the ability to manage UDFs in the cluster.
28  *
29  * Management capabilities include:
30  * - aerospike_udf_list() - List the UDF modules in the cluster.
31  * - aerospike_udf_foreach() - List the UDF modules in the cluster.
32  * - aerospike_udf_get() - Download a UDF module.
33  * - aerospike_udf_put() - Upload a UDF module.
34  * - aerospike_udf_remove() - Remove a UDF module.
35  *
36  */
37 
38 #pragma once
39 
40 #include <aerospike/aerospike.h>
41 #include <aerospike/as_error.h>
42 #include <aerospike/as_policy.h>
43 #include <aerospike/as_status.h>
44 #include <aerospike/as_udf.h>
45 
46 /******************************************************************************
47  * TYPES
48  *****************************************************************************/
49 
50 /**
51  * Callback for the `aerospike_udf_foreach()` function.
52  *
53  * @ingroup udf_operations
54  */
55 typedef int (* aerospike_udf_foreach_callback)(const as_udf_file *, void *);
56 
57 /******************************************************************************
58  * FUNCTIONS
59  *****************************************************************************/
60 
61 /**
62  * List the UDF files in the cluster.
63  *
64  * ~~~~~~~~~~{.c}
65  * as_udf_files files;
66  * as_udf_files_init(&files, 0);
67  *
68  * if ( aerospike_udf_list(&as, &err, NULL, &files) != AEROSPIKE_OK ) {
69  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
70  * }
71  * else {
72  * printf("files[%d]:\n", files.size);
73  * for( int i = 0; i < files.size; i++ ) {
74  * as_udf_file * file = &files.entries[i];
75  * printf(" - %s (%d) [%s]\n", file->name, file->type, file->hash);
76  * }
77  * }
78  *
79  * as_udf_files_destroy(&files);
80  * ~~~~~~~~~~
81  *
82  *
83  * @param as The aerospike instance to use for this operation.
84  * @param err The as_error to be populated if an error occurs.
85  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
86  * @param files The list to populate with the results from the request.
87  *
88  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
89  *
90  * @ingroup udf_operations
91  */
93  aerospike * as, as_error * err, const as_policy_info * policy,
94  as_udf_files * files
95  );
96 
97 /**
98  * Call the callback function for each the UDF file in the cluster.
99  *
100  * ~~~~~~~~~~{.c}
101  * bool callback(cont as_udf_file * file, void * udata) {
102  * printf(" - %s (%d) [%s]\n", file->name, file->type, file->hash);
103  * return true;
104  * }
105  *
106  * printf("files[%d]:\n", list.size);
107  * if ( aerospike_udf_foreach(&as, &err, NULL, callback, NULL) != AEROSPIKE_OK ) {
108  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
109  * }
110  * ~~~~~~~~~~
111  *
112  *
113  * @param as The aerospike instance to use for this operation.
114  * @param err The as_error to be populated if an error occurs.
115  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
116  * @param callback The function to call for each udf file returned.
117  * @param udata User-data to be sent to the callback.
118  *
119  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
120  *
121  * @ingroup udf_operations
122  */
124  aerospike * as, as_error * err, const as_policy_info * policy,
125  aerospike_udf_foreach_callback callback, void * udata
126  );
127 
128 /**
129  * Get specified UDF file from the cluster.
130  *
131  * ~~~~~~~~~~{.c}
132  * as_udf_file file;
133  * as_udf_file_init(&file);
134  *
135  * if ( aerospike_udf_get(&as, &err, NULL, "my.lua", AS_UDF_TYPE_LUA, &file) != AEROSPIKE_OK ) {
136  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
137  * }
138  * else {
139  * printf("%s type=%d hash=%s size=%d:\n", file.name, file.type. file.hash, file.content.size);
140  * if ( file.type == AS_UDF_TYPE_UDF ) {
141  * printf("%s", file.content.bytes)
142  * }
143  * }
144  *
145  * as_udf_file_destroy(&file);
146  * ~~~~~~~~~~
147  *
148  *
149  * @param as The aerospike instance to use for this operation.
150  * @param err The as_error to be populated if an error occurs.
151  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
152  * @param filename The name of the UDF file.
153  * @param type The type of UDF file.
154  * @param file The file from the cluster.
155  *
156  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
157  *
158  * @ingroup udf_operations
159  */
161  aerospike * as, as_error * err, const as_policy_info * policy,
162  const char * filename, as_udf_type type, as_udf_file * file
163  );
164 
165 /**
166  * Put a UDF file into the cluster.
167  *
168  * ~~~~~~~~~~{.c}
169  * as_bytes content;
170  * as_bytes_init(&content);
171  * ...
172  *
173  * if ( aerospike_udf_put(&as, &err, NULL, "my.lua", AS_UDF_TYPE_LUA, &content) != AEROSPIKE_OK ) {
174  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
175  * }
176  *
177  * as_bytes_destroy(&content);
178  * ~~~~~~~~~~
179  *
180  *
181  * @param as The aerospike instance to use for this operation.
182  * @param err The as_error to be populated if an error occurs.
183  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
184  * @param filename The name of the UDF file.
185  * @param type The type of UDF file.
186  * @param content The file of the UDF file.
187  *
188  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
189  *
190  * @ingroup udf_operations
191  */
193  aerospike * as, as_error * err, const as_policy_info * policy,
194  const char * filename, as_udf_type type, as_bytes * content
195  );
196 
197 /**
198  * Remove a UDF file from the cluster.
199  *
200  * ~~~~~~~~~~{.c}
201  * if ( aerospike_udf_remove(&as, &err, NULL, "my.lua") != AEROSPIKE_OK ) {
202  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
203  * }
204  * ~~~~~~~~~~
205  *
206  * @param as The aerospike instance to use for this operation.
207  * @param err The as_error to be populated if an error occurs.
208  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
209  * @param filename The name of the UDF file.
210  *
211  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
212  *
213  * @ingroup udf_operations
214  */
216  aerospike * as, as_error * err, const as_policy_info * policy,
217  const char * filename
218  );
as_status
Definition: as_status.h:32
as_status aerospike_udf_list(aerospike *as, as_error *err, const as_policy_info *policy, as_udf_files *files)
as_status aerospike_udf_put(aerospike *as, as_error *err, const as_policy_info *policy, const char *filename, as_udf_type type, as_bytes *content)
as_status aerospike_udf_foreach(aerospike *as, as_error *err, const as_policy_info *policy, aerospike_udf_foreach_callback callback, void *udata)
int(* aerospike_udf_foreach_callback)(const as_udf_file *, void *)
Definition: aerospike_udf.h:55
as_udf_type
Definition: as_udf.h:117
as_status aerospike_udf_remove(aerospike *as, as_error *err, const as_policy_info *policy, const char *filename)
as_status aerospike_udf_get(aerospike *as, as_error *err, const as_policy_info *policy, const char *filename, as_udf_type type, as_udf_file *file)