All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
aerospike_udf.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2014 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 (3.0 only)
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 /******************************************************************************
40  * FUNCTIONS
41  *****************************************************************************/
42 
43 /**
44  * List the UDF files in the cluster.
45  *
46  * ~~~~~~~~~~{.c}
47  * as_udf_files files;
48  * as_udf_files_init(&files, 0);
49  *
50  * if ( aerospike_udf_list(&as, &err, NULL, &files) != AEROSPIKE_OK ) {
51  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
52  * }
53  * else {
54  * printf("files[%d]:\n", files.size);
55  * for( int i = 0; i < files.size; i++ ) {
56  * as_udf_file * file = &files.entries[i];
57  * printf(" - %s (%d) [%s]\n", file->name, file->type, file->hash);
58  * }
59  * }
60  *
61  * as_udf_files_destroy(&files);
62  * ~~~~~~~~~~
63  *
64  *
65  * @param as The aerospike instance to use for this operation.
66  * @param err The as_error to be populated if an error occurs.
67  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
68  * @param files The list to populate with the results from the request.
69  *
70  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
71  *
72  * @ingroup udf_operations
73  */
75  aerospike * as, as_error * err, const as_policy_info * policy,
76  as_udf_files * files
77  );
78 
79 
80 /**
81  * Get specified UDF file from the cluster.
82  *
83  * ~~~~~~~~~~{.c}
84  * as_udf_file file;
85  * as_udf_file_init(&file);
86  *
87  * if ( aerospike_udf_get(&as, &err, NULL, "my.lua", AS_UDF_TYPE_LUA, &file) != AEROSPIKE_OK ) {
88  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
89  * }
90  * else {
91  * printf("%s type=%d hash=%s size=%d:\n", file.name, file.type. file.hash, file.content.size);
92  * if ( file.type == AS_UDF_TYPE_UDF ) {
93  * printf("%s", file.content.bytes)
94  * }
95  * }
96  *
97  * as_udf_file_destroy(&file);
98  * ~~~~~~~~~~
99  *
100  *
101  * @param as The aerospike instance to use for this operation.
102  * @param err The as_error to be populated if an error occurs.
103  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
104  * @param filename The name of the UDF file.
105  * @param type The type of UDF file.
106  * @param file The file from the cluster.
107  *
108  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
109  *
110  * @ingroup udf_operations
111  */
113  aerospike * as, as_error * err, const as_policy_info * policy,
114  const char * filename, as_udf_type type, as_udf_file * file
115  );
116 
117 /**
118  * Put a UDF file into the cluster.
119  *
120  * ~~~~~~~~~~{.c}
121  * as_bytes content;
122  * as_bytes_init(&content);
123  * ...
124  *
125  * if ( aerospike_udf_put(&as, &err, NULL, "my.lua", AS_UDF_TYPE_LUA, &content) != AEROSPIKE_OK ) {
126  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
127  * }
128  *
129  * as_bytes_destroy(&content);
130  * ~~~~~~~~~~
131  *
132  *
133  * @param as The aerospike instance to use for this operation.
134  * @param err The as_error to be populated if an error occurs.
135  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
136  * @param filename The name of the UDF file.
137  * @param type The type of UDF file.
138  * @param content The file of the UDF file.
139  *
140  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
141  *
142  * @ingroup udf_operations
143  */
145  aerospike * as, as_error * err, const as_policy_info * policy,
146  const char * filename, as_udf_type type, as_bytes * content
147  );
148 
149 /**
150  * Wait for asynchronous udf put to complete using given polling interval.
151  *
152  * ~~~~~~~~~~{.c}
153  * as_bytes content;
154  * as_bytes_init(&content);
155  *
156  * if (aerospike_udf_put(&as, &err, NULL, "my.lua", AS_UDF_TYPE_LUA, &content) == AEROSPIKE_OK ) {
157  * aerospike_udf_put_wait(&as, &err, NULL, "my.lua", 0);
158  * }
159  * as_bytes_destroy(&content);
160  * ~~~~~~~~~~
161  *
162  * @param as The aerospike instance to use for this operation.
163  * @param err The as_error to be populated if an error occurs.
164  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
165  * @param filename The name of the UDF file.
166  * @param interval_ms The polling interval in milliseconds. If zero, 1000 ms is used.
167  *
168  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
169  *
170  * @ingroup udf_operations
171  */
173  aerospike * as, as_error * err, const as_policy_info * policy,
174  const char * filename, uint32_t interval_ms);
175 
176 /**
177  * Remove a UDF file from the cluster.
178  *
179  * ~~~~~~~~~~{.c}
180  * if ( aerospike_udf_remove(&as, &err, NULL, "my.lua") != AEROSPIKE_OK ) {
181  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
182  * }
183  * ~~~~~~~~~~
184  *
185  * @param as The aerospike instance to use for this operation.
186  * @param err The as_error to be populated if an error occurs.
187  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
188  * @param filename The name of the UDF file.
189  *
190  * @return AEROSPIKE_OK if successful. Otherwise an error occurred.
191  *
192  * @ingroup udf_operations
193  */
195  aerospike * as, as_error * err, const as_policy_info * policy,
196  const char * filename
197  );
as_status
Definition: as_status.h:26
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_udf_type
Definition: as_udf.h:111
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 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)