Search in sources :

Example 1 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService in project geode by apache.

the class ClientCQPostAuthorizationDUnitTest method allowCQsToRegister.

private void allowCQsToRegister(final int number) {
    final int num = number;
    WaitCriterion wc = new WaitCriterion() {

        @Override
        public boolean done() {
            CqService cqService = GemFireCacheImpl.getInstance().getCqService();
            cqService.start();
            Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
            if (cqs != null) {
                return cqs.size() >= num;
            } else {
                return false;
            }
        }

        @Override
        public String description() {
            return num + "Waited for " + num + " CQs to be registered on this server.";
        }
    };
    waitForCriterion(wc, 60 * 1000, 100, false);
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CqService(org.apache.geode.cache.query.internal.cq.CqService)

Example 2 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService in project geode by apache.

the class CloseCQ 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 close CQ request from {} cqName: {}", serverConnection.getName(), serverConnection.getSocketString(), cqName);
    }
    // Process the query request
    if (cqName == null) {
        String err = LocalizedStrings.CloseCQ_THE_CQNAME_FOR_THE_CQ_CLOSE_REQUEST_IS_NULL.toLocalizedString();
        sendCqResponse(MessageType.CQDATAERROR_MSG_TYPE, err, clientMessage.getTransactionId(), null, serverConnection);
        return;
    }
    this.securityService.authorizeDataManage();
    // Process CQ close request
    try {
        // Append Client ID to CQ name
        CqService cqService = crHelper.getCache().getCqService();
        cqService.start();
        String serverCqName = cqName;
        if (id != null) {
            serverCqName = cqService.constructServerCqName(cqName, id);
        }
        InternalCqQuery cqQuery = cqService.getCq(serverCqName);
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            String queryStr = null;
            Set cqRegionNames = null;
            if (cqQuery != null) {
                queryStr = cqQuery.getQueryString();
                cqRegionNames = new HashSet();
                cqRegionNames.add(((InternalCqQuery) cqQuery).getRegionName());
                authzRequest.closeCQAuthorize(cqName, queryStr, cqRegionNames);
            }
        }
        // String cqNameWithClientId = new String(cqName + "__" +
        // getMembershipID());
        cqService.closeCq(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.CloseCQ_EXCEPTION_WHILE_CLOSING_CQ_CQNAME_0.toLocalizedString(cqName);
        sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, err, clientMessage.getTransactionId(), e, serverConnection);
        return;
    }
    // Send OK to client
    sendCqResponse(MessageType.REPLY, LocalizedStrings.CloseCQ_CQ_CLOSED_SUCCESSFULLY.toLocalizedString(), clientMessage.getTransactionId(), null, serverConnection);
    serverConnection.setAsTrue(RESPONDED);
    {
        long oldStart = start;
        start = DistributionStats.getStatTime();
        stats.incProcessCloseCqTime(start - oldStart);
    }
}
Also used : CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) Set(java.util.Set) HashSet(java.util.HashSet) CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) CqException(org.apache.geode.cache.query.CqException) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) CqService(org.apache.geode.cache.query.internal.cq.CqService) IOException(java.io.IOException) CqException(org.apache.geode.cache.query.CqException) HashSet(java.util.HashSet)

Example 3 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService in project geode by apache.

the class ExecuteCQ method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
    AcceptorImpl acceptor = serverConnection.getAcceptor();
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    ClientProxyMembershipID id = serverConnection.getProxyID();
    CacheServerStats stats = serverConnection.getCacheServerStats();
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
    // Retrieve the data from the message parts
    String cqName = clientMessage.getPart(0).getString();
    String cqQueryString = clientMessage.getPart(1).getString();
    int cqState = clientMessage.getPart(2).getInt();
    Part isDurablePart = clientMessage.getPart(3);
    byte[] isDurableByte = isDurablePart.getSerializedForm();
    boolean isDurable = (isDurableByte == null || isDurableByte[0] == 0) ? false : true;
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received {} request from {} CqName: {} queryString: {}", serverConnection.getName(), MessageType.getString(clientMessage.getMessageType()), serverConnection.getSocketString(), cqName, cqQueryString);
    }
    DefaultQueryService qService = null;
    CqService cqServiceForExec = null;
    Query query = null;
    Set cqRegionNames = null;
    ExecuteCQOperationContext executeCQContext = null;
    ServerCQ cqQuery = null;
    try {
        qService = (DefaultQueryService) crHelper.getCache().getLocalQueryService();
        // Authorization check
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            query = qService.newQuery(cqQueryString);
            cqRegionNames = ((DefaultQuery) query).getRegionsInQuery(null);
            executeCQContext = authzRequest.executeCQAuthorize(cqName, cqQueryString, cqRegionNames);
            String newCqQueryString = executeCQContext.getQuery();
            if (!cqQueryString.equals(newCqQueryString)) {
                query = qService.newQuery(newCqQueryString);
                cqQueryString = newCqQueryString;
                cqRegionNames = executeCQContext.getRegionNames();
                if (cqRegionNames == null) {
                    cqRegionNames = ((DefaultQuery) query).getRegionsInQuery(null);
                }
            }
        }
        cqServiceForExec = qService.getCqService();
        cqQuery = cqServiceForExec.executeCq(cqName, cqQueryString, cqState, id, acceptor.getCacheClientNotifier(), isDurable, false, 0, null);
    } catch (CqException cqe) {
        sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, "", clientMessage.getTransactionId(), cqe, serverConnection);
        return;
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        return;
    }
    long oldstart = start;
    boolean sendResults = false;
    boolean successQuery = false;
    if (clientMessage.getMessageType() == MessageType.EXECUTECQ_WITH_IR_MSG_TYPE) {
        sendResults = true;
    }
    // Execute the query and send the result-set to client.
    try {
        if (query == null) {
            query = qService.newQuery(cqQueryString);
            cqRegionNames = ((DefaultQuery) query).getRegionsInQuery(null);
        }
        ((DefaultQuery) query).setIsCqQuery(true);
        successQuery = processQuery(clientMessage, query, cqQueryString, cqRegionNames, start, cqQuery, executeCQContext, serverConnection, sendResults);
        // Update the CQ statistics.
        cqQuery.getVsdStats().setCqInitialResultsTime((DistributionStats.getStatTime()) - oldstart);
        stats.incProcessExecuteCqWithIRTime((DistributionStats.getStatTime()) - oldstart);
    // logger.fine("Time spent in execute with initial results :" +
    // DistributionStats.getStatTime() + ", " + oldstart);
    } finally {
        // If failure to execute the query, close the CQ.
        if (!successQuery) {
            try {
                cqServiceForExec.closeCq(cqName, id);
            } catch (Exception ex) {
            // Ignore.
            }
        }
    }
    if (!sendResults && successQuery) {
        // Send OK to client
        sendCqResponse(MessageType.REPLY, LocalizedStrings.ExecuteCQ_CQ_CREATED_SUCCESSFULLY.toLocalizedString(), clientMessage.getTransactionId(), null, serverConnection);
        long start2 = DistributionStats.getStatTime();
        stats.incProcessCreateCqTime(start2 - oldstart);
    }
    serverConnection.setAsTrue(RESPONDED);
}
Also used : Set(java.util.Set) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) CqException(org.apache.geode.cache.query.CqException) CqService(org.apache.geode.cache.query.internal.cq.CqService) IOException(java.io.IOException) CqException(org.apache.geode.cache.query.CqException) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) Part(org.apache.geode.internal.cache.tier.sockets.Part) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) ServerCQ(org.apache.geode.cache.query.internal.cq.ServerCQ) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) ExecuteCQOperationContext(org.apache.geode.cache.operations.ExecuteCQOperationContext)

Example 4 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService in project geode by apache.

the class GetCQStats method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException {
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    CacheServerStats stats = serverConnection.getCacheServerStats();
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (isDebugEnabled) {
        logger.debug("{}: Received close all client CQs request from {}", serverConnection.getName(), serverConnection.getSocketString());
    }
    // Retrieve the data from the message parts
    String cqName = clientMessage.getPart(0).getString();
    if (isDebugEnabled) {
        logger.debug("{}: Received close CQ request from {} cqName: {}", serverConnection.getName(), serverConnection.getSocketString(), cqName);
    }
    // Process the query request
    if (cqName == null) {
        String err = "The cqName for the cq stats request is null";
        sendCqResponse(MessageType.CQDATAERROR_MSG_TYPE, err, clientMessage.getTransactionId(), null, serverConnection);
        return;
    }
    this.securityService.authorizeClusterRead();
    // Process the cq request
    try {
        // make sure the cqservice has been created
        // since that is what registers the stats
        CqService cqService = crHelper.getCache().getCqService();
        cqService.start();
    } catch (Exception e) {
        String err = "Exception while Getting the CQ Statistics. ";
        sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, err, clientMessage.getTransactionId(), e, serverConnection);
        return;
    }
    // Send OK to client
    sendCqResponse(MessageType.REPLY, "cq stats sent successfully.", clientMessage.getTransactionId(), null, serverConnection);
    serverConnection.setAsTrue(RESPONDED);
    {
        long oldStart = start;
        start = DistributionStats.getStatTime();
        stats.incProcessGetCqStatsTime(start - oldStart);
    }
}
Also used : CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) CqService(org.apache.geode.cache.query.internal.cq.CqService) IOException(java.io.IOException)

Example 5 with CqService

use of org.apache.geode.cache.query.internal.cq.CqService in project geode by apache.

the class GetDurableCQs method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
    AcceptorImpl acceptor = serverConnection.getAcceptor();
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    ClientProxyMembershipID id = serverConnection.getProxyID();
    CacheServerStats stats = serverConnection.getCacheServerStats();
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received {} request from {}", serverConnection.getName(), MessageType.getString(clientMessage.getMessageType()), serverConnection.getSocketString());
    }
    DefaultQueryService qService = null;
    CqService cqServiceForExec = null;
    try {
        qService = (DefaultQueryService) crHelper.getCache().getLocalQueryService();
        this.securityService.authorizeClusterRead();
        // Authorization check
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            authzRequest.getDurableCQsAuthorize();
        }
        cqServiceForExec = qService.getCqService();
        List<String> durableCqs = cqServiceForExec.getAllDurableClientCqs(id);
        ChunkedMessage chunkedResponseMsg = serverConnection.getChunkedResponseMessage();
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        List durableCqList = new ArrayList(MAXIMUM_CHUNK_SIZE);
        final boolean isTraceEnabled = logger.isTraceEnabled();
        for (Iterator it = durableCqs.iterator(); it.hasNext(); ) {
            Object durableCqName = it.next();
            durableCqList.add(durableCqName);
            if (isTraceEnabled) {
                logger.trace("{}: getDurableCqsResponse <{}>; list size was {}", serverConnection.getName(), durableCqName, durableCqList.size());
            }
            if (durableCqList.size() == MAXIMUM_CHUNK_SIZE) {
                // Send the chunk and clear the list
                sendDurableCqsResponseChunk(durableCqList, false, serverConnection);
                durableCqList.clear();
            }
        }
        // Send the last chunk even if the list is of zero size.
        sendDurableCqsResponseChunk(durableCqList, true, serverConnection);
    } catch (CqException cqe) {
        sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, "", clientMessage.getTransactionId(), cqe, serverConnection);
        return;
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        return;
    }
}
Also used : AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) CqException(org.apache.geode.cache.query.CqException) ArrayList(java.util.ArrayList) CqService(org.apache.geode.cache.query.internal.cq.CqService) IOException(java.io.IOException) CqException(org.apache.geode.cache.query.CqException) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) ChunkedMessage(org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)

Aggregations

CqService (org.apache.geode.cache.query.internal.cq.CqService)36 InternalCqQuery (org.apache.geode.cache.query.internal.cq.InternalCqQuery)15 CacheException (org.apache.geode.cache.CacheException)11 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)11 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)10 IOException (java.io.IOException)9 Collection (java.util.Collection)9 Set (java.util.Set)8 CqException (org.apache.geode.cache.query.CqException)8 HashSet (java.util.HashSet)7 Region (org.apache.geode.cache.Region)7 ServerCQImpl (org.apache.geode.cache.query.internal.cq.ServerCQImpl)7 Host (org.apache.geode.test.dunit.Host)7 VM (org.apache.geode.test.dunit.VM)7 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)7 Test (org.junit.Test)7 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)6 Portfolio (org.apache.geode.cache.query.data.Portfolio)5 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)5 CacheServerStats (org.apache.geode.internal.cache.tier.sockets.CacheServerStats)5