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-2018 Aerospike, Inc.
3  *
4  * Portions may be licensed to Aerospike, Inc. under one or more contributor
5  * license agreements.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8  * use this file except in compliance with the License. You may obtain a copy of
9  * the License at http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14  * License for the specific language governing permissions and limitations under
15  * the License.
16  */
17 #pragma once
18 
19 /**
20  * @defgroup udf_operations UDF Operations
21  * @ingroup client_operations
22  *
23  * The UDF API provides the ability to manage UDFs in the cluster.
24  *
25  * Management capabilities include:
26  * - aerospike_udf_list() - List the UDF modules in the cluster.
27  * - aerospike_udf_get() - Download a UDF module.
28  * - aerospike_udf_put() - Upload a UDF module.
29  * - aerospike_udf_remove() - Remove a UDF module.
30  *
31  */
32 
33 #include <aerospike/aerospike.h>
34 #include <aerospike/as_error.h>
35 #include <aerospike/as_policy.h>
36 #include <aerospike/as_status.h>
37 #include <aerospike/as_udf.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /******************************************************************************
44  * FUNCTIONS
45  *****************************************************************************/
46 
47 /**
48  * List the UDF files in the cluster.
49  *
50  * ~~~~~~~~~~{.c}
51  * as_udf_files files;
52  * as_udf_files_init(&files, 0);
53  *
54  * if (aerospike_udf_list(&as, &err, NULL, &files) != AEROSPIKE_OK) {
55  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
56  * }
57  * else {
58  * printf("files[%d]:\n", files.size);
59  * for(int i = 0; i < files.size; i++) {
60  * as_udf_file * file = &files.entries[i];
61  * printf(" - %s (%d) [%s]\n", file->name, file->type, file->hash);
62  * }
63  * }
64  *
65  * as_udf_files_destroy(&files);
66  * ~~~~~~~~~~
67  *
68  * @param as The aerospike instance to use for this operation.
69  * @param err The as_error to be populated if an error occurs.
70  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
71  * @param files The list to populate with the results from the request.
72  *
73  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
74  *
75  * @ingroup udf_operations
76  */
79  aerospike* as, as_error* err, const as_policy_info* policy, as_udf_files* files
80  );
81 
82 /**
83  * Get specified UDF file from the cluster.
84  *
85  * ~~~~~~~~~~{.c}
86  * as_udf_file file;
87  * as_udf_file_init(&file);
88  *
89  * if (aerospike_udf_get(&as, &err, NULL, "my.lua", AS_UDF_TYPE_LUA, &file) != AEROSPIKE_OK) {
90  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
91  * }
92  * else {
93  * printf("%s type=%d hash=%s size=%d:\n", file.name, file.type. file.hash, file.content.size);
94  * if (file.type == AS_UDF_TYPE_UDF) {
95  * printf("%s", file.content.bytes)
96  * }
97  * }
98  *
99  * as_udf_file_destroy(&file);
100  * ~~~~~~~~~~
101  *
102  * @param as The aerospike instance to use for this operation.
103  * @param err The as_error to be populated if an error occurs.
104  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
105  * @param filename The name of the UDF file.
106  * @param type The type of UDF file.
107  * @param file The file from the cluster.
108  *
109  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
110  *
111  * @ingroup udf_operations
112  */
115  aerospike* as, as_error* err, const as_policy_info* policy,
116  const char* filename, as_udf_type type, as_udf_file * file
117  );
118 
119 /**
120  * Put a UDF file into the cluster. This function will return before the put is completed on
121  * all nodes. Use aerospike_udf_put_wait() when need to wait for completion.
122  *
123  * ~~~~~~~~~~{.c}
124  * as_bytes content;
125  * as_bytes_init(&content);
126  * ...
127  *
128  * if (aerospike_udf_put(&as, &err, NULL, "my.lua", AS_UDF_TYPE_LUA, &content) != AEROSPIKE_OK) {
129  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
130  * }
131  *
132  * as_bytes_destroy(&content);
133  * ~~~~~~~~~~
134  *
135  * @param as The aerospike instance to use for this operation.
136  * @param err The as_error to be populated if an error occurs.
137  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
138  * @param filename The name of the UDF file.
139  * @param type The type of UDF file.
140  * @param content The file of the UDF file.
141  *
142  * @return AEROSPIKE_OK if UDF put was started. Otherwise an error occurred.
143  *
144  * @ingroup udf_operations
145  */
148  aerospike* as, as_error* err, const as_policy_info* policy,
149  const char* filename, as_udf_type type, as_bytes* content
150  );
151 
152 /**
153  * Wait for asynchronous udf put to complete using given polling interval.
154  *
155  * ~~~~~~~~~~{.c}
156  * as_bytes content;
157  * as_bytes_init(&content);
158  *
159  * if (aerospike_udf_put(&as, &err, NULL, "my.lua", AS_UDF_TYPE_LUA, &content) == AEROSPIKE_OK ) {
160  * aerospike_udf_put_wait(&as, &err, NULL, "my.lua", 0);
161  * }
162  * as_bytes_destroy(&content);
163  * ~~~~~~~~~~
164  *
165  * @param as The aerospike instance to use for this operation.
166  * @param err The as_error to be populated if an error occurs.
167  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
168  * @param filename The name of the UDF file.
169  * @param interval_ms The polling interval in milliseconds. If zero, 1000 ms is used.
170  *
171  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
172  *
173  * @ingroup udf_operations
174  */
177  aerospike* as, as_error* err, const as_policy_info* policy,
178  const char* filename, uint32_t interval_ms
179  );
180 
181 /**
182  * Remove a UDF file from the cluster. This function will return before the remove is completed on
183  * all nodes. Use aerospike_udf_remove_wait() when need to wait for completion.
184  *
185  * ~~~~~~~~~~{.c}
186  * if (aerospike_udf_remove(&as, &err, NULL, "my.lua") != AEROSPIKE_OK) {
187  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
188  * }
189  * ~~~~~~~~~~
190  *
191  * @param as The aerospike instance to use for this operation.
192  * @param err The as_error to be populated if an error occurs.
193  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
194  * @param filename The name of the UDF file.
195  *
196  * @return AEROSPIKE_OK if remove was started. Otherwise an error occurred.
197  *
198  * @ingroup udf_operations
199  */
202  aerospike* as, as_error* err, const as_policy_info* policy, const char* filename
203  );
204 
205 /**
206  * Wait for asynchronous udf remove to complete using given polling interval.
207  *
208  * ~~~~~~~~~~{.c} *
209  * if (aerospike_udf_remove(&as, &err, NULL, "my.lua") == AEROSPIKE_OK) {
210  * aerospike_udf_remove_wait(&as, &err, NULL, "my.lua", 0);
211  * }
212  * ~~~~~~~~~~
213  *
214  * @param as The aerospike instance to use for this operation.
215  * @param err The as_error to be populated if an error occurs.
216  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
217  * @param filename The name of the UDF file.
218  * @param interval_ms The polling interval in milliseconds. If zero, 1000 ms is used.
219  *
220  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
221  *
222  * @ingroup udf_operations
223  */
226  aerospike* as, as_error* err, const as_policy_info* policy,
227  const char* filename, uint32_t interval_ms
228  );
229 
230 #ifdef __cplusplus
231 } // end extern "C"
232 #endif
uint8_t type
Definition: as_proto.h:36
AS_EXTERN as_status aerospike_udf_put_wait(aerospike *as, as_error *err, const as_policy_info *policy, const char *filename, uint32_t interval_ms)
as_status
Definition: as_status.h:30
AS_EXTERN as_status aerospike_udf_remove(aerospike *as, as_error *err, const as_policy_info *policy, const char *filename)
AS_EXTERN 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)
#define AS_EXTERN
Definition: as_std.h:25
AS_EXTERN as_status aerospike_udf_remove_wait(aerospike *as, as_error *err, const as_policy_info *policy, const char *filename, uint32_t interval_ms)
AS_EXTERN as_status aerospike_udf_list(aerospike *as, as_error *err, const as_policy_info *policy, as_udf_files *files)
as_udf_type
Definition: as_udf.h:115
AS_EXTERN 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)