Search in sources :

Example 1 with CacheClientNotifier

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

the class CacheClientNotifierDUnitTest method checkCacheServer.

private void checkCacheServer(VM vm, final int serverPort, final boolean withCSC, final int capacity) {
    SerializableRunnable checkCacheServer = new SerializableRunnable() {

        @Override
        public void run() throws Exception {
            List<CacheServer> cacheServers = ((GemFireCacheImpl) cache).getCacheServersAndGatewayReceiver();
            CacheServerImpl server = null;
            for (CacheServer cs : cacheServers) {
                if (cs.getPort() == serverPort) {
                    server = (CacheServerImpl) cs;
                    break;
                }
            }
            assertNotNull(server);
            CacheClientNotifier ccn = server.getAcceptor().getCacheClientNotifier();
            HAContainerRegion haContainer = (HAContainerRegion) ccn.getHaContainer();
            if (server.getAcceptor().isGatewayReceiver()) {
                assertNull(haContainer);
                return;
            }
            Region internalRegion = haContainer.getMapForTest();
            RegionAttributes ra = internalRegion.getAttributes();
            EvictionAttributes ea = ra.getEvictionAttributes();
            if (withCSC) {
                assertNotNull(ea);
                assertEquals(capacity, ea.getMaximum());
                assertEquals(EvictionAction.OVERFLOW_TO_DISK, ea.getAction());
            } else {
                assertNull(ea);
            }
        }
    };
    vm.invoke(checkCacheServer);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) RegionAttributes(org.apache.geode.cache.RegionAttributes) HAContainerRegion(org.apache.geode.internal.cache.ha.HAContainerRegion) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) CacheServer(org.apache.geode.cache.server.CacheServer) Region(org.apache.geode.cache.Region) HAContainerRegion(org.apache.geode.internal.cache.ha.HAContainerRegion) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Example 2 with CacheClientNotifier

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

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

the class Bug48571DUnitTest method verifyProxyHasBeenPaused.

private static void verifyProxyHasBeenPaused() {
    WaitCriterion criterion = new WaitCriterion() {

        @Override
        public boolean done() {
            CacheClientNotifier ccn = CacheClientNotifier.getInstance();
            Collection<CacheClientProxy> ccProxies = ccn.getClientProxies();
            Iterator<CacheClientProxy> itr = ccProxies.iterator();
            while (itr.hasNext()) {
                CacheClientProxy ccp = itr.next();
                System.out.println("proxy status " + ccp.getState());
                if (ccp.isPaused())
                    return true;
            }
            return false;
        }

        @Override
        public String description() {
            return "Proxy has not paused yet";
        }
    };
    Wait.waitForCriterion(criterion, 15 * 1000, 200, true);
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier)

Example 4 with CacheClientNotifier

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

the class CloseDurableClientFunction method execute.

@Override
public void execute(FunctionContext context) {
    String durableClientId = (String) context.getArguments();
    final Cache cache = CliUtil.getCacheIfExists();
    final String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
    MemberResult memberResult = new MemberResult(memberNameOrId);
    try {
        CacheClientNotifier cacheClientNotifier = CacheClientNotifier.getInstance();
        if (cacheClientNotifier != null) {
            CacheClientProxy ccp = cacheClientNotifier.getClientProxy(durableClientId);
            if (ccp != null) {
                boolean isClosed = cacheClientNotifier.closeDurableClientProxy(durableClientId);
                if (isClosed) {
                    memberResult.setSuccessMessage(CliStrings.format(CliStrings.CLOSE_DURABLE_CLIENTS__SUCCESS, durableClientId));
                } else {
                    memberResult.setErrorMessage(CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId));
                }
            } else {
                memberResult.setErrorMessage(CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId));
            }
        } else {
            memberResult.setErrorMessage(CliStrings.NO_CLIENT_FOUND);
        }
    } catch (Exception e) {
        memberResult.setExceptionMessage(e.getMessage());
    } finally {
        context.getResultSender().lastResult(memberResult);
    }
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) MemberResult(org.apache.geode.management.internal.cli.domain.MemberResult) Cache(org.apache.geode.cache.Cache)

Example 5 with CacheClientNotifier

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

the class Query651 method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
    // Based on MessageType.DESTROY
    // Added by gregp 10/18/05
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
    // Retrieve the data from the message parts
    String queryString = clientMessage.getPart(0).getString();
    long compiledQueryId = 0;
    Object[] queryParams = null;
    try {
        if (clientMessage.getMessageType() == MessageType.QUERY_WITH_PARAMETERS) {
            // Query with parameters supported from 6.6 onwards.
            // Number of parameters.
            int params = clientMessage.getPart(1).getInt();
            // In case of native client there will be extra two parameters at 2 and 3 index.
            int paramStartIndex = 2;
            if (clientMessage.getNumberOfParts() > (1 + /* type */
            1 + /* query string */
            1 + /* params length */
            params)) {
                int timeout = clientMessage.getPart(3).getInt();
                serverConnection.setRequestSpecificTimeout(timeout);
                paramStartIndex = 4;
            }
            // Get the query execution parameters.
            queryParams = new Object[params];
            for (int i = 0; i < queryParams.length; i++) {
                queryParams[i] = clientMessage.getPart(i + paramStartIndex).getObject();
            }
        } else {
            // need to take care while adding new message
            if (clientMessage.getNumberOfParts() == 3) {
                int timeout = clientMessage.getPart(2).getInt();
                serverConnection.setRequestSpecificTimeout(timeout);
            }
        }
    } catch (ClassNotFoundException cne) {
        throw new QueryInvalidException(cne.getMessage() + queryString);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received query request from {} queryString: {}{}", serverConnection.getName(), serverConnection.getSocketString(), queryString, (queryParams != null ? (" with num query parameters :" + queryParams.length) : ""));
    }
    try {
        // Create query
        QueryService queryService = serverConnection.getCachedRegionHelper().getCache().getLocalQueryService();
        org.apache.geode.cache.query.Query query = null;
        if (queryParams != null) {
            // Its a compiled query.
            CacheClientNotifier ccn = serverConnection.getAcceptor().getCacheClientNotifier();
            query = ccn.getCompiledQuery(queryString);
            if (query == null) {
                // This is first time the query is seen by this server.
                query = queryService.newQuery(queryString);
                ccn.addCompiledQuery((DefaultQuery) query);
            }
            ccn.getStats().incCompiledQueryUsedCount(1);
            ((DefaultQuery) query).setLastUsed(true);
        } else {
            query = queryService.newQuery(queryString);
        }
        Set regionNames = ((DefaultQuery) query).getRegionsInQuery(queryParams);
        // Authorization check
        QueryOperationContext queryContext = null;
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            queryContext = authzRequest.queryAuthorize(queryString, regionNames, queryParams);
            String newQueryString = queryContext.getQuery();
            if (queryString != null && !queryString.equals(newQueryString)) {
                query = queryService.newQuery(newQueryString);
                queryString = newQueryString;
                regionNames = queryContext.getRegionNames();
                if (regionNames == null) {
                    regionNames = ((DefaultQuery) query).getRegionsInQuery(null);
                }
            }
        }
        processQueryUsingParams(clientMessage, query, queryString, regionNames, start, null, queryContext, serverConnection, true, queryParams);
    } catch (QueryInvalidException e) {
        throw new QueryInvalidException(e.getMessage() + queryString);
    }
}
Also used : DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Set(java.util.Set) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) QueryOperationContext(org.apache.geode.cache.operations.QueryOperationContext) QueryService(org.apache.geode.cache.query.QueryService)

Aggregations

CacheClientNotifier (org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier)17 CacheClientProxy (org.apache.geode.internal.cache.tier.sockets.CacheClientProxy)11 Cache (org.apache.geode.cache.Cache)4 IOException (java.io.IOException)3 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)3 Set (java.util.Set)2 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)2 CqService (org.apache.geode.cache.query.internal.cq.CqService)2 CacheServerImpl (org.apache.geode.internal.cache.CacheServerImpl)2 AcceptorImpl (org.apache.geode.internal.cache.tier.sockets.AcceptorImpl)2 ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)2 Part (org.apache.geode.internal.cache.tier.sockets.Part)2 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)2 MemberResult (org.apache.geode.management.internal.cli.domain.MemberResult)2 Iterator (java.util.Iterator)1 CancelCriterion (org.apache.geode.CancelCriterion)1 EvictionAttributes (org.apache.geode.cache.EvictionAttributes)1 Region (org.apache.geode.cache.Region)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 Pool (org.apache.geode.cache.client.Pool)1