Search in sources :

Example 6 with RemoteTransportConfig

use of org.apache.geode.internal.admin.remote.RemoteTransportConfig in project geode by apache.

the class GMSMembershipManagerJUnitTest method initMocks.

@Before
public void initMocks() throws Exception {
    Properties nonDefault = new Properties();
    nonDefault.put(ACK_WAIT_THRESHOLD, "1");
    nonDefault.put(ACK_SEVERE_ALERT_THRESHOLD, "10");
    nonDefault.put(DISABLE_TCP, "true");
    nonDefault.put(MCAST_PORT, "0");
    nonDefault.put(MCAST_TTL, "0");
    nonDefault.put(LOG_FILE, "");
    nonDefault.put(LOG_LEVEL, "fine");
    nonDefault.put(MEMBER_TIMEOUT, "2000");
    nonDefault.put(LOCATORS, "localhost[10344]");
    distConfig = new DistributionConfigImpl(nonDefault);
    distProperties = nonDefault;
    RemoteTransportConfig tconfig = new RemoteTransportConfig(distConfig, DistributionManager.NORMAL_DM_TYPE);
    mockConfig = mock(ServiceConfig.class);
    when(mockConfig.getDistributionConfig()).thenReturn(distConfig);
    when(mockConfig.getTransport()).thenReturn(tconfig);
    authenticator = mock(Authenticator.class);
    myMemberId = new InternalDistributedMember("localhost", 8887);
    messenger = mock(Messenger.class);
    when(messenger.getMemberID()).thenReturn(myMemberId);
    stopper = mock(Stopper.class);
    when(stopper.isCancelInProgress()).thenReturn(false);
    healthMonitor = mock(HealthMonitor.class);
    when(healthMonitor.getFailureDetectionPort()).thenReturn(Integer.valueOf(-1));
    joinLeave = mock(JoinLeave.class);
    services = mock(Services.class);
    when(services.getAuthenticator()).thenReturn(authenticator);
    when(services.getConfig()).thenReturn(mockConfig);
    when(services.getMessenger()).thenReturn(messenger);
    when(services.getCancelCriterion()).thenReturn(stopper);
    when(services.getHealthMonitor()).thenReturn(healthMonitor);
    when(services.getJoinLeave()).thenReturn(joinLeave);
    Timer t = new Timer(true);
    when(services.getTimer()).thenReturn(t);
    Random r = new Random();
    mockMembers = new InternalDistributedMember[5];
    for (int i = 0; i < mockMembers.length; i++) {
        mockMembers[i] = new InternalDistributedMember("localhost", 8888 + i);
        GMSMember m = (GMSMember) mockMembers[i].getNetMember();
        UUID uuid = new UUID(r.nextLong(), r.nextLong());
        m.setUUID(uuid);
    }
    members = new ArrayList<>(Arrays.asList(mockMembers));
    listener = mock(DistributedMembershipListener.class);
    manager = new GMSMembershipManager(listener);
    manager.init(services);
    when(services.getManager()).thenReturn(manager);
}
Also used : JoinLeave(org.apache.geode.distributed.internal.membership.gms.interfaces.JoinLeave) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember) HealthMonitor(org.apache.geode.distributed.internal.membership.gms.interfaces.HealthMonitor) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig) Messenger(org.apache.geode.distributed.internal.membership.gms.interfaces.Messenger) DistributedMembershipListener(org.apache.geode.distributed.internal.membership.DistributedMembershipListener) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Services(org.apache.geode.distributed.internal.membership.gms.Services) Stopper(org.apache.geode.distributed.internal.membership.gms.Services.Stopper) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Timer(java.util.Timer) Random(java.util.Random) ServiceConfig(org.apache.geode.distributed.internal.membership.gms.ServiceConfig) DistributionConfigImpl(org.apache.geode.distributed.internal.DistributionConfigImpl) UUID(org.jgroups.util.UUID) Authenticator(org.apache.geode.distributed.internal.membership.gms.interfaces.Authenticator) Before(org.junit.Before)

Example 7 with RemoteTransportConfig

use of org.apache.geode.internal.admin.remote.RemoteTransportConfig in project geode by apache.

the class MembershipJUnitTest method testLocatorAndTwoServersJoinUsingDiffeHellman.

/**
   * This test ensures that secure communications are enabled.
   *
   * This test creates a locator with a colocated membership manager and then creates a second
   * manager that joins the system of the first.
   *
   * It then makes assertions about the state of the membership view, closes one of the managers and
   * makes more assertions.
   */
@Test
public void testLocatorAndTwoServersJoinUsingDiffeHellman() throws Exception {
    MembershipManager m1 = null, m2 = null;
    Locator l = null;
    int mcastPort = AvailablePortHelper.getRandomAvailableUDPPort();
    try {
        // boot up a locator
        int port = AvailablePortHelper.getRandomAvailableTCPPort();
        InetAddress localHost = SocketCreator.getLocalHost();
        Properties p = new Properties();
        p.setProperty(ConfigurationProperties.SECURITY_UDP_DHALGO, "AES:128");
        // this locator will hook itself up with the first MembershipManager
        // to be created
        l = InternalLocator.startLocator(port, new File(""), null, null, null, localHost, false, p, null);
        // create configuration objects
        Properties nonDefault = new Properties();
        nonDefault.put(DistributionConfig.DISABLE_TCP_NAME, "true");
        nonDefault.put(DistributionConfig.MCAST_PORT_NAME, String.valueOf(mcastPort));
        nonDefault.put(DistributionConfig.LOG_FILE_NAME, "");
        nonDefault.put(DistributionConfig.LOG_LEVEL_NAME, "fine");
        nonDefault.put(DistributionConfig.GROUPS_NAME, "red, blue");
        nonDefault.put(DistributionConfig.MEMBER_TIMEOUT_NAME, "2000");
        nonDefault.put(DistributionConfig.LOCATORS_NAME, localHost.getHostName() + '[' + port + ']');
        nonDefault.put(ConfigurationProperties.SECURITY_UDP_DHALGO, "AES:128");
        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;
                }
            }
        }
        System.out.println("testing multicast availability");
        assertTrue(m1.testMulticast());
        System.out.println("multicasting SerialAckedMessage from m1 to m2");
        SerialAckedMessage msg = new SerialAckedMessage();
        msg.setRecipient(m2.getLocalMember());
        msg.setMulticast(true);
        m1.send(new InternalDistributedMember[] { m2.getLocalMember() }, msg, null);
        giveUp = System.currentTimeMillis() + 5000;
        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) {
            if (problem != null) {
                problem.printStackTrace();
            }
            fail("Expected a multicast message to be received");
        }
        // 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);
    } 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) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 8 with RemoteTransportConfig

use of org.apache.geode.internal.admin.remote.RemoteTransportConfig in project geode by apache.

the class MembershipJUnitTest method testJoinTimeoutSetting.

@Test
public void testJoinTimeoutSetting() throws Exception {
    long timeout = 30000;
    Properties nonDefault = new Properties();
    nonDefault.put(MEMBER_TIMEOUT, "" + timeout);
    DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
    RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
    ServiceConfig sc = new ServiceConfig(transport, config);
    assertEquals(2 * timeout + ServiceConfig.MEMBER_REQUEST_COLLECTION_INTERVAL, sc.getJoinTimeout());
    nonDefault.clear();
    config = new DistributionConfigImpl(nonDefault);
    transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
    sc = new ServiceConfig(transport, config);
    assertEquals(24000, sc.getJoinTimeout());
    nonDefault.clear();
    nonDefault.put(LOCATORS, SocketCreator.getLocalHost().getHostAddress() + "[" + 12345 + "]");
    config = new DistributionConfigImpl(nonDefault);
    transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
    sc = new ServiceConfig(transport, config);
    assertEquals(60000, sc.getJoinTimeout());
    timeout = 2000;
    System.setProperty("p2p.joinTimeout", "" + timeout);
    try {
        config = new DistributionConfigImpl(nonDefault);
        transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
        sc = new ServiceConfig(transport, config);
        assertEquals(timeout, sc.getJoinTimeout());
    } finally {
        System.getProperties().remove("p2p.joinTimeout");
    }
}
Also used : ServiceConfig(org.apache.geode.distributed.internal.membership.gms.ServiceConfig) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 9 with RemoteTransportConfig

use of org.apache.geode.internal.admin.remote.RemoteTransportConfig in project geode by apache.

the class ConsoleDistributionManagerDUnitTest method postSetUp.

@Override
public final void postSetUp() throws Exception {
    boolean finishedSetup = false;
    IgnoredException.addIgnoredException("Error occurred while reading system log");
    try {
        if (firstTime) {
            // make sure there's no ldm lying around
            disconnectFromDS();
            try {
                Thread.sleep(5 * 1000);
            } catch (InterruptedException ie) {
                fail("interrupted");
            }
            firstTime = false;
        }
        DistributionManager.isDedicatedAdminVM = true;
        populateCache();
        RemoteTransportConfig transport = null;
        {
            boolean created = !isConnectedToDS();
            InternalDistributedSystem ds = getSystem();
            transport = new RemoteTransportConfig(ds.getConfig(), DistributionManager.ADMIN_ONLY_DM_TYPE);
            if (created) {
                disconnectFromDS();
            }
        }
        // create a GfManagerAgent in the master vm.
        this.agent = GfManagerAgentFactory.getManagerAgent(new GfManagerAgentConfig(null, transport, LogWriterUtils.getLogWriter(), Alert.SEVERE, this, null));
        if (!agent.isConnected()) {
            WaitCriterion ev = new WaitCriterion() {

                public boolean done() {
                    return agent.isConnected();
                }

                public String description() {
                    return null;
                }
            };
            Wait.waitForCriterion(ev, 60 * 1000, 200, true);
        }
        finishedSetup = true;
    } finally {
        if (!finishedSetup) {
            try {
                this.agent.disconnect();
            } catch (VirtualMachineError e) {
                SystemFailure.initiateFailure(e);
                throw e;
            } catch (Throwable ignore) {
            }
            try {
                super.preTearDown();
            } catch (VirtualMachineError e) {
                SystemFailure.initiateFailure(e);
                throw e;
            } catch (Throwable ignore) {
            }
            try {
                disconnectFromDS();
            } catch (VirtualMachineError e) {
                SystemFailure.initiateFailure(e);
                throw e;
            } catch (Throwable ignore) {
            }
            DistributionManager.isDedicatedAdminVM = false;
        }
    }
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) GfManagerAgentConfig(org.apache.geode.internal.admin.GfManagerAgentConfig) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig)

Example 10 with RemoteTransportConfig

use of org.apache.geode.internal.admin.remote.RemoteTransportConfig in project geode by apache.

the class DistributionManager method create.

/**
   * Creates a new distribution manager and discovers the other members of the distributed system.
   * Note that it does not check to see whether or not this VM already has a distribution manager.
   * 
   * @param system The distributed system to which this distribution manager will send messages.
   */
public static DistributionManager create(InternalDistributedSystem system) {
    DistributionManager distributionManager = null;
    try {
        int vmKind;
        if (Boolean.getBoolean(InternalLocator.FORCE_LOCATOR_DM_TYPE)) {
            // if this DM is starting for a locator, set it to be a locator DM
            vmKind = LOCATOR_DM_TYPE;
        } else if (isDedicatedAdminVM) {
            vmKind = ADMIN_ONLY_DM_TYPE;
        } else {
            vmKind = NORMAL_DM_TYPE;
        }
        RemoteTransportConfig transport = new RemoteTransportConfig(system.getConfig(), vmKind);
        transport.setIsReconnectingDS(system.isReconnectingDS());
        transport.setOldDSMembershipInfo(system.oldDSMembershipInfo());
        long start = System.currentTimeMillis();
        distributionManager = new DistributionManager(system, transport);
        distributionManager.assertDistributionManagerType();
        {
            InternalDistributedMember id = distributionManager.getDistributionManagerId();
            if (!"".equals(id.getName())) {
                for (InternalDistributedMember m : (List<InternalDistributedMember>) distributionManager.getViewMembers()) {
                    if (m.equals(id)) {
                        // SO once we find ourself break out of this loop.
                        break;
                    }
                    if (id.getName().equals(m.getName())) {
                        if (distributionManager.getMembershipManager().verifyMember(m, "member is using the name of " + id)) {
                            throw new IncompatibleSystemException("Member " + id + " could not join this distributed system because the existing member " + m + " used the same name. Set the \"name\" gemfire property to a unique value.");
                        }
                    }
                }
            }
            // add ourselves
            distributionManager.addNewMember(id);
            // ShutdownException could be thrown here
            distributionManager.selectElder();
        }
        // Send out a StartupMessage to the other members.
        StartupOperation op = new StartupOperation(distributionManager, transport);
        try {
            if (!distributionManager.sendStartupMessage(op, true)) {
                // we're the first one.
                if (distributionManager.getOtherDistributionManagerIds().size() == 0) {
                    logger.info(LocalizedMessage.create(LocalizedStrings.DistributionManager_DIDNT_HEAR_BACK_FROM_ANY_OTHER_SYSTEM_I_AM_THE_FIRST_ONE));
                } else if (transport.isMcastEnabled()) {
                    // perform a multicast ping test
                    if (!distributionManager.testMulticast()) {
                        logger.warn(LocalizedMessage.create(LocalizedStrings.DistributionManager_RECEIVED_NO_STARTUP_RESPONSES_BUT_OTHER_MEMBERS_EXIST_MULTICAST_IS_NOT_RESPONSIVE));
                    }
                }
            }
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
            // This is ALWAYS bad; don't consult a CancelCriterion.
            throw new InternalGemFireException(LocalizedStrings.DistributionManager_INTERRUPTED_WHILE_WAITING_FOR_FIRST_STARTUPRESPONSEMESSAGE.toLocalizedString(), ex);
        } catch (IncompatibleSystemException ex) {
            logger.fatal(ex.getMessage(), ex);
            throw ex;
        } finally {
            distributionManager.readyToSendMsgs();
        }
        if (logger.isInfoEnabled()) {
            long delta = System.currentTimeMillis() - start;
            Object[] logArgs = new Object[] { distributionManager.getDistributionManagerId(), transport, Integer.valueOf(distributionManager.getOtherDistributionManagerIds().size()), distributionManager.getOtherDistributionManagerIds(), (logger.isInfoEnabled(LogMarker.DM) ? " (VERBOSE, took " + delta + " ms)" : ""), ((distributionManager.getDMType() == ADMIN_ONLY_DM_TYPE) ? " (admin only)" : (distributionManager.getDMType() == LOCATOR_DM_TYPE) ? " (locator)" : "") };
            logger.info(LogMarker.DM, LocalizedMessage.create(LocalizedStrings.DistributionManager_DISTRIBUTIONMANAGER_0_STARTED_ON_1_THERE_WERE_2_OTHER_DMS_3_4_5, logArgs));
            MembershipLogger.logStartup(distributionManager.getDistributionManagerId());
        }
        return distributionManager;
    } catch (RuntimeException r) {
        if (distributionManager != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("cleaning up incompletely started DistributionManager due to exception", r);
            }
            distributionManager.uncleanShutdown(true);
        }
        throw r;
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalGemFireException(org.apache.geode.InternalGemFireException) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig) IncompatibleSystemException(org.apache.geode.IncompatibleSystemException)

Aggregations

RemoteTransportConfig (org.apache.geode.internal.admin.remote.RemoteTransportConfig)13 Properties (java.util.Properties)9 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)8 ServiceConfig (org.apache.geode.distributed.internal.membership.gms.ServiceConfig)6 Services (org.apache.geode.distributed.internal.membership.gms.Services)5 Test (org.junit.Test)5 DistributionConfigImpl (org.apache.geode.distributed.internal.DistributionConfigImpl)4 JoinLeave (org.apache.geode.distributed.internal.membership.gms.interfaces.JoinLeave)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 File (java.io.File)3 InetAddress (java.net.InetAddress)3 Locator (org.apache.geode.distributed.Locator)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 GMSJoinLeave (org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave)3 GemFireConfigException (org.apache.geode.GemFireConfigException)2 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)2 DistributedMembershipListener (org.apache.geode.distributed.internal.membership.DistributedMembershipListener)2 Stopper (org.apache.geode.distributed.internal.membership.gms.Services.Stopper)2 HealthMonitor (org.apache.geode.distributed.internal.membership.gms.interfaces.HealthMonitor)2 GMSMembershipManager (org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager)2