QueryUtil { public static String getConnectionUrl(Properties props, Configuration conf) throws ClassNotFoundException, SQLException { Class.forName(PhoenixDriver.class.getName()); String server = ZKConfig.getZKQuorumServersString(conf); String[] rawServers = server.split(","); List<String> servers = new ArrayList<String>(rawServers.length); boolean first = true; int port = -1; for (String serverPort : rawServers) { try { server = Addressing.parseHostname(serverPort); int specifiedPort = Addressing.parsePort(serverPort); if (port > 0 && specifiedPort != port) { throw new IllegalStateException("Phoenix/HBase only supports connecting to a " + "single zookeeper client port. Specify servers only as host names in " + "HBase configuration"); } port = specifiedPort; servers.add(server); } catch (IllegalArgumentException e) { } } if (port == -1) { port = conf.getInt(QueryServices.ZOOKEEPER_PORT_ATTRIB, -1); if (port == -1) { throw new RuntimeException("Client zk port was not set!"); } } server = Joiner.on(',').join(servers); return getUrl(server, port); } private  QueryUtil(); static String toSQL(CompareOp op); static String constructUpsertStatement(String tableName, List<ColumnInfo> columnInfos); static String constructGenericUpsertStatement(String tableName, int numColumns); static String constructSelectStatement(String fullTableName, List<ColumnInfo> columnInfos,final String conditions); static String getUrl(String server); static String getUrl(String server, long port); static String getExplainPlan(ResultSet rs); static String getExplainPlan(ResultIterator iterator); static Connection getConnection(Configuration conf); static Connection getConnection(Properties props, Configuration conf); static String getConnectionUrl(Properties props, Configuration conf); static String getViewStatement(String schemaName, String tableName, String where); static final int COLUMN_FAMILY_POSITION; static final int COLUMN_NAME_POSITION; static final int DATA_TYPE_POSITION; static final int DATA_TYPE_NAME_POSITION; }
@Test public void testCreateConnectionFromConfiguration() throws Exception { Properties props = new Properties(); Configuration conf = new Configuration(false); conf.set(HConstants.ZOOKEEPER_QUORUM, "localhost"); conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, "2181"); String conn = QueryUtil.getConnectionUrl(props, conf); validateUrl(conn); conf.set(HConstants.ZOOKEEPER_QUORUM, "host.at.some.domain.1,localhost," + "host.at.other.domain.3"); conn = QueryUtil.getConnectionUrl(props, conf); validateUrl(conn); conf.set("hbase.zookeeper.peerport", "3338"); conf.set("hbase.zookeeper.leaderport", "3339"); conn = QueryUtil.getConnectionUrl(props, conf); validateUrl(conn); }