Search in sources :

Example 1 with ClientProxyMembershipID

use of org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID in project geode by apache.

the class CqServiceUnitTest method constructCqServerNameShouldReturnCorrectResultsEvenAfterCqClosingRemovesValuesFromOptimizedCache.

@Test
public void constructCqServerNameShouldReturnCorrectResultsEvenAfterCqClosingRemovesValuesFromOptimizedCache() throws Exception {
    CqServiceImpl cqService = new CqServiceImpl(Fakes.cache());
    ClientProxyMembershipID proxyMembershipID = new ClientProxyMembershipID(Fakes.cache().getDistributedSystem().getDistributedMember());
    String name1 = cqService.constructServerCqName("myCq", proxyMembershipID);
    cqService.closeCq("myCq", proxyMembershipID);
    String name2 = cqService.constructServerCqName("myCq", proxyMembershipID);
    assertEquals(name1, name2);
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 2 with ClientProxyMembershipID

use of org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID 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 ClientProxyMembershipID

use of org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID 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 ClientProxyMembershipID

use of org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID in project geode by apache.

the class ExecuteCQ61 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;
    // region data policy
    Part regionDataPolicyPart = clientMessage.getPart(clientMessage.getNumberOfParts() - 1);
    byte[] regionDataPolicyPartBytes = regionDataPolicyPart.getSerializedForm();
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received {} request from {} CqName: {} queryString: {}", serverConnection.getName(), MessageType.getString(clientMessage.getMessageType()), serverConnection.getSocketString(), cqName, cqQueryString);
    }
    // Check if the Server is running in NotifyBySubscription=true mode.
    CacheClientNotifier ccn = acceptor.getCacheClientNotifier();
    if (ccn != null) {
        CacheClientProxy proxy = ccn.getClientProxy(id);
        if (proxy != null && !proxy.isNotifyBySubscription()) {
            // This should have been taken care at the client.
            String err = LocalizedStrings.ExecuteCQ_SERVER_NOTIFYBYSUBSCRIPTION_MODE_IS_SET_TO_FALSE_CQ_EXECUTION_IS_NOT_SUPPORTED_IN_THIS_MODE.toLocalizedString();
            sendCqResponse(MessageType.CQDATAERROR_MSG_TYPE, err, clientMessage.getTransactionId(), null, serverConnection);
            return;
        }
    }
    DefaultQueryService qService = null;
    CqServiceImpl cqServiceForExec = null;
    Query query = null;
    Set cqRegionNames = null;
    ExecuteCQOperationContext executeCQContext = null;
    ServerCQImpl 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);
                }
            }
        }
        if (CqServiceProvider.VMOTION_DURING_CQ_REGISTRATION_FLAG) {
            VMotionObserver vmo = VMotionObserverHolder.getInstance();
            vmo.vMotionBeforeCQRegistration();
        }
        cqServiceForExec = (CqServiceImpl) qService.getCqService();
        // registering cq with serverConnection so that when CCP will require auth info it can access
        // that
        // registering cq auth before as possibility that you may get event
        serverConnection.setCq(cqName, isDurable);
        cqQuery = (ServerCQImpl) cqServiceForExec.executeCq(cqName, cqQueryString, cqState, id, ccn, isDurable, true, regionDataPolicyPartBytes[0], null);
    } catch (CqException cqe) {
        sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, "", clientMessage.getTransactionId(), cqe, serverConnection);
        serverConnection.removeCq(cqName, isDurable);
        return;
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.removeCq(cqName, isDurable);
        return;
    }
    long oldstart = start;
    boolean sendResults = false;
    boolean successQuery = false;
    if (clientMessage.getMessageType() == MessageType.EXECUTECQ_WITH_IR_MSG_TYPE) {
        sendResults = true;
    }
    // if it is a non PR query with execute query and maintain keys flags set
    if (sendResults || (CqServiceImpl.EXECUTE_QUERY_DURING_INIT && CqServiceProvider.MAINTAIN_KEYS && !cqQuery.isPR())) {
        // 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.
                }
            }
        }
    } else {
        // Don't execute query for cq.execute and
        // if it is a PR query with execute query and maintain keys flags not set
        cqQuery.cqResultKeysInitialized = true;
        successQuery = true;
    }
    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 : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) Set(java.util.Set) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) CqException(org.apache.geode.cache.query.CqException) VMotionObserver(org.apache.geode.internal.cache.vmotion.VMotionObserver) ServerCQImpl(org.apache.geode.cache.query.internal.cq.ServerCQImpl) CqException(org.apache.geode.cache.query.CqException) IOException(java.io.IOException) CqServiceImpl(org.apache.geode.cache.query.internal.cq.CqServiceImpl) 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) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) ExecuteCQOperationContext(org.apache.geode.cache.operations.ExecuteCQOperationContext)

Example 5 with ClientProxyMembershipID

use of org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID in project geode by apache.

the class CqServiceImpl method getAllDurableClientCqs.

@Override
public List<String> getAllDurableClientCqs(ClientProxyMembershipID clientProxyId) throws CqException {
    if (clientProxyId == null) {
        throw new CqException(LocalizedStrings.CqService_UNABLE_TO_RETRIEVE_DURABLE_CQS_FOR_CLIENT_PROXY_ID.toLocalizedString());
    }
    List<ServerCQ> cqs = getAllClientCqs(clientProxyId);
    ArrayList<String> durableClientCqs = new ArrayList<>();
    for (ServerCQ cq : cqs) {
        ServerCQImpl cQuery = (ServerCQImpl) cq;
        if (cQuery != null && cQuery.isDurable()) {
            ClientProxyMembershipID id = cQuery.getClientProxyId();
            if (id != null && id.equals(clientProxyId)) {
                durableClientCqs.add(cQuery.getName());
            }
        }
    }
    return durableClientCqs;
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) CqException(org.apache.geode.cache.query.CqException) ArrayList(java.util.ArrayList)

Aggregations

ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)30 Test (org.junit.Test)10 IOException (java.io.IOException)7 CacheClientProxy (org.apache.geode.internal.cache.tier.sockets.CacheClientProxy)7 CqException (org.apache.geode.cache.query.CqException)6 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 CqService (org.apache.geode.cache.query.internal.cq.CqService)5 EventID (org.apache.geode.internal.cache.EventID)5 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)5 AcceptorImpl (org.apache.geode.internal.cache.tier.sockets.AcceptorImpl)5 CacheServerStats (org.apache.geode.internal.cache.tier.sockets.CacheServerStats)5 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)5 UnitTest (org.apache.geode.test.junit.categories.UnitTest)5 Iterator (java.util.Iterator)4 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)4 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)4 HashSet (java.util.HashSet)3 CacheException (org.apache.geode.cache.CacheException)3 ServerCQ (org.apache.geode.cache.query.internal.cq.ServerCQ)3