Search in sources :

Example 1 with Locator

use of org.apache.geode.distributed.Locator in project geode by apache.

the class ManagementAdapter method handleCacheCreation.

/**
   * Adapter life cycle is tied with the Cache . So its better to make all cache level artifacts as
   * instance variable
   *
   * @param cache gemfire cache
   */
public void handleCacheCreation(InternalCache cache) throws ManagementException {
    try {
        this.internalCache = cache;
        this.service = (SystemManagementService) ManagementService.getManagementService(internalCache);
        this.memberMBeanBridge = new MemberMBeanBridge(internalCache, service).init();
        this.memberBean = new MemberMBean(memberMBeanBridge);
        this.memberLevelNotifEmitter = memberBean;
        ObjectName memberMBeanName = MBeanJMXAdapter.getMemberMBeanName(InternalDistributedSystem.getConnectedInstance().getDistributedMember());
        memberSource = MBeanJMXAdapter.getMemberNameOrId(internalCache.getDistributedSystem().getDistributedMember());
        // Type casting to MemberMXBean to expose only those methods described in
        // the interface;
        ObjectName changedMBeanName = service.registerInternalMBean((MemberMXBean) memberBean, memberMBeanName);
        service.federate(changedMBeanName, MemberMXBean.class, true);
        this.serviceInitialised = true;
        // For situations where locator is created before any cache is created
        if (InternalLocator.hasLocator()) {
            Locator loc = InternalLocator.getLocator();
            handleLocatorStart(loc);
        }
        if (cache.getInternalDistributedSystem().getConfig().getJmxManager()) {
            this.service.createManager();
            if (cache.getInternalDistributedSystem().getConfig().getJmxManagerStart()) {
                this.service.startManager();
            }
        }
    } finally {
        if (!serviceInitialised && service != null) {
            service.close();
            if (logger.isDebugEnabled()) {
                logger.debug("Management Service Could not initialise hence closing");
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Management Service is initialised and Running");
            }
        }
    }
}
Also used : Locator(org.apache.geode.distributed.Locator) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) ObjectName(javax.management.ObjectName)

Example 2 with Locator

use of org.apache.geode.distributed.Locator in project geode by apache.

the class WANBootStrapping_Site1_Remove method main.

public static void main(String[] args) {
    // On this locator, I am not expecting a listener to take any action, so a empty listener is a
    // passed
    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "DistributedSystemListener", "");
    System.out.println("Starting a locator with negative ds id -1");
    // start a stand alone locator with distributed-system-is = -1
    Properties properties = new Properties();
    properties.setProperty(MCAST_PORT, "0");
    properties.setProperty(DISTRIBUTED_SYSTEM_ID, "" + (-1));
    properties.setProperty(REMOTE_LOCATORS, "localhost[" + 20202 + "]");
    properties.setProperty(LOG_LEVEL, "warning");
    Locator locator = null;
    try {
        locator = Locator.startLocatorAndDS(40445, null, properties);
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    // stop locator
    System.out.println("Stoping locator");
    locator.stop();
    System.out.println("Locator stopped ");
    System.exit(0);
}
Also used : Locator(org.apache.geode.distributed.Locator) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties)

Example 3 with Locator

use of org.apache.geode.distributed.Locator in project geode by apache.

the class WANBootStrapping_Site2_Remove method main.

public static void main(String[] args) {
    // On this locator, I am not expecting a listener to take any action, so a
    // empty listener is a passed
    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "DistributedSystemListener", "");
    System.out.println("Starting a locator with negative ds id -2");
    Properties properties = new Properties();
    properties.setProperty(MCAST_PORT, "0");
    properties.setProperty(DISTRIBUTED_SYSTEM_ID, "" + (-2));
    properties.setProperty(REMOTE_LOCATORS, "localhost[" + 10101 + "]");
    properties.setProperty(LOG_LEVEL, "warning");
    Locator locator = null;
    try {
        locator = Locator.startLocatorAndDS(30445, null, properties);
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    System.out.println("Stoping locator");
    locator.stop();
    System.out.println("Locator stopped ");
    System.exit(0);
}
Also used : Locator(org.apache.geode.distributed.Locator) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties)

Example 4 with Locator

use of org.apache.geode.distributed.Locator in project geode by apache.

the class LocatorTestBase method preTearDown.

@Override
public final void preTearDown() throws Exception {
    SerializableRunnable tearDown = new SerializableRunnable("tearDown") {

        public void run() {
            Locator locator = (Locator) remoteObjects.get(LOCATOR_KEY);
            if (locator != null) {
                try {
                    locator.stop();
                } catch (Exception e) {
                // do nothing
                }
            }
            Cache cache = (Cache) remoteObjects.get(CACHE_KEY);
            if (cache != null) {
                try {
                    cache.close();
                } catch (Exception e) {
                // do nothing
                }
            }
            remoteObjects.clear();
        }
    };
    // We seem to like leaving the DS open if we can for
    // speed, but lets at least destroy our cache and locator.
    Invoke.invokeInEveryVM(tearDown);
    tearDown.run();
    postTearDownLocatorTestBase();
}
Also used : Locator(org.apache.geode.distributed.Locator) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Cache(org.apache.geode.cache.Cache)

Example 5 with Locator

use of org.apache.geode.distributed.Locator in project geode by apache.

the class MembershipJUnitTest method doTestMultipleManagersInSameProcessWithGroups.

/**
   * this runs the test with a given set of member groups. Returns the groups of the member that was
   * not the coordinator for verification that they were correctly transmitted
   */
private List<String> doTestMultipleManagersInSameProcessWithGroups(String groups) throws Exception {
    MembershipManager m1 = null, m2 = null;
    Locator l = null;
    try {
        // boot up a locator
        int port = AvailablePortHelper.getRandomAvailableTCPPort();
        InetAddress localHost = SocketCreator.getLocalHost();
        // this locator will hook itself up with the first MembershipManager
        // to be created
        l = InternalLocator.startLocator(port, new File(""), null, null, null, localHost, false, new Properties(), null);
        // create configuration objects
        Properties nonDefault = new Properties();
        nonDefault.put(DISABLE_TCP, "true");
        nonDefault.put(MCAST_PORT, "0");
        nonDefault.put(LOG_FILE, "");
        nonDefault.put(LOG_LEVEL, "fine");
        nonDefault.put(GROUPS, groups);
        nonDefault.put(MEMBER_TIMEOUT, "2000");
        nonDefault.put(LOCATORS, localHost.getHostName() + '[' + port + ']');
        DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
        RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
        // start the first membership manager
        try {
            System.setProperty(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY, "true");
            DistributedMembershipListener listener1 = mock(DistributedMembershipListener.class);
            DMStats stats1 = mock(DMStats.class);
            System.out.println("creating 1st membership manager");
            m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1);
            m1.startEventProcessing();
        } finally {
            System.getProperties().remove(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY);
        }
        // start the second membership manager
        DistributedMembershipListener listener2 = mock(DistributedMembershipListener.class);
        DMStats stats2 = mock(DMStats.class);
        System.out.println("creating 2nd membership manager");
        m2 = MemberFactory.newMembershipManager(listener2, config, transport, stats2);
        m2.startEventProcessing();
        // we have to check the views with JoinLeave because the membership
        // manager queues new views for processing through the DM listener,
        // which is a mock object in this test
        System.out.println("waiting for views to stabilize");
        JoinLeave jl1 = ((GMSMembershipManager) m1).getServices().getJoinLeave();
        JoinLeave jl2 = ((GMSMembershipManager) m2).getServices().getJoinLeave();
        long giveUp = System.currentTimeMillis() + 15000;
        for (; ; ) {
            try {
                assertTrue("view = " + jl2.getView(), jl2.getView().size() == 2);
                assertTrue("view = " + jl1.getView(), jl1.getView().size() == 2);
                assertTrue(jl1.getView().getCreator().equals(jl2.getView().getCreator()));
                assertTrue(jl1.getView().getViewId() == jl2.getView().getViewId());
                break;
            } catch (AssertionError e) {
                if (System.currentTimeMillis() > giveUp) {
                    throw e;
                }
            }
        }
        NetView view = jl1.getView();
        InternalDistributedMember notCreator;
        if (view.getCreator().equals(jl1.getMemberID())) {
            notCreator = view.getMembers().get(1);
        } else {
            notCreator = view.getMembers().get(0);
        }
        List<String> result = notCreator.getGroups();
        System.out.println("sending SerialAckedMessage from m1 to m2");
        SerialAckedMessage msg = new SerialAckedMessage();
        msg.setRecipient(m2.getLocalMember());
        msg.setMulticast(false);
        m1.send(new InternalDistributedMember[] { m2.getLocalMember() }, msg, null);
        giveUp = System.currentTimeMillis() + 15000;
        boolean verified = false;
        Throwable problem = null;
        while (giveUp > System.currentTimeMillis()) {
            try {
                verify(listener2).messageReceived(isA(SerialAckedMessage.class));
                verified = true;
                break;
            } catch (Error e) {
                problem = e;
                Thread.sleep(500);
            }
        }
        if (!verified) {
            AssertionError error = new AssertionError("Expected a message to be received");
            if (problem != null) {
                error.initCause(error);
            }
            throw error;
        }
        // let the managers idle for a while and get used to each other
        // Thread.sleep(4000l);
        m2.shutdown();
        assertTrue(!m2.isConnected());
        assertTrue(m1.getView().size() == 1);
        return result;
    } finally {
        if (m2 != null) {
            m2.shutdown();
        }
        if (m1 != null) {
            m1.shutdown();
        }
        if (l != null) {
            l.stop();
        }
    }
}
Also used : GMSJoinLeave(org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave) JoinLeave(org.apache.geode.distributed.internal.membership.gms.interfaces.JoinLeave) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Locator(org.apache.geode.distributed.Locator) GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) InetAddress(java.net.InetAddress) File(java.io.File)

Aggregations

Locator (org.apache.geode.distributed.Locator)23 Properties (java.util.Properties)13 InternalLocator (org.apache.geode.distributed.internal.InternalLocator)10 File (java.io.File)9 IOException (java.io.IOException)8 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)8 InetAddress (java.net.InetAddress)7 Test (org.junit.Test)5 UnknownHostException (java.net.UnknownHostException)4 Set (java.util.Set)4 RemoteTransportConfig (org.apache.geode.internal.admin.remote.RemoteTransportConfig)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ConcurrentSkipListSet (java.util.concurrent.ConcurrentSkipListSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DiskStore (org.apache.geode.cache.DiskStore)2