use of org.apache.geode.cache.query.QueryInvocationTargetException in project geode by apache.
the class PartitionedIndex method getBucketIndex.
/**
* Returns the index for the bucket.
*/
public static AbstractIndex getBucketIndex(PartitionedRegion pr, String indexName, Integer bId) throws QueryInvocationTargetException {
try {
pr.checkReadiness();
} catch (Exception ex) {
throw new QueryInvocationTargetException(ex.getMessage());
}
PartitionedRegionDataStore prds = pr.getDataStore();
BucketRegion bukRegion;
bukRegion = (BucketRegion) prds.getLocalBucketById(bId);
if (bukRegion == null) {
throw new BucketMovedException("Bucket not found for the id :" + bId);
}
AbstractIndex index = null;
if (bukRegion.getIndexManager() != null) {
index = (AbstractIndex) (bukRegion.getIndexManager().getIndex(indexName));
} else {
if (pr.getCache().getLogger().fineEnabled()) {
pr.getCache().getLogger().fine("Index Manager not found for the bucket region " + bukRegion.getFullPath() + " unable to fetch the index " + indexName);
}
throw new QueryInvocationTargetException("Index Manager not found, " + " unable to fetch the index " + indexName);
}
return index;
}
use of org.apache.geode.cache.query.QueryInvocationTargetException in project geode by apache.
the class PRQueryProcessor method executeQueryOnBuckets.
private void executeQueryOnBuckets(Collection<Collection> resultCollector, ExecutionContext context) throws ForceReattemptException, QueryInvocationTargetException, QueryException {
// Check if QueryMonitor is enabled, if so add query to be monitored.
QueryMonitor queryMonitor = null;
context.setCqQueryContext(query.isCqQuery());
if (GemFireCacheImpl.getInstance() != null) {
queryMonitor = GemFireCacheImpl.getInstance().getQueryMonitor();
}
try {
if (queryMonitor != null) {
// Add current thread to be monitored by QueryMonitor.
queryMonitor.monitorQueryThread(Thread.currentThread(), query);
}
Object results = query.executeUsingContext(context);
synchronized (resultCollector) {
// TODO: In what situation would the results object itself be undefined?
// The elements of the results can be undefined , but not the resultset itself
this.resultType = ((SelectResults) results).getCollectionType().getElementType();
resultCollector.add((Collection) results);
}
isIndexUsedForLocalQuery = ((QueryExecutionContext) context).isIndexUsed();
} catch (BucketMovedException bme) {
if (logger.isDebugEnabled()) {
logger.debug("Query targeted local bucket not found. {}", bme.getMessage(), bme);
}
throw new ForceReattemptException("Query targeted local bucket not found." + bme.getMessage(), bme);
} catch (RegionDestroyedException rde) {
throw new QueryInvocationTargetException("The Region on which query is executed may have been destroyed." + rde.getMessage(), rde);
} catch (QueryException qe) {
// Check if PR is locally destroyed.
if (pr.isLocallyDestroyed || pr.isClosed) {
throw new ForceReattemptException("Local Partition Region or the targeted bucket has been moved");
}
throw qe;
} finally {
if (queryMonitor != null) {
queryMonitor.stopMonitoringQueryThread(Thread.currentThread(), query);
}
}
}
use of org.apache.geode.cache.query.QueryInvocationTargetException in project geode by apache.
the class QueryUsingFunctionContextDUnitTest method testQueriesWithFilterKeysOnPRWithRebalancing.
// GEODE-575: ignores lots of exceptions, non-thread-safe test hooks
@Category(FlakyTest.class)
@Test
public void testQueriesWithFilterKeysOnPRWithRebalancing() {
IgnoredException.addIgnoredException("QueryInvocationTargetException");
IgnoredException.addIgnoredException("java.net.SocketException");
IgnoredException.addIgnoredException("ServerConnectivityException");
IgnoredException.addIgnoredException("FunctionException");
IgnoredException.addIgnoredException("IOException");
// Close cache on server1
server1.invoke(new CacheSerializableRunnable("Set QueryObserver in cache on server1") {
@Override
public void run2() throws CacheException {
class MyQueryObserver extends IndexTrackingQueryObserver {
@Override
public void startQuery(Query query) {
Region pr = CacheFactory.getAnyInstance().getRegion(PartitionedRegionName1);
Region KeyRegion = null;
for (int i = 6; i < 9; i++) {
KeyRegion = ((PartitionedRegion) pr).getBucketRegion(i);
if (KeyRegion != null)
KeyRegion.destroyRegion();
}
}
}
;
QueryObserverHolder.setInstance(new MyQueryObserver());
}
});
client.invoke(new CacheSerializableRunnable("Run function on PR") {
@Override
public void run2() throws CacheException {
Set filter = new HashSet();
ResultCollector rcollector = null;
filter.addAll(getFilter(6, 9));
for (int i = 0; i < queries.length; i++) {
try {
function = new TestQueryFunction("queryFunction");
rcollector = FunctionService.onRegion(CacheFactory.getAnyInstance().getRegion(PartitionedRegionName1)).setArguments(queries[i]).withFilter(filter).execute(function);
// Should not come here, an exception is expected from above function call.
fail("Function call did not fail for query with function context");
} catch (FunctionException ex) {
if (!((ex.getCause() instanceof QueryInvocationTargetException) || (ex.getCause() instanceof ServerConnectivityException))) {
if (ex.getCause() instanceof FunctionException) {
FunctionException fe = (FunctionException) ex.getCause();
if (!fe.getMessage().startsWith("IOException")) {
fail("Should have received an QueryInvocationTargetException but recieved" + ex.getMessage());
}
} else {
fail("Should have received an QueryInvocationTargetException but recieved" + ex.getMessage());
}
}
}
}
// For loop ends here.
}
});
// Close cache on server1
server1.invoke(new CacheSerializableRunnable("Reset Query Observer on server1") {
@Override
public void run2() throws CacheException {
QueryObserverHolder.reset();
}
});
}
use of org.apache.geode.cache.query.QueryInvocationTargetException in project geode by apache.
the class GroupByQueryDUnitTest method runQuery.
private void runQuery(VM queryVM) throws Exception {
// createIndex(vm0, "compactRangeIndex", "entry.value",
// "/region.entrySet entry");
// Do Puts
queryVM.invoke(new SerializableRunnable("putting data") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("portfolio");
for (int i = 1; i < 200; ++i) {
Portfolio pf = new Portfolio(i);
pf.shortID = (short) ((short) i / 5);
region.put("" + i, pf);
}
}
});
queryVM.invoke(new SerializableRunnable("query") {
public void run() {
try {
QueryService qs = getCache().getQueryService();
String queryStr = "select p.shortID as short_id from /portfolio p where p.ID >= 0 group by short_id ";
Query query = qs.newQuery(queryStr);
SelectResults<Struct> results = (SelectResults<Struct>) query.execute();
Iterator<Struct> iter = results.iterator();
int counter = 0;
while (iter.hasNext()) {
Struct str = iter.next();
assertEquals(counter++, ((Short) str.get("short_id")).intValue());
}
assertEquals(39, counter - 1);
} catch (QueryInvocationTargetException e) {
fail(e.toString());
} catch (NameResolutionException e) {
fail(e.toString());
} catch (TypeMismatchException e) {
fail(e.toString());
} catch (FunctionDomainException e) {
fail(e.toString());
}
}
});
}
use of org.apache.geode.cache.query.QueryInvocationTargetException in project geode by apache.
the class GetDeliveredOrders method execute.
public void execute(FunctionContext context) {
Cache c = null;
ArrayList<Object> vals = new ArrayList<Object>();
try {
c = CacheFactory.getAnyInstance();
} catch (CacheClosedException ex) {
vals.add("NoCacheFoundResult");
context.getResultSender().lastResult(vals);
}
String oql = "SELECT o.purchaseOrderNo, o.deliveryDate FROM /orders o WHERE o.deliveryDate != NULL";
final Query query = c.getQueryService().newQuery(oql);
SelectResults result = null;
try {
result = (SelectResults) query.execute();
int resultSize = result.size();
if (result instanceof Collection<?>)
for (Object item : result) {
vals.add(item);
}
} catch (FunctionDomainException e) {
if (c != null)
c.getLogger().info("Caught FunctionDomainException while executing function GetDeliveredOrders: " + e.getMessage());
} catch (TypeMismatchException e) {
if (c != null)
c.getLogger().info("Caught TypeMismatchException while executing function GetDeliveredOrders: " + e.getMessage());
} catch (NameResolutionException e) {
if (c != null)
c.getLogger().info("Caught NameResolutionException while executing function GetDeliveredOrders: " + e.getMessage());
} catch (QueryInvocationTargetException e) {
if (c != null)
c.getLogger().info("Caught QueryInvocationTargetException while executing function GetDeliveredOrders: " + e.getMessage());
}
context.getResultSender().lastResult(vals);
}
Aggregations