Author: thejas Date: Mon Jan 26 21:27:55 2015 New Revision: 1654900 URL: http://svn.apache.org/r1654900 Log: HIVE-6977 : Delete Hiveserver1 (Ashutosh Chauhan via Vaibhav Gumashta)
Modified: hive/branches/branch-1.0/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java hive/branches/branch-1.0/cli/src/java/org/apache/hadoop/hive/cli/CliSessionState.java hive/branches/branch-1.0/cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java hive/branches/branch-1.0/cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java hive/branches/branch-1.0/cli/src/test/org/apache/hadoop/hive/cli/TestCliSessionState.java hive/branches/branch-1.0/cli/src/test/org/apache/hadoop/hive/cli/TestOptionsProcessor.java Modified: hive/branches/branch-1.0/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java URL: http://svn.apache.org/viewvc/hive/branches/branch-1.0/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java?rev=1654900&r1=1654899&r2=1654900&view=diff ============================================================================== --- hive/branches/branch-1.0/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java (original) +++ hive/branches/branch-1.0/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java Mon Jan 26 21:27:55 2015 @@ -68,10 +68,7 @@ import org.apache.hadoop.hive.ql.process import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse; import org.apache.hadoop.hive.ql.session.SessionState; import org.apache.hadoop.hive.ql.session.SessionState.LogHelper; -import org.apache.hadoop.hive.service.HiveClient; -import org.apache.hadoop.hive.service.HiveServerException; import org.apache.hadoop.io.IOUtils; -import org.apache.thrift.TException; import sun.misc.Signal; import sun.misc.SignalHandler; @@ -150,50 +147,7 @@ public class CliDriver { stringifyException(e)); ret = 1; } - } else if (ss.isRemoteMode()) { // remote mode -- connecting to remote hive server - HiveClient client = ss.getClient(); - PrintStream out = ss.out; - PrintStream err = ss.err; - - try { - client.execute(cmd_trimmed); - List<String> results; - do { - results = client.fetchN(LINES_TO_FETCH); - for (String line : results) { - out.println(line); - } - } while (results.size() == LINES_TO_FETCH); - } catch (HiveServerException e) { - ret = e.getErrorCode(); - if (ret != 0) { // OK if ret == 0 -- reached the EOF - String errMsg = e.getMessage(); - if (errMsg == null) { - errMsg = e.toString(); - } - ret = e.getErrorCode(); - err.println("[Hive Error]: " + errMsg); - } - } catch (TException e) { - String errMsg = e.getMessage(); - if (errMsg == null) { - errMsg = e.toString(); - } - ret = -10002; - err.println("[Thrift Error]: " + errMsg); - } finally { - try { - client.clean(); - } catch (TException e) { - String errMsg = e.getMessage(); - if (errMsg == null) { - errMsg = e.toString(); - } - err.println("[Thrift Error]: Hive server is not cleaned due to thrift exception: " - + errMsg); - } - } - } else { // local mode + } else { // local mode try { CommandProcessor proc = CommandProcessorFactory.get(tokens, (HiveConf) conf); ret = processLocalCmd(cmd, proc, ss); @@ -695,31 +649,6 @@ public class CliDriver { private int executeDriver(CliSessionState ss, HiveConf conf, OptionsProcessor oproc) throws Exception { - // connect to Hive Server - if (ss.getHost() != null) { - ss.connect(); - if (ss.isRemoteMode()) { - prompt = "[" + ss.host + ':' + ss.port + "] " + prompt; - char[] spaces = new char[prompt.length()]; - Arrays.fill(spaces, ' '); - prompt2 = new String(spaces); - } - } - - // CLI remote mode is a thin client: only load auxJars in local mode - if (!ss.isRemoteMode()) { - // hadoop-20 and above - we need to augment classpath using hiveconf - // components - // see also: code in ExecDriver.java - ClassLoader loader = conf.getClassLoader(); - String auxJars = HiveConf.getVar(conf, HiveConf.ConfVars.HIVEAUXJARS); - if (StringUtils.isNotBlank(auxJars)) { - loader = Utilities.addToClassPath(loader, StringUtils.split(auxJars, ",")); - } - conf.setClassLoader(loader); - Thread.currentThread().setContextClassLoader(loader); - } - CliDriver cli = new CliDriver(); cli.setHiveVariables(oproc.getHiveVariables()); Modified: hive/branches/branch-1.0/cli/src/java/org/apache/hadoop/hive/cli/CliSessionState.java URL: http://svn.apache.org/viewvc/hive/branches/branch-1.0/cli/src/java/org/apache/hadoop/hive/cli/CliSessionState.java?rev=1654900&r1=1654899&r2=1654900&view=diff ============================================================================== --- hive/branches/branch-1.0/cli/src/java/org/apache/hadoop/hive/cli/CliSessionState.java (original) +++ hive/branches/branch-1.0/cli/src/java/org/apache/hadoop/hive/cli/CliSessionState.java Mon Jan 26 21:27:55 2015 @@ -25,13 +25,6 @@ import java.util.Properties; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.ql.session.SessionState; -import org.apache.hadoop.hive.service.HiveClient; -import org.apache.thrift.TException; -import org.apache.thrift.protocol.TBinaryProtocol; -import org.apache.thrift.protocol.TProtocol; -import org.apache.thrift.transport.TSocket; -import org.apache.thrift.transport.TTransport; -import org.apache.thrift.transport.TTransportException; /** * SessionState for hive cli. @@ -63,66 +56,16 @@ public class CliSessionState extends Ses */ public List<String> initFiles = new ArrayList<String>(); - /** - * host name and port number of remote Hive server - */ - protected String host; - protected int port; - - private boolean remoteMode; - - private TTransport transport; - private HiveClient client; - public CliSessionState(HiveConf conf) { super(conf); - remoteMode = false; - } - - /** - * Connect to Hive Server - */ - public void connect() throws TTransportException { - transport = new TSocket(host, port); - TProtocol protocol = new TBinaryProtocol(transport); - client = new HiveClient(protocol); - transport.open(); - remoteMode = true; - } - - public void setHost(String host) { - this.host = host; - } - - public String getHost() { - return host; - } - - public int getPort() { - return port; } @Override public void close() { try { super.close(); - if (remoteMode) { - client.clean(); - transport.close(); - } } catch (IOException ioe) { ioe.printStackTrace(); - } catch (TException e) { - e.printStackTrace(); - } + } } - - public boolean isRemoteMode() { - return remoteMode; - } - - public HiveClient getClient() { - return client; - } - } Modified: hive/branches/branch-1.0/cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java URL: http://svn.apache.org/viewvc/hive/branches/branch-1.0/cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java?rev=1654900&r1=1654899&r2=1654900&view=diff ============================================================================== --- hive/branches/branch-1.0/cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java (original) +++ hive/branches/branch-1.0/cli/src/java/org/apache/hadoop/hive/cli/OptionsProcessor.java Mon Jan 26 21:27:55 2015 @@ -83,20 +83,6 @@ public class OptionsProcessor { .withDescription("Use value for given property") .create()); - // -h hostname/ippaddress - options.addOption(OptionBuilder - .hasArg() - .withArgName("hostname") - .withDescription("connecting to Hive Server on remote host") - .create('h')); - - // -p port - options.addOption(OptionBuilder - .hasArg() - .withArgName("port") - .withDescription("connecting to Hive Server on port number") - .create('p')); - // Substitution option -d, --define options.addOption(OptionBuilder .withValueSeparator() @@ -169,10 +155,6 @@ public class OptionsProcessor { ss.setIsVerbose(commandLine.hasOption('v')); - ss.host = (String) commandLine.getOptionValue('h'); - - ss.port = Integer.parseInt((String) commandLine.getOptionValue('p', "10000")); - String[] initFiles = commandLine.getOptionValues('i'); if (null != initFiles) { ss.initFiles = Arrays.asList(initFiles); Modified: hive/branches/branch-1.0/cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java URL: http://svn.apache.org/viewvc/hive/branches/branch-1.0/cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java?rev=1654900&r1=1654899&r2=1654900&view=diff ============================================================================== --- hive/branches/branch-1.0/cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java (original) +++ hive/branches/branch-1.0/cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java Mon Jan 26 21:27:55 2015 @@ -56,10 +56,7 @@ import org.apache.hadoop.hive.metastore. import org.apache.hadoop.hive.ql.CommandNeedRetryException; import org.apache.hadoop.hive.ql.Driver; import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse; -import org.apache.hadoop.hive.service.HiveClient; -import org.apache.hadoop.hive.service.HiveServerException; import org.apache.hadoop.util.Shell; -import org.apache.thrift.TException; // Cannot call class TestCliDriver since that's the name of the generated @@ -231,66 +228,6 @@ public class TestCliDriverMethods extend } - /** - * test remote execCommand - */ - public void testRemoteCall() throws Exception { - MyCliSessionState ss = new MyCliSessionState(new HiveConf(), - org.apache.hadoop.hive.cli.TestCliDriverMethods.MyCliSessionState.ClientResult.RETURN_OK); - ss.err = System.err; - ByteArrayOutputStream data = new ByteArrayOutputStream(); - ss.out = new PrintStream(data); - MyCliSessionState.start(ss); - - CliDriver cliDriver = new CliDriver(); - cliDriver.processCmd("remote command"); - assertTrue(data.toString().contains("test result")); - - } - - /** - * test remote Exception - */ - public void testServerException() throws Exception { - MyCliSessionState ss = new MyCliSessionState( - new HiveConf(), - org.apache.hadoop.hive.cli.TestCliDriverMethods.MyCliSessionState.ClientResult.RETURN_SERVER_EXCEPTION); - ByteArrayOutputStream data = new ByteArrayOutputStream(); - ss.err = new PrintStream(data); - ss.out = System.out; - MyCliSessionState.start(ss); - - CliDriver cliDriver = new CliDriver(); - cliDriver.processCmd("remote command"); - assertTrue(data.toString().contains("[Hive Error]: test HiveServerException")); - data.reset(); - - - } - - /** - * test remote Exception - */ - public void testServerTException() throws Exception { - MyCliSessionState ss = new MyCliSessionState( - new HiveConf(), - org.apache.hadoop.hive.cli.TestCliDriverMethods.MyCliSessionState.ClientResult.RETURN_T_EXCEPTION); - ByteArrayOutputStream data = new ByteArrayOutputStream(); - ss.err = new PrintStream(data); - ss.out = System.out; - MyCliSessionState.start(ss); - - CliDriver cliDriver = new CliDriver(); - cliDriver.processCmd("remote command"); - assertTrue(data.toString().contains("[Thrift Error]: test TException")); - assertTrue(data.toString().contains( - "[Thrift Error]: Hive server is not cleaned due to thrift exception: test TException")); - - } - - /** - * test remote Exception - */ public void testProcessSelectDatabase() throws Exception { CliSessionState sessinState = new CliSessionState(new HiveConf()); CliSessionState.start(sessinState); @@ -521,63 +458,4 @@ public class TestCliDriverMethods extend return status; } } - - private static class MyCliSessionState extends CliSessionState { - - public enum ClientResult { - RETURN_OK, RETURN_SERVER_EXCEPTION, RETURN_T_EXCEPTION - }; - - private final ClientResult result; - - public MyCliSessionState(HiveConf conf, ClientResult result) { - super(conf); - this.result = result; - } - - @Override - public boolean isRemoteMode() { - return true; - } - - @Override - public HiveClient getClient() { - - HiveClient result = mock(HiveClient.class); - if (ClientResult.RETURN_OK.equals(this.result)) { - List<String> fetchResult = new ArrayList<String>(1); - fetchResult.add("test result"); - try { - when(result.fetchN(anyInt())).thenReturn(fetchResult); - } catch (HiveServerException e) { - } catch (Exception e) { - } - } else if (ClientResult.RETURN_SERVER_EXCEPTION.equals(this.result)) { - HiveServerException exception = new HiveServerException("test HiveServerException", 10, - "sql state"); - try { - when(result.fetchN(anyInt())).thenThrow(exception); - - when(result.fetchN(anyInt())).thenThrow(exception); - } catch (TException e) { - ; - } - return result; - } else if (ClientResult.RETURN_T_EXCEPTION.equals(this.result)) { - TException exception = new TException("test TException"); - try { - // org.mockito.Mockito. - doThrow(exception).when(result).clean(); - when(result.fetchN(anyInt())).thenThrow(exception); - } catch (TException e) { - e.printStackTrace(); - } - return result; - } - return result; - } - - } - - } Modified: hive/branches/branch-1.0/cli/src/test/org/apache/hadoop/hive/cli/TestCliSessionState.java URL: http://svn.apache.org/viewvc/hive/branches/branch-1.0/cli/src/test/org/apache/hadoop/hive/cli/TestCliSessionState.java?rev=1654900&r1=1654899&r2=1654900&view=diff ============================================================================== --- hive/branches/branch-1.0/cli/src/test/org/apache/hadoop/hive/cli/TestCliSessionState.java (original) +++ hive/branches/branch-1.0/cli/src/test/org/apache/hadoop/hive/cli/TestCliSessionState.java Mon Jan 26 21:27:55 2015 @@ -18,21 +18,10 @@ package org.apache.hadoop.hive.cli; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.metastore.MetaStoreUtils; import org.apache.hadoop.hive.ql.session.SessionState; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; /** @@ -40,46 +29,6 @@ import org.junit.Test; */ public class TestCliSessionState { - private static TCPServer server; - private static String command = null; - - @BeforeClass - public static void start() throws Exception { - // start fake server - server = new TCPServer(); - Thread thread = new Thread(server); - thread.start(); - // wait for start server; - while (server.getPort() == 0) { - Thread.sleep(20); - } - } - - @AfterClass - public static void stop() throws IOException { - server.stop(); - } - - /** - * test CliSessionState for remote - */ - @Test - public void testConnect() throws Exception { - CliSessionState sessionState = new CliSessionState(new HiveConf()); - sessionState.port = server.getPort(); - sessionState.setHost(InetAddress.getLocalHost().getHostName()); - // check connect - sessionState.connect(); - assertTrue(sessionState.isRemoteMode()); - assertEquals(server.getPort(), sessionState.getPort()); - assertEquals(InetAddress.getLocalHost().getHostName(), sessionState.getHost()); - assertNotNull(sessionState.getClient()); - sessionState.close(); - // close should send command clean - assertEquals(command, "clean"); - - } - /** * test default db name */ @@ -89,44 +38,4 @@ public class TestCliSessionState { assertEquals(MetaStoreUtils.DEFAULT_DATABASE_NAME, SessionState.get().getCurrentDatabase()); } - - /** - * fake hive server - */ - private static class TCPServer implements Runnable { - private int port = 0; - private boolean stop = false; - private ServerSocket welcomeSocket; - - public void run() { - try { - - welcomeSocket = new ServerSocket(0); - port = welcomeSocket.getLocalPort(); - while (!stop) { - byte[] buffer = new byte[512]; - Socket connectionSocket = welcomeSocket.accept(); - InputStream input = connectionSocket.getInputStream(); - OutputStream output = connectionSocket.getOutputStream(); - int read = input.read(buffer); - // command without service bytes - command = new String(buffer, 8, read - 13); - // send derived - output.write(buffer, 0, read); - } - } catch (IOException e) { - ; - } - - } - - public int getPort() { - return port; - } - - public void stop() throws IOException { - stop = true; - welcomeSocket.close(); - } - } } Modified: hive/branches/branch-1.0/cli/src/test/org/apache/hadoop/hive/cli/TestOptionsProcessor.java URL: http://svn.apache.org/viewvc/hive/branches/branch-1.0/cli/src/test/org/apache/hadoop/hive/cli/TestOptionsProcessor.java?rev=1654900&r1=1654899&r2=1654900&view=diff ============================================================================== --- hive/branches/branch-1.0/cli/src/test/org/apache/hadoop/hive/cli/TestOptionsProcessor.java (original) +++ hive/branches/branch-1.0/cli/src/test/org/apache/hadoop/hive/cli/TestOptionsProcessor.java Mon Jan 26 21:27:55 2015 @@ -41,8 +41,7 @@ public class TestOptionsProcessor { System.clearProperty("hivevar"); assertNull(System.getProperty("_A")); String[] args = { "-hiveconf", "_A=B", "-define", "C=D", "-hivevar", "X=Y", - "-S", "true", "-database", "testDb", "-e", "execString", "-v", "true", - "-h", "yahoo.host", "-p", "3000"}; + "-S", "true", "-database", "testDb", "-e", "execString", "-v", "true"}; // stage 1 assertTrue(processor.process_stage1(args)); @@ -55,8 +54,6 @@ public class TestOptionsProcessor { processor.process_stage2(sessionState); assertEquals("testDb", sessionState.database); assertEquals("execString", sessionState.execString); - assertEquals("yahoo.host", sessionState.host); - assertEquals(3000, sessionState.port); assertEquals(0, sessionState.initFiles.size()); assertTrue(sessionState.getIsVerbose()); sessionState.setConf(null);