use of org.apache.geode.cache.query.CqException in project geode by apache.
the class StopCQ method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException {
CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
ClientProxyMembershipID id = serverConnection.getProxyID();
CacheServerStats stats = serverConnection.getCacheServerStats();
// Based on MessageType.QUERY
// Added by Rao 2/1/2007
serverConnection.setAsTrue(REQUIRES_RESPONSE);
serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
start = DistributionStats.getStatTime();
// Retrieve the data from the message parts
String cqName = clientMessage.getPart(0).getString();
if (logger.isDebugEnabled()) {
logger.debug("{}: Received stop CQ request from {} cqName: {}", serverConnection.getName(), serverConnection.getSocketString(), cqName);
}
// Process the query request
if (cqName == null) {
String err = LocalizedStrings.StopCQ_THE_CQNAME_FOR_THE_CQ_STOP_REQUEST_IS_NULL.toLocalizedString();
sendCqResponse(MessageType.CQDATAERROR_MSG_TYPE, err, clientMessage.getTransactionId(), null, serverConnection);
return;
}
// Process CQ stop request
try {
// Append Client ID to CQ name
CqService cqService = crHelper.getCache().getCqService();
cqService.start();
// String cqNameWithClientId = new String(cqName + "__" +
// getMembershipID());
String serverCqName = cqName;
if (id != null) {
serverCqName = cqService.constructServerCqName(cqName, id);
}
InternalCqQuery cqQuery = cqService.getCq(serverCqName);
this.securityService.authorizeDataManage();
AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
if (authzRequest != null) {
String queryStr = null;
Set cqRegionNames = null;
if (cqQuery != null) {
queryStr = cqQuery.getQueryString();
cqRegionNames = new HashSet();
cqRegionNames.add(((CqQueryImpl) cqQuery).getRegionName());
}
authzRequest.stopCQAuthorize(cqName, queryStr, cqRegionNames);
}
cqService.stopCq(cqName, id);
if (cqQuery != null)
serverConnection.removeCq(cqName, cqQuery.isDurable());
} catch (CqException cqe) {
sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, "", clientMessage.getTransactionId(), cqe, serverConnection);
return;
} catch (Exception e) {
String err = LocalizedStrings.StopCQ_EXCEPTION_WHILE_STOPPING_CQ_NAMED_0.toLocalizedString(cqName);
sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, err, clientMessage.getTransactionId(), e, serverConnection);
return;
}
// Send OK to client
sendCqResponse(MessageType.REPLY, LocalizedStrings.StopCQ_CQ_STOPPED_SUCCESSFULLY.toLocalizedString(), clientMessage.getTransactionId(), null, serverConnection);
serverConnection.setAsTrue(RESPONDED);
{
long oldStart = start;
start = DistributionStats.getStatTime();
stats.incProcessStopCqTime(start - oldStart);
}
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class CqDataUsingPoolDUnitTest method createCq.
private CqQuery createCq(String regionName, String cqName) {
// Create CQ Attributes.
CqAttributesFactory cqAf = new CqAttributesFactory();
// Initialize and set CqListener.
CqListener[] cqListeners = { new CqListener() {
@Override
public void close() {
}
@Override
public void onEvent(CqEvent aCqEvent) {
}
@Override
public void onError(CqEvent aCqEvent) {
}
} };
cqAf.initCqListeners(cqListeners);
CqAttributes cqa = cqAf.create();
// Create cq's
// Get the query service for the Pool
QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
CqQuery query = null;
try {
query = queryService.newCq(cqName, "Select * from /" + regionName, cqa);
query.execute();
} catch (CqExistsException e) {
fail("Could not find specified region:" + regionName + ":", e);
} catch (CqException e) {
fail("Could not find specified region:" + regionName + ":", e);
} catch (RegionNotFoundException e) {
fail("Could not find specified region:" + regionName + ":", e);
}
return query;
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class CqStatsDUnitTest method validateCQStats.
public void validateCQStats(VM vm, final String cqName, final int creates, final int updates, final int deletes, final int totalEvents, final int cqListenerInvocations) {
vm.invoke(new CacheSerializableRunnable("Validate CQs") {
@Override
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("### Validating CQ Stats. ### " + cqName);
// Get CQ Service.
QueryService qService = null;
try {
qService = getCache().getQueryService();
} catch (Exception cqe) {
cqe.printStackTrace();
fail("Failed to get query service.");
}
CqService cqService = null;
try {
cqService = ((DefaultQueryService) qService).getCqService();
} catch (CqException e) {
// TODO Auto-generated catch block
e.printStackTrace();
fail("Failed to get CqService, CQ : " + cqName);
}
Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
if (cqs.size() == 0) {
fail("Failed to get CqQuery for CQ : " + cqName);
}
CqQueryImpl cQuery = (CqQueryImpl) cqs.iterator().next();
CqStatistics cqStats = cQuery.getStatistics();
CqQueryVsdStats cqVsdStats = cQuery.getVsdStats();
if (cqStats == null || cqVsdStats == null) {
fail("Failed to get CqQuery Stats for CQ : " + cqName);
}
getCache().getLogger().info("#### CQ stats for " + cQuery.getName() + ": " + " Events Total: " + cqStats.numEvents() + " Events Created: " + cqStats.numInserts() + " Events Updated: " + cqStats.numUpdates() + " Events Deleted: " + cqStats.numDeletes() + " CQ Listener invocations: " + cqVsdStats.getNumCqListenerInvocations() + " Initial results time (nano sec): " + cqVsdStats.getCqInitialResultsTime());
// Check for totalEvents count.
if (totalEvents != CqQueryDUnitTest.noTest) {
// Result size validation.
assertEquals("Total Event Count mismatch", totalEvents, cqStats.numEvents());
}
// Check for create count.
if (creates != CqQueryDUnitTest.noTest) {
assertEquals("Create Event mismatch", creates, cqStats.numInserts());
}
// Check for update count.
if (updates != CqQueryDUnitTest.noTest) {
assertEquals("Update Event mismatch", updates, cqStats.numUpdates());
}
// Check for delete count.
if (deletes != CqQueryDUnitTest.noTest) {
assertEquals("Delete Event mismatch", deletes, cqStats.numDeletes());
}
// Check for CQ listener invocations.
if (cqListenerInvocations != CqQueryDUnitTest.noTest) {
assertEquals("CQ Listener invocations mismatch", cqListenerInvocations, cqVsdStats.getNumCqListenerInvocations());
}
//// Check for initial results time.
// if (initialResultsTime != CqQueryDUnitTest.noTest && cqVsdStats.getCqInitialResultsTime()
//// <= 0) {
// assertIndexDetailsEquals("Initial results time mismatch", initialResultsTime,
//// cqVsdStats.getCqInitialResultsTime());
// }
}
});
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class CqStatsUsingPoolDUnitTest method validateCQServiceStats.
private void validateCQServiceStats(VM vm, final int created, final int activated, final int stopped, final int closed, final int cqsOnClient, final int cqsOnRegion, final int clientsWithCqs) {
vm.invoke(new CacheSerializableRunnable("Validate CQ Service Stats") {
@Override
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("### Validating CQ Service Stats. ### ");
// Get CQ Service.
QueryService qService = null;
try {
qService = getCache().getQueryService();
} catch (Exception cqe) {
cqe.printStackTrace();
fail("Failed to getCQService.");
}
CqServiceStatistics cqServiceStats = null;
cqServiceStats = qService.getCqStatistics();
CqServiceVsdStats cqServiceVsdStats = null;
try {
cqServiceVsdStats = ((CqServiceImpl) ((DefaultQueryService) qService).getCqService()).stats();
} catch (CqException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (cqServiceStats == null) {
fail("Failed to get CQ Service Stats");
}
getCache().getLogger().info("#### CQ Service stats: " + " CQs created: " + cqServiceStats.numCqsCreated() + " CQs active: " + cqServiceStats.numCqsActive() + " CQs stopped: " + cqServiceStats.numCqsStopped() + " CQs closed: " + cqServiceStats.numCqsClosed() + " CQs on Client: " + cqServiceStats.numCqsOnClient() + " CQs on region /root/regionA : " + cqServiceVsdStats.numCqsOnRegion(GemFireCacheImpl.getInstance(), "/root/regionA") + " Clients with CQs: " + cqServiceVsdStats.getNumClientsWithCqs());
// Check for created count.
if (created != CqQueryUsingPoolDUnitTest.noTest) {
assertEquals("Number of CQs created mismatch", created, cqServiceStats.numCqsCreated());
}
// Check for activated count.
if (activated != CqQueryUsingPoolDUnitTest.noTest) {
assertEquals("Number of CQs activated mismatch", activated, cqServiceStats.numCqsActive());
}
// Check for stopped count.
if (stopped != CqQueryUsingPoolDUnitTest.noTest) {
assertEquals("Number of CQs stopped mismatch", stopped, cqServiceStats.numCqsStopped());
}
// Check for closed count.
if (closed != CqQueryUsingPoolDUnitTest.noTest) {
assertEquals("Number of CQs closed mismatch", closed, cqServiceStats.numCqsClosed());
}
// Check for CQs on client count.
if (cqsOnClient != CqQueryUsingPoolDUnitTest.noTest) {
assertEquals("Number of CQs on client mismatch", cqsOnClient, cqServiceStats.numCqsOnClient());
}
// Check for CQs on region.
if (cqsOnRegion != CqQueryUsingPoolDUnitTest.noTest) {
assertEquals("Number of CQs on region /root/regionA mismatch", cqsOnRegion, cqServiceVsdStats.numCqsOnRegion(GemFireCacheImpl.getInstance(), "/root/regionA"));
}
// Check for clients with CQs count.
if (clientsWithCqs != CqQueryUsingPoolDUnitTest.noTest) {
assertEquals("Clints with CQs mismatch", clientsWithCqs, cqServiceVsdStats.getNumClientsWithCqs());
}
}
});
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class DurableClientSimpleDUnitTest method testRejectClientWhenDrainingCq.
/**
* Tests situation where a client is trying to reconnect while a cq is being drained. The client
* should be rejected until no cqs are currently being drained
*/
@Test
public void testRejectClientWhenDrainingCq() throws Exception {
try {
IgnoredException.addIgnoredException(LocalizedStrings.CacheClientNotifier_COULD_NOT_CONNECT_DUE_TO_CQ_BEING_DRAINED.toLocalizedString());
IgnoredException.addIgnoredException("Could not initialize a primary queue on startup. No queue servers available.");
String greaterThan5Query = "select * from /" + regionName + " p where p.ID > 5";
String allQuery = "select * from /" + regionName + " p where p.ID > -1";
String lessThan5Query = "select * from /" + regionName + " p where p.ID < 5";
// Start server 1
Integer[] ports = ((Integer[]) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServerReturnPorts(regionName, new Boolean(true))));
final int serverPort = ports[0].intValue();
final String durableClientId = getName() + "_client";
this.durableClientVM.invoke(() -> CacheServerTestUtil.disableShufflingOfEndpoints());
startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
// register durable cqs
createCq(durableClientVM, "GreaterThan5", greaterThan5Query, true);
createCq(durableClientVM, "All", allQuery, true);
createCq(durableClientVM, "LessThan5", lessThan5Query, true);
// send client ready
sendClientReady(durableClientVM);
verifyDurableClientOnServer(server1VM, durableClientId);
// Stop the durable client
this.disconnectDurableClient(true);
// Start normal publisher client
startClient(publisherClientVM, serverPort, regionName);
// Publish some entries
publishEntries(publisherClientVM, regionName, 10);
this.server1VM.invoke(new CacheSerializableRunnable("Set test hook") {
@Override
public void run2() throws CacheException {
// Set the Test Hook!
// This test hook will pause during the drain process
CacheClientProxy.testHook = new RejectClientReconnectTestHook();
}
});
this.server1VM.invokeAsync(new CacheSerializableRunnable("Close cq for durable client") {
@Override
public void run2() throws CacheException {
final CacheClientNotifier ccnInstance = CacheClientNotifier.getInstance();
final CacheClientProxy clientProxy = ccnInstance.getClientProxy(durableClientId);
ClientProxyMembershipID proxyId = clientProxy.getProxyID();
try {
ccnInstance.closeClientCq(durableClientId, "All");
} catch (CqException e) {
fail("failed", e);
}
}
});
// Restart the durable client
startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
this.server1VM.invoke(new CacheSerializableRunnable("verify was rejected at least once") {
@Override
public void run2() throws CacheException {
WaitCriterion ev = new WaitCriterion() {
@Override
public boolean done() {
return CacheClientProxy.testHook != null && (((RejectClientReconnectTestHook) CacheClientProxy.testHook).wasClientRejected());
}
@Override
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 10 * 1000, 200, true);
assertTrue(((RejectClientReconnectTestHook) CacheClientProxy.testHook).wasClientRejected());
}
});
checkPrimaryUpdater(durableClientVM);
// After rejection, the client will retry and eventually connect
// Verify durable client on server2
verifyDurableClientOnServer(server1VM, durableClientId);
createCq(durableClientVM, "GreaterThan5", "select * from /" + regionName + " p where p.ID > 5", true);
createCq(durableClientVM, "All", "select * from /" + regionName + " p where p.ID > -1", true);
createCq(durableClientVM, "LessThan5", "select * from /" + regionName + " p where p.ID < 5", true);
// send client ready
sendClientReady(durableClientVM);
checkCqListenerEvents(durableClientVM, "GreaterThan5", 4, /* numEventsExpected */
4, /* numEventsToWaitFor */
15);
checkCqListenerEvents(durableClientVM, "LessThan5", 5, /* numEventsExpected */
5, /* numEventsToWaitFor */
15);
checkCqListenerEvents(durableClientVM, "All", 0, /* numEventsExpected */
1, /* numEventsToWaitFor */
5);
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the publisher client
this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the server
this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
} finally {
this.server1VM.invoke(new CacheSerializableRunnable("unset test hook") {
@Override
public void run2() throws CacheException {
CacheClientProxy.testHook = null;
}
});
}
}
Aggregations