incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cr...@apache.org
Subject git commit: Used the correct user setup
Date Mon, 09 Jun 2014 17:05:23 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/apache-blur-0.2 4a4338af2 -> 15e8c679b


Used the correct user setup


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/15e8c679
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/15e8c679
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/15e8c679

Branch: refs/heads/apache-blur-0.2
Commit: 15e8c679be1b59fea3ce53f57d7563629be06a6c
Parents: 4a4338a
Author: Chris Rohr <rohr.chris@gmail.com>
Authored: Mon Jun 9 13:05:14 2014 -0400
Committer: Chris Rohr <rohr.chris@gmail.com>
Committed: Mon Jun 9 13:05:14 2014 -0400

----------------------------------------------------------------------
 .../org/apache/blur/console/util/Config.java    |  19 +-
 .../apache/blur/console/util/SearchUtil.java    | 238 +++++++++++--------
 2 files changed, 148 insertions(+), 109 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/15e8c679/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java b/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java
index 3b98267..784440b 100644
--- a/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java
+++ b/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java
@@ -26,13 +26,15 @@ import java.util.Map;
 
 import org.apache.blur.BlurConfiguration;
 import org.apache.blur.manager.clusterstatus.ZookeeperClusterStatus;
+import org.apache.blur.thrift.BlurClient;
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.apache.blur.user.User;
+import org.apache.blur.user.UserContext;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.codehaus.jackson.JsonFactory;
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.map.JsonMappingException;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jackson.type.TypeReference;
 
@@ -53,9 +55,6 @@ public class Config {
 	public static BlurConfiguration getBlurConfig() {
 		return blurConfig;
 	}
-	public static Map<String, String> getUserProperties() {
-		return globalUserProperties;
-	}
 	
 	public static void setupConfig() throws IOException {
 		if (cluster == null) {
@@ -147,4 +146,14 @@ public class Config {
 	    	cluster = null;
 	    }
 	}
+	
+	public static Iface getClient(String username) throws IOException {
+		Iface client = BlurClient.getClient(getConnectionString());
+		
+		if (globalUserProperties != null) {
+			UserContext.setUser(new User(username, globalUserProperties));
+		}
+		
+		return client;
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/15e8c679/contrib/blur-console/src/main/java/org/apache/blur/console/util/SearchUtil.java
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/java/org/apache/blur/console/util/SearchUtil.java
b/contrib/blur-console/src/main/java/org/apache/blur/console/util/SearchUtil.java
index ccf66d2..b0a07b7 100644
--- a/contrib/blur-console/src/main/java/org/apache/blur/console/util/SearchUtil.java
+++ b/contrib/blur-console/src/main/java/org/apache/blur/console/util/SearchUtil.java
@@ -11,7 +11,6 @@ import java.util.TreeMap;
 
 import org.apache.blur.console.model.ResultRow;
 import org.apache.blur.thirdparty.thrift_0_9_0.TException;
-import org.apache.blur.thrift.BlurClient;
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.blur.thrift.generated.BlurQuery;
@@ -26,7 +25,7 @@ import org.apache.blur.thrift.generated.Record;
 import org.apache.blur.thrift.generated.Row;
 import org.apache.blur.thrift.generated.ScoreType;
 import org.apache.blur.thrift.generated.Selector;
-import org.apache.blur.thrift.generated.User;
+import org.apache.blur.user.UserContext;
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.StringUtils;
 
@@ -72,7 +71,7 @@ public class SearchUtil {
 		}
 		
 		if (ArrayUtils.contains(families, "recordid")) {
-			return fetchRecord(table, query, families);
+			return fetchRecord(table, query, families, remoteHost);
 		}
 		
 		return searchAndFetch(table, query, rowQuery, start, fetch, families, remoteHost);
@@ -80,118 +79,155 @@ public class SearchUtil {
 	
 	@SuppressWarnings({ "unchecked", "rawtypes" })
 	private static Map<String, Object> searchAndFetch(String table, String query, String
rowQuery, String start, String fetch, String[] families, String remoteHost) throws IOException,
BlurException, TException {
-		Iface client = BlurClient.getClient(Config.getConnectionString());
-		setUser(client, remoteHost);
-		
-		boolean recordsOnly = RECORD_RECORD_OPTION.equalsIgnoreCase(rowQuery);
-		
-		BlurQuery blurQuery = new BlurQuery();
-		
-		Query q = new Query(query, ROW_ROW_OPTION.equalsIgnoreCase(rowQuery), ScoreType.SUPER,
null, null);
-		blurQuery.setQuery(q);
-		blurQuery.setStart(Long.parseLong(start));
-		blurQuery.setFetch(Integer.parseInt(fetch));
-		
-		Selector s = new Selector();
-		s.setRecordOnly(recordsOnly);
-		s.setColumnFamiliesToFetch(new HashSet<String>(Arrays.asList(families)));
-		blurQuery.setSelector(s);
-		
-		BlurResults blurResults = client.query(table, blurQuery);
-		
-		Map<String, Object> results = new HashMap<String, Object>();
-		results.put(TOTAL_KEY, blurResults.getTotalResults());
-		
-		Map<String, List> rows = new HashMap<String, List>();
-		for (BlurResult result : blurResults.getResults()) {
-			FetchResult fetchResult = result.getFetchResult();
-			
-			if (recordsOnly) {
-				// Record Result
-				FetchRecordResult recordResult = fetchResult.getRecordResult();
-				Record record = recordResult.getRecord();
-				
-				String family = record.getFamily();
+		try {
+			Iface client = Config.getClient(remoteHost);
+			
+			boolean recordsOnly = RECORD_RECORD_OPTION.equalsIgnoreCase(rowQuery);
+			
+			BlurQuery blurQuery = new BlurQuery();
+			
+			Query q = new Query(query, ROW_ROW_OPTION.equalsIgnoreCase(rowQuery), ScoreType.SUPER,
null, null);
+			blurQuery.setQuery(q);
+			blurQuery.setStart(Long.parseLong(start));
+			blurQuery.setFetch(Integer.parseInt(fetch));
+			
+			Selector s = new Selector();
+			s.setRecordOnly(recordsOnly);
+			s.setColumnFamiliesToFetch(new HashSet<String>(Arrays.asList(families)));
+			blurQuery.setSelector(s);
+			
+			BlurResults blurResults = client.query(table, blurQuery);
+			
+			Map<String, Object> results = new HashMap<String, Object>();
+			results.put(TOTAL_KEY, blurResults.getTotalResults());
+			
+			Map<String, List> rows = new HashMap<String, List>();
+			for (BlurResult result : blurResults.getResults()) {
+				FetchResult fetchResult = result.getFetchResult();
 				
-				List<Map<String, String>> fam = (List<Map<String, String>>) getFam(family,
rows, recordsOnly);
-				fam.add(buildRow(record.getColumns(), record.getRecordId()));
-			} else {
-				// Row Result
-				FetchRowResult rowResult = fetchResult.getRowResult();
-				Row row = rowResult.getRow();
-				if (row.getRecords() == null || row.getRecords().size() == 0) {
-					for(String family : families) {
-						List<ResultRow> fam = (List<ResultRow>) getFam(family, rows, recordsOnly);
-						getRow(row.getId(), fam);
-					}
+				if (recordsOnly) {
+					// Record Result
+					FetchRecordResult recordResult = fetchResult.getRecordResult();
+					Record record = recordResult.getRecord();
+					
+					String family = record.getFamily();
+					
+					List<Map<String, String>> fam = (List<Map<String, String>>)
getFam(family, rows, recordsOnly);
+					fam.add(buildRow(record.getColumns(), record.getRecordId()));
 				} else {
-					for (Record record : row.getRecords()) {
-						String family = record.getFamily();
-						
-						List<ResultRow> fam = (List<ResultRow>) getFam(family, rows, recordsOnly);
-						ResultRow rowData = getRow(row.getId(), fam);
-						rowData.getRecords().add(buildRow(record.getColumns(), record.getRecordId()));
+					// Row Result
+					FetchRowResult rowResult = fetchResult.getRowResult();
+					Row row = rowResult.getRow();
+					if (row.getRecords() == null || row.getRecords().size() == 0) {
+						for(String family : families) {
+							List<ResultRow> fam = (List<ResultRow>) getFam(family, rows, recordsOnly);
+							getRow(row.getId(), fam);
+						}
+					} else {
+						for (Record record : row.getRecords()) {
+							String family = record.getFamily();
+							
+							List<ResultRow> fam = (List<ResultRow>) getFam(family, rows, recordsOnly);
+							ResultRow rowData = getRow(row.getId(), fam);
+							rowData.getRecords().add(buildRow(record.getColumns(), record.getRecordId()));
+						}
 					}
 				}
 			}
+			
+			results.put(FAMILY_KEY, new HashSet<String>(Arrays.asList(families)));
+			results.put(DATA_KEY, rows);
+			
+			return results;
+		} finally {
+			UserContext.reset();
 		}
-		
-		results.put(FAMILY_KEY, new HashSet<String>(Arrays.asList(families)));
-		results.put(DATA_KEY, rows);
-		
-		return results;
 	}
 	
 	private static Map<String, Object> fullTextSearch(String table, String query, String
remoteHost) throws IOException, BlurException, TException {
-		Iface client = BlurClient.getClient(Config.getConnectionString());
-		setUser(client, remoteHost);
-		
-		BlurQuery blurQuery = new BlurQuery();
-		
-		Query q = new Query(query, true, ScoreType.SUPER, null, null);
-		blurQuery.setQuery(q);
-		BlurResults blurResults = client.query(table, blurQuery);
-		
-		Map<String, Object> results = new HashMap<String, Object>();
-		results.put(TOTAL_KEY, blurResults.getTotalResults());
-		return results;
+		try {
+			Iface client = Config.getClient(remoteHost);
+			
+			BlurQuery blurQuery = new BlurQuery();
+			
+			Query q = new Query(query, true, ScoreType.SUPER, null, null);
+			blurQuery.setQuery(q);
+			BlurResults blurResults = client.query(table, blurQuery);
+			
+			Map<String, Object> results = new HashMap<String, Object>();
+			results.put(TOTAL_KEY, blurResults.getTotalResults());
+			return results;
+		} finally {
+			UserContext.reset();
+		}
 	}
 	
 	@SuppressWarnings({ "unchecked", "rawtypes" })
 	private static Map<String, Object> fetchRow(String table, String query, String[] families,
String remoteHost) throws IOException, BlurException, TException {
-		Iface client = BlurClient.getClient(Config.getConnectionString());
-		setUser(client, remoteHost);
-		
-		Selector selector = new Selector();
-		String rowid = StringUtils.remove(query, "rowid:");
-		selector.setRowId(rowid);
-		selector.setColumnFamiliesToFetch(new HashSet<String>(Arrays.asList(families)));
-		
-		FetchResult fetchRow = client.fetchRow(table, selector);
-		
-		Map<String, Object> results = new HashMap<String, Object>();
-		results.put(TOTAL_KEY, fetchRow.getRowResult().getRow() == null ? 0 : 1);
-		
-		Map<String, List> rows = new HashMap<String, List>();
-		Row row = fetchRow.getRowResult().getRow();
-		if (row != null) {
-			for (Record record : row.getRecords()) {
-				String family = record.getFamily();
-				
-				List<ResultRow> fam = (List<ResultRow>) getFam(family, rows, false);
-				ResultRow rowData = getRow(row.getId(), fam);
-				rowData.getRecords().add(buildRow(record.getColumns(), record.getRecordId()));
+		try {
+			Iface client = Config.getClient(remoteHost);
+			
+			Selector selector = new Selector();
+			String rowid = StringUtils.remove(query, "rowid:");
+			selector.setRowId(rowid);
+			selector.setColumnFamiliesToFetch(new HashSet<String>(Arrays.asList(families)));
+			
+			FetchResult fetchRow = client.fetchRow(table, selector);
+			
+			Map<String, Object> results = new HashMap<String, Object>();
+			results.put(TOTAL_KEY, fetchRow.getRowResult().getRow() == null ? 0 : 1);
+			
+			Map<String, List> rows = new HashMap<String, List>();
+			Row row = fetchRow.getRowResult().getRow();
+			if (row != null) {
+				for (Record record : row.getRecords()) {
+					String family = record.getFamily();
+					
+					List<ResultRow> fam = (List<ResultRow>) getFam(family, rows, false);
+					ResultRow rowData = getRow(row.getId(), fam);
+					rowData.getRecords().add(buildRow(record.getColumns(), record.getRecordId()));
+				}
 			}
+			results.put(DATA_KEY, rows);
+			results.put(FAMILY_KEY, new HashSet<String>(Arrays.asList(families)));
+			
+			return results;
+		} finally {
+			UserContext.reset();
 		}
-		results.put(DATA_KEY, rows);
-		results.put(FAMILY_KEY, new HashSet<String>(Arrays.asList(families)));
-		
-		return null;
 	}
 	
-	private static Map<String, Object> fetchRecord(String table, String query, String[]
families) throws IOException {
-//		Iface client = BlurClient.getClient(Config.getConnectionString());
-		return null;
+	@SuppressWarnings({ "rawtypes", "unchecked" })
+	private static Map<String, Object> fetchRecord(String table, String query, String[]
families, String remoteHost) throws IOException, BlurException, TException {
+		try {
+			Iface client = Config.getClient(remoteHost);
+			
+			Selector selector = new Selector();
+			String recordId = StringUtils.remove(query, "recordid:");
+			selector.setRecordId(recordId);
+			selector.setRecordOnly(true);
+			selector.setColumnFamiliesToFetch(new HashSet<String>(Arrays.asList(families)));
+			
+			FetchResult fetchRow = client.fetchRow(table, selector);
+			
+			Map<String, Object> results = new HashMap<String, Object>();
+			results.put(TOTAL_KEY, fetchRow.getRecordResult().getRecord() == null ? 0 : 1);
+			
+			Map<String, List> rows = new HashMap<String, List>();
+			Record record = fetchRow.getRecordResult().getRecord();
+			if (record != null) {
+				String family = record.getFamily();
+					
+				List<Map<String, String>> fam = (List<Map<String, String>>) getFam(family,
rows, true);
+				fam.add(buildRow(record.getColumns(), record.getRecordId()));
+			}
+			results.put(DATA_KEY, rows);
+			results.put(FAMILY_KEY, new HashSet<String>(Arrays.asList(families)));
+			
+			return results;
+		} finally {
+			UserContext.reset();
+		}
 	}
 	
 	private static Map<String, String> buildRow(List<Column> columns, String recordid)
{
@@ -237,10 +273,4 @@ public class SearchUtil {
 		
 		return row;
 	}
-	
-	private static void setUser(Iface client, String username) throws TException {
-		if (Config.getUserProperties() != null) {
-			client.setUser(new User(username, Config.getUserProperties()));
-		}
-	}
 }


Mime
View raw message