/**
  * Return a client based on the given socket that points to the configured keyspace, and is logged
  * in with the configured credentials.
  *
  * @param socket a socket pointing to a particular node, seed or otherwise
  * @param conf a job configuration
  * @return a cassandra client
  * @throws InvalidRequestException
  * @throws TException
  * @throws AuthenticationException
  * @throws AuthorizationException
  */
 public static Cassandra.Client createAuthenticatedClient(TSocket socket, Configuration conf)
     throws InvalidRequestException, TException, AuthenticationException, AuthorizationException {
   TBinaryProtocol binaryProtocol = new TBinaryProtocol(new TFramedTransport(socket));
   Cassandra.Client client = new Cassandra.Client(binaryProtocol);
   socket.open();
   client.set_keyspace(ConfigHelper.getOutputKeyspace(conf));
   if (ConfigHelper.getOutputKeyspaceUserName(conf) != null) {
     Map<String, String> creds = new HashMap<String, String>();
     creds.put(SimpleAuthenticator.USERNAME_KEY, ConfigHelper.getOutputKeyspaceUserName(conf));
     creds.put(SimpleAuthenticator.PASSWORD_KEY, ConfigHelper.getOutputKeyspacePassword(conf));
     AuthenticationRequest authRequest = new AuthenticationRequest(creds);
     client.login(authRequest);
   }
   return client;
 }
 /**
  * Connects to the given server:port and returns a client based on the given socket that points to
  * the configured keyspace, and is logged in with the configured credentials.
  *
  * @param host fully qualified host name to connect to
  * @param port RPC port of the server
  * @param conf a job configuration
  * @return a cassandra client
  * @throws Exception set of thrown exceptions may be implementation defined, depending on the used
  *     transport factory
  */
 public static Cassandra.Client createAuthenticatedClient(
     String host, int port, Configuration conf) throws Exception {
   logger.debug("Creating authenticated client for CF output format");
   TTransport transport = ConfigHelper.getClientTransportFactory(conf).openTransport(host, port);
   TProtocol binaryProtocol = new TBinaryProtocol(transport, true, true);
   Cassandra.Client client = new Cassandra.Client(binaryProtocol);
   client.set_keyspace(ConfigHelper.getOutputKeyspace(conf));
   if (ConfigHelper.getOutputKeyspaceUserName(conf) != null) {
     Map<String, String> creds = new HashMap<String, String>();
     creds.put(IAuthenticator.USERNAME_KEY, ConfigHelper.getOutputKeyspaceUserName(conf));
     creds.put(IAuthenticator.PASSWORD_KEY, ConfigHelper.getOutputKeyspacePassword(conf));
     AuthenticationRequest authRequest = new AuthenticationRequest(creds);
     client.login(authRequest);
   }
   logger.debug("Authenticated client for CF output format created successfully");
   return client;
 }