List of usage examples for org.apache.solr.client.solrj.impl CloudSolrClient commit
public UpdateResponse commit(String collection, boolean waitFlush, boolean waitSearcher) throws SolrServerException, IOException
From source file:org.apache.sentry.tests.e2e.solr.DocLevelGenerator.java
License:Apache License
/** * Generates docs according to the following parameters: * * @param client Solr client to use/*w w w . j av a2s . c o m*/ * @param numDocs number of documents to generate * @param evenDocsToken every even number doc gets this token added to the authField * @param oddDocsToken every odd number doc gets this token added to the authField * @param extraAuthFieldsCount generates this number of bogus entries in the authField */ public void generateDocs(CloudSolrClient client, int numDocs, String evenDocsToken, String oddDocsToken, int extraAuthFieldsCount) throws Exception { // create documents ArrayList<SolrInputDocument> docs = new ArrayList<SolrInputDocument>(); for (int i = 0; i < numDocs; ++i) { SolrInputDocument doc = new SolrInputDocument(); String iStr = Long.toString(i); doc.addField("id", iStr); doc.addField("description", "description" + iStr); // put some bogus tokens in for (int k = 0; k < extraAuthFieldsCount; ++k) { doc.addField(authField, authField + Long.toString(k)); } // even docs get evenDocsToken, odd docs get oddDocsToken if (i % 2 == 0) { doc.addField(authField, evenDocsToken); } else { doc.addField(authField, oddDocsToken); } // add a token to all docs so we can check that we can get all // documents returned doc.addField(authField, "doclevel_role"); docs.add(doc); } client.add(collection, docs); client.commit(collection, true, true); }
From source file:org.apache.sentry.tests.e2e.solr.DocLevelGenerator.java
License:Apache License
public void generateDocsForSubsetQueries(CloudSolrClient client, int numDocs, int numTokens, String tokenPrefix) throws Exception { Assert.assertTrue("Num Tokens should be divisible by numTokens", numDocs % numTokens == 0); // create documents ArrayList<SolrInputDocument> docs = new ArrayList<SolrInputDocument>(); for (int i = 0; i < numDocs; ++i) { int tokenCount = 0; SolrInputDocument doc = new SolrInputDocument(); String iStr = Long.toString(i); doc.addField("id", iStr); doc.addField("description", "description" + iStr); for (int j = 0; j < numTokens; j++) { if ((i & 1 << j) == 1 << j) { doc.addField(authField, tokenPrefix + j); tokenCount++;/*from www . j a v a 2 s . c o m*/ } } doc.addField("sentry_auth_count", tokenCount); System.out.println(doc); docs.add(doc); } client.add(collection, docs); client.commit(collection, true, true); }
From source file:org.apache.sentry.tests.e2e.solr.TestAbacOperations.java
License:Apache License
@Test public void simpleTest() throws Exception { String collectionName = "simpleCollection"; createCollection(ADMIN_USER, collectionName, "cloud-minimal_abac", NUM_SERVERS, 1); CloudSolrClient client = cluster.getSolrClient(); /*abacuser1 has the following: orGroupsAttr: group1/*www. jav a2s.c om*/ orGroupsAttr: group2 andGroupsAttr: group11 andGroupsAttr: group12 lteAttr: THREE gteAttr: THIRTY */ // Add a set of docs that we know will match ArrayList<SolrInputDocument> docs = new ArrayList<SolrInputDocument>(); for (int i = 0; i < numDocs; ++i) { SolrInputDocument doc = new SolrInputDocument(); String iStr = Long.toString(i); doc.addField("id", iStr); doc.addField("description", "description" + iStr); doc.addField(lteFieldName, "THREE"); doc.addField(gteFieldName, "THIRTY"); doc.addField(orGroupsFieldName, "group1"); doc.addField(andGroupsFieldName, "group11"); doc.addField(andGroupsCountFieldName, 1); docs.add(doc); } //Add one further doc that won't match SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", numDocs); doc.addField("description", "description" + numDocs); doc.addField(lteFieldName, "ONE"); doc.addField(gteFieldName, "FIFTY"); doc.addField(orGroupsFieldName, "group9"); doc.addField(andGroupsFieldName, "group99"); doc.addField(andGroupsCountFieldName, 1); docs.add(doc); client.add(collectionName, docs); client.commit(collectionName, true, true); QueryRequest request = new QueryRequest(new SolrQuery("*:*")); setAuthenticationUser("abacuser1"); QueryResponse rsp = request.process(client, collectionName); SolrDocumentList docList = rsp.getResults(); assertEquals(numDocs, docList.getNumFound()); }
From source file:org.apache.sentry.tests.e2e.solr.TestAbacOperations.java
License:Apache License
@Test public void lteFilterTest() throws Exception { /*//w w w . java 2s .c om We're going to test with three users, each with different values for lteAttr, ONE, THREE and FIVE All other attributes for those users will be fixed. */ String collectionName = "lteCollection"; createCollection(ADMIN_USER, collectionName, "cloud-minimal_abac", NUM_SERVERS, 1); CloudSolrClient client = cluster.getSolrClient(); String[] lteValues = { "ONE", "TWO", "THREE", "FOUR", "FIVE" }; ArrayList<SolrInputDocument> docs = new ArrayList<SolrInputDocument>(); for (int i = 0; i < numDocs * lteValues.length; ++i) { SolrInputDocument doc = new SolrInputDocument(); String iStr = Long.toString(i); doc.addField("id", iStr); doc.addField("description", "lte Test Doc: " + iStr); doc.addField(lteFieldName, lteValues[i % lteValues.length]); doc.addField(gteFieldName, "THIRTY"); doc.addField(orGroupsFieldName, "group1"); doc.addField(andGroupsFieldName, "group11"); doc.addField(andGroupsCountFieldName, 1); docs.add(doc); } client.add(collectionName, docs); client.commit(collectionName, true, true); QueryRequest request = new QueryRequest(new SolrQuery("*:*")); /* lteuser1 has lteAttr of ONE -> Should see numDocs docs lteuser2 has lteAttr of THREE -> Should see numDocs * 3 lteuser3 has lteAttr of FIVE -> Should see numDocs * 5 docs */ setAuthenticationUser("lteuser1"); QueryResponse rsp = request.process(client, collectionName); SolrDocumentList docList = rsp.getResults(); assertEquals(numDocs, docList.getNumFound()); setAuthenticationUser("lteuser2"); rsp = request.process(client, collectionName); docList = rsp.getResults(); assertEquals(numDocs * 3, docList.getNumFound()); setAuthenticationUser("lteuser3"); rsp = request.process(client, collectionName); docList = rsp.getResults(); assertEquals(numDocs * 5, docList.getNumFound()); }
From source file:org.apache.sentry.tests.e2e.solr.TestAbacOperations.java
License:Apache License
@Test public void gteFilterTest() throws Exception { /*/*from ww w .ja v a2s . c o m*/ We're going to test with three users, each with different values for gteAttr, TEN, THIRTY and FIFTY All other attributes for those users will be fixed. */ String collectionName = "gteCollection"; createCollection(ADMIN_USER, collectionName, "cloud-minimal_abac", NUM_SERVERS, 1); CloudSolrClient client = cluster.getSolrClient(); String[] gteValues = { "TEN", "TWENTY", "THIRTY", "FORTY", "FIFTY" }; ArrayList<SolrInputDocument> docs = new ArrayList<SolrInputDocument>(); for (int i = 0; i < numDocs * gteValues.length; ++i) { SolrInputDocument doc = new SolrInputDocument(); String iStr = Long.toString(i); doc.addField("id", iStr); doc.addField("description", "gte Test Doc: " + iStr); doc.addField(gteFieldName, gteValues[i % gteValues.length]); doc.addField(lteFieldName, "THREE"); doc.addField(orGroupsFieldName, "group1"); doc.addField(andGroupsFieldName, "group11"); doc.addField(andGroupsCountFieldName, 1); docs.add(doc); } client.add(collectionName, docs); client.commit(collectionName, true, true); QueryRequest request = new QueryRequest(new SolrQuery("*:*")); /* gteuser1 has gteAttr of TEN -> Should see numDocs * 5 docs gteuser2 has gteAttr of THIRTY -> Should see numDocs * 3 gteuser3 has gteAttr of FIFTY -> Should see numDocs docs */ setAuthenticationUser("gteuser1"); QueryResponse rsp = request.process(client, collectionName); SolrDocumentList docList = rsp.getResults(); assertEquals(numDocs * 5, docList.getNumFound()); setAuthenticationUser("gteuser2"); rsp = request.process(client, collectionName); docList = rsp.getResults(); assertEquals(numDocs * 3, docList.getNumFound()); setAuthenticationUser("gteuser3"); rsp = request.process(client, collectionName); docList = rsp.getResults(); assertEquals(numDocs, docList.getNumFound()); }
From source file:org.apache.sentry.tests.e2e.solr.TestAbacOperations.java
License:Apache License
@Test public void orGroupsFilterTest() throws Exception { /*//from w w w .j a v a 2 s . c om We're going to test with three users, each with different values for orGroups All other attributes for those users will be fixed. */ String collectionName = "orGroupsCollection"; createCollection(ADMIN_USER, collectionName, "cloud-minimal_abac", NUM_SERVERS, 1); CloudSolrClient client = cluster.getSolrClient(); int[] groupDocCount = new int[3]; ArrayList<SolrInputDocument> docs = new ArrayList<SolrInputDocument>(); for (int i = 0; i < numDocs * 4; ++i) { SolrInputDocument doc = new SolrInputDocument(); String iStr = Long.toString(i); doc.addField("id", iStr); doc.addField("description", "Or Groups Test Doc: " + iStr); doc.addField(gteFieldName, "THIRTY"); doc.addField(lteFieldName, "THREE"); if (i % 2 == 0) { groupDocCount[0]++; doc.addField(orGroupsFieldName, "group1"); } if (i % 3 == 0) { doc.addField(orGroupsFieldName, "group2"); } if (i % 4 == 0) { doc.addField(orGroupsFieldName, "group3"); } if (i % 2 == 0 || i % 3 == 0) { groupDocCount[1]++; } if (i % 2 == 0 || i % 3 == 0 || i % 4 == 0) { groupDocCount[2]++; } doc.addField(andGroupsFieldName, "group11"); doc.addField(andGroupsCountFieldName, 1); docs.add(doc); } client.add(collectionName, docs); client.commit(collectionName, true, true); QueryRequest request = new QueryRequest(new SolrQuery("*:*")); /* oruser1 has group1 oruser2 has group1, group2 oruser3 has group1, group2, group3 */ setAuthenticationUser("oruser1"); QueryResponse rsp = request.process(client, collectionName); SolrDocumentList docList = rsp.getResults(); assertEquals(groupDocCount[0], docList.getNumFound()); setAuthenticationUser("oruser2"); rsp = request.process(client, collectionName); docList = rsp.getResults(); assertEquals(groupDocCount[1], docList.getNumFound()); setAuthenticationUser("oruser3"); rsp = request.process(client, collectionName); docList = rsp.getResults(); assertEquals(groupDocCount[2], docList.getNumFound()); }
From source file:org.apache.sentry.tests.e2e.solr.TestAbacOperations.java
License:Apache License
@Test public void andGroupsFilterTest() throws Exception { /*/*from w w w .j a va 2 s .c om*/ We're going to test with three users, each with different values for andGroups All other attributes for those users will be fixed. */ String collectionName = "andGroupsCollection"; createCollection(ADMIN_USER, collectionName, "cloud-minimal_abac", NUM_SERVERS, 1); CloudSolrClient client = cluster.getSolrClient(); int[] groupDocCount = new int[3]; ArrayList<SolrInputDocument> docs = new ArrayList<SolrInputDocument>(); for (int i = 0; i < numDocs * 4; ++i) { int andGroups = 0; SolrInputDocument doc = new SolrInputDocument(); String iStr = Long.toString(i); doc.addField("id", iStr); doc.addField("description", "Or Groups Test Doc: " + iStr); doc.addField(gteFieldName, "THIRTY"); doc.addField(lteFieldName, "THREE"); if (i % 2 == 0) { doc.addField(andGroupsFieldName, "group11"); andGroups++; } if (i % 3 == 0) { doc.addField(andGroupsFieldName, "group12"); andGroups++; } if (i % 4 == 0) { doc.addField(andGroupsFieldName, "group13"); andGroups++; } if (i % 2 == 0 && (i % 3 != 0 && i % 4 != 0)) { groupDocCount[0]++; } if ((i % 2 == 0 || i % 3 == 0) && i % 4 != 0) { groupDocCount[1]++; } if (i % 2 == 0 || i % 3 == 0 || i % 4 == 0) { groupDocCount[2]++; } doc.addField(andGroupsCountFieldName, andGroups); doc.addField(orGroupsFieldName, "group1"); docs.add(doc); } client.add(collectionName, docs); client.commit(collectionName, true, true); QueryRequest request = new QueryRequest(new SolrQuery("*:*")); /* anduser1 has group11 anduser2 has group11, group12 anduser3 has group11, group12, group13 */ setAuthenticationUser("anduser1"); QueryResponse rsp = request.process(client, collectionName); SolrDocumentList docList = rsp.getResults(); assertEquals(groupDocCount[0], docList.getNumFound()); setAuthenticationUser("anduser2"); rsp = request.process(client, collectionName); docList = rsp.getResults(); assertEquals(groupDocCount[1], docList.getNumFound()); setAuthenticationUser("anduser3"); rsp = request.process(client, collectionName); docList = rsp.getResults(); assertEquals(groupDocCount[2], docList.getNumFound()); }
From source file:org.apache.sentry.tests.e2e.solr.TestAbacOperations.java
License:Apache License
@Test public void nestedOrGroupsFilterTest() throws Exception { /*/*w ww. j ava 2 s . co m*/ We're going to test with three users, each with different values for orGroups All other attributes for those users will be fixed. */ String collectionName = "nestedOrGroupsCollection"; createCollection(ADMIN_USER, collectionName, "cloud-minimal_abac", NUM_SERVERS, 1); CloudSolrClient client = cluster.getSolrClient(); int[] groupDocCount = new int[3]; ArrayList<SolrInputDocument> docs = new ArrayList<SolrInputDocument>(); for (int i = 0; i < numDocs * 4; ++i) { SolrInputDocument doc = new SolrInputDocument(); String iStr = Long.toString(i); doc.addField("id", iStr); doc.addField("description", "Nested Or Groups Test Doc: " + iStr); doc.addField(gteFieldName, "THIRTY"); doc.addField(lteFieldName, "THREE"); if (i % 2 == 0) { doc.addField(orGroupsFieldName, "nestedgroup1"); doc.addField(orGroupsFieldName, "nestedgroup4"); } if (i % 3 == 0) { doc.addField(orGroupsFieldName, "nestedgroup2"); doc.addField(orGroupsFieldName, "nestedgroup5"); } if (i % 4 == 0) { doc.addField(orGroupsFieldName, "nestedgroup3"); doc.addField(orGroupsFieldName, "nestedgroup6"); } if (i % 2 == 0 || i % 3 == 0 || i % 4 == 0) { groupDocCount[0]++; } doc.addField(andGroupsFieldName, "group11"); doc.addField(andGroupsCountFieldName, 1); docs.add(doc); } client.add(collectionName, docs); client.commit(collectionName, true, true); QueryRequest request = new QueryRequest(new SolrQuery("*:*")); /* nesteduser1 has nestedgroup1, nestedgroup2 and nestedgroup3 nesteduser2 has nestedgroup4, nestedgroup5 and nestedgroup6 oruser1 does not have any of the nested groups so should return zero */ setAuthenticationUser("oruser1"); QueryResponse rsp = request.process(client, collectionName); SolrDocumentList docList = rsp.getResults(); assertEquals(0, docList.getNumFound()); setAuthenticationUser("nesteduser1"); rsp = request.process(client, collectionName); docList = rsp.getResults(); assertEquals(groupDocCount[0], docList.getNumFound()); setAuthenticationUser("nesteduser2"); rsp = request.process(client, collectionName); docList = rsp.getResults(); assertEquals(groupDocCount[0], docList.getNumFound()); }
From source file:org.apache.sentry.tests.e2e.solr.TestSubsetQueryOperations.java
License:Apache License
private void testAllRolesAndMissingValues(boolean allowMissingValues) throws Exception { String collectionName;//from w ww . j a v a 2s . c o m if (allowMissingValues) { collectionName = "allRolesCollection1"; createCollection(ADMIN_USER, collectionName, "cloud-minimal_subset_match", NUM_SERVERS, 1); } else { collectionName = "allRolesCollection2"; createCollection(ADMIN_USER, collectionName, "cloud-minimal_subset_match_missing_false", NUM_SERVERS, 1); } String allRolesToken = "OR"; /* Going to create: 4 with no auth tokens 5 with the junit role, 3 of which have all roles token 13 with the junit2 role, 7 of which have all roles token 17 with junit2 AND junit1, 2 of which have no roles 19 with just all roles token Expected results: junit user can see 19 + 5 + 4 = 28 docs when allow_missing_val is true, and 24 when not admin user can see 19 + 4 = 23 roles when allow_missing_val is true, and 19 when not */ String junitRole = "junit_role"; String junit2Role = "junit_role2"; int junit = 5; int junitAllRoles = 3; int junit2 = 13; int junit2AllRoles = 7; int allRolesOnly = 19; int noRoles = 4; int junit1Andjunit2 = 17; int junit1Andjunit2AllRoles = 2; int counter = 0; ArrayList<SolrInputDocument> docs = new ArrayList<SolrInputDocument>(); for (int i = 0; i < junit; i++) { Set<String> roles = Sets.newHashSet(junitRole); if (i < junitAllRoles) { roles.add(allRolesToken); } docs.add(createAllDocsTestDocument(counter++, roles)); } for (int i = 0; i < junit2; i++) { Set<String> roles = Sets.newHashSet(junit2Role); if (i < junit2AllRoles) { roles.add(allRolesToken); } docs.add(createAllDocsTestDocument(counter++, roles)); } for (int i = 0; i < allRolesOnly; i++) { Set<String> roles = Sets.newHashSet(allRolesToken); docs.add(createAllDocsTestDocument(counter++, roles)); } for (int i = 0; i < noRoles; i++) { Set<String> roles = Sets.newHashSet(); docs.add(createAllDocsTestDocument(counter++, roles)); } for (int i = 0; i < junit1Andjunit2; i++) { Set<String> roles = Sets.newHashSet(junitRole, junit2Role); if (i < junit1Andjunit2AllRoles) { roles.add(allRolesToken); } docs.add(createAllDocsTestDocument(counter++, roles)); } CloudSolrClient client = cluster.getSolrClient(); client.add(collectionName, docs); client.commit(collectionName, true, true); testAllRolesTokenQueries(collectionName, allowMissingValues, junit, allRolesOnly, noRoles, client); //TODO SecureRealTimeGetRequest //checkAllRolesToken(getRealTimeGetRequest(), server, // totalAllRolesAdded, totalOnlyAllRolesAdded, allRolesFactor, totalJunitAdded, junitFactor); }