|
From: Peter P. <pr...@us...> - 2007-02-21 13:10:34
|
Update of /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/api In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14405/src/edu/harvard/syrah/pyxida/api Modified Files: ExternalAPI.java XMLRPC_API.java Log Message: Improved Pyxida node webpage Index: ExternalAPI.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/api/ExternalAPI.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ExternalAPI.java 8 Jan 2007 14:07:57 -0000 1.18 --- ExternalAPI.java 21 Feb 2007 13:10:29 -0000 1.19 *************** *** 1,12 **** package edu.harvard.syrah.pyxida.api; ! import java.util.ArrayList; ! import java.util.Hashtable; ! import java.util.List; ! import java.util.Map; ! import java.util.Vector; import edu.harvard.syrah.prp.Log; import edu.harvard.syrah.prp.NetUtil; import edu.harvard.syrah.pyxida.nc.NCManager; import edu.harvard.syrah.pyxida.nc.lib.Coordinate; --- 1,9 ---- package edu.harvard.syrah.pyxida.api; ! import java.util.*; import edu.harvard.syrah.prp.Log; import edu.harvard.syrah.prp.NetUtil; + import edu.harvard.syrah.pyxida.Pyxida; import edu.harvard.syrah.pyxida.nc.NCManager; import edu.harvard.syrah.pyxida.nc.lib.Coordinate; *************** *** 20,38 **** public class ExternalAPI extends HTTPCallbackHandler implements ExternalAPIIF { private static final Log log = new Log(ExternalAPI.class); ! private static String HTTP_COORD_BEGIN = ! "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" ! + "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">" ! + "<head>" ! + "<title>Pyxida Node</title>" ! + "</head>" ! + "<body>"; ! ! private static String HTTP_COORD_END = ! "</body>" ! + "</html>"; private NCManager ncManager; ! public ExternalAPI(NCManager ncManager) { this.ncManager = ncManager; --- 17,55 ---- public class ExternalAPI extends HTTPCallbackHandler implements ExternalAPIIF { private static final Log log = new Log(ExternalAPI.class); ! private static String HTTP_COORD_BEGIN = ! "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" ! + "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n" ! + "<head>\n" ! + "<title>Pyxida Node</title>\n" ! + "<style type=\"text/css\">\n" ! + "body { margin-top: 1em; margin-bottom: 1em; margin-left: 1em; margin-right: 1em; }\n" ! + "</style>\n" ! + "</head>\n" ! + "<body>\n" ! + "<img style=\"float: left; margin-right: 1em; \" alt=\"Pyxida Logo\" src=\"http://pyxida.sourceforge.net/img/pyxida4-scaled.jpg\"/>\n" ! + "<center><h2><a href=\"http://pyxida.sourceforge.net\">Pyxida</a> Node Information</h2>\n" ! + "<table>\n" ! + "<tr><td width=\"40%\" align=\"center\"><h3>Node Information</h3></td>\n" ! + "<td width=\"10%\"> </td>\n" ! + "<td><h3 width=\"50%\" align=\"center\">Neighbour Information</h3></td>\n" ! + "</tr>\n" ! + "<tr><td align=\"center\" valign=\"top\">\n" ! + "<table>\n"; ! ! private static String HTTP_COORD_MIDDLE = ! "</td>\n" ! + "<td></td><td></table>\n" ! + "</td><td> </td><td valign=\"top\"><table width=\"100%\">\n"; ! ! private static String HTTP_COORD_END = ! "</table>\n" ! + "</td></tr></table>\n" ! + "</center>\n" ! + "</body>\n" ! + "</html>\n"; private NCManager ncManager; ! public ExternalAPI(NCManager ncManager) { this.ncManager = ncManager; *************** *** 40,44 **** public void createProxyCoord(String remoteNodeStr, final int lease, ! final CB1<String> cbResult) { AddressFactory.createResolved(remoteNodeStr, new CB1<AddressIF>() { protected void cb(CBResult nsResult, AddressIF remoteNode) { --- 57,61 ---- public void createProxyCoord(String remoteNodeStr, final int lease, ! final CB1<String> cbResult) { AddressFactory.createResolved(remoteNodeStr, new CB1<AddressIF>() { protected void cb(CBResult nsResult, AddressIF remoteNode) { *************** *** 59,67 **** } } ! }); } public void getProxyCoord(String remoteNodeStr, ! final CB2<Vector<Double>,String> cbProxyCoord) { AddressFactory.createResolved(remoteNodeStr, new CB1<AddressIF>() { protected void cb(CBResult nsResult, AddressIF remoteNode) { --- 76,84 ---- } } ! }); } public void getProxyCoord(String remoteNodeStr, ! final CB2<Vector<Double>,String> cbProxyCoord) { AddressFactory.createResolved(remoteNodeStr, new CB1<AddressIF>() { protected void cb(CBResult nsResult, AddressIF remoteNode) { *************** *** 82,90 **** } } ! }); } public void destroyProxyCoord(String remoteNodeStr, ! final CB1<String> cbResult) { AddressFactory.createResolved(remoteNodeStr, new CB1<AddressIF>() { protected void cb(CBResult nsResult, AddressIF remoteNode) { --- 99,107 ---- } } ! }); } public void destroyProxyCoord(String remoteNodeStr, ! final CB1<String> cbResult) { AddressFactory.createResolved(remoteNodeStr, new CB1<AddressIF>() { protected void cb(CBResult nsResult, AddressIF remoteNode) { *************** *** 104,108 **** } } ! }); } --- 121,125 ---- } } ! }); } *************** *** 113,127 **** case OK: { log.debug("estimateRTT a="+nodeA+" b="+nodeB); ! if (addrMap.get(nodeA) == null) { ! String error = "Could not resolve a="+nodeA; ! log.warn(error); ! cbDistance.call(CBResult.ERROR(error),new Double(0)); ! } else if (addrMap.get(nodeB) == null) { ! String error = "Could not resolve b="+nodeB; ! log.warn(error); ! cbDistance.call(CBResult.ERROR(error),new Double(0)); ! } else { ! ncManager.estimateRTT(addrMap.get(nodeA), addrMap.get(nodeB), cbDistance); ! } break; } --- 130,144 ---- case OK: { log.debug("estimateRTT a="+nodeA+" b="+nodeB); ! if (addrMap.get(nodeA) == null) { ! String error = "Could not resolve a="+nodeA; ! log.warn(error); ! cbDistance.call(CBResult.ERROR(error),new Double(0)); ! } else if (addrMap.get(nodeB) == null) { ! String error = "Could not resolve b="+nodeB; ! log.warn(error); ! cbDistance.call(CBResult.ERROR(error),new Double(0)); ! } else { ! ncManager.estimateRTT(addrMap.get(nodeA), addrMap.get(nodeB), cbDistance); ! } break; } *************** *** 129,139 **** case ERROR: { log.warn(result.toString()); ! cbDistance.call(result,new Double(0)); } } } }); ! ! } --- 146,156 ---- case ERROR: { log.warn(result.toString()); ! cbDistance.call(result,new Double(0)); } } } }); ! ! } *************** *** 153,164 **** } ! public void getRemoteCoords(final Hashtable<String, Object> remoteNodesMap, ! final CB1<Map<String, Object>> cbRemoteCoords) { ! String [] nodesStr = new String[remoteNodesMap.size()]; int i = 0; for (Object obj : remoteNodesMap.keySet()) { String remoteNode = (String) obj; ! log.debug ("getRemoteCoords["+i+"]= "+remoteNode); nodesStr[i] = remoteNode; i++; --- 170,181 ---- } ! public void getRemoteCoords(final Hashtable<String, Object> remoteNodesMap, ! final CB1<Map<String, Object>> cbRemoteCoords) { ! String [] nodesStr = new String[remoteNodesMap.size()]; int i = 0; for (Object obj : remoteNodesMap.keySet()) { String remoteNode = (String) obj; ! log.debug ("getRemoteCoords["+i+"]= "+remoteNode); nodesStr[i] = remoteNode; i++; *************** *** 171,226 **** switch (result.state) { case OK: ! ! //TODO jonathan: why do you handle OK and TIMEOUT together and why is there an ERROR clause? ! // The way createResolved works is that it always returns OK but only includes the hostnames ! // that resolved correctly in the map. Let me know if you don't like this behaviour and I can change it. case TIMEOUT: { ! //StringBuffer dnsErrors = new StringBuffer(); List<AddressIF> remoteNodes = new ArrayList<AddressIF>(); ! for (AddressIF node : addrMap.values()) { ! if (node != null && node.hasPort()) { ! remoteNodes.add(node); ! } ! //else { ! //dnsErrors.append("Could not resolve "+node); ! //} ! } ncManager.getRemoteCoords(remoteNodes, new CB2<Map<AddressIF,Coordinate>,String>() { ! protected void cb(CBResult ncResult, ! Map<AddressIF,Coordinate> addr2coord, ! String errorString) { ! // TODO this does not work ! // We want to return DNS failures to the client ! ! // combine the two errors if there is already one in there ! // caused through DNS resolution problem below ! if (errorString.equals("Success")) { ! if (resultMap.get("result") == null) { ! resultMap.put("result", "Success"); ! } ! } else { ! if (resultMap.get("result") == null) { ! resultMap.put("result", errorString); ! } else { ! resultMap.put("result", resultMap.get("result") + "\n"+errorString); ! } ! } ! ! log.debug("responding to client addr2coord="+addr2coord.size()+ ! " errorString="+resultMap.get("result")); ! for (Map.Entry<AddressIF,Coordinate> entry : addr2coord.entrySet()) { ! resultMap.put(entry.getKey().toString(false), ! getVectorFromCoord(entry.getValue())); } - cbRemoteCoords.call(CBResult.OK(), resultMap); } ! }); break; } ! case ERROR: { // problem resolving one or more of the addresses log.warn(result.toString()); --- 188,243 ---- switch (result.state) { case OK: ! ! //TODO jonathan: why do you handle OK and TIMEOUT together and why is there an ERROR clause? ! // The way createResolved works is that it always returns OK but only includes the hostnames ! // that resolved correctly in the map. Let me know if you don't like this behaviour and I can change it. case TIMEOUT: { ! //StringBuffer dnsErrors = new StringBuffer(); List<AddressIF> remoteNodes = new ArrayList<AddressIF>(); ! for (AddressIF node : addrMap.values()) { ! if (node != null && node.hasPort()) { ! remoteNodes.add(node); ! } ! //else { ! //dnsErrors.append("Could not resolve "+node); ! //} ! } ncManager.getRemoteCoords(remoteNodes, new CB2<Map<AddressIF,Coordinate>,String>() { ! protected void cb(CBResult ncResult, ! Map<AddressIF,Coordinate> addr2coord, ! String errorString) { ! // TODO this does not work ! // We want to return DNS failures to the client ! ! // combine the two errors if there is already one in there ! // caused through DNS resolution problem below ! if (errorString.equals("Success")) { ! if (resultMap.get("result") == null) { ! resultMap.put("result", "Success"); ! } ! } else { ! if (resultMap.get("result") == null) { ! resultMap.put("result", errorString); ! } else { ! resultMap.put("result", resultMap.get("result") + "\n"+errorString); } } ! ! log.debug("responding to client addr2coord="+addr2coord.size()+ ! " errorString="+resultMap.get("result")); ! for (Map.Entry<AddressIF,Coordinate> entry : addr2coord.entrySet()) { ! resultMap.put(entry.getKey().toString(false), ! getVectorFromCoord(entry.getValue())); ! } ! cbRemoteCoords.call(CBResult.OK(), resultMap); ! } ! }); break; } ! case ERROR: { // problem resolving one or more of the addresses log.warn(result.toString()); *************** *** 235,239 **** public void getRemoteCoord(final String remoteNodeStr, ! final CB1<Map<String, Object>> cbRemoteCoord) { AddressFactory.createResolved(remoteNodeStr, new CB1<AddressIF>() { protected void cb(CBResult nsResult, AddressIF remoteNode) { --- 252,256 ---- public void getRemoteCoord(final String remoteNodeStr, ! final CB1<Map<String, Object>> cbRemoteCoord) { AddressFactory.createResolved(remoteNodeStr, new CB1<AddressIF>() { protected void cb(CBResult nsResult, AddressIF remoteNode) { *************** *** 250,268 **** cbRemoteCoord.call(CBResult.OK(), resultMap); return; ! */ ! ncManager.getRemoteCoord(remoteNode, new CB1<Coordinate>() { protected void cb(CBResult ncResult, Coordinate remoteCoord) { Map<String, Object> resultMap = new Hashtable<String, Object>(); ! switch (ncResult.state) { ! case OK: { ! Vector<Double> listCoord = getVectorFromCoord(remoteCoord); ! resultMap.put("coord", listCoord); ! resultMap.put("result", "Success"); ! cbRemoteCoord.call(CBResult.OK(), resultMap); ! break; ! } case TIMEOUT: case ERROR: { --- 267,285 ---- cbRemoteCoord.call(CBResult.OK(), resultMap); return; ! */ ! ncManager.getRemoteCoord(remoteNode, new CB1<Coordinate>() { protected void cb(CBResult ncResult, Coordinate remoteCoord) { Map<String, Object> resultMap = new Hashtable<String, Object>(); ! switch (ncResult.state) { ! case OK: { ! Vector<Double> listCoord = getVectorFromCoord(remoteCoord); ! resultMap.put("coord", listCoord); ! resultMap.put("result", "Success"); ! cbRemoteCoord.call(CBResult.OK(), resultMap); ! break; ! } case TIMEOUT: case ERROR: { *************** *** 285,294 **** break; } ! } } }); } ! public void getLocalError(CB1<Double> cbLocalError) { cbLocalError.call(CBResult.OK(), ncManager.getLocalError()); --- 302,311 ---- break; } ! } } }); } ! public void getLocalError(CB1<Double> cbLocalError) { cbLocalError.call(CBResult.OK(), ncManager.getLocalError()); *************** *** 296,300 **** public void renewProxyCoord(String remoteNodeStr, final int lease, ! final CB1<String> cbResult) { AddressFactory.createResolved(remoteNodeStr, new CB1<AddressIF>() { protected void cb(CBResult nsResult, AddressIF remoteNode) { --- 313,317 ---- public void renewProxyCoord(String remoteNodeStr, final int lease, ! final CB1<String> cbResult) { AddressFactory.createResolved(remoteNodeStr, new CB1<AddressIF>() { protected void cb(CBResult nsResult, AddressIF remoteNode) { *************** *** 314,318 **** } } ! }); } --- 331,335 ---- } } ! }); } *************** *** 320,332 **** protected void cb(CBResult result, AddressIF remoteAddr, String path, String requestData, CB2<String, byte[]> cbResponse) { ! Coordinate coord = ncManager.getLocalCoord(); ! String response = ! HTTP_COORD_BEGIN ! + "<a href=\"http://pyxida.sourceforge.net\"><img style=\"float: left; \" alt=\"Pyxida Logo\" src=\"http://pyxida.sourceforge.net/img/pyxida4-scaled.jpg\"/></a>" ! + "Local Network Coordinate: " + coord + "\n" ! + HTTP_COORD_END; ! cbResponse.call(result, "text/html", NetUtil.toHTTPBytes(response)); } --- 337,392 ---- protected void cb(CBResult result, AddressIF remoteAddr, String path, String requestData, CB2<String, byte[]> cbResponse) { ! Coordinate coord = ncManager.getLocalCoord(); + + StringBuffer sb = new StringBuffer(); + + sb.append(HTTP_COORD_BEGIN); ! sb.append("<tr><td><em>Version:</em></td><td width=10></td><td>" + Pyxida.VERSION + "</td></tr>\n"); ! sb.append("<tr><td><em>Uptime:</em></td><td width=10></td><td>" + Pyxida.getUptimeStr() + "</td></tr>\n"); ! ! sb.append("<tr><td> </td></tr>\n"); ! ! sb.append("<tr><td><em>Primary Sys Coord:</em></td><td width=10></td><td>" + ncManager.getLocalCoord() + "</td></tr>\n"); ! sb.append("<tr><td><em>Primary Sys Coord Error:</em></td><td width=10></td><td>" + ncManager.getLocalError() + "</td></tr>\n"); ! sb.append("<tr><td><em>Primary App Coord:</em></td><td width=10></td><td>" + ncManager.getStableCoord() + "</td></tr>\n"); ! ! sb.append("<tr><td> </td></tr>\n"); ! ! sb.append("<tr><td><em>Secondary Sys Coord:</em></td><td width=10></td><td>" + ncManager.getLocalSecondaryCoord() + "</td></tr>\n"); ! sb.append("<tr><td><em>Secondary Sys Coord Error:</em></td><td width=10></td><td>" + ncManager.getLocalSecondaryError() + "</td></tr>\n"); ! sb.append("<tr><td><em>Secondary App Coord:</em></td><td width=10></td><td>" + ncManager.getStableSecondaryCoord() + "</td></tr>\n"); ! ! sb.append(HTTP_COORD_MIDDLE); ! ! Set<AddressIF> upNeighbours = ncManager.getUpNeighbours(); ! sb.append("<tr><td align=\"center\"><em>Up Neighbours (" + upNeighbours.size() + ")</em></td></tr>\n"); ! for (AddressIF upNeighbour : upNeighbours) { ! sb.append("<tr><td align=\"left\"><a href=\"http://" + upNeighbour.getHostname() + ":" + XMLRPC_API.API_PORT + "/\">"); ! sb.append(upNeighbour.getHostname() + ":" + XMLRPC_API.API_PORT + "</a></td></tr>\n"); ! } ! ! sb.append("<tr><td> </td></tr>\n"); ! ! Set<AddressIF> pendingNeighbours = ncManager.getPendingNeighbours(); ! sb.append("<tr><td align=\"center\"><em>Pending Neighbours (" + pendingNeighbours.size() + ")</em></td></tr>\n"); ! for (AddressIF pendingNeighbour : pendingNeighbours) { ! sb.append("<tr><td align=\"left\"><a href=\"http://" + pendingNeighbour.getHostname() + ":" + XMLRPC_API.API_PORT + "/\">"); ! sb.append(pendingNeighbour.getHostname() + ":" + XMLRPC_API.API_PORT + "</a></td></tr>\n"); ! } ! ! sb.append("<tr><td> </td></tr>\n"); ! ! Set<AddressIF> downNeighbours = ncManager.getDownNeighbours(); ! sb.append("<tr><td align=\"center\"><em>Down Neighbours (" + downNeighbours.size() + ")</em></td></tr>\n"); ! for (AddressIF downNeighbour : downNeighbours) { ! sb.append("<tr><td align=\"left\"><a href=\"http://" + downNeighbour.getHostname() + ":" + XMLRPC_API.API_PORT + "/\">"); ! sb.append(downNeighbour.getHostname() + ":" + XMLRPC_API.API_PORT + "</a></td></tr>\n"); ! } ! ! sb.append(HTTP_COORD_END); ! ! cbResponse.call(result, "text/html", NetUtil.toHTTPBytes(sb.toString())); } Index: XMLRPC_API.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/api/XMLRPC_API.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** XMLRPC_API.java 13 Dec 2006 14:23:12 -0000 1.5 --- XMLRPC_API.java 21 Feb 2007 13:10:29 -0000 1.6 *************** *** 14,17 **** --- 14,19 ---- private static final String XMLRPC_OBJECT_NAME = "pyxida"; + static final int API_PORT = Integer.parseInt(Config.getProperty("pyxida.api.port", "55501")); + // App comm interface private XMLRPCCommIF apiComm; *************** *** 25,31 **** public void init(CB0 cbDone) { apiComm = new XMLRPCComm(); ! int port = Integer.parseInt(Config.getProperty("pyxida.api.port", "55501")); ! log.debug("Using port=" + port); ! AddressIF apiAddress = AddressFactory.createServer(port); apiComm.registerXMLRPCHandler(XMLRPC_OBJECT_NAME, api); apiComm.registerHandler("/", api); --- 27,32 ---- public void init(CB0 cbDone) { apiComm = new XMLRPCComm(); ! log.debug("Using port=" + API_PORT); ! AddressIF apiAddress = AddressFactory.createServer(API_PORT); apiComm.registerXMLRPCHandler(XMLRPC_OBJECT_NAME, api); apiComm.registerHandler("/", api); |