1717 */
1818
1919#include "exception.h"
20+ #include "jclasses.h"
2021#include "jni_helper.h"
2122#include "native_mini_dfs.h"
2223#include "platform.h"
3637
3738#define MINIDFS_CLUSTER_BUILDER "org/apache/hadoop/hdfs/MiniDFSCluster$Builder"
3839#define MINIDFS_CLUSTER "org/apache/hadoop/hdfs/MiniDFSCluster"
39- #define HADOOP_CONF "org/apache/hadoop/conf/Configuration"
4040#define HADOOP_NAMENODE "org/apache/hadoop/hdfs/server/namenode/NameNode"
41- #define JAVA_INETSOCKETADDRESS "java/net/InetSocketAddress"
4241
4342struct NativeMiniDfsCluster {
4443 /**
@@ -60,8 +59,7 @@ static int hdfsDisableDomainSocketSecurity(void)
6059 errno = EINTERNAL ;
6160 return -1 ;
6261 }
63- jthr = invokeMethod (env , NULL , STATIC , NULL ,
64- "org/apache/hadoop/net/unix/DomainSocket" ,
62+ jthr = invokeMethod (env , NULL , STATIC , NULL , JC_DOMAIN_SOCKET ,
6563 "disableBindPathValidation" , "()V" );
6664 if (jthr ) {
6765 errno = printExceptionAndFree (env , jthr , PRINT_EXC_ALL ,
@@ -126,11 +124,6 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
126124 "nmdCreate: new Configuration" );
127125 goto error ;
128126 }
129- if (jthr ) {
130- printExceptionAndFree (env , jthr , PRINT_EXC_ALL ,
131- "nmdCreate: Configuration::setBoolean" );
132- goto error ;
133- }
134127 // Disable 'minimum block size' -- it's annoying in tests.
135128 (* env )-> DeleteLocalRef (env , jconfStr );
136129 jconfStr = NULL ;
@@ -140,8 +133,9 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
140133 "nmdCreate: new String" );
141134 goto error ;
142135 }
143- jthr = invokeMethod (env , NULL , INSTANCE , cobj , HADOOP_CONF ,
144- "setLong" , "(Ljava/lang/String;J)V" , jconfStr , 0LL );
136+ jthr = invokeMethod (env , NULL , INSTANCE , cobj ,
137+ JC_CONFIGURATION , "setLong" , "(Ljava/lang/String;J)V" , jconfStr ,
138+ 0LL );
145139 if (jthr ) {
146140 printExceptionAndFree (env , jthr , PRINT_EXC_ALL ,
147141 "nmdCreate: Configuration::setLong" );
@@ -163,7 +157,7 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
163157 goto error ;
164158 }
165159 }
166- jthr = invokeMethod (env , & val , INSTANCE , bld , MINIDFS_CLUSTER_BUILDER ,
160+ jthr = findClassAndInvokeMethod (env , & val , INSTANCE , bld , MINIDFS_CLUSTER_BUILDER ,
167161 "format" , "(Z)L" MINIDFS_CLUSTER_BUILDER ";" , conf -> doFormat );
168162 if (jthr ) {
169163 printExceptionAndFree (env , jthr , PRINT_EXC_ALL , "nmdCreate: "
@@ -172,7 +166,7 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
172166 }
173167 (* env )-> DeleteLocalRef (env , val .l );
174168 if (conf -> webhdfsEnabled ) {
175- jthr = invokeMethod (env , & val , INSTANCE , bld , MINIDFS_CLUSTER_BUILDER ,
169+ jthr = findClassAndInvokeMethod (env , & val , INSTANCE , bld , MINIDFS_CLUSTER_BUILDER ,
176170 "nameNodeHttpPort" , "(I)L" MINIDFS_CLUSTER_BUILDER ";" ,
177171 conf -> namenodeHttpPort );
178172 if (jthr ) {
@@ -183,7 +177,7 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
183177 (* env )-> DeleteLocalRef (env , val .l );
184178 }
185179 if (conf -> numDataNodes ) {
186- jthr = invokeMethod (env , & val , INSTANCE , bld , MINIDFS_CLUSTER_BUILDER ,
180+ jthr = findClassAndInvokeMethod (env , & val , INSTANCE , bld , MINIDFS_CLUSTER_BUILDER ,
187181 "numDataNodes" , "(I)L" MINIDFS_CLUSTER_BUILDER ";" , conf -> numDataNodes );
188182 if (jthr ) {
189183 printExceptionAndFree (env , jthr , PRINT_EXC_ALL , "nmdCreate: "
@@ -192,7 +186,7 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
192186 }
193187 }
194188 (* env )-> DeleteLocalRef (env , val .l );
195- jthr = invokeMethod (env , & val , INSTANCE , bld , MINIDFS_CLUSTER_BUILDER ,
189+ jthr = findClassAndInvokeMethod (env , & val , INSTANCE , bld , MINIDFS_CLUSTER_BUILDER ,
196190 "build" , "()L" MINIDFS_CLUSTER ";" );
197191 if (jthr ) {
198192 printExceptionAndFree (env , jthr , PRINT_EXC_ALL ,
@@ -242,7 +236,7 @@ int nmdShutdown(struct NativeMiniDfsCluster* cl)
242236 fprintf (stderr , "nmdShutdown: getJNIEnv failed\n" );
243237 return - EIO ;
244238 }
245- jthr = invokeMethod (env , NULL , INSTANCE , cl -> obj ,
239+ jthr = findClassAndInvokeMethod (env , NULL , INSTANCE , cl -> obj ,
246240 MINIDFS_CLUSTER , "shutdown" , "()V" );
247241 if (jthr ) {
248242 printExceptionAndFree (env , jthr , PRINT_EXC_ALL ,
@@ -260,7 +254,7 @@ int nmdWaitClusterUp(struct NativeMiniDfsCluster *cl)
260254 fprintf (stderr , "nmdWaitClusterUp: getJNIEnv failed\n" );
261255 return - EIO ;
262256 }
263- jthr = invokeMethod (env , NULL , INSTANCE , cl -> obj ,
257+ jthr = findClassAndInvokeMethod (env , NULL , INSTANCE , cl -> obj ,
264258 MINIDFS_CLUSTER , "waitClusterUp" , "()V" );
265259 if (jthr ) {
266260 printExceptionAndFree (env , jthr , PRINT_EXC_ALL ,
@@ -282,7 +276,7 @@ int nmdGetNameNodePort(const struct NativeMiniDfsCluster *cl)
282276 }
283277 // Note: this will have to be updated when HA nativeMiniDfs clusters are
284278 // supported
285- jthr = invokeMethod (env , & jVal , INSTANCE , cl -> obj ,
279+ jthr = findClassAndInvokeMethod (env , & jVal , INSTANCE , cl -> obj ,
286280 MINIDFS_CLUSTER , "getNameNodePort" , "()I" );
287281 if (jthr ) {
288282 printExceptionAndFree (env , jthr , PRINT_EXC_ALL ,
@@ -307,7 +301,7 @@ int nmdGetNameNodeHttpAddress(const struct NativeMiniDfsCluster *cl,
307301 return - EIO ;
308302 }
309303 // First get the (first) NameNode of the cluster
310- jthr = invokeMethod (env , & jVal , INSTANCE , cl -> obj , MINIDFS_CLUSTER ,
304+ jthr = findClassAndInvokeMethod (env , & jVal , INSTANCE , cl -> obj , MINIDFS_CLUSTER ,
311305 "getNameNode" , "()L" HADOOP_NAMENODE ";" );
312306 if (jthr ) {
313307 printExceptionAndFree (env , jthr , PRINT_EXC_ALL ,
@@ -318,8 +312,8 @@ int nmdGetNameNodeHttpAddress(const struct NativeMiniDfsCluster *cl,
318312 jNameNode = jVal .l ;
319313
320314 // Then get the http address (InetSocketAddress) of the NameNode
321- jthr = invokeMethod (env , & jVal , INSTANCE , jNameNode , HADOOP_NAMENODE ,
322- "getHttpAddress" , "()L" JAVA_INETSOCKETADDRESS ";" );
315+ jthr = findClassAndInvokeMethod (env , & jVal , INSTANCE , jNameNode , HADOOP_NAMENODE ,
316+ "getHttpAddress" , "()L" JAVA_NET_ISA ";" );
323317 if (jthr ) {
324318 ret = printExceptionAndFree (env , jthr , PRINT_EXC_ALL ,
325319 "nmdGetNameNodeHttpAddress: "
@@ -328,8 +322,8 @@ int nmdGetNameNodeHttpAddress(const struct NativeMiniDfsCluster *cl,
328322 }
329323 jAddress = jVal .l ;
330324
331- jthr = invokeMethod (env , & jVal , INSTANCE , jAddress ,
332- JAVA_INETSOCKETADDRESS , "getPort" , "()I" );
325+ jthr = findClassAndInvokeMethod (env , & jVal , INSTANCE , jAddress ,
326+ JAVA_NET_ISA , "getPort" , "()I" );
333327 if (jthr ) {
334328 ret = printExceptionAndFree (env , jthr , PRINT_EXC_ALL ,
335329 "nmdGetNameNodeHttpAddress: "
@@ -338,7 +332,7 @@ int nmdGetNameNodeHttpAddress(const struct NativeMiniDfsCluster *cl,
338332 }
339333 * port = jVal .i ;
340334
341- jthr = invokeMethod (env , & jVal , INSTANCE , jAddress , JAVA_INETSOCKETADDRESS ,
335+ jthr = findClassAndInvokeMethod (env , & jVal , INSTANCE , jAddress , JAVA_NET_ISA ,
342336 "getHostName" , "()Ljava/lang/String;" );
343337 if (jthr ) {
344338 ret = printExceptionAndFree (env , jthr , PRINT_EXC_ALL ,
0 commit comments