Search in sources :

Example 11 with RemoteTransportConfig

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

the class JGroupsMessenger method init.

@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
public void init(Services s) {
    this.services = s;
    RemoteTransportConfig transport = services.getConfig().getTransport();
    DistributionConfig dc = services.getConfig().getDistributionConfig();
    boolean b = dc.getEnableNetworkPartitionDetection();
    System.setProperty("jgroups.resolve_dns", String.valueOf(!b));
    InputStream is;
    String r;
    if (transport.isMcastEnabled()) {
        r = JGROUPS_MCAST_CONFIG_FILE_NAME;
    } else {
        r = DEFAULT_JGROUPS_TCP_CONFIG;
    }
    is = ClassPathLoader.getLatest().getResourceAsStream(getClass(), r);
    if (is == null) {
        throw new GemFireConfigException(LocalizedStrings.GroupMembershipService_CANNOT_FIND_0.toLocalizedString(r));
    }
    String properties;
    try {
        // PlainConfigurator config = PlainConfigurator.getInstance(is);
        // properties = config.getProtocolStackString();
        StringBuilder sb = new StringBuilder(3000);
        BufferedReader br;
        br = new BufferedReader(new InputStreamReader(is, "US-ASCII"));
        String input;
        while ((input = br.readLine()) != null) {
            sb.append(input);
        }
        br.close();
        properties = sb.toString();
    } catch (Exception ex) {
        throw new GemFireConfigException(LocalizedStrings.GroupMembershipService_AN_EXCEPTION_WAS_THROWN_WHILE_READING_JGROUPS_CONFIG.toLocalizedString(), ex);
    }
    if (properties.startsWith("<!--")) {
        int commentEnd = properties.indexOf("-->");
        properties = properties.substring(commentEnd + 3);
    }
    if (transport.isMcastEnabled()) {
        properties = replaceStrings(properties, "MCAST_PORT", String.valueOf(transport.getMcastId().getPort()));
        properties = replaceStrings(properties, "MCAST_ADDRESS", dc.getMcastAddress().getHostAddress());
        properties = replaceStrings(properties, "MCAST_TTL", String.valueOf(dc.getMcastTtl()));
        properties = replaceStrings(properties, "MCAST_SEND_BUFFER_SIZE", String.valueOf(dc.getMcastSendBufferSize()));
        properties = replaceStrings(properties, "MCAST_RECV_BUFFER_SIZE", String.valueOf(dc.getMcastRecvBufferSize()));
        properties = replaceStrings(properties, "MCAST_RETRANSMIT_INTERVAL", "" + Integer.getInteger(DistributionConfig.GEMFIRE_PREFIX + "mcast-retransmit-interval", 500));
        properties = replaceStrings(properties, "RETRANSMIT_LIMIT", String.valueOf(dc.getUdpFragmentSize() - 256));
    }
    if (transport.isMcastEnabled() || transport.isTcpDisabled() || (dc.getUdpRecvBufferSize() != DistributionConfig.DEFAULT_UDP_RECV_BUFFER_SIZE)) {
        properties = replaceStrings(properties, "UDP_RECV_BUFFER_SIZE", "" + dc.getUdpRecvBufferSize());
    } else {
        properties = replaceStrings(properties, "UDP_RECV_BUFFER_SIZE", "" + DistributionConfig.DEFAULT_UDP_RECV_BUFFER_SIZE_REDUCED);
    }
    properties = replaceStrings(properties, "UDP_SEND_BUFFER_SIZE", "" + dc.getUdpSendBufferSize());
    String str = transport.getBindAddress();
    // JGroups UDP protocol requires a bind address
    if (str == null || str.length() == 0) {
        try {
            str = SocketCreator.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            throw new GemFireConfigException(e.getMessage(), e);
        }
    }
    properties = replaceStrings(properties, "BIND_ADDR_SETTING", "bind_addr=\"" + str + "\"");
    int port = Integer.getInteger(DistributionConfig.GEMFIRE_PREFIX + "jg-bind-port", 0);
    if (port != 0) {
        properties = replaceStrings(properties, "MEMBERSHIP_PORT_RANGE_START", "" + port);
        properties = replaceStrings(properties, "MEMBERSHIP_PORT_RANGE", "" + 0);
    } else {
        int[] ports = dc.getMembershipPortRange();
        properties = replaceStrings(properties, "MEMBERSHIP_PORT_RANGE_START", "" + ports[0]);
        properties = replaceStrings(properties, "MEMBERSHIP_PORT_RANGE", "" + (ports[1] - ports[0]));
    }
    properties = replaceStrings(properties, "UDP_FRAGMENT_SIZE", "" + dc.getUdpFragmentSize());
    properties = replaceStrings(properties, "FC_MAX_CREDITS", "" + dc.getMcastFlowControl().getByteAllowance());
    properties = replaceStrings(properties, "FC_THRESHOLD", "" + dc.getMcastFlowControl().getRechargeThreshold());
    properties = replaceStrings(properties, "FC_MAX_BLOCK", "" + dc.getMcastFlowControl().getRechargeBlockMs());
    this.jgStackConfig = properties;
    if (!dc.getSecurityUDPDHAlgo().isEmpty()) {
        try {
            this.encrypt = new GMSEncrypt(services);
            logger.info("Initializing GMSEncrypt ");
        } catch (Exception e) {
            throw new GemFireConfigException("problem initializing encryption protocol", e);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) UnknownHostException(java.net.UnknownHostException) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig) MemberShunnedException(org.apache.geode.internal.tcp.MemberShunnedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GemFireIOException(org.apache.geode.GemFireIOException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) GemFireConfigException(org.apache.geode.GemFireConfigException) BufferedReader(java.io.BufferedReader)

Example 12 with RemoteTransportConfig

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

the class GMSMembershipManager method init.

@Override
public void init(Services services) {
    this.services = services;
    Assert.assertTrue(services != null);
    DistributionConfig config = services.getConfig().getDistributionConfig();
    RemoteTransportConfig transport = services.getConfig().getTransport();
    this.membershipCheckTimeout = config.getSecurityPeerMembershipTimeout();
    this.wasReconnectingSystem = transport.getIsReconnectingDS();
    // cache these settings for use in send()
    this.mcastEnabled = transport.isMcastEnabled();
    this.tcpDisabled = transport.isTcpDisabled();
    if (!this.tcpDisabled) {
        dcReceiver = new MyDCReceiver(listener);
    }
    surpriseMemberTimeout = Math.max(20 * DistributionConfig.DEFAULT_MEMBER_TIMEOUT, 20 * config.getMemberTimeout());
    surpriseMemberTimeout = Integer.getInteger(DistributionConfig.GEMFIRE_PREFIX + "surprise-member-timeout", surpriseMemberTimeout).intValue();
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig)

Example 13 with RemoteTransportConfig

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

the class GMSLocatorRecoveryJUnitTest method testRecoverFromOther.

@Test
public void testRecoverFromOther() 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 = Locator.startLocator(port, new File(""), localHost);
        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(LOCATORS, localHost.getHostAddress() + '[' + port + ']');
        nonDefault.put(BIND_ADDRESS, localHost.getHostAddress());
        DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
        RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
        // start the first membership manager
        DistributedMembershipListener listener1 = mock(DistributedMembershipListener.class);
        DMStats stats1 = mock(DMStats.class);
        m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1);
        // hook up the locator to the membership manager
        ((InternalLocator) l).getLocatorHandler().setMembershipManager(m1);
        GMSLocator l2 = new GMSLocator(SocketCreator.getLocalHost(), new File("l2.dat"), m1.getLocalMember().getHost() + "[" + port + "]", true, true, new LocatorStats(), "");
        l2.init(null);
        assertTrue("expected view to contain " + m1.getLocalMember() + ": " + l2.getMembers(), l2.getMembers().contains(m1.getLocalMember()));
    } finally {
        if (m1 != null) {
            m1.shutdown();
        }
        if (l != null) {
            l.stop();
        }
    }
}
Also used : Locator(org.apache.geode.distributed.Locator) MembershipManager(org.apache.geode.distributed.internal.membership.MembershipManager) RemoteTransportConfig(org.apache.geode.internal.admin.remote.RemoteTransportConfig) DistributedMembershipListener(org.apache.geode.distributed.internal.membership.DistributedMembershipListener) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) InetAddress(java.net.InetAddress) File(java.io.File) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

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