Search in sources :

Example 6 with GemFireConfigException

use of org.apache.geode.GemFireConfigException in project geode by apache.

the class SocketCreator method createServerSocket.

private ServerSocket createServerSocket(int nport, int backlog, InetAddress bindAddr, int socketBufferSize, boolean sslConnection) throws IOException {
    printConfig();
    if (sslConnection) {
        if (this.sslContext == null) {
            throw new GemFireConfigException("SSL not configured correctly, Please look at previous error");
        }
        ServerSocketFactory ssf = this.sslContext.getServerSocketFactory();
        SSLServerSocket serverSocket = (SSLServerSocket) ssf.createServerSocket();
        serverSocket.setReuseAddress(true);
        // java.net.ServerSocket.setReceiverBufferSize javadocs)
        if (socketBufferSize != -1) {
            serverSocket.setReceiveBufferSize(socketBufferSize);
        }
        serverSocket.bind(new InetSocketAddress(bindAddr, nport), backlog);
        finishServerSocket(serverSocket);
        return serverSocket;
    } else {
        // log.info("Opening server socket on " + nport, new Exception("SocketCreation"));
        ServerSocket result = new ServerSocket();
        result.setReuseAddress(true);
        // java.net.ServerSocket.setReceiverBufferSize javadocs)
        if (socketBufferSize != -1) {
            result.setReceiveBufferSize(socketBufferSize);
        }
        try {
            result.bind(new InetSocketAddress(bindAddr, nport), backlog);
        } catch (BindException e) {
            BindException throwMe = new BindException(LocalizedStrings.SocketCreator_FAILED_TO_CREATE_SERVER_SOCKET_ON_0_1.toLocalizedString(new Object[] { bindAddr, Integer.valueOf(nport) }));
            throwMe.initCause(e);
            throw throwMe;
        }
        return result;
    }
}
Also used : GemFireConfigException(org.apache.geode.GemFireConfigException) ServerSocketFactory(javax.net.ServerSocketFactory) InetSocketAddress(java.net.InetSocketAddress) BindException(java.net.BindException) ServerSocket(java.net.ServerSocket) TransportFilterServerSocket(org.apache.geode.internal.cache.wan.TransportFilterServerSocket) SSLServerSocket(javax.net.ssl.SSLServerSocket) SSLServerSocket(javax.net.ssl.SSLServerSocket)

Example 7 with GemFireConfigException

use of org.apache.geode.GemFireConfigException in project geode by apache.

the class JGroupsMessenger method start.

@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
public void start() {
    // create the configuration XML string for JGroups
    String properties = this.jgStackConfig;
    long start = System.currentTimeMillis();
    // start the jgroups channel and establish the membership ID
    boolean reconnecting = false;
    try {
        Object oldChannel = services.getConfig().getTransport().getOldDSMembershipInfo();
        if (oldChannel != null) {
            logger.debug("Reusing JGroups channel from previous system", properties);
            myChannel = (JChannel) oldChannel;
            // scrub the old channel
            ViewId vid = new ViewId(new JGAddress(), 0);
            View jgv = new View(vid, new ArrayList<>());
            this.myChannel.down(new Event(Event.VIEW_CHANGE, jgv));
            UUID logicalAddress = (UUID) myChannel.getAddress();
            if (logicalAddress instanceof JGAddress) {
                ((JGAddress) logicalAddress).setVmViewId(-1);
            }
            reconnecting = true;
        } else {
            logger.debug("JGroups configuration: {}", properties);
            checkForIPv6();
            InputStream is = new ByteArrayInputStream(properties.getBytes("UTF-8"));
            myChannel = new JChannel(is);
        }
    } catch (Exception e) {
        throw new GemFireConfigException("unable to create jgroups channel", e);
    }
    // give the stats to the jchannel statistics recorder
    StatRecorder sr = (StatRecorder) myChannel.getProtocolStack().findProtocol(StatRecorder.class);
    if (sr != null) {
        sr.setServices(services);
    }
    Transport transport = (Transport) myChannel.getProtocolStack().getTransport();
    transport.setMessenger(this);
    nackack2HeaderId = ClassConfigurator.getProtocolId(NAKACK2.class);
    try {
        myChannel.setReceiver(null);
        myChannel.setReceiver(new JGroupsReceiver());
        if (!reconnecting) {
            // apache g***** (whatever we end up calling it)
            myChannel.connect("AG");
        }
    } catch (Exception e) {
        myChannel.close();
        throw new SystemConnectException("unable to create jgroups channel", e);
    }
    if (JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK) {
        JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK = false;
        throw new SystemConnectException("failing for test");
    }
    establishLocalAddress();
    logger.info("JGroups channel {} (took {}ms)", (reconnecting ? "reinitialized" : "created"), System.currentTimeMillis() - start);
}
Also used : JChannel(org.jgroups.JChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) NetView(org.apache.geode.distributed.internal.membership.NetView) View(org.jgroups.View) 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) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) ByteArrayInputStream(java.io.ByteArrayInputStream) GemFireConfigException(org.apache.geode.GemFireConfigException) ViewId(org.jgroups.ViewId) Event(org.jgroups.Event) UUID(org.jgroups.util.UUID) SystemConnectException(org.apache.geode.SystemConnectException)

Example 8 with GemFireConfigException

use of org.apache.geode.GemFireConfigException in project geode by apache.

the class GMSJoinLeave method findCoordinator.

/**
   * This contacts the locators to find out who the current coordinator is. All locators are
   * contacted. If they don't agree then we choose the oldest coordinator and return it.
   */
private boolean findCoordinator() {
    SearchState state = searchState;
    assert this.localAddress != null;
    // the coordinator
    if (!state.hasContactedAJoinedLocator && state.view != null) {
        return findCoordinatorFromView();
    }
    String dhalgo = services.getConfig().getDistributionConfig().getSecurityUDPDHAlgo();
    FindCoordinatorRequest request = new FindCoordinatorRequest(this.localAddress, state.alreadyTried, state.viewId, services.getMessenger().getPublicKey(localAddress), services.getMessenger().getRequestId(), dhalgo);
    Set<InternalDistributedMember> possibleCoordinators = new HashSet<InternalDistributedMember>();
    Set<InternalDistributedMember> coordinatorsWithView = new HashSet<InternalDistributedMember>();
    long giveUpTime = System.currentTimeMillis() + ((long) services.getConfig().getLocatorWaitTime() * 1000L);
    int connectTimeout = (int) services.getConfig().getMemberTimeout() * 2;
    boolean anyResponses = false;
    logger.debug("sending {} to {}", request, locators);
    state.hasContactedAJoinedLocator = false;
    state.locatorsContacted = 0;
    do {
        for (InetSocketAddress addr : locators) {
            try {
                Object o = tcpClientWrapper.sendCoordinatorFindRequest(addr, request, connectTimeout);
                FindCoordinatorResponse response = (o instanceof FindCoordinatorResponse) ? (FindCoordinatorResponse) o : null;
                if (response != null) {
                    if (response.getRejectionMessage() != null) {
                        throw new GemFireConfigException(response.getRejectionMessage());
                    }
                    setCoordinatorPublicKey(response);
                    state.locatorsContacted++;
                    if (!state.hasContactedAJoinedLocator && response.getSenderId() != null && response.getSenderId().getVmViewId() >= 0) {
                        logger.debug("Locator's address indicates it is part of a distributed system " + "so I will not become membership coordinator on this attempt to join");
                        state.hasContactedAJoinedLocator = true;
                    }
                    if (response.getCoordinator() != null) {
                        anyResponses = true;
                        NetView v = response.getView();
                        int viewId = v == null ? -1 : v.getViewId();
                        if (viewId > state.viewId) {
                            state.viewId = viewId;
                            state.view = v;
                            state.registrants.clear();
                            if (response.getRegistrants() != null) {
                                state.registrants.addAll(response.getRegistrants());
                            }
                        }
                        if (viewId > -1) {
                            coordinatorsWithView.add(response.getCoordinator());
                        }
                        possibleCoordinators.add(response.getCoordinator());
                    }
                }
            } catch (IOException | ClassNotFoundException problem) {
            }
        }
    } while (!anyResponses && System.currentTimeMillis() < giveUpTime);
    if (possibleCoordinators.isEmpty()) {
        return false;
    }
    if (coordinatorsWithView.size() > 0) {
        // lets check current coordinators in view only
        possibleCoordinators = coordinatorsWithView;
    }
    Iterator<InternalDistributedMember> it = possibleCoordinators.iterator();
    if (possibleCoordinators.size() == 1) {
        state.possibleCoordinator = it.next();
    } else {
        InternalDistributedMember oldest = it.next();
        while (it.hasNext()) {
            InternalDistributedMember candidate = it.next();
            if (oldest.compareTo(candidate) > 0) {
                oldest = candidate;
            }
        }
        state.possibleCoordinator = oldest;
    }
    InternalDistributedMember coord = null;
    boolean coordIsNoob = true;
    for (; it.hasNext(); ) {
        InternalDistributedMember mbr = it.next();
        if (!state.alreadyTried.contains(mbr)) {
            boolean mbrIsNoob = (mbr.getVmViewId() < 0);
            if (mbrIsNoob) {
                // member has not yet joined
                if (coordIsNoob && (coord == null || coord.compareTo(mbr) > 0)) {
                    coord = mbr;
                }
            } else {
                // member has already joined
                if (coordIsNoob || mbr.getVmViewId() > coord.getVmViewId()) {
                    coord = mbr;
                    coordIsNoob = false;
                }
            }
        }
    }
    return true;
}
Also used : FindCoordinatorResponse(org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse) InetSocketAddress(java.net.InetSocketAddress) NetView(org.apache.geode.distributed.internal.membership.NetView) IOException(java.io.IOException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) GemFireConfigException(org.apache.geode.GemFireConfigException) FindCoordinatorRequest(org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorRequest) HashSet(java.util.HashSet)

Example 9 with GemFireConfigException

use of org.apache.geode.GemFireConfigException in project geode by apache.

the class GMSMembershipManager method join.

/**
   * Joins the distributed system
   *
   * @throws GemFireConfigException - configuration error
   * @throws SystemConnectException - problem joining
   */
private void join() {
    services.setShutdownCause(null);
    services.getCancelCriterion().cancel(null);
    latestViewWriteLock.lock();
    try {
        try {
            // added for bug #44373
            this.isJoining = true;
            // connect
            long start = System.currentTimeMillis();
            boolean ok = services.getJoinLeave().join();
            if (!ok) {
                throw new GemFireConfigException("Unable to join the distributed system.  " + "Operation either timed out, was stopped or Locator does not exist.");
            }
            long delta = System.currentTimeMillis() - start;
            logger.info(LogMarker.DISTRIBUTION, LocalizedMessage.create(LocalizedStrings.GroupMembershipService_JOINED_TOOK__0__MS, delta));
            NetView initialView = services.getJoinLeave().getView();
            latestView = new NetView(initialView, initialView.getViewId());
            listener.viewInstalled(latestView);
        } catch (RuntimeException ex) {
            throw ex;
        } catch (Exception ex) {
            if (ex.getCause() != null && ex.getCause().getCause() instanceof SystemConnectException) {
                throw (SystemConnectException) (ex.getCause().getCause());
            }
            throw new DistributionException(LocalizedStrings.GroupMembershipService_AN_EXCEPTION_WAS_THROWN_WHILE_JOINING.toLocalizedString(), ex);
        } finally {
            this.isJoining = false;
        }
    } finally {
        latestViewWriteLock.unlock();
    }
}
Also used : GemFireConfigException(org.apache.geode.GemFireConfigException) NetView(org.apache.geode.distributed.internal.membership.NetView) DistributionException(org.apache.geode.distributed.internal.DistributionException) MemberShunnedException(org.apache.geode.internal.tcp.MemberShunnedException) TimeoutException(java.util.concurrent.TimeoutException) ShunnedMemberException(org.apache.geode.distributed.internal.direct.ShunnedMemberException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CancelException(org.apache.geode.CancelException) DistributionException(org.apache.geode.distributed.internal.DistributionException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) ToDataException(org.apache.geode.ToDataException) SystemConnectException(org.apache.geode.SystemConnectException)

Example 10 with GemFireConfigException

use of org.apache.geode.GemFireConfigException in project geode by apache.

the class GMSJoinLeave method init.

@Override
public void init(Services s) {
    this.services = s;
    DistributionConfig dc = services.getConfig().getDistributionConfig();
    if (dc.getMcastPort() != 0 && StringUtils.isBlank(dc.getLocators()) && StringUtils.isBlank(dc.getStartLocator())) {
        throw new GemFireConfigException("Multicast cannot be configured for a non-distributed cache." + "  Please configure the locator services for this cache using " + LOCATORS + " or " + START_LOCATOR + ".");
    }
    services.getMessenger().addHandler(JoinRequestMessage.class, this);
    services.getMessenger().addHandler(JoinResponseMessage.class, this);
    services.getMessenger().addHandler(InstallViewMessage.class, this);
    services.getMessenger().addHandler(ViewAckMessage.class, this);
    services.getMessenger().addHandler(LeaveRequestMessage.class, this);
    services.getMessenger().addHandler(RemoveMemberMessage.class, this);
    services.getMessenger().addHandler(FindCoordinatorRequest.class, this);
    services.getMessenger().addHandler(FindCoordinatorResponse.class, this);
    services.getMessenger().addHandler(NetworkPartitionMessage.class, this);
    int ackCollectionTimeout = dc.getMemberTimeout() * 2 * 12437 / 10000;
    if (ackCollectionTimeout < 1500) {
        ackCollectionTimeout = 1500;
    } else if (ackCollectionTimeout > 12437) {
        ackCollectionTimeout = 12437;
    }
    ackCollectionTimeout = Integer.getInteger(DistributionConfig.GEMFIRE_PREFIX + "VIEW_ACK_TIMEOUT", ackCollectionTimeout).intValue();
    this.viewAckTimeout = ackCollectionTimeout;
    this.quorumRequired = services.getConfig().getDistributionConfig().getEnableNetworkPartitionDetection();
    DistributionConfig dconfig = services.getConfig().getDistributionConfig();
    String bindAddr = dconfig.getBindAddress();
    locators = GMSUtil.parseLocators(dconfig.getLocators(), bindAddr);
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) GemFireConfigException(org.apache.geode.GemFireConfigException)

Aggregations

GemFireConfigException (org.apache.geode.GemFireConfigException)28 IOException (java.io.IOException)11 SystemConnectException (org.apache.geode.SystemConnectException)10 Properties (java.util.Properties)7 ForcedDisconnectException (org.apache.geode.ForcedDisconnectException)7 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)6 Test (org.junit.Test)6 UnknownHostException (java.net.UnknownHostException)5 CancelException (org.apache.geode.CancelException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 DataInputStream (java.io.DataInputStream)4 InetSocketAddress (java.net.InetSocketAddress)4 GemFireIOException (org.apache.geode.GemFireIOException)4 VersionedDataInputStream (org.apache.geode.internal.VersionedDataInputStream)4 MemberShunnedException (org.apache.geode.internal.tcp.MemberShunnedException)4 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)4 InputStream (java.io.InputStream)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ServerSocket (java.net.ServerSocket)3 NetView (org.apache.geode.distributed.internal.membership.NetView)3