title: Switch name node - Hadoop Java api with camel , jms
body: <p>Hi I am using camel to get the messages from the JMS queue, process the message store it in Hadoop using FS java API and then transfer it to another queue</p>
  
  <p>Currently my JMS concurrent is 20. so at one shot camel JMS consumes 20 messages at a time. For every message, I create the fs connection and perform an operation that creates a file and writes a file. </p>
  
  <p>Here is the issue </p>
  
  <p>What i see is sometimes while writing the content to the file, due to some reason my namenode goes down, in this case, I want to switch my name to the active name node</p>
  
  <p>Here is a log I get</p>
  
  <p>[Camel (camel-1) thread #1 a failover occurred since the last call #169 ClientNamenodeProtocolTranslatorPD.getFileInfo over {name_node_address_allias/ip:port}</p>
  
  <p>When I debug it I show Operation category WRITE is not supported in state standby</p>
  
  <p>I want at that time to switch to the active name node</p>
  
  <p>Hadoop Java API Sample code</p>
  
  <pre><code>package org.myorg;
  import org.apache.hadoop.conf.*;
  import org.apache.hadoop.security.UserGroupInformation;
  import org.apache.hadoop.fs.Path;
  import org.apache.hadoop.fs.FileSystem;
  import org.apache.hadoop.fs.FileStatus;
  
  public class HdfsTest {
      public static void main(String args[]) {
          conf.addResource("path-of-core-site.xml");
          conf.addResource("path-of-hdfs-site.xml");
          conf.set("fs.defaultFS", "hdfs://cloudera:8020");
          conf.set("hadoop.security.authentication", "kerberos");
          UserGroupInformation.setConfiguration(conf);
          UserGroupInformation.loginUserFromKeytab("hdfs@CLOUDERA", "/etc/hadoop/conf/hdfs.keytab");
          FileSystem fs = FileSystem.get(conf);    
          //logic to create a file and write
          //close the cfile and connection
      }
  }
  </code></pre>