public void writeDOT( String filename ) { Util.invokeInstanceMethod( graph, "writeDOT", new Object[]{filename}, new Class[]{String.class} ); } }
public static Object invokeInstanceMethodSafe( Object target, String methodName, Object[] parameters, Class[] parameterTypes ) { try { return invokeInstanceMethod( target, methodName, parameters, parameterTypes ); } catch( Exception exception ) { return null; } }
public static <C> C copyConfiguration( C parent ) { if( parent == null ) throw new IllegalArgumentException( "parent may not be null" ); if( !( parent instanceof Configuration ) ) throw new IllegalArgumentException( "parent must be of type Configuration" ); Configuration conf = (Configuration) parent; // see https://github.com/Cascading/cascading/pull/21 // The JobConf(JobConf) constructor causes derived JobConfs to share Credentials. We want to avoid this, in // case those Credentials are mutated later on down the road (which they will be, during job submission, in // separate threads!). Using the JobConf(Configuration) constructor avoids Credentials-sharing. Configuration configurationCopy = new Configuration( conf ); Configuration copiedConf = callCopyConstructor( parent.getClass(), configurationCopy ); if( Util.hasInstanceMethod( parent, "getCredentials", null ) ) { Object result = invokeInstanceMethod( parent, "getCredentials", null, null ); Object credentials = invokeInstanceMethod( copiedConf, "getCredentials", null, null ); invokeInstanceMethod( credentials, "addAll", new Object[]{result}, new Class[]{credentials.getClass()} ); } return (C) copiedConf; }
public static <C> C copyConfiguration( C parent ) { if( parent == null ) throw new IllegalArgumentException( "parent may not be null" ); if( !( parent instanceof Configuration ) ) throw new IllegalArgumentException( "parent must be of type Configuration" ); Configuration conf = (Configuration) parent; // see https://github.com/Cascading/cascading/pull/21 // The JobConf(JobConf) constructor causes derived JobConfs to share Credentials. We want to avoid this, in // case those Credentials are mutated later on down the road (which they will be, during job submission, in // separate threads!). Using the JobConf(Configuration) constructor avoids Credentials-sharing. Configuration configurationCopy = new Configuration( conf ); Configuration copiedConf = callCopyConstructor( parent.getClass(), configurationCopy ); if( Util.hasInstanceMethod( parent, "getCredentials", null ) ) { Object result = invokeInstanceMethod( parent, "getCredentials", null, null ); Object credentials = invokeInstanceMethod( copiedConf, "getCredentials", null, null ); invokeInstanceMethod( credentials, "addAll", new Object[]{result}, new Class[]{credentials.getClass()} ); } return (C) copiedConf; }
public static String setLog4jLevel( String logger, String level ) { // removing logj4 dependency // org.apache.log4j.Logger.getLogger( logger[ 0 ] ).setLevel( org.apache.log4j.Level.toLevel( logger[ 1 ] ) ); Object loggerObject = Util.invokeStaticMethod( "org.apache.log4j.Logger", "getLogger", new Object[]{logger}, new Class[]{String.class} ); Object levelObject = null; if( level != null ) levelObject = Util.invokeStaticMethod( "org.apache.log4j.Level", "toLevel", new Object[]{level}, new Class[]{String.class} ); Object oldLevel = Util.invokeInstanceMethod( loggerObject, "getLevel", new Object[]{}, new Class[]{} ); Util.invokeInstanceMethod( loggerObject, "setLevel", new Object[]{levelObject}, new Class[]{Util.loadClass( "org.apache.log4j.Level" )} ); if( oldLevel == null ) return null; return oldLevel.toString(); }
@Test public void testSetLogLevel() { Configuration jobConf = new Configuration(); jobConf.set( "log4j.logger", "cascading=DEBUG" ); HadoopUtil.initLog4j( jobConf ); Object loggerObject = Util.invokeStaticMethod( "org.apache.log4j.Logger", "getLogger", new Object[]{"cascading"}, new Class[]{String.class} ); Object levelObject = Util.invokeStaticMethod( "org.apache.log4j.Level", "toLevel", new Object[]{"DEBUG"}, new Class[]{String.class} ); Object returnedLevel = Util.invokeInstanceMethod( loggerObject, "getLevel", new Object[]{}, new Class[]{} ); assertEquals( levelObject, returnedLevel ); } }
@Test public void testSetLogLevel() { Configuration jobConf = new Configuration(); jobConf.set( "log4j.logger", "cascading=DEBUG" ); HadoopUtil.initLog4j( jobConf ); Object loggerObject = Util.invokeStaticMethod( "org.apache.log4j.Logger", "getLogger", new Object[]{"cascading"}, new Class[]{String.class} ); Object levelObject = Util.invokeStaticMethod( "org.apache.log4j.Level", "toLevel", new Object[]{"DEBUG"}, new Class[]{String.class} ); Object returnedLevel = Util.invokeInstanceMethod( loggerObject, "getLevel", new Object[]{}, new Class[]{} ); assertEquals( levelObject, returnedLevel ); } }