Search in sources :

Example 1 with DistributionAdvisee

use of org.apache.geode.distributed.internal.DistributionAdvisee in project geode by apache.

the class CreateRegionProcessor method getRecipients.

protected Set getRecipients() {
    DistributionAdvisee parent = this.newRegion.getParentAdvisee();
    Set recps = null;
    if (parent == null) {
        // root region, all recipients
        InternalDistributedSystem system = this.newRegion.getSystem();
        recps = system.getDistributionManager().getOtherDistributionManagerIds();
    } else {
        // get recipients that have the parent region defined as distributed.
        recps = getAdvice();
    }
    return recps;
}
Also used : Set(java.util.Set) DistributionAdvisee(org.apache.geode.distributed.internal.DistributionAdvisee) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 2 with DistributionAdvisee

use of org.apache.geode.distributed.internal.DistributionAdvisee in project geode by apache.

the class GridAdvisorDUnitTest method test2by2usingGroups.

@Test
public void test2by2usingGroups() throws Exception {
    disconnectAllFromDS();
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    List<Keeper> freeTCPPorts = AvailablePortHelper.getRandomAvailableTCPPortKeepers(6);
    final Keeper keeper1 = freeTCPPorts.get(0);
    final int port1 = keeper1.getPort();
    final Keeper keeper2 = freeTCPPorts.get(1);
    final int port2 = keeper2.getPort();
    final Keeper bsKeeper1 = freeTCPPorts.get(2);
    final int bsPort1 = bsKeeper1.getPort();
    final Keeper bsKeeper2 = freeTCPPorts.get(3);
    final int bsPort2 = bsKeeper2.getPort();
    final Keeper bsKeeper3 = freeTCPPorts.get(4);
    final int bsPort3 = bsKeeper3.getPort();
    final Keeper bsKeeper4 = freeTCPPorts.get(5);
    final int bsPort4 = bsKeeper4.getPort();
    final String host0 = NetworkUtils.getServerHostName(host);
    final String locators = host0 + "[" + port1 + "]" + "," + host0 + "[" + port2 + "]";
    final Properties dsProps = new Properties();
    dsProps.setProperty(LOCATORS, locators);
    dsProps.setProperty(MCAST_PORT, "0");
    dsProps.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
    dsProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
    keeper1.release();
    vm0.invoke(new SerializableRunnable("Start locators on " + port1) {

        public void run() {
            File logFile = new File(getUniqueName() + "-locator" + port1 + ".log");
            try {
                Locator.startLocatorAndDS(port1, logFile, null, dsProps, true, true, null);
            } catch (IOException ex) {
                Assert.fail("While starting locator on port " + port1, ex);
            }
        }
    });
    // try { Thread.currentThread().sleep(4000); } catch (InterruptedException ie) { }
    keeper2.release();
    vm3.invoke(new SerializableRunnable("Start locators on " + port2) {

        public void run() {
            File logFile = new File(getUniqueName() + "-locator" + port2 + ".log");
            try {
                Locator.startLocatorAndDS(port2, logFile, null, dsProps, true, true, "locator2HNFC");
            } catch (IOException ex) {
                Assert.fail("While starting locator on port " + port2, ex);
            }
        }
    });
    vm1.invoke(new SerializableRunnable("Connect to " + locators) {

        public void run() {
            Properties props = new Properties();
            props.setProperty(MCAST_PORT, "0");
            props.setProperty(LOCATORS, locators);
            props.setProperty(GROUPS, "bs1Group1, bs1Group2");
            props.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            CacheFactory.create(DistributedSystem.connect(props));
        }
    });
    vm2.invoke(new SerializableRunnable("Connect to " + locators) {

        public void run() {
            Properties props = new Properties();
            props.setProperty(MCAST_PORT, "0");
            props.setProperty(LOCATORS, locators);
            props.setProperty(GROUPS, "bs2Group1, bs2Group2");
            props.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            CacheFactory.create(DistributedSystem.connect(props));
        }
    });
    SerializableRunnable startBS1 = new SerializableRunnable("start bridgeServer on " + bsPort1) {

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                CacheServer bs = c.addCacheServer();
                bs.setPort(bsPort1);
                bs.start();
            } catch (IOException ex) {
                RuntimeException re = new RuntimeException();
                re.initCause(ex);
                throw re;
            }
        }
    };
    SerializableRunnable startBS3 = new SerializableRunnable("start bridgeServer on " + bsPort3) {

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                CacheServer bs = c.addCacheServer();
                bs.setPort(bsPort3);
                bs.start();
            } catch (IOException ex) {
                RuntimeException re = new RuntimeException();
                re.initCause(ex);
                throw re;
            }
        }
    };
    bsKeeper1.release();
    vm1.invoke(startBS1);
    bsKeeper3.release();
    vm1.invoke(startBS3);
    bsKeeper2.release();
    vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort2) {

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                CacheServer bs = c.addCacheServer();
                bs.setPort(bsPort2);
                bs.start();
            } catch (IOException ex) {
                RuntimeException re = new RuntimeException();
                re.initCause(ex);
                throw re;
            }
        }
    });
    bsKeeper4.release();
    vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort4) {

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                CacheServer bs = c.addCacheServer();
                bs.setPort(bsPort4);
                bs.start();
            } catch (IOException ex) {
                RuntimeException re = new RuntimeException();
                re.initCause(ex);
                throw re;
            }
        }
    });
    // verify that locators know about each other
    vm0.invoke(new SerializableRunnable("Verify other locator on " + port2) {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            List others = ca.fetchControllers();
            assertEquals(1, others.size());
            {
                ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
                assertEquals(port2, cp.getPort());
                assertEquals("locator2HNFC", cp.getHost());
            }
            others = ca.fetchBridgeServers();
            assertEquals(4, others.size());
            for (int j = 0; j < others.size(); j++) {
                CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
                if (bsp.getPort() == bsPort1) {
                    assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort2) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort3) {
                    assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    vm3.invoke(new SerializableRunnable("Verify other locator on " + port1) {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            List others = ca.fetchControllers();
            assertEquals(1, others.size());
            {
                ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
                assertEquals(port1, cp.getPort());
            }
            others = ca.fetchBridgeServers();
            assertEquals(4, others.size());
            for (int j = 0; j < others.size(); j++) {
                CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
                if (bsp.getPort() == bsPort1) {
                    assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort2) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort3) {
                    assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    vm1.invoke(new SerializableRunnable("Verify bridge server view on " + bsPort1 + " and on " + bsPort3) {

        public void run() {
            Cache c = CacheFactory.getAnyInstance();
            List bslist = c.getCacheServers();
            assertEquals(2, bslist.size());
            for (int i = 0; i < bslist.size(); i++) {
                DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
                CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
                List others = bsa.fetchBridgeServers();
                LogWriterUtils.getLogWriter().info("found these bridgeservers in " + advisee + ": " + others);
                assertEquals(3, others.size());
                others = bsa.fetchControllers();
                assertEquals(2, others.size());
                for (int j = 0; j < others.size(); j++) {
                    ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
                    if (cp.getPort() == port1) {
                    // ok
                    } else if (cp.getPort() == port2) {
                        assertEquals("locator2HNFC", cp.getHost());
                    // ok
                    } else {
                        fail("unexpected port " + cp.getPort() + " in " + cp);
                    }
                }
            }
        }
    });
    vm2.invoke(new SerializableRunnable("Verify bridge server view on " + bsPort2 + " and on " + bsPort4) {

        public void run() {
            Cache c = CacheFactory.getAnyInstance();
            List bslist = c.getCacheServers();
            assertEquals(2, bslist.size());
            for (int i = 0; i < bslist.size(); i++) {
                DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
                CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
                List others = bsa.fetchBridgeServers();
                LogWriterUtils.getLogWriter().info("found these bridgeservers in " + advisee + ": " + others);
                assertEquals(3, others.size());
                others = bsa.fetchControllers();
                assertEquals(2, others.size());
                for (int j = 0; j < others.size(); j++) {
                    ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
                    if (cp.getPort() == port1) {
                    // ok
                    } else if (cp.getPort() == port2) {
                        assertEquals("locator2HNFC", cp.getHost());
                    // ok
                    } else {
                        fail("unexpected port " + cp.getPort() + " in " + cp);
                    }
                }
            }
        }
    });
    SerializableRunnable stopBS = new SerializableRunnable("stop bridge server") {

        public void run() {
            Cache c = CacheFactory.getAnyInstance();
            List bslist = c.getCacheServers();
            assertEquals(2, bslist.size());
            CacheServer bs = (CacheServer) bslist.get(0);
            bs.stop();
        }
    };
    vm1.invoke(stopBS);
    // now check to see if everyone else noticed him going away
    vm0.invoke(new SerializableRunnable("Verify other locator on " + port2) {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            List others = ca.fetchControllers();
            assertEquals(1, others.size());
            {
                ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
                assertEquals(port2, cp.getPort());
                assertEquals("locator2HNFC", cp.getHost());
            }
            others = ca.fetchBridgeServers();
            assertEquals(3, others.size());
            for (int j = 0; j < others.size(); j++) {
                CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
                if (bsp.getPort() == bsPort2) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort3) {
                    assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    vm3.invoke(new SerializableRunnable("Verify other locator on " + port1) {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            List others = ca.fetchControllers();
            assertEquals(1, others.size());
            {
                ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
                assertEquals(port1, cp.getPort());
            }
            others = ca.fetchBridgeServers();
            assertEquals(3, others.size());
            for (int j = 0; j < others.size(); j++) {
                CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
                if (bsp.getPort() == bsPort2) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort3) {
                    assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    SerializableRunnable disconnect = new SerializableRunnable("Disconnect from " + locators) {

        public void run() {
            InternalDistributedSystem.getAnyInstance().disconnect();
        }
    };
    SerializableRunnable stopLocator = new SerializableRunnable("Stop locator") {

        public void run() {
            assertTrue(Locator.hasLocator());
            Locator.getLocator().stop();
            assertFalse(Locator.hasLocator());
        }
    };
    vm0.invoke(stopLocator);
    // now make sure everyone else saw the locator go away
    vm3.invoke(new SerializableRunnable("Verify locator stopped ") {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            List others = ca.fetchControllers();
            assertEquals(0, others.size());
        }
    });
    vm2.invoke(new SerializableRunnable("Verify bridge server saw locator stop") {

        public void run() {
            Cache c = CacheFactory.getAnyInstance();
            List bslist = c.getCacheServers();
            assertEquals(2, bslist.size());
            for (int i = 0; i < bslist.size(); i++) {
                DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
                CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
                List others = bsa.fetchControllers();
                assertEquals(1, others.size());
                for (int j = 0; j < others.size(); j++) {
                    ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
                    if (cp.getPort() == port2) {
                        assertEquals("locator2HNFC", cp.getHost());
                    // ok
                    } else {
                        fail("unexpected port " + cp.getPort() + " in " + cp);
                    }
                }
            }
        }
    });
    vm1.invoke(new SerializableRunnable("Verify bridge server saw locator stop") {

        public void run() {
            Cache c = CacheFactory.getAnyInstance();
            List bslist = c.getCacheServers();
            assertEquals(2, bslist.size());
            for (int i = 0; i < bslist.size(); i++) {
                DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
                if (i == 0) {
                    // skip this one since it is stopped
                    continue;
                }
                CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
                List others = bsa.fetchControllers();
                assertEquals(1, others.size());
                for (int j = 0; j < others.size(); j++) {
                    ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
                    if (cp.getPort() == port2) {
                        assertEquals("locator2HNFC", cp.getHost());
                    // ok
                    } else {
                        fail("unexpected port " + cp.getPort() + " in " + cp);
                    }
                }
            }
        }
    });
    SerializableRunnable restartBS = new SerializableRunnable("restart bridge server") {

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                List bslist = c.getCacheServers();
                assertEquals(2, bslist.size());
                CacheServer bs = (CacheServer) bslist.get(0);
                bs.setHostnameForClients("nameForClients");
                bs.start();
            } catch (IOException ex) {
                RuntimeException re = new RuntimeException();
                re.initCause(ex);
                throw re;
            }
        }
    };
    // restart bridge server 1 and see if controller sees it
    vm1.invoke(restartBS);
    vm3.invoke(new SerializableRunnable("Verify bridge server restart ") {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            assertEquals(0, ca.fetchControllers().size());
            List others = ca.fetchBridgeServers();
            assertEquals(4, others.size());
            for (int j = 0; j < others.size(); j++) {
                CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
                if (bsp.getPort() == bsPort1) {
                    assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                    assertEquals("nameForClients", bsp.getHost());
                } else if (bsp.getPort() == bsPort2) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                    assertFalse(bsp.getHost().equals("nameForClients"));
                } else if (bsp.getPort() == bsPort3) {
                    assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    vm1.invoke(disconnect);
    vm2.invoke(disconnect);
    // now make sure controller saw all bridge servers stop
    vm3.invoke(new SerializableRunnable("Verify locator stopped ") {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            assertEquals(0, ca.fetchControllers().size());
            assertEquals(0, ca.fetchBridgeServers().size());
        }
    });
    vm3.invoke(stopLocator);
}
Also used : DistributionAdvisee(org.apache.geode.distributed.internal.DistributionAdvisee) Keeper(org.apache.geode.internal.AvailablePort.Keeper) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) VM(org.apache.geode.test.dunit.VM) CacheServer(org.apache.geode.cache.server.CacheServer) List(java.util.List) File(java.io.File) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 3 with DistributionAdvisee

use of org.apache.geode.distributed.internal.DistributionAdvisee in project geode by apache.

the class CreateRegionProcessor method getAdvice.

private Set getAdvice() {
    if (this.newRegion instanceof BucketRegion) {
        return ((Bucket) this.newRegion).getBucketAdvisor().adviseProfileExchange();
    } else {
        DistributionAdvisee rgn = this.newRegion.getParentAdvisee();
        DistributionAdvisor advisor = rgn.getDistributionAdvisor();
        return advisor.adviseGeneric();
    }
}
Also used : DistributionAdvisor(org.apache.geode.distributed.internal.DistributionAdvisor) DistributionAdvisee(org.apache.geode.distributed.internal.DistributionAdvisee)

Example 4 with DistributionAdvisee

use of org.apache.geode.distributed.internal.DistributionAdvisee in project geode by apache.

the class GemFireCacheImpl method addGatewaySender.

@Override
public void addGatewaySender(GatewaySender sender) {
    if (isClient()) {
        throw new UnsupportedOperationException("operation is not supported on a client cache");
    }
    this.stopper.checkCancelInProgress(null);
    synchronized (this.allGatewaySendersLock) {
        if (!this.allGatewaySenders.contains(sender)) {
            new UpdateAttributesProcessor((DistributionAdvisee) sender).distribute(true);
            Set<GatewaySender> newSenders = new HashSet<>(this.allGatewaySenders.size() + 1);
            if (!this.allGatewaySenders.isEmpty()) {
                newSenders.addAll(this.allGatewaySenders);
            }
            newSenders.add(sender);
            this.allGatewaySenders = Collections.unmodifiableSet(newSenders);
        } else {
            throw new IllegalStateException(LocalizedStrings.GemFireCache_A_GATEWAYSENDER_WITH_ID_0_IS_ALREADY_DEFINED_IN_THIS_CACHE.toLocalizedString(sender.getId()));
        }
    }
    synchronized (this.rootRegions) {
        Set<LocalRegion> applicationRegions = getApplicationRegions();
        for (LocalRegion region : applicationRegions) {
            Set<String> senders = region.getAllGatewaySenderIds();
            if (senders.contains(sender.getId()) && !sender.isParallel()) {
                region.senderCreated();
            }
        }
    }
    if (!sender.isParallel()) {
        Region dynamicMetaRegion = getRegion(DynamicRegionFactory.dynamicRegionListName);
        if (dynamicMetaRegion == null) {
            if (logger.isDebugEnabled()) {
                logger.debug(" The dynamic region is null. ");
            }
        } else {
            dynamicMetaRegion.getAttributesMutator().addGatewaySenderId(sender.getId());
        }
    }
    if (!(sender.getRemoteDSId() < 0)) {
        this.system.handleResourceEvent(ResourceEvent.GATEWAYSENDER_CREATE, sender);
    }
}
Also used : AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) GatewaySender(org.apache.geode.cache.wan.GatewaySender) DistributionAdvisee(org.apache.geode.distributed.internal.DistributionAdvisee) Region(org.apache.geode.cache.Region) HashSet(java.util.HashSet) ConcurrentHashSet(org.apache.geode.internal.concurrent.ConcurrentHashSet)

Example 5 with DistributionAdvisee

use of org.apache.geode.distributed.internal.DistributionAdvisee in project geode by apache.

the class GridAdvisorDUnitTest method test2by2.

/**
   * Tests 2 controllers and 2 bridge servers
   */
@Test
public void test2by2() throws Exception {
    disconnectAllFromDS();
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    List<Keeper> freeTCPPorts = AvailablePortHelper.getRandomAvailableTCPPortKeepers(6);
    final Keeper keeper1 = freeTCPPorts.get(0);
    final int port1 = keeper1.getPort();
    final Keeper keeper2 = freeTCPPorts.get(1);
    final int port2 = keeper2.getPort();
    final Keeper bsKeeper1 = freeTCPPorts.get(2);
    final int bsPort1 = bsKeeper1.getPort();
    final Keeper bsKeeper2 = freeTCPPorts.get(3);
    final int bsPort2 = bsKeeper2.getPort();
    final Keeper bsKeeper3 = freeTCPPorts.get(4);
    final int bsPort3 = bsKeeper3.getPort();
    final Keeper bsKeeper4 = freeTCPPorts.get(5);
    final int bsPort4 = bsKeeper4.getPort();
    final String host0 = NetworkUtils.getServerHostName(host);
    final String locators = host0 + "[" + port1 + "]" + "," + host0 + "[" + port2 + "]";
    final Properties dsProps = new Properties();
    dsProps.setProperty(LOCATORS, locators);
    dsProps.setProperty(MCAST_PORT, "0");
    dsProps.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
    dsProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
    keeper1.release();
    vm0.invoke(new SerializableRunnable("Start locator on " + port1) {

        public void run() {
            File logFile = new File(getUniqueName() + "-locator" + port1 + ".log");
            try {
                Locator.startLocatorAndDS(port1, logFile, null, dsProps, true, true, null);
            } catch (IOException ex) {
                Assert.fail("While starting locator on port " + port1, ex);
            }
        }
    });
    // try { Thread.currentThread().sleep(4000); } catch (InterruptedException ie) { }
    keeper2.release();
    vm3.invoke(new SerializableRunnable("Start locators on " + port2) {

        public void run() {
            File logFile = new File(getUniqueName() + "-locator" + port2 + ".log");
            try {
                Locator.startLocatorAndDS(port2, logFile, null, dsProps, true, true, "locator2HNFC");
            } catch (IOException ex) {
                Assert.fail("While starting locator on port " + port2, ex);
            }
        }
    });
    SerializableRunnable connect = new SerializableRunnable("Connect to " + locators) {

        public void run() {
            Properties props = new Properties();
            props.setProperty(MCAST_PORT, "0");
            props.setProperty(LOCATORS, locators);
            dsProps.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            CacheFactory.create(DistributedSystem.connect(props));
        }
    };
    vm1.invoke(connect);
    vm2.invoke(connect);
    SerializableRunnable startBS1 = new SerializableRunnable("start bridgeServer on " + bsPort1) {

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                CacheServer bs = c.addCacheServer();
                bs.setPort(bsPort1);
                bs.setGroups(new String[] { "bs1Group1", "bs1Group2" });
                bs.start();
            } catch (IOException ex) {
                RuntimeException re = new RuntimeException();
                re.initCause(ex);
                throw re;
            }
        }
    };
    SerializableRunnable startBS3 = new SerializableRunnable("start bridgeServer on " + bsPort3) {

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                CacheServer bs = c.addCacheServer();
                bs.setPort(bsPort3);
                bs.setGroups(new String[] { "bs3Group1", "bs3Group2" });
                bs.start();
            } catch (IOException ex) {
                RuntimeException re = new RuntimeException();
                re.initCause(ex);
                throw re;
            }
        }
    };
    bsKeeper1.release();
    vm1.invoke(startBS1);
    bsKeeper3.release();
    vm1.invoke(startBS3);
    bsKeeper2.release();
    vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort2) {

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                CacheServer bs = c.addCacheServer();
                bs.setPort(bsPort2);
                bs.setGroups(new String[] { "bs2Group1", "bs2Group2" });
                bs.start();
            } catch (IOException ex) {
                RuntimeException re = new RuntimeException();
                re.initCause(ex);
                throw re;
            }
        }
    });
    bsKeeper4.release();
    vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort4) {

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                CacheServer bs = c.addCacheServer();
                bs.setPort(bsPort4);
                bs.setGroups(new String[] { "bs4Group1", "bs4Group2" });
                bs.start();
            } catch (IOException ex) {
                RuntimeException re = new RuntimeException();
                re.initCause(ex);
                throw re;
            }
        }
    });
    // verify that locators know about each other
    vm0.invoke(new SerializableRunnable("Verify other locator on " + port2) {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            List others = ca.fetchControllers();
            assertEquals(1, others.size());
            {
                ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
                assertEquals(port2, cp.getPort());
                assertEquals("locator2HNFC", cp.getHost());
            }
            others = ca.fetchBridgeServers();
            assertEquals(4, others.size());
            for (int j = 0; j < others.size(); j++) {
                CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
                if (bsp.getPort() == bsPort1) {
                    assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort2) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort3) {
                    assertEquals(Arrays.asList(new String[] { "bs3Group1", "bs3Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs4Group1", "bs4Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    vm3.invoke(new SerializableRunnable("Verify other locator on " + port1) {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            List others = ca.fetchControllers();
            assertEquals(1, others.size());
            {
                ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
                assertEquals(port1, cp.getPort());
            }
            others = ca.fetchBridgeServers();
            assertEquals(4, others.size());
            for (int j = 0; j < others.size(); j++) {
                CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
                if (bsp.getPort() == bsPort1) {
                    assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort2) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort3) {
                    assertEquals(Arrays.asList(new String[] { "bs3Group1", "bs3Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs4Group1", "bs4Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    vm1.invoke(new SerializableRunnable("Verify bridge server view on " + bsPort1 + " and on " + bsPort3) {

        public void run() {
            Cache c = CacheFactory.getAnyInstance();
            List bslist = c.getCacheServers();
            assertEquals(2, bslist.size());
            for (int i = 0; i < bslist.size(); i++) {
                DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
                CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
                List others = bsa.fetchBridgeServers();
                LogWriterUtils.getLogWriter().info("found these bridgeservers in " + advisee + ": " + others);
                assertEquals(3, others.size());
                others = bsa.fetchControllers();
                assertEquals(2, others.size());
                for (int j = 0; j < others.size(); j++) {
                    ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
                    if (cp.getPort() == port1) {
                    // ok
                    } else if (cp.getPort() == port2) {
                        assertEquals("locator2HNFC", cp.getHost());
                    // ok
                    } else {
                        fail("unexpected port " + cp.getPort() + " in " + cp);
                    }
                }
            }
        }
    });
    vm2.invoke(new SerializableRunnable("Verify bridge server view on " + bsPort2 + " and on " + bsPort4) {

        public void run() {
            Cache c = CacheFactory.getAnyInstance();
            List bslist = c.getCacheServers();
            assertEquals(2, bslist.size());
            for (int i = 0; i < bslist.size(); i++) {
                DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
                CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
                List others = bsa.fetchBridgeServers();
                LogWriterUtils.getLogWriter().info("found these bridgeservers in " + advisee + ": " + others);
                assertEquals(3, others.size());
                others = bsa.fetchControllers();
                assertEquals(2, others.size());
                for (int j = 0; j < others.size(); j++) {
                    ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
                    if (cp.getPort() == port1) {
                    // ok
                    } else if (cp.getPort() == port2) {
                        assertEquals("locator2HNFC", cp.getHost());
                    // ok
                    } else {
                        fail("unexpected port " + cp.getPort() + " in " + cp);
                    }
                }
            }
        }
    });
    SerializableRunnable stopBS = new SerializableRunnable("stop bridge server") {

        public void run() {
            Cache c = CacheFactory.getAnyInstance();
            List bslist = c.getCacheServers();
            assertEquals(2, bslist.size());
            CacheServer bs = (CacheServer) bslist.get(0);
            bs.stop();
        }
    };
    vm1.invoke(stopBS);
    // now check to see if everyone else noticed him going away
    vm0.invoke(new SerializableRunnable("Verify other locator on " + port2) {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            List others = ca.fetchControllers();
            assertEquals(1, others.size());
            {
                ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
                assertEquals(port2, cp.getPort());
                assertEquals("locator2HNFC", cp.getHost());
            }
            others = ca.fetchBridgeServers();
            assertEquals(3, others.size());
            for (int j = 0; j < others.size(); j++) {
                CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
                if (bsp.getPort() == bsPort2) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort3) {
                    assertEquals(Arrays.asList(new String[] { "bs3Group1", "bs3Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs4Group1", "bs4Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    vm3.invoke(new SerializableRunnable("Verify other locator on " + port1) {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            List others = ca.fetchControllers();
            assertEquals(1, others.size());
            {
                ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(0);
                assertEquals(port1, cp.getPort());
            }
            others = ca.fetchBridgeServers();
            assertEquals(3, others.size());
            for (int j = 0; j < others.size(); j++) {
                CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
                if (bsp.getPort() == bsPort2) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort3) {
                    assertEquals(Arrays.asList(new String[] { "bs3Group1", "bs3Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs4Group1", "bs4Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    SerializableRunnable disconnect = new SerializableRunnable("Disconnect from " + locators) {

        public void run() {
            Properties props = new Properties();
            props.setProperty(MCAST_PORT, "0");
            props.setProperty(LOCATORS, locators);
            DistributedSystem.connect(props).disconnect();
        }
    };
    SerializableRunnable stopLocator = new SerializableRunnable("Stop locator") {

        public void run() {
            assertTrue(Locator.hasLocator());
            Locator.getLocator().stop();
            assertFalse(Locator.hasLocator());
        }
    };
    vm0.invoke(stopLocator);
    // now make sure everyone else saw the locator go away
    vm3.invoke(new SerializableRunnable("Verify locator stopped ") {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            List others = ca.fetchControllers();
            assertEquals(0, others.size());
        }
    });
    vm2.invoke(new SerializableRunnable("Verify bridge server saw locator stop") {

        public void run() {
            Cache c = CacheFactory.getAnyInstance();
            List bslist = c.getCacheServers();
            assertEquals(2, bslist.size());
            for (int i = 0; i < bslist.size(); i++) {
                DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
                CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
                List others = bsa.fetchControllers();
                assertEquals(1, others.size());
                for (int j = 0; j < others.size(); j++) {
                    ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
                    if (cp.getPort() == port2) {
                        assertEquals("locator2HNFC", cp.getHost());
                    // ok
                    } else {
                        fail("unexpected port " + cp.getPort() + " in " + cp);
                    }
                }
            }
        }
    });
    vm1.invoke(new SerializableRunnable("Verify bridge server saw locator stop") {

        public void run() {
            Cache c = CacheFactory.getAnyInstance();
            List bslist = c.getCacheServers();
            assertEquals(2, bslist.size());
            for (int i = 0; i < bslist.size(); i++) {
                DistributionAdvisee advisee = (DistributionAdvisee) bslist.get(i);
                if (i == 0) {
                    // skip this one since it is stopped
                    continue;
                }
                CacheServerAdvisor bsa = (CacheServerAdvisor) advisee.getDistributionAdvisor();
                List others = bsa.fetchControllers();
                assertEquals(1, others.size());
                for (int j = 0; j < others.size(); j++) {
                    ControllerAdvisor.ControllerProfile cp = (ControllerAdvisor.ControllerProfile) others.get(j);
                    if (cp.getPort() == port2) {
                        assertEquals("locator2HNFC", cp.getHost());
                    // ok
                    } else {
                        fail("unexpected port " + cp.getPort() + " in " + cp);
                    }
                }
            }
        }
    });
    SerializableRunnable restartBS = new SerializableRunnable("restart bridge server") {

        public void run() {
            try {
                Cache c = CacheFactory.getAnyInstance();
                List bslist = c.getCacheServers();
                assertEquals(2, bslist.size());
                CacheServer bs = (CacheServer) bslist.get(0);
                bs.setHostnameForClients("nameForClients");
                bs.start();
            } catch (IOException ex) {
                RuntimeException re = new RuntimeException();
                re.initCause(ex);
                throw re;
            }
        }
    };
    // restart bridge server 1 and see if controller sees it
    vm1.invoke(restartBS);
    vm3.invoke(new SerializableRunnable("Verify bridge server restart ") {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            assertEquals(0, ca.fetchControllers().size());
            List others = ca.fetchBridgeServers();
            assertEquals(4, others.size());
            for (int j = 0; j < others.size(); j++) {
                CacheServerAdvisor.CacheServerProfile bsp = (CacheServerAdvisor.CacheServerProfile) others.get(j);
                if (bsp.getPort() == bsPort1) {
                    assertEquals(Arrays.asList(new String[] { "bs1Group1", "bs1Group2" }), Arrays.asList(bsp.getGroups()));
                    assertEquals("nameForClients", bsp.getHost());
                } else if (bsp.getPort() == bsPort2) {
                    assertEquals(Arrays.asList(new String[] { "bs2Group1", "bs2Group2" }), Arrays.asList(bsp.getGroups()));
                    assertFalse(bsp.getHost().equals("nameForClients"));
                } else if (bsp.getPort() == bsPort3) {
                    assertEquals(Arrays.asList(new String[] { "bs3Group1", "bs3Group2" }), Arrays.asList(bsp.getGroups()));
                } else if (bsp.getPort() == bsPort4) {
                    assertEquals(Arrays.asList(new String[] { "bs4Group1", "bs4Group2" }), Arrays.asList(bsp.getGroups()));
                } else {
                    fail("unexpected port " + bsp.getPort() + " in " + bsp);
                }
            }
        }
    });
    vm1.invoke(disconnect);
    vm2.invoke(disconnect);
    // now make sure controller saw all bridge servers stop
    vm3.invoke(new SerializableRunnable("Verify locator stopped ") {

        public void run() {
            assertTrue(Locator.hasLocator());
            InternalLocator l = (InternalLocator) Locator.getLocator();
            DistributionAdvisee advisee = l.getServerLocatorAdvisee();
            ControllerAdvisor ca = (ControllerAdvisor) advisee.getDistributionAdvisor();
            assertEquals(0, ca.fetchControllers().size());
            assertEquals(0, ca.fetchBridgeServers().size());
        }
    });
    vm3.invoke(stopLocator);
}
Also used : DistributionAdvisee(org.apache.geode.distributed.internal.DistributionAdvisee) Keeper(org.apache.geode.internal.AvailablePort.Keeper) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) VM(org.apache.geode.test.dunit.VM) CacheServer(org.apache.geode.cache.server.CacheServer) List(java.util.List) File(java.io.File) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

DistributionAdvisee (org.apache.geode.distributed.internal.DistributionAdvisee)5 File (java.io.File)2 IOException (java.io.IOException)2 List (java.util.List)2 Properties (java.util.Properties)2 Cache (org.apache.geode.cache.Cache)2 CacheServer (org.apache.geode.cache.server.CacheServer)2 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)2 InternalLocator (org.apache.geode.distributed.internal.InternalLocator)2 Keeper (org.apache.geode.internal.AvailablePort.Keeper)2 Host (org.apache.geode.test.dunit.Host)2 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)2 VM (org.apache.geode.test.dunit.VM)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Region (org.apache.geode.cache.Region)1 GatewaySender (org.apache.geode.cache.wan.GatewaySender)1 DistributionAdvisor (org.apache.geode.distributed.internal.DistributionAdvisor)1