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