Search in sources :

Example 1 with RegionNotFoundException

use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.

the class PutAllCSDUnitTest method testOneServer.

/**
   * Tests putAll to one server.
   */
@Test
public void testOneServer() throws CacheException, InterruptedException {
    final String title = "testOneServer:";
    final Host host = Host.getHost(0);
    VM server = host.getVM(0);
    VM client1 = host.getVM(2);
    VM client2 = host.getVM(3);
    final String regionName = getUniqueName();
    final String serverHost = NetworkUtils.getServerHostName(server.getHost());
    // set <false, true> means <PR=false, notifyBySubscription=true> to enable registerInterest and
    // CQ
    final int serverPort = createBridgeServer(server, regionName, 0, false, 0, null);
    createClient(client1, regionName, serverHost, new int[] { serverPort }, -1, -1, false, true, true);
    createClient(client2, regionName, serverHost, new int[] { serverPort }, -1, -1, false, true, true);
    server.invoke(new CacheSerializableRunnable(title + "server add listener") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            region.getAttributesMutator().addCacheListener(new MyListener(false));
        }
    });
    client2.invoke(new CacheSerializableRunnable(title + "client2 registerInterest and add listener") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            region.getAttributesMutator().addCacheListener(new MyListener(false));
            // registerInterest for ALL_KEYS
            region.registerInterest("ALL_KEYS");
            LogWriterUtils.getLogWriter().info("client2 registerInterest ALL_KEYS at " + region.getFullPath());
        }
    });
    client1.invoke(new CacheSerializableRunnable(title + "client1 create local region and run putAll") {

        @Override
        public void run2() throws CacheException {
            AttributesFactory factory2 = new AttributesFactory();
            factory2.setScope(Scope.LOCAL);
            factory2.addCacheListener(new MyListener(false));
            createRegion("localsave", factory2.create());
            Region region = doPutAll(regionName, "key-", numberOfEntries);
            assertEquals(numberOfEntries, region.size());
        }
    });
    AsyncInvocation async1 = client1.invokeAsync(new CacheSerializableRunnable(title + "client1 create CQ") {

        @Override
        public void run2() throws CacheException {
            // create a CQ for key 10-20
            Region localregion = getRootRegion().getSubregion("localsave");
            CqAttributesFactory cqf1 = new CqAttributesFactory();
            EOCQEventListener EOCQListener = new EOCQEventListener(localregion);
            cqf1.addCqListener(EOCQListener);
            CqAttributes cqa1 = cqf1.create();
            String cqName1 = "EOInfoTracker";
            String queryStr1 = "SELECT ALL * FROM /root/" + regionName + " ii WHERE ii.getTicker() >= '10' and ii.getTicker() < '20'";
            LogWriterUtils.getLogWriter().info("Query String: " + queryStr1);
            try {
                QueryService cqService = getCache().getQueryService();
                CqQuery EOTracker = cqService.newCq(cqName1, queryStr1, cqa1);
                SelectResults rs1 = EOTracker.executeWithInitialResults();
                List list1 = rs1.asList();
                for (int i = 0; i < list1.size(); i++) {
                    Struct s = (Struct) list1.get(i);
                    TestObject o = (TestObject) s.get("value");
                    LogWriterUtils.getLogWriter().info("InitialResult:" + i + ":" + o);
                    localregion.put("key-" + i, o);
                }
                if (localregion.size() > 0) {
                    LogWriterUtils.getLogWriter().info("CQ is ready");
                    synchronized (lockObject) {
                        lockObject.notify();
                    }
                }
                waitTillNotify(lockObject2, 20000, (EOCQListener.num_creates == 5 && EOCQListener.num_updates == 5));
                EOTracker.close();
            } catch (CqClosedException e) {
                Assert.fail("CQ", e);
            } catch (RegionNotFoundException e) {
                Assert.fail("CQ", e);
            } catch (QueryInvalidException e) {
                Assert.fail("CQ", e);
            } catch (CqExistsException e) {
                Assert.fail("CQ", e);
            } catch (CqException e) {
                Assert.fail("CQ", e);
            }
        }
    });
    server.invoke(new CacheSerializableRunnable(title + "verify Bridge Server") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            assertEquals(numberOfEntries, region.size());
            for (int i = 0; i < numberOfEntries; i++) {
                TestObject obj = (TestObject) region.getEntry("key-" + i).getValue();
                assertEquals(i, obj.getPrice());
            }
        }
    });
    // verify CQ is ready
    client1.invoke(new CacheSerializableRunnable(title + "verify CQ is ready") {

        @Override
        public void run2() throws CacheException {
            Region localregion = getRootRegion().getSubregion("localsave");
            waitTillNotify(lockObject, 10000, (localregion.size() > 0));
            assertTrue(localregion.size() > 0);
        }
    });
    // verify registerInterest result at client2
    client2.invoke(new CacheSerializableRunnable(title + "verify client2") {

        @Override
        public void run2() throws CacheException {
            final Region region = getRootRegion().getSubregion(regionName);
            checkRegionSize(region, numberOfEntries);
            for (int i = 0; i < numberOfEntries; i++) {
                TestObject obj = (TestObject) region.getEntry("key-" + i).getValue();
                assertEquals(i, obj.getPrice());
            }
            // then do update for key 10-20 to trigger CQ at server2
            // destroy key 10-14 to simulate create/update mix case
            region.removeAll(Arrays.asList("key-10", "key-11", "key-12", "key-13", "key-14"), "removeAllCallback");
            assertEquals(null, region.get("key-10"));
            assertEquals(null, region.get("key-11"));
            assertEquals(null, region.get("key-12"));
            assertEquals(null, region.get("key-13"));
            assertEquals(null, region.get("key-14"));
        }
    });
    // verify CQ result at client1
    client1.invoke(new CacheSerializableRunnable(title + "Verify client1") {

        @Override
        public void run2() throws CacheException {
            Region localregion = getRootRegion().getSubregion("localsave");
            for (int i = 10; i < 15; i++) {
                TestObject obj = null;
                int cnt = 0;
                while (cnt < 100) {
                    obj = (TestObject) localregion.get("key-" + i);
                    if (obj != null) {
                        // wait for the key to be destroyed
                        Wait.pause(100);
                        if (LogWriterUtils.getLogWriter().fineEnabled()) {
                            LogWriterUtils.getLogWriter().info("Waiting 100ms(" + cnt + ") for key-" + i + " to be destroyed");
                        }
                        cnt++;
                    } else {
                        break;
                    }
                }
            }
        }
    });
    client2.invoke(new CacheSerializableRunnable(title + "verify client2") {

        @Override
        public void run2() throws CacheException {
            final Region region = getRootRegion().getSubregion(regionName);
            LinkedHashMap map = new LinkedHashMap();
            for (int i = 10; i < 20; i++) {
                map.put("key-" + i, new TestObject(i * 10));
            }
            region.putAll(map, "putAllCallback");
        }
    });
    // verify CQ result at client1
    client1.invoke(new CacheSerializableRunnable(title + "Verify client1") {

        @Override
        public void run2() throws CacheException {
            Region localregion = getRootRegion().getSubregion("localsave");
            for (int i = 10; i < 20; i++) {
                TestObject obj = null;
                int cnt = 0;
                while (cnt < 100) {
                    obj = (TestObject) localregion.get("key-" + i);
                    if (obj == null || obj.getPrice() != i * 10) {
                        Wait.pause(100);
                        LogWriterUtils.getLogWriter().info("Waiting 100ms(" + cnt + ") for obj.getPrice() == i*10 at entry " + i);
                        cnt++;
                    } else {
                        break;
                    }
                }
                assertEquals(i * 10, obj.getPrice());
            }
            synchronized (lockObject2) {
                lockObject2.notify();
            }
        }
    });
    ThreadUtils.join(async1, 30 * 1000);
    // verify stats for client putAll into distributed region
    // 1. verify client staus
    /*
     * server2.invoke(new CacheSerializableRunnable("server2 execute putAll") { public void run2()
     * throws CacheException { try { DistributedSystemConfig config =
     * AdminDistributedSystemFactory.defineDistributedSystem(system, null); AdminDistributedSystem
     * ads = AdminDistributedSystemFactory.getDistributedSystem(config); ads.connect();
     * DistributedMember distributedMember = system.getDistributedMember(); SystemMember member =
     * ads.lookupSystemMember(distributedMember);
     * 
     * StatisticResource[] resources = member.getStats(); for (int i=0; i<resources.length; i++) {
     * System.out.println("GGG:"+resources[i].getType()); if
     * (resources[i].getType().equals("CacheServerClientStats")) { Statistic[] stats =
     * resources[i].getStatistics(); for (int j=0; i<stats.length; i++) { if
     * (stats[j].getName().equals("putAll")) {
     * System.out.println("GGG:"+stats[j].getName()+":"+stats[j].getValue()); } else if
     * (stats[j].getName().equals("sendPutAllTime")) {
     * System.out.println("GGG:"+stats[j].getName()+":"+stats[j].getValue()); } } } } } catch
     * (AdminException e) { fail("Failed while creating AdminDS", e); } } });
     */
    // Test Exception handling
    // verify CQ is ready
    client1.invoke(new CacheSerializableRunnable(title + "test exception handling") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            Map m = null;
            boolean NPEthrowed = false;
            try {
                region.putAll(m, "putAllCallback");
                fail("Should have thrown NullPointerException");
            } catch (NullPointerException ex) {
                NPEthrowed = true;
            }
            assertTrue(NPEthrowed);
            region.localDestroyRegion();
            boolean RDEthrowed = false;
            try {
                m = new HashMap();
                for (int i = 1; i < 21; i++) {
                    m.put(new Integer(i), Integer.toString(i));
                }
                region.putAll(m, "putAllCallback");
                fail("Should have thrown RegionDestroyedException");
            } catch (RegionDestroyedException ex) {
                RDEthrowed = true;
            }
            assertTrue(RDEthrowed);
            try {
                region.removeAll(Arrays.asList("key-10", "key-11"), "removeAllCallback");
                fail("Should have thrown RegionDestroyedException");
            } catch (RegionDestroyedException expected) {
            }
        }
    });
    // Stop server
    stopBridgeServers(getCache());
}
Also used : CacheException(org.apache.geode.cache.CacheException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CqClosedException(org.apache.geode.cache.query.CqClosedException) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Struct(org.apache.geode.cache.query.Struct) LinkedHashMap(java.util.LinkedHashMap) AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SelectResults(org.apache.geode.cache.query.SelectResults) List(java.util.List) ArrayList(java.util.ArrayList) CqQuery(org.apache.geode.cache.query.CqQuery) CqException(org.apache.geode.cache.query.CqException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) Host(org.apache.geode.test.dunit.Host) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CqAttributes(org.apache.geode.cache.query.CqAttributes) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) CqExistsException(org.apache.geode.cache.query.CqExistsException) Region(org.apache.geode.cache.Region) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 2 with RegionNotFoundException

use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.

the class ServerCQImpl method registerCq.

@Override
public void registerCq(ClientProxyMembershipID p_clientProxyId, CacheClientNotifier p_ccn, int p_cqState) throws CqException, RegionNotFoundException {
    CacheClientProxy clientProxy = null;
    this.clientProxyId = p_clientProxyId;
    if (p_ccn != null) {
        this.ccn = p_ccn;
        clientProxy = p_ccn.getClientProxy(p_clientProxyId, true);
    }
    validateCq();
    final boolean isDebugEnabled = logger.isDebugEnabled();
    StringId msg = LocalizedStrings.ONE_ARG;
    Throwable t = null;
    try {
        this.query = constructServerSideQuery();
        if (isDebugEnabled) {
            logger.debug("Server side query for the cq: {} is: {}", cqName, this.query.getQueryString());
        }
    } catch (Exception ex) {
        t = ex;
        if (ex instanceof ClassNotFoundException) {
            msg = LocalizedStrings.CqQueryImpl_CLASS_NOT_FOUND_EXCEPTION_THE_ANTLRJAR_OR_THE_SPCIFIED_CLASS_MAY_BE_MISSING_FROM_SERVER_SIDE_CLASSPATH_ERROR_0;
        } else {
            msg = LocalizedStrings.CqQueryImpl_ERROR_WHILE_PARSING_THE_QUERY_ERROR_0;
        }
    } finally {
        if (t != null) {
            String s = msg.toLocalizedString(t);
            if (isDebugEnabled) {
                logger.debug(s, t);
            }
            throw new CqException(s);
        }
    }
    // Update Regions Book keeping.
    // TODO replace getRegion() with getRegionByPathForProcessing() so this doesn't block
    // if the region is still being initialized
    this.cqBaseRegion = (LocalRegion) cqService.getCache().getRegion(regionName);
    if (this.cqBaseRegion == null) {
        throw new RegionNotFoundException(LocalizedStrings.CqQueryImpl_REGION__0_SPECIFIED_WITH_CQ_NOT_FOUND_CQNAME_1.toLocalizedString(new Object[] { regionName, this.cqName }));
    }
    // Make sure that the region is partitioned or
    // replicated with distributed ack or global.
    DataPolicy dp = this.cqBaseRegion.getDataPolicy();
    this.isPR = dp.withPartitioning();
    if (!(this.isPR || dp.withReplication())) {
        String errMsg = null;
        // replicated regions with eviction set to local destroy get turned into preloaded
        if (dp.withPreloaded() && cqBaseRegion.getAttributes().getEvictionAttributes() != null && cqBaseRegion.getAttributes().getEvictionAttributes().getAction().equals(EvictionAction.LOCAL_DESTROY)) {
            errMsg = LocalizedStrings.CqQueryImpl_CQ_NOT_SUPPORTED_FOR_REPLICATE_WITH_LOCAL_DESTROY.toString(this.regionName, cqBaseRegion.getAttributes().getEvictionAttributes().getAction());
        } else {
            errMsg = "The region " + this.regionName + "  specified in CQ creation is neither replicated nor partitioned; " + "only replicated or partitioned regions are allowed in CQ creation.";
        }
        if (isDebugEnabled) {
            logger.debug(errMsg);
        }
        throw new CqException(errMsg);
    }
    if ((dp.withReplication() && (!(cqBaseRegion.getAttributes().getScope().isDistributedAck() || cqBaseRegion.getAttributes().getScope().isGlobal())))) {
        String errMsg = "The replicated region " + this.regionName + " specified in CQ creation does not have scope supported by CQ." + " The CQ supported scopes are DISTRIBUTED_ACK and GLOBAL.";
        if (isDebugEnabled) {
            logger.debug(errMsg);
        }
        throw new CqException(errMsg);
    }
    // Can be null by the time we are here
    if (clientProxy != null) {
        clientProxy.incCqCount();
        if (clientProxy.hasOneCq()) {
            cqService.stats().incClientsWithCqs();
        }
        if (isDebugEnabled) {
            logger.debug("Added CQ to the base region: {} With key as: {}", cqBaseRegion.getFullPath(), serverCqName);
        }
    }
    this.updateCqCreateStats();
    // Initialize the state of CQ.
    if (this.cqState.getState() != p_cqState) {
        setCqState(p_cqState);
    }
    // it to other matching cqs for performance reasons
    if (p_cqState == CqStateImpl.RUNNING) {
        // Add to the matchedCqMap.
        cqService.addToMatchingCqMap(this);
    }
    // Initialize CQ results (key) cache.
    if (CqServiceProvider.MAINTAIN_KEYS) {
        this.cqResultKeys = new HashMap<Object, Object>();
        // added to the results cache (not from the CQ Results).
        if (this.isPR) {
            this.setCqResultsCacheInitialized();
        } else {
            this.destroysWhileCqResultsInProgress = new HashSet<Object>();
        }
    }
    if (p_ccn != null) {
        try {
            cqService.addToCqMap(this);
        } catch (CqExistsException cqe) {
            // Should not happen.
            throw new CqException(LocalizedStrings.CqQueryImpl_UNABLE_TO_CREATE_CQ_0_ERROR__1.toLocalizedString(new Object[] { cqName, cqe.getMessage() }));
        }
        this.cqBaseRegion.getFilterProfile().registerCq(this);
    }
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CqException(org.apache.geode.cache.query.CqException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqException(org.apache.geode.cache.query.CqException) CqClosedException(org.apache.geode.cache.query.CqClosedException) IOException(java.io.IOException) QueryException(org.apache.geode.cache.query.QueryException) StringId(org.apache.geode.i18n.StringId) CqExistsException(org.apache.geode.cache.query.CqExistsException) DataPolicy(org.apache.geode.cache.DataPolicy)

Example 3 with RegionNotFoundException

use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.

the class CqDataUsingPoolDUnitTest method testGetDurableCqsFromServerCycleClientsAndMoreCqs.

@Test
public void testGetDurableCqsFromServerCycleClientsAndMoreCqs() {
    final String regionName = "testGetAllDurableCqsFromServerCycleClients";
    final Host host = Host.getHost(0);
    VM server = host.getVM(0);
    VM client1 = host.getVM(1);
    VM client2 = host.getVM(2);
    int timeout = 60000;
    // Start server 1
    final int server1Port = ((Integer) server.invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true)))).intValue();
    // Start client 1
    client1.invoke(() -> CacheServerTestUtil.createClientCache(getClientPool(NetworkUtils.getServerHostName(client1.getHost()), server1Port), regionName, getDurableClientProperties("client1_dc", timeout)));
    // Start client 2
    client2.invoke(() -> CacheServerTestUtil.createClientCache(getClientPool(NetworkUtils.getServerHostName(client2.getHost()), server1Port), regionName, getDurableClientProperties("client2_dc", timeout)));
    // create the test cqs
    createClient1CqsAndDurableCqs(client1, regionName);
    createClient2CqsAndDurableCqs(client2, regionName);
    cycleDurableClient(client1, "client1_dc", server1Port, regionName, timeout);
    cycleDurableClient(client2, "client2_dc", server1Port, regionName, timeout);
    client1.invoke(new CacheSerializableRunnable("Register more cq for client 1") {

        @Override
        public void run2() throws CacheException {
            // register the cq's
            QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
            CqAttributesFactory cqAf = new CqAttributesFactory();
            CqAttributes attributes = cqAf.create();
            try {
                queryService.newCq("client1MoreDCQ1", "Select * From /" + regionName + " where id = 1", attributes, true).execute();
                queryService.newCq("client1MoreDCQ2", "Select * From /" + regionName + " where id = 10", attributes, true).execute();
                queryService.newCq("client1MoreNoDC1", "Select * From /" + regionName, attributes, false).execute();
                queryService.newCq("client1MoreNoDC2", "Select * From /" + regionName + " where id = 3", attributes, false).execute();
            } catch (RegionNotFoundException e) {
                fail("failed", e);
            } catch (CqException e) {
                fail("failed", e);
            } catch (CqExistsException e) {
                fail("failed", e);
            }
        }
    });
    client2.invoke(new CacheSerializableRunnable("Register more cq for client 2") {

        @Override
        public void run2() throws CacheException {
            // register the cq's
            QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
            CqAttributesFactory cqAf = new CqAttributesFactory();
            CqAttributes attributes = cqAf.create();
            try {
                queryService.newCq("client2MoreDCQ1", "Select * From /" + regionName + " where id = 1", attributes, true).execute();
                queryService.newCq("client2MoreDCQ2", "Select * From /" + regionName + " where id = 10", attributes, true).execute();
                queryService.newCq("client2MoreDCQ3", "Select * From /" + regionName, attributes, true).execute();
                queryService.newCq("client2MoreDCQ4", "Select * From /" + regionName + " where id = 3", attributes, true).execute();
            } catch (RegionNotFoundException e) {
                fail("failed", e);
            } catch (CqException e) {
                fail("failed", e);
            } catch (CqExistsException e) {
                fail("failed", e);
            }
        }
    });
    // Cycle clients a second time
    cycleDurableClient(client1, "client1_dc", server1Port, regionName, timeout);
    cycleDurableClient(client2, "client2_dc", server1Port, regionName, timeout);
    client2.invoke(new CacheSerializableRunnable("check durable cqs for client 2") {

        @Override
        public void run2() throws CacheException {
            QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
            List<String> list = null;
            try {
                list = queryService.getAllDurableCqsFromServer();
            } catch (CqException e) {
                fail("failed", e);
            }
            assertEquals(8, list.size());
            assertTrue(list.contains("client2DCQ1"));
            assertTrue(list.contains("client2DCQ2"));
            assertTrue(list.contains("client2DCQ3"));
            assertTrue(list.contains("client2DCQ4"));
            assertTrue(list.contains("client2MoreDCQ1"));
            assertTrue(list.contains("client2MoreDCQ2"));
            assertTrue(list.contains("client2MoreDCQ3"));
            assertTrue(list.contains("client2MoreDCQ4"));
        }
    });
    client1.invoke(new CacheSerializableRunnable("check durable cqs for client 1") {

        @Override
        public void run2() throws CacheException {
            QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
            List<String> list = null;
            try {
                list = queryService.getAllDurableCqsFromServer();
            } catch (CqException e) {
                fail("failed", e);
            }
            assertEquals(4, list.size());
            assertTrue(list.contains("client1DCQ1"));
            assertTrue(list.contains("client1DCQ2"));
            assertTrue(list.contains("client1MoreDCQ1"));
            assertTrue(list.contains("client1MoreDCQ2"));
        }
    });
    client1.invoke(() -> CacheServerTestUtil.closeCache());
    client2.invoke(() -> CacheServerTestUtil.closeCache());
    server.invoke(() -> CacheServerTestUtil.closeCache());
}
Also used : CacheException(org.apache.geode.cache.CacheException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqException(org.apache.geode.cache.query.CqException) Host(org.apache.geode.test.dunit.Host) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) VM(org.apache.geode.test.dunit.VM) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) List(java.util.List) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 4 with RegionNotFoundException

use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.

the class ClientCQImpl method initConnectionProxy.

/**
   * Initializes the connection using the pool from the client region. Also sets the cqBaseRegion
   * value of this CQ.
   */
private void initConnectionProxy() throws CqException, RegionNotFoundException {
    cqBaseRegion = (LocalRegion) cqService.getCache().getRegion(regionName);
    // is obtained by the Bridge Client/writer/loader on the local region.
    if (cqBaseRegion == null) {
        throw new RegionNotFoundException(LocalizedStrings.CqQueryImpl_REGION_ON_WHICH_QUERY_IS_SPECIFIED_NOT_FOUND_LOCALLY_REGIONNAME_0.toLocalizedString(regionName));
    }
    ServerRegionProxy srp = cqBaseRegion.getServerProxy();
    if (srp != null) {
        if (logger.isTraceEnabled()) {
            logger.trace("Found server region proxy on region. RegionName: {}", regionName);
        }
        this.cqProxy = new ServerCQProxyImpl(srp);
        if (!srp.getPool().getSubscriptionEnabled()) {
            throw new CqException("The 'queueEnabled' flag on Pool installed on Region " + regionName + " is set to false.");
        }
    } else {
        throw new CqException("Unable to get the connection pool. The Region does not have a pool configured.");
    }
}
Also used : RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) CqException(org.apache.geode.cache.query.CqException) ServerCQProxyImpl(org.apache.geode.cache.client.internal.ServerCQProxyImpl)

Example 5 with RegionNotFoundException

use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.

the class ClientCQImpl method executeCqOnRedundantsAndPrimary.

/**
   * This executes the CQ first on the redundant server and then on the primary server. This is
   * required to keep the redundancy behavior in accordance with the HAQueue expectation (wherein
   * the events are delivered only from the primary).
   * 
   * @param executeWithInitialResults boolean
   * @return Object SelectResults in case of executeWithInitialResults
   */
private Object executeCqOnRedundantsAndPrimary(boolean executeWithInitialResults) throws CqClosedException, RegionNotFoundException, CqException {
    Object initialResults = null;
    synchronized (this.cqState) {
        if (this.isClosed()) {
            throw new CqClosedException(LocalizedStrings.CqQueryImpl_CQ_IS_CLOSED_CQNAME_0.toLocalizedString(this.cqName));
        }
        if (this.isRunning()) {
            throw new IllegalStateException(LocalizedStrings.CqQueryImpl_CQ_IS_IN_RUNNING_STATE_CQNAME_0.toLocalizedString(this.cqName));
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Performing Execute {} request for CQ. CqName: {}", ((executeWithInitialResults) ? "WithInitialResult" : ""), this.cqName);
        }
        this.cqBaseRegion = (LocalRegion) cqService.getCache().getRegion(this.regionName);
        // If not server send the request to server.
        if (!cqService.isServer()) {
            // pool that initializes the CQ. Else its set using the Region proxy.
            if (this.cqProxy == null) {
                initConnectionProxy();
            }
            boolean success = false;
            try {
                if (this.proxyCache != null) {
                    if (this.proxyCache.isClosed()) {
                        throw new CacheClosedException("Cache is closed for this user.");
                    }
                    UserAttributes.userAttributes.set(this.proxyCache.getUserAttributes());
                }
                if (executeWithInitialResults) {
                    initialResults = cqProxy.createWithIR(this);
                    if (initialResults == null) {
                        String errMsg = "Failed to execute the CQ.  CqName: " + this.cqName + ", Query String is: " + this.queryString;
                        throw new CqException(errMsg);
                    }
                } else {
                    cqProxy.create(this);
                }
                success = true;
            } catch (Exception ex) {
                // Check for system shutdown.
                if (this.shutdownInProgress()) {
                    throw new CqException("System shutdown in progress.");
                }
                if (ex.getCause() instanceof GemFireSecurityException) {
                    if (securityLogWriter.warningEnabled()) {
                        securityLogWriter.warning(LocalizedStrings.CqQueryImpl_EXCEPTION_WHILE_EXECUTING_CQ_EXCEPTION_0, ex, null);
                    }
                    throw new CqException(ex.getCause().getMessage(), ex.getCause());
                } else if (ex instanceof CqException) {
                    throw (CqException) ex;
                } else {
                    String errMsg = LocalizedStrings.CqQueryImpl_FAILED_TO_EXECUTE_THE_CQ_CQNAME_0_QUERY_STRING_IS_1_ERROR_FROM_LAST_SERVER_2.toLocalizedString(this.cqName, this.queryString, ex.getLocalizedMessage());
                    if (logger.isDebugEnabled()) {
                        logger.debug(errMsg, ex);
                    }
                    throw new CqException(errMsg, ex);
                }
            } finally {
                if (!success && !this.shutdownInProgress()) {
                    try {
                        cqProxy.close(this);
                    } catch (Exception e) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("Exception cleaning up failed cq", e);
                        }
                        UserAttributes.userAttributes.set(null);
                    }
                }
                UserAttributes.userAttributes.set(null);
            }
        }
        this.cqState.setState(CqStateImpl.RUNNING);
    }
    // If client side, alert listeners that a cqs have been connected
    if (!cqService.isServer()) {
        connected = true;
        CqListener[] cqListeners = getCqAttributes().getCqListeners();
        for (int lCnt = 0; lCnt < cqListeners.length; lCnt++) {
            if (cqListeners[lCnt] != null) {
                if (cqListeners[lCnt] instanceof CqStatusListener) {
                    CqStatusListener listener = (CqStatusListener) cqListeners[lCnt];
                    listener.onCqConnected();
                }
            }
        }
    }
    // Update CQ-base region for book keeping.
    this.cqService.stats().incCqsActive();
    this.cqService.stats().decCqsStopped();
    return initialResults;
}
Also used : CqException(org.apache.geode.cache.query.CqException) CqListener(org.apache.geode.cache.query.CqListener) CqClosedException(org.apache.geode.cache.query.CqClosedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqException(org.apache.geode.cache.query.CqException) CacheClosedException(org.apache.geode.cache.CacheClosedException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) CqClosedException(org.apache.geode.cache.query.CqClosedException) CqStatusListener(org.apache.geode.cache.query.CqStatusListener) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException)

Aggregations

RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)26 Test (org.junit.Test)11 Region (org.apache.geode.cache.Region)9 CqException (org.apache.geode.cache.query.CqException)9 QueryService (org.apache.geode.cache.query.QueryService)9 CqExistsException (org.apache.geode.cache.query.CqExistsException)7 IndexExistsException (org.apache.geode.cache.query.IndexExistsException)7 IndexNameConflictException (org.apache.geode.cache.query.IndexNameConflictException)7 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)7 Cache (org.apache.geode.cache.Cache)6 CacheClosedException (org.apache.geode.cache.CacheClosedException)6 CacheException (org.apache.geode.cache.CacheException)6 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 CancelException (org.apache.geode.CancelException)5 CqAttributes (org.apache.geode.cache.query.CqAttributes)5 CqAttributesFactory (org.apache.geode.cache.query.CqAttributesFactory)5 CqClosedException (org.apache.geode.cache.query.CqClosedException)5 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)5 Host (org.apache.geode.test.dunit.Host)5