From: <tk...@hy...> - 2008-06-26 23:36:58
|
Author: tkeeney Date: 2008-06-26 16:36:56 -0700 (Thu, 26 Jun 2008) New Revision: 9898 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=9898 Modified: trunk/src/org/hyperic/hq/bizapp/agent/client/AgentClient.java trunk/src/org/hyperic/hq/bizapp/client/BizappCallbackClient.java trunk/src/org/hyperic/hq/bizapp/server/session/LatherDispatcher.java Log: Updated agent setup to permit switching between unidirectional and non-unidirectional agents. Modified: trunk/src/org/hyperic/hq/bizapp/agent/client/AgentClient.java =================================================================== --- trunk/src/org/hyperic/hq/bizapp/agent/client/AgentClient.java 2008-06-26 23:35:13 UTC (rev 9897) +++ trunk/src/org/hyperic/hq/bizapp/agent/client/AgentClient.java 2008-06-26 23:36:56 UTC (rev 9898) @@ -731,6 +731,12 @@ } } } + + // The old agent token may be needed if re-registering an existing agent + // but changing from non-unidirectional to unidirectional transport. + // In this case, the agent port will change, so we will need to lookup + // the agent by the old agent token instead of agent IP and port. + String oldAgentToken = null; /* Check to see if this agent already has a setup for a server. If it does, allow the user to re-register with the new IP address */ @@ -738,6 +744,8 @@ providerInfo.getProviderAddress() != null && providerInfo.getAgentToken() != null) { + oldAgentToken = providerInfo.getAgentToken(); + boolean setupTokens; SYSTEM_OUT.println("- Agent is already setup for " + @@ -755,7 +763,9 @@ try { response = bizapp.updateAgent(providerInfo.getAgentToken(), user, pword, agentIP, - agentPort); + agentPort, + isNewTransportAgent, + unidirectional); if(response != null) SYSTEM_ERR.println("- Error updating agent: " + response); @@ -763,6 +773,21 @@ SYSTEM_ERR.println("- Error updating agent: " + exc.getMessage()); } + + if (providerInfo.isNewTransport()!=isNewTransportAgent || + providerInfo.isUnidirectional()!=unidirectional) { + + ProviderInfo registeredProviderInfo = + new ProviderInfo(provider, providerInfo.getAgentToken()); + + if (isNewTransportAgent) { + registeredProviderInfo.setNewTransport(unidirectional, + unidirectionalPort); + } + + this.camCommands.setProviderInfo(registeredProviderInfo); + } + return; } } @@ -783,7 +808,9 @@ SYSTEM_OUT.println("- Registering agent with " + PRODUCT); RegisterAgentResult result; try { - result = bizapp.registerAgent(user, pword, tokenRes.getToken(), + result = bizapp.registerAgent(oldAgentToken, + user, pword, + tokenRes.getToken(), agentIP, agentPort, ProductProperties.getVersion(), getCpuCount(), isNewTransportAgent, @@ -840,7 +867,7 @@ String unidirectionalPortString = ""; if (providerInfo.isUnidirectional()) { unidirectionalPortString = ", port="+ - providerInfo.getUnidirectionalPort(); + providerInfo.getUnidirectionalPort(); } SYSTEM_OUT.println("- Agent using new transport, unidirectional="+ Modified: trunk/src/org/hyperic/hq/bizapp/client/BizappCallbackClient.java =================================================================== --- trunk/src/org/hyperic/hq/bizapp/client/BizappCallbackClient.java 2008-06-26 23:35:13 UTC (rev 9897) +++ trunk/src/org/hyperic/hq/bizapp/client/BizappCallbackClient.java 2008-06-26 23:36:56 UTC (rev 9898) @@ -76,7 +76,24 @@ return res.isValid(); } - public RegisterAgentResult registerAgent(String user, String pword, + /** + * Register an agent with the server. + * + * @param oldAgentToken The old agent token or <code>null</code> if the agent + * has never been registered before. + * @param user The user name for connecting the agent to the server. + * @param pword The password for connecting the agent to the server. + * @param authToken The authorization token. + * @param agentIP The agent IP address. + * @param agentPort The agent port where the agent commands services are listening. + * @param version The version. + * @param cpuCount The host platform cpu count. + * @param isNewTransportAgent <code>true</code> if the agent is using the new transport layer. + * @param unidirectional <code>true</code> if the agent is unidirectional. + * @return The result containing the new agent token. + */ + public RegisterAgentResult registerAgent(String oldAgentToken, + String user, String pword, String authToken, String agentIP, int agentPort, String version, @@ -94,6 +111,11 @@ args = new RegisterAgent_args(); args.setUser(user); args.setPword(pword); + + if (oldAgentToken != null) { + args.setAgentToken(oldAgentToken); + } + args.setAuthToken(authToken); args.setAgentIP(agentIP); args.setAgentPort(agentPort); @@ -111,7 +133,9 @@ } public String updateAgent(String agentToken, String user, String pword, - String agentIp, int agentPort) + String agentIp, int agentPort, + boolean isNewTransportAgent, + boolean unidirectional) throws AgentCallbackClientException { UpdateAgent_result res; @@ -126,6 +150,10 @@ args.setAgentIP(agentIp); args.setAgentPort(agentPort); args.setAgentToken(agentToken); + + if (isNewTransportAgent) { + args.setNewTransportAgent(unidirectional); + } res = (UpdateAgent_result)this.invokeLatherCall(provider, CommandInfo.CMD_UPDATE_AGENT, Modified: trunk/src/org/hyperic/hq/bizapp/server/session/LatherDispatcher.java =================================================================== --- trunk/src/org/hyperic/hq/bizapp/server/session/LatherDispatcher.java 2008-06-26 23:35:13 UTC (rev 9897) +++ trunk/src/org/hyperic/hq/bizapp/server/session/LatherDispatcher.java 2008-06-26 23:36:56 UTC (rev 9898) @@ -48,9 +48,7 @@ import org.hyperic.hq.agent.AgentRemoteException; import org.hyperic.hq.agent.client.AgentCommandsClient; import org.hyperic.hq.agent.client.AgentCommandsClientFactory; -import org.hyperic.hq.agent.client.LegacyAgentCommandsClientImpl; import org.hyperic.hq.appdef.Agent; -import org.hyperic.hq.appdef.server.session.AgentManagerEJBImpl; import org.hyperic.hq.appdef.server.session.Platform; import org.hyperic.hq.appdef.server.session.ResourceRefreshZevent; import org.hyperic.hq.appdef.server.session.Server; @@ -76,7 +74,6 @@ import org.hyperic.hq.autoinventory.AutoinventoryException; import org.hyperic.hq.autoinventory.ScanStateCore; import org.hyperic.hq.autoinventory.shared.AutoinventoryManagerLocal; -import org.hyperic.hq.bizapp.agent.client.SecureAgentConnection; import org.hyperic.hq.bizapp.shared.lather.AiSendReport_args; import org.hyperic.hq.bizapp.shared.lather.AiSendRuntimeReport_args; import org.hyperic.hq.bizapp.shared.lather.CommandInfo; @@ -315,21 +312,35 @@ if(errRes != null){ return new RegisterAgent_result(errRes); } - - // Generate a unique agent token + + boolean isOldAgentToken = true; + String agentToken = args.getAgentToken(); AgentManagerLocal agentMan = getAgentManager(); - String agentToken = SecurityUtil.generateRandomToken(); - - while (!agentMan.isAgentTokenUnique(agentToken)) { + if (agentToken == null) { + // Generate a unique agent token agentToken = SecurityUtil.generateRandomToken(); + + while (!agentMan.isAgentTokenUnique(agentToken)) { + agentToken = SecurityUtil.generateRandomToken(); + } + + isOldAgentToken = false; } - - // Check the to see if the agent already exists + + // Check the to see if the agent already exists. + // Lookup the agent by agent token (if it exists). Otherwise, use the + // agent IP and port. Collection ids = null; try { - Agent origAgent = agentMan.getAgent(agentIP, port); - + Agent origAgent; + + if (isOldAgentToken) { + origAgent = agentMan.getAgent(agentToken); + } else { + origAgent = agentMan.getAgent(agentIP, port); + } + try { ids = getPlatformManager(). getPlatformPksByAgentToken(getOverlord(), @@ -337,12 +348,39 @@ } catch (Exception e) { // No platforms found, no a big deal } - - log.info("Updating agent information for " + agentIP + ":" + port); - agentMan.updateAgent(agentIP, port, args.getAuthToken(), - agentToken, version); + + log.info("Found preexisting agent during agent registration. " + + "Updating agent information for " + agentIP + ":" + port + + "; new transport="+isNewTransportAgent+ + "; unidirectional="+unidirectional); + + if (isOldAgentToken) { + if (isNewTransportAgent) { + agentMan.updateNewTransportAgent(agentToken, + agentIP, port, + args.getAuthToken(), + version, + unidirectional); + } else { + agentMan.updateLegacyAgent(agentToken, + agentIP, + port, + args.getAuthToken(), + version); + } + } else { + if (isNewTransportAgent) { + agentMan.updateNewTransportAgent(agentIP, port, args.getAuthToken(), + agentToken, version, unidirectional); + } else { + agentMan.updateLegacyAgent(agentIP, port, args.getAuthToken(), + agentToken, version); + } + } } catch(AgentNotFoundException exc){ - log.info("Registering agent at " + agentIP + ":" + port); + log.info("Registering agent at " + agentIP + ":" + port+"" + + "; new transport="+isNewTransportAgent+ + "; unidirectional="+unidirectional); try { if (isNewTransportAgent) { agentMan.createNewTransportAgent(agentIP, @@ -373,7 +411,7 @@ return new RegisterAgent_result("Error updating agent: " + "Internal system error"); } - + RegisterAgent_result result = new RegisterAgent_result("token:" + agentToken); @@ -448,21 +486,39 @@ } validateAgent(ctx, args.getAgentToken(), false); + + String agentIP = args.getAgentIP(); + int port = args.getAgentPort(); + boolean isNewTransportAgent = args.isNewTransportAgent(); + boolean unidirectional = args.isUnidirectional(); + try { agent = getAgentManager().getAgent(args.getAgentToken()); - if((errRes = testAgentConn(args.getAgentIP(), - args.getAgentPort(), + if((errRes = testAgentConn(agentIP, + port, agent.getAuthToken(), - agent.isNewTransportAgent(), - agent.isUnidirectional())) != null) + isNewTransportAgent, + unidirectional)) != null) { return new UpdateAgent_result(errRes); } + + log.info("Updating agent at " + agentIP + ":" + port+"" + + "; new transport="+isNewTransportAgent+ + "; unidirectional="+unidirectional); + + if (isNewTransportAgent) { + getAgentManager().updateNewTransportAgent(args.getAgentToken(), + agentIP, + port, + unidirectional); + } else { + getAgentManager().updateLegacyAgent(args.getAgentToken(), + agentIP, + port); + } - getAgentManager().updateAgent(args.getAgentToken(), - args.getAgentIP(), - args.getAgentPort()); } catch(AgentNotFoundException exc){ return new UpdateAgent_result("Agent not found for update"); } |