Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.io.IOException;
- import javax.security.auth.Subject;
- import javax.security.auth.login.LoginContext;
- import javax.security.auth.login.LoginException;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.security.UserGroupInformation;
- public class GetTest2 {
- /* JAAS.CONF
- com.sun.security.jgss.krb5.initiate {
- com.sun.security.auth.module.Krb5LoginModule required
- doNotPrompt=true
- principal="[email protected]"
- useKeyTab=true
- keyTab="./conf/devp.keytab"
- storeKey=false
- debug=false
- useTicketCache=false;
- };
- */
- public static void main(String[] args) throws IOException, LoginException {
- if(args.length != 6){
- System.out.println(String.join(",", args));
- System.out.println("Classpath Jars found from: export jars=$(hadoop classpath):($hbase classpath)");
- System.out.println("Usage: /usr/jdk64/jdk1.8.0_60/bin/java -cp $jars:FSHBaseTEST.jar test.GetTest2 HDFSFolder HBaseTable HBaseKey HBaseColFam HBaseCell HBaseVal");
- System.out.println("conf/ folder should contain jaas.conf, hbase-site.xml, core-site.xml, hdfs-site.xml");
- return;
- }
- System.out.println();
- System.setProperty("sun.security.krb5.debug", "false");
- System.setProperty("java.security.auth.login.config", "./conf/jaas.conf");
- System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
- System.setProperty("java.security.krb5.conf", "./conf/krb5.conf");
- LoginContext context = new LoginContext("com.sun.security.jgss.krb5.initiate");
- context.login();
- Subject subject = context.getSubject();
- Configuration conf = new Configuration();
- conf.addResource(new Path("./conf/hdfs-site.xml"));
- conf.addResource(new Path("./conf/core-site.xml"));
- conf.addResource(new Path("./conf/hbase-site.xml"));
- UserGroupInformation.setConfiguration(conf);
- UserGroupInformation.loginUserFromSubject(subject);
- System.out.println("NAME -> " + conf.get("dfs.namenode.http-address"));
- System.out.println("SECURITY -> " + conf.get("hadoop.security.authentication"));
- System.out.println("defaultFS -> " + conf.get("fs.defaultFS"));
- FileSystem fs = FileSystem.get(conf);
- RemoteIterator<LocatedFileStatus> lfs = fs.listFiles(new Path(args[0]), false);
- while (lfs.hasNext()){
- System.out.println(lfs.next().getPath());
- }
- //HBASE TEST
- Connection connection = ConnectionFactory.createConnection(conf);
- Table table = connection.getTable(TableName.valueOf(args[1]));
- Put pp = new Put(Bytes.toBytes(args[2]));
- pp.add(Bytes.toBytes(args[3]), Bytes.toBytes(args[4]), Bytes.toBytes(args[5]));
- table.put(pp);
- Get g = new Get(Bytes.toBytes(args[2]));
- Result result = table.get(g);
- //System.out.println(result.toString());
- byte[] value = result.getValue(Bytes.toBytes(args[3]), Bytes.toBytes(args[4]));
- // Printing the values
- String stuff = Bytes.toString(value);
- System.out.println("stuff " + stuff);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment