Debian Codegraph @

src/extensions/java/gov/llnl/lc/chaos/Genders.java

raw
1 /*****************************************************************************\
2 * Copyright (C) 2007-2019 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2001-2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Jim Garlick <[email protected]> and Albert Chu <[email protected]>.
6 * UCRL-CODE-2003-004.
7 *
8 * This file is part of Genders, a cluster configuration database.
9 * For details, see <http://www.llnl.gov/linux/genders/>.
10 *
11 * Genders is free software; you can redistribute it and/or modify it under
12 * the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
14 * any later version.
15 *
16 * Genders is distributed in the hope that it will be useful, but WITHOUT ANY
17 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with Genders. If not, see <http://www.gnu.org/licenses/>.
23 \*****************************************************************************/
24 package gov.llnl.lc.chaos;
25
26 /**
27 * Java JNI extensions wrapper around libgenders C library. Most
28 * library functions behave similarly to C api functions with minor
29 * exceptions documented below.
30 */
31 public class Genders
32 {
33 private long gh_addr = 0;
34
35 private native int genders_constructor(String filename);
36
37 /**
38 * Creates a Genders object, loading the default genders database
39 */
40 public Genders() throws GendersException
41 {
42 genders_constructor(null);
43 }
44
45 /**
46 * Creates a Genders object, loading the specified genders database
47 */
48 public Genders(String filename) throws GendersException
49 {
50 genders_constructor(filename);
51 }
52
53 /**
54 * Returns number of nodes parsed in the genders database
55 *
56 * @throws GendersException on error
57 */
58 public native int getnumnodes() throws GendersException;
59
60 /**
61 * Returns number of attributes parsed in the genders database
62 *
63 * @throws GendersException on error
64 */
65 public native int getnumattrs() throws GendersException;
66
67 /**
68 * Returns maximum number of attributes of any one node parsed in
69 * the genders database
70 *
71 * @throws GendersException on error
72 */
73 public native int getmaxattrs() throws GendersException;
74
75 /**
76 * Returns the current node you are on, in shortened hostname
77 * format.
78 *
79 * @throws GendersException on error
80 */
81 public native String getnodename() throws GendersException;
82
83 /**
84 * Returns all the nodes in the genders database
85 *
86 * @throws GendersException on error
87 */
88 public native String[] getnodes() throws GendersException;
89
90 /**
91 * Returns all the nodes with the specified attribute
92 *
93 * @throws GendersException on error
94 */
95 public native String[] getnodes(String attr) throws GendersException;
96
97 /**
98 * Returns all the nodes with the specified attribute and value
99 *
100 * @throws GendersException on error
101 */
102 public native String[] getnodes(String attr, String val) throws GendersException;
103
104 /**
105 * Returns all the attributes of the node you are running on
106 *
107 * @throws GendersException on error
108 */
109 public native String[] getattr() throws GendersException;
110
111 /**
112 * Returns all the attributes of the specified node
113 *
114 * @throws GendersException on error
115 */
116 public native String[] getattr(String node) throws GendersException;
117
118 /**
119 * Returns all of the attributes in the genders database
120 *
121 * @throws GendersException on error
122 */
123 public native String[] getattr_all() throws GendersException;
124
125 /**
126 * Returns the value of the specified attribute on the current
127 * node you are running on
128 *
129 * @throws GendersException on error
130 */
131 public native String getattrval(String attr) throws GendersException;
132
133 /**
134 * Returns the value of the specified attribute on the specified
135 * node. May be an empty string if the attribute contains no
136 * value.
137 *
138 * @throws GendersException on error
139 */
140 public native String getattrval(String node, String attr) throws GendersException;
141
142 /**
143 * Tests if the current node has the specified attribute
144 *
145 * @throws GendersException on error
146 */
147 public native boolean testattr(String attr) throws GendersException;
148
149 /**
150 * Tests if the specified node has the specified attribute
151 *
152 * @throws GendersException on error
153 */
154 public native boolean testattr(String node, String attr) throws GendersException;
155
156 /**
157 * Tests if the current node has the specified attribute and value.
158 *
159 * @throws GendersException on error
160 */
161 public native boolean testattrval(String attr, String val) throws GendersException;
162
163 /**
164 * Tests if the specified node has the specified attribute and value.
165 *
166 * @throws GendersException on error
167 */
168 public native boolean testattrval(String node, String attr, String val) throws GendersException;
169
170 /**
171 * Tests if the specified node exists in the genders database
172 *
173 * @throws GendersException on error
174 */
175 public native boolean isnode(String node) throws GendersException;
176
177 /**
178 * Tests if the specified attribute exists in the genders database
179 *
180 * @throws GendersException on error
181 */
182 public native boolean isattr(String attr) throws GendersException;
183
184 /**
185 * Tests if the specified value exists in the genders database
186 *
187 * @throws GendersException on error
188 */
189 public native boolean isattrval(String attr, String val) throws GendersException;
190
191 /**
192 * Returns nodes specified via the specified query. Signify union
193 * with '||', intersection with '&amp;&amp;', * difference with '--', and
194 * complement with '~'. Operations are performed left to
195 * right. Parentheses can be used to change the order of
196 * operations.
197 *
198 * @throws GendersException on error
199 */
200 public native String[] query(String query) throws GendersException;
201
202 /**
203 * Test if the current node meets the conditions of the specified query.
204 *
205 * @throws GendersException on error
206 */
207 public native boolean testquery(String query) throws GendersException;
208
209 /**
210 * Test if the specified node meets the conditions of the specified query.
211 *
212 * @throws GendersException on error
213 */
214 public native boolean testquery(String node, String query) throws GendersException;
215
216 /**
217 * Cleans up allocated memory. Must be called to free memory from
218 * underlying calls. After this method is called, all genders
219 * methods above cannot be called and will result in errors.
220 */
221 public native void cleanup();
222
223 static
224 {
225 System.loadLibrary("Gendersjni");
226 }
227 }