All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
src/include/aerospike/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_get() - Download a UDF module.
32  * - aerospike_udf_put() - Upload a UDF module.
33  * - aerospike_udf_remove() - Remove a UDF module.
34  *
35  */
36 
37 #pragma once
38 
39 #include <aerospike/aerospike.h>
40 #include <aerospike/as_error.h>
41 #include <aerospike/as_policy.h>
42 #include <aerospike/as_status.h>
43 #include <aerospike/as_udf.h>
44 
45 /******************************************************************************
46  * FUNCTIONS
47  *****************************************************************************/
48 
49 /**
50  * List the UDF files in the cluster.
51  *
52  * ~~~~~~~~~~{.c}
53  * as_udf_files files;
54  * as_udf_files_init(&files, 0);
55  *
56  * if ( aerospike_udf_list(&as, &err, NULL, &files) != AEROSPIKE_OK ) {
57  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
58  * }
59  * else {
60  * printf("files[%d]:\n", files.size);
61  * for( int i = 0; i < files.size; i++ ) {
62  * as_udf_file * file = &files.entries[i];
63  * printf(" - %s (%d) [%s]\n", file->name, file->type, file->hash);
64  * }
65  * }
66  *
67  * as_udf_files_destroy(&files);
68  * ~~~~~~~~~~
69  *
70  *
71  * @param as The aerospike instance to use for this operation.
72  * @param err The as_error to be populated if an error occurs.
73  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
74  * @param files The list to populate with the results from the request.
75  *
76  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
77  *
78  * @ingroup udf_operations
79  */
81  aerospike * as, as_error * err, const as_policy_info * policy,
82  as_udf_files * files
83  );
84 
85 
86 /**
87  * Get specified UDF file from the cluster.
88  *
89  * ~~~~~~~~~~{.c}
90  * as_udf_file file;
91  * as_udf_file_init(&file);
92  *
93  * if ( aerospike_udf_get(&as, &err, NULL, "my.lua", AS_UDF_TYPE_LUA, &file) != AEROSPIKE_OK ) {
94  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
95  * }
96  * else {
97  * printf("%s type=%d hash=%s size=%d:\n", file.name, file.type. file.hash, file.content.size);
98  * if ( file.type == AS_UDF_TYPE_UDF ) {
99  * printf("%s", file.content.bytes)
100  * }
101  * }
102  *
103  * as_udf_file_destroy(&file);
104  * ~~~~~~~~~~
105  *
106  *
107  * @param as The aerospike instance to use for this operation.
108  * @param err The as_error to be populated if an error occurs.
109  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
110  * @param filename The name of the UDF file.
111  * @param type The type of UDF file.
112  * @param file The file from the cluster.
113  *
114  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
115  *
116  * @ingroup udf_operations
117  */
119  aerospike * as, as_error * err, const as_policy_info * policy,
120  const char * filename, as_udf_type type, as_udf_file * file
121  );
122 
123 /**
124  * Put a UDF file into the cluster.
125  *
126  * ~~~~~~~~~~{.c}
127  * as_bytes content;
128  * as_bytes_init(&content);
129  * ...
130  *
131  * if ( aerospike_udf_put(&as, &err, NULL, "my.lua", AS_UDF_TYPE_LUA, &content) != AEROSPIKE_OK ) {
132  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
133  * }
134  *
135  * as_bytes_destroy(&content);
136  * ~~~~~~~~~~
137  *
138  *
139  * @param as The aerospike instance to use for this operation.
140  * @param err The as_error to be populated if an error occurs.
141  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
142  * @param filename The name of the UDF file.
143  * @param type The type of UDF file.
144  * @param content The file of the UDF file.
145  *
146  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
147  *
148  * @ingroup udf_operations
149  */
151  aerospike * as, as_error * err, const as_policy_info * policy,
152  const char * filename, as_udf_type type, as_bytes * content
153  );
154 
155 /**
156  * Remove a UDF file from the cluster.
157  *
158  * ~~~~~~~~~~{.c}
159  * if ( aerospike_udf_remove(&as, &err, NULL, "my.lua") != AEROSPIKE_OK ) {
160  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
161  * }
162  * ~~~~~~~~~~
163  *
164  * @param as The aerospike instance to use for this operation.
165  * @param err The as_error to be populated if an error occurs.
166  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
167  * @param filename The name of the UDF file.
168  *
169  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
170  *
171  * @ingroup udf_operations
172  */
174  aerospike * as, as_error * err, const as_policy_info * policy,
175  const char * filename
176  );