// 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);