Package org.rhq.core.domain.cloud.composite

Examples of org.rhq.core.domain.cloud.composite.FailoverListComposite$ServerEntry


                throw new AgentRegistrationException(new WrappedRemotingException(e));
            }
        }

        // get existing or generate new server list for the registering agent
        FailoverListComposite failoverList = getPartitionEventManager().agentPartitionEvent(
            getSubjectManager().getOverlord(), agentByName.getName(), PartitionEventType.AGENT_REGISTRATION,
            agentByName.getName() + " - " + registeringServer.getName());

        AgentRegistrationResults results = new AgentRegistrationResults();
        results.setAgentToken(agentByName.getAgentToken());
View Full Code Here


                // However, it the agent is sending and we have a failover list, then we need to check
                // to see if the server we are currently talking to is the same as primary server, listed
                // at the top of the failover list. If not the same, we ask the agent to switch to that server.
                ClientCommandSender sender = this.agent.getClientCommandSender();
                if (sender.isSending()) {
                    FailoverListComposite failoverList = this.agent.downloadServerFailoverList(); // ask the server for a new one

                    // if the failover list doesn't have any servers, skip our poll and wait some more
                    if (failoverList.size() > 0) {
                        AgentConfiguration config = this.agent.getConfiguration();
                        String transport = config.getServerTransport();
                        String transportParams = config.getServerTransportParams();
                        String currentServerAddress = config.getServerBindAddress();
                        int currentServerPort = config.getServerBindPort();

                        ServerEntry primary = failoverList.get(0); // get the top of the list, aka primary server
                        String primaryAddress = primary.address;
                        int primaryPort = (SecurityUtil.isTransportSecure(transport)) ? primary.securePort
                            : primary.port;

                        if (!primaryAddress.equals(currentServerAddress) || primaryPort != currentServerPort) {
                            LOG.info(AgentI18NResourceKeys.NOT_TALKING_TO_PRIMARY_SERVER, primaryAddress, primaryPort,
                                currentServerAddress, currentServerPort);
                            // create our own comm so we ping in an isolated client - don't reuse the sender's comm for this
                            RemoteCommunicator comm = this.agent.createServerRemoteCommunicator(transport,
                                primaryAddress, primaryPort, transportParams);
                            if (ping(comm)) {
                                LOG.info(AgentI18NResourceKeys.PRIMARY_SERVER_UP, primaryAddress, primaryPort);
                                failoverList.resetIndex(); // so the failover method call starts at the top
                                this.agent.failoverToNewServer(sender.getRemoteCommunicator()); // note that we make sure we pass in the sender's comm
                            } else {
                                LOG.info(AgentI18NResourceKeys.PRIMARY_SERVER_STILL_DOWN, primaryAddress, primaryPort);
                            }
                        }
View Full Code Here

            // constantly attempting failovers
            command.getConfiguration().remove(FAILOVER_ATTEMPTS); // something's wrong with the value, so remove it
            return false;
        }

        FailoverListComposite failoverList = this.agent.getServerFailoverList();
        if (failoverList.hasNext() == false) {
            return false; // nothing to do, there isn't a next server in the list
        }

        int numFailoverServers = failoverList.size();

        // if we tried all the servers in our failover list, then stop trying
        if (failoverAttempts >= numFailoverServers) {
            LOG.warn(AgentI18NResourceKeys.TOO_MANY_FAILOVER_ATTEMPTS, numFailoverServers, theProblem);
            command.getConfiguration().remove(FAILOVER_ATTEMPTS);
View Full Code Here

        // we don't have it yet - read our backed up version from the last time we were given the list

        // as a safety measure, return a dummy, empty list if we aren't configured yet; but we really should not
        // be calling this method until we are configured properly
        if (m_configuration == null) {
            return new FailoverListComposite(new ArrayList<ServerEntry>());
        }

        File dataDir = m_configuration.getDataDirectory();
        File failoverListFile = new File(dataDir, FILENAME_SERVER_FAILOVER_LIST);

        FailoverListComposite list;

        if (!failoverListFile.exists()) {
            // a non-existant file implies an empty list (i.e. no failover servers defined)
            list = new FailoverListComposite(new ArrayList<ServerEntry>());
        } else {
            try {
                byte[] bytes = StreamUtil.slurp(new FileInputStream(failoverListFile));
                list = FailoverListComposite.readAsText(new String(bytes));
                LOG.debug(AgentI18NResourceKeys.FAILOVER_LIST_LOADED, failoverListFile, list.size());
            } catch (Exception e) {
                list = new FailoverListComposite(new ArrayList<ServerEntry>());
                LOG.warn(e, AgentI18NResourceKeys.FAILOVER_LIST_CANNOT_BE_LOADED, failoverListFile,
                    ThrowableUtil.getAllMessages(e));
            }
        }
View Full Code Here

            ClientCommandSender sender = getClientCommandSender();
            if (sender != null) {
                String agent_name = this.getConfiguration().getAgentName();
                ClientRemotePojoFactory factory = sender.getClientRemotePojoFactory();
                CoreServerService pojo = factory.getRemotePojo(CoreServerService.class);
                FailoverListComposite list = pojo.getFailoverList(agent_name);
                if (list == null) {
                    list = new FailoverListComposite(new ArrayList<ServerEntry>());
                }
                // if we do not yet have a list or the new list is different than our current one, store the new one
                if (!list.equals(m_serverFailoverList)) {
                    storeServerFailoverList(list);
                    m_serverFailoverList = list;
                    LOG.debug(AgentI18NResourceKeys.FAILOVER_LIST_DOWNLOADED, m_serverFailoverList.size());
                }
            }
View Full Code Here

                                // delete any old token so request is unauthenticated to get server to accept it
                                agent_config.setAgentSecurityToken(null);
                                m_commServices.addCustomData(
                                    SecurityTokenCommandAuthenticator.CMDCONFIG_PROP_SECURITY_TOKEN, null);

                                FailoverListComposite failover_list = null;
                                try {
                                    AgentRegistrationResults results = remote_pojo.registerAgent(request);
                                    failover_list = results.getFailoverList();
                                    token = results.getAgentToken(); // make sure our finally block gets this - BZ 963982

                                    // Try to do a simple connect to each server in the failover list
                                    // If only some of the servers are unreachable, just keep going;
                                    //    the agent will eventually switchover to one of the live servers.
                                    // But if all servers in the list are unreachable, we need to keep retrying hoping
                                    // someone fixes the servers' public endpoints so the agent can reach one or more of them.
                                    boolean test_failover_list = m_configuration.isTestFailoverListAtStartupEnabled();
                                    if (test_failover_list) {
                                        List<String> failed = testFailoverList(failover_list);
                                        if (failed.size() > 0) {
                                            if (failed.size() == failover_list.size()) {
                                                retry = true;
                                                retry_interval = 30000L;
                                                if (!hide_failover_list_warning) {
                                                    String msg_id = AgentI18NResourceKeys.FAILOVER_LIST_CHECK_FAILED;
                                                    LOG.warn(msg_id, failed.size(), failed.toString());
                                                    getOut().println(
                                                        MSG.getMsg(msg_id, failed.size(), failed.toString()));
                                                    getOut().println();
                                                    hide_failover_list_warning = true; // don't bother logging more than once
                                                }
                                                continue; // immediately go back and start the retry
                                            }
                                        }
                                    } else {
                                        LOG.info(AgentI18NResourceKeys.TEST_FAILOVER_LIST_AT_STARTUP_DISABLED);
                                    }

                                    m_registration = results;
                                    got_registered = true;
                                    retry = false;
                                    LOG.info(AgentI18NResourceKeys.AGENT_REGISTRATION_RESULTS, results);
                                } finally {
                                    // stores the new one if successful; restores the old one if we failed for some reason to register
                                    // Note that we don't retry even if storing the token fails since this kind
                                    // of failure is probably not recoverable even if we try again.
                                    agent_config.setAgentSecurityToken(token);
                                    m_commServices.addCustomData(
                                        SecurityTokenCommandAuthenticator.CMDCONFIG_PROP_SECURITY_TOKEN, token);

                                    LOG.debug(AgentI18NResourceKeys.NEW_SECURITY_TOKEN, token);
                                }

                                storeServerFailoverList(failover_list);
                                m_serverFailoverList = failover_list;

                                // switch away from the registration server and point this agent to the top of the list
                                // - this is our primary server that we should connect to
                                // note that if we are already pointing to the one at the head of the failover list,
                                // we don't have to failover to another server; the current one is the one we already want
                                if (failover_list.hasNext()) {
                                    String currentAddress = agent_config.getServerBindAddress();
                                    int currentPort = agent_config.getServerBindPort();
                                    String currentTransport = agent_config.getServerTransport();
                                    ServerEntry nextServer = failover_list.peek();

                                    if (currentAddress.equals(nextServer.address)
                                        && currentPort == (SecurityUtil.isTransportSecure(currentTransport) ? nextServer.securePort
                                            : nextServer.port)) {
                                        // we are already pointing to the primary server, so all we have to do is
                                        // call next to move the index to the next in the list for when we have to failover in the future
                                        nextServer = failover_list.next();

                                        // [mazz] I don't think we need to do this here anymore - with the addition of
                                        // the remote communicator's initialize callback, this connect request
                                        // will be made the next time a command is sent by the sender
                                        //sendConnectRequestToServer(sender.getRemoteCommunicator(), false);
View Full Code Here

            // if we just recently (within the last 10s) switched, don't try to do anything and abort
            if (System.currentTimeMillis() - m_lastFailoverTime[0] < 10000) {
                return;
            }

            FailoverListComposite failoverList = getServerFailoverList();
            if (failoverList.hasNext() == false) {
                return;
            }

            AgentConfiguration config = getConfiguration();
            String currentTransport = config.getServerTransport();
            String currentTransportParams = config.getServerTransportParams();

            ServerEntry nextServer = failoverList.next();

            boolean ok = switchCommServer(comm, nextServer, currentTransport, currentTransportParams);
            if (ok) {
                // we've successfully failed over; the design of the HA system calls for us to start
                // over at the top of the failover list the next time we get a failure.
                failoverList.resetIndex();

                m_lastFailoverTime[0] = System.currentTimeMillis();
            }
            return;
        }
View Full Code Here

public class FailoverListCompositeTest {
    public void testEquals() {
        ArrayList<ServerEntry> servers = new ArrayList<ServerEntry>();
        ArrayList<ServerEntry> servers2 = new ArrayList<ServerEntry>();

        FailoverListComposite list = new FailoverListComposite(servers);
        FailoverListComposite list2 = new FailoverListComposite(servers2);
        assert list != null;
        assert list.equals(list2);

        servers.add(new FailoverListComposite.ServerEntry("addr1", 111, 222));
        list = new FailoverListComposite(servers);
        assert !list.equals(list2);
        assert !list2.equals(list);

        servers2.add(new FailoverListComposite.ServerEntry("addr1", 111, 222));
        list2 = new FailoverListComposite(servers2);
        assert list.equals(list2);
        assert list2.equals(list);

        servers.add(new FailoverListComposite.ServerEntry("addr2.com", 7777, 12345));
        list = new FailoverListComposite(servers);
        assert !list.equals(list2);
        assert !list2.equals(list);

        servers2.add(new FailoverListComposite.ServerEntry("addr2.com", 7777, 12345));
        list2 = new FailoverListComposite(servers2);
        assert list.equals(list2);
        assert list2.equals(list);

        servers.add(new FailoverListComposite.ServerEntry("addrX.com", 7777, 12345));
        servers.add(new FailoverListComposite.ServerEntry("addrY.com", 7, 1));
        list = new FailoverListComposite(servers);
        assert !list.equals(list2);
        assert !list2.equals(list);

        // reverse X and Y - lists should not be equal because the order isn't the same
        servers2.add(new FailoverListComposite.ServerEntry("addrY.com", 7, 1));
        servers2.add(new FailoverListComposite.ServerEntry("addrX.com", 7777, 12345));
        list2 = new FailoverListComposite(servers2);
        assert !list.equals(list2);
        assert !list2.equals(list);
    }
View Full Code Here

        assert !list2.equals(list);
    }

    public void testTextForm() {
        ArrayList<ServerEntry> servers = new ArrayList<ServerEntry>();
        FailoverListComposite listToTest;
        ServerEntry server;

        FailoverListComposite list = new FailoverListComposite(servers);
        String text = list.writeAsText();
        assert text != null;
        assert text.length() == 0 : text.length();
        listToTest = FailoverListComposite.readAsText(text);
        assert listToTest != null;
        assert listToTest.size() == 0 : listToTest.size();

        servers.add(new FailoverListComposite.ServerEntry("addr1", 111, 222));
        list = new FailoverListComposite(servers);
        text = list.writeAsText();
        assert text != null;
        assert text.equals("addr1:111/222") : text;
        listToTest = FailoverListComposite.readAsText(text);
        assert listToTest != null;
        assert listToTest.size() == 1 : listToTest.size();
        server = listToTest.next();
        assert server != null;
        assert server.address.equals("addr1") : server;
        assert server.port == 111 : server;
        assert server.securePort == 222 : server;

        servers.add(new FailoverListComposite.ServerEntry("addr2.com", 7777, 12345));
        list = new FailoverListComposite(servers);
        text = list.writeAsText();
        assert text != null;
        assert text.equals("addr1:111/222\naddr2.com:7777/12345") : text;
        listToTest = FailoverListComposite.readAsText(text);
        assert listToTest != null;
        assert listToTest.size() == 2 : listToTest.size();
        server = listToTest.next();
        assert server != null;
        assert server.address.equals("addr1") : server;
        assert server.port == 111 : server;
        assert server.securePort == 222 : server;
        server = listToTest.next();
        assert server != null;
        assert server.address.equals("addr2.com") : server;
        assert server.port == 7777 : server;
        assert server.securePort == 12345 : server;

        servers.add(new FailoverListComposite.ServerEntry("another.host.net", 80, 90));
        list = new FailoverListComposite(servers);
        text = list.writeAsText();
        assert text != null;
        assert text.equals("addr1:111/222\naddr2.com:7777/12345\nanother.host.net:80/90") : text;
        listToTest = FailoverListComposite.readAsText(text);
        assert listToTest != null;
        assert listToTest.size() == 3 : listToTest.size();
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.cloud.composite.FailoverListComposite$ServerEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.