Search in sources :

Example 1 with MemberAttributes

use of org.apache.geode.distributed.internal.membership.MemberAttributes in project geode by apache.

the class JGroupsMessenger method establishLocalAddress.

private void establishLocalAddress() {
    UUID logicalAddress = (UUID) myChannel.getAddress();
    logicalAddress = logicalAddress.copy();
    IpAddress ipaddr = (IpAddress) myChannel.down(new Event(Event.GET_PHYSICAL_ADDRESS));
    if (ipaddr != null) {
        this.jgAddress = new JGAddress(logicalAddress, ipaddr);
    } else {
        UDP udp = (UDP) myChannel.getProtocolStack().getTransport();
        try {
            Method getAddress = UDP.class.getDeclaredMethod("getPhysicalAddress");
            getAddress.setAccessible(true);
            ipaddr = (IpAddress) getAddress.invoke(udp, new Object[0]);
            this.jgAddress = new JGAddress(logicalAddress, ipaddr);
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
            logger.info("Unable to find getPhysicallAddress method in UDP - parsing its address instead");
        }
    // if (this.jgAddress == null) {
    // String addr = udp.getLocalPhysicalAddress();
    // int cidx = addr.lastIndexOf(':'); // IPv6 literals might have colons
    // String host = addr.substring(0, cidx);
    // int jgport = Integer.parseInt(addr.substring(cidx+1, addr.length()));
    // try {
    // this.jgAddress = new JGAddress(logicalAddress, new IpAddress(InetAddress.getByName(host),
    // jgport));
    // } catch (UnknownHostException e) {
    // myChannel.disconnect();
    // throw new SystemConnectException("unable to initialize jgroups address", e);
    // }
    // }
    }
    // install the address in the JGroups channel protocols
    myChannel.down(new Event(Event.SET_LOCAL_ADDRESS, this.jgAddress));
    DistributionConfig config = services.getConfig().getDistributionConfig();
    boolean isLocator = (services.getConfig().getTransport().getVmKind() == DistributionManager.LOCATOR_DM_TYPE) || !services.getConfig().getDistributionConfig().getStartLocator().isEmpty();
    // establish the DistributedSystem's address
    DurableClientAttributes dca = null;
    if (config.getDurableClientId() != null) {
        dca = new DurableClientAttributes(config.getDurableClientId(), config.getDurableClientTimeout());
    }
    MemberAttributes attr = new MemberAttributes(-1, /* dcPort - not known at this time */
    OSProcess.getId(), services.getConfig().getTransport().getVmKind(), -1, /* view id - not known at this time */
    config.getName(), MemberAttributes.parseGroups(config.getRoles(), config.getGroups()), dca);
    localAddress = new InternalDistributedMember(jgAddress.getInetAddress(), jgAddress.getPort(), config.getEnableNetworkPartitionDetection(), isLocator, attr);
    // add the JGroups logical address to the GMSMember
    UUID uuid = this.jgAddress;
    GMSMember gmsMember = (GMSMember) localAddress.getNetMember();
    gmsMember.setUUID(uuid);
    gmsMember.setMemberWeight((byte) (services.getConfig().getMemberWeight() & 0xff));
    gmsMember.setNetworkPartitionDetectionEnabled(services.getConfig().getDistributionConfig().getEnableNetworkPartitionDetection());
}
Also used : UDP(org.jgroups.protocols.UDP) MemberAttributes(org.apache.geode.distributed.internal.membership.MemberAttributes) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Event(org.jgroups.Event) IpAddress(org.jgroups.stack.IpAddress) UUID(org.jgroups.util.UUID) DurableClientAttributes(org.apache.geode.distributed.DurableClientAttributes)

Example 2 with MemberAttributes

use of org.apache.geode.distributed.internal.membership.MemberAttributes in project geode by apache.

the class GMSMember method setAttributes.

public void setAttributes(MemberAttributes p_attr) {
    MemberAttributes attr = p_attr;
    if (attr == null) {
        attr = MemberAttributes.INVALID;
    }
    processId = attr.getVmPid();
    vmKind = (byte) attr.getVmKind();
    directPort = attr.getPort();
    vmViewId = attr.getVmViewId();
    name = attr.getName();
    groups = attr.getGroups();
    durableClientAttributes = attr.getDurableClientAttributes();
}
Also used : MemberAttributes(org.apache.geode.distributed.internal.membership.MemberAttributes)

Example 3 with MemberAttributes

use of org.apache.geode.distributed.internal.membership.MemberAttributes in project geode by apache.

the class GMSMemberJUnitTest method testNoNPEWhenSetAttributesWithNull.

/**
   * Makes sure a NPE is not thrown
   */
@Test
public void testNoNPEWhenSetAttributesWithNull() {
    GMSMember member = new GMSMember();
    member.setAttributes(null);
    MemberAttributes attrs = member.getAttributes();
    MemberAttributes invalid = MemberAttributes.INVALID;
    assertEquals(attrs.getVmKind(), invalid.getVmKind());
    assertEquals(attrs.getPort(), invalid.getPort());
    assertEquals(attrs.getVmViewId(), invalid.getVmViewId());
    assertEquals(attrs.getName(), invalid.getName());
}
Also used : MemberAttributes(org.apache.geode.distributed.internal.membership.MemberAttributes) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 4 with MemberAttributes

use of org.apache.geode.distributed.internal.membership.MemberAttributes in project geode by apache.

the class GMSMemberJUnitTest method testGMSMemberBackwardCompatibility.

/**
   * <p>
   * GEODE-2875 - adds vmKind to on-wire form of GMSMember.writeEssentialData
   * </p>
   * <p>
   * This must be backward-compatible with Geode 1.0 (Version.GFE_90)
   * </p>
   * 
   * @throws Exception
   */
@Test
public void testGMSMemberBackwardCompatibility() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    MemberAttributes attributes = new MemberAttributes(10, 20, 1, 2, "member", null, null);
    GMSMember member = new GMSMember();
    member.setAttributes(attributes);
    DataOutput dataOutput = new DataOutputStream(baos);
    member.writeEssentialData(dataOutput);
    // vmKind should be transmitted to a member with the current version
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    DataInput dataInput = new DataInputStream(bais);
    GMSMember newMember = new GMSMember();
    newMember.readEssentialData(dataInput);
    assertEquals(1, newMember.getVmKind());
    // vmKind should not be transmitted to a member with version GFE_90 or earlier
    dataOutput = new HeapDataOutputStream(Version.GFE_90);
    member.writeEssentialData(dataOutput);
    bais = new ByteArrayInputStream(baos.toByteArray());
    dataInput = new VersionedDataInputStream(new DataInputStream(bais), Version.GFE_90);
    newMember = new GMSMember();
    newMember.readEssentialData(dataInput);
    assertEquals(0, newMember.getVmKind());
}
Also used : DataInput(java.io.DataInput) DataOutput(java.io.DataOutput) MemberAttributes(org.apache.geode.distributed.internal.membership.MemberAttributes) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Aggregations

MemberAttributes (org.apache.geode.distributed.internal.membership.MemberAttributes)4 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInput (java.io.DataInput)1 DataInputStream (java.io.DataInputStream)1 DataOutput (java.io.DataOutput)1 DataOutputStream (java.io.DataOutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 DurableClientAttributes (org.apache.geode.distributed.DurableClientAttributes)1 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 GMSMember (org.apache.geode.distributed.internal.membership.gms.GMSMember)1 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)1 VersionedDataInputStream (org.apache.geode.internal.VersionedDataInputStream)1 Event (org.jgroups.Event)1 UDP (org.jgroups.protocols.UDP)1