Commit 9143326f authored by Jonathon Duerig's avatar Jonathon Duerig

Made rpc call names and module names ('sa'/'cm'/'ch') centralized rather than...

Made rpc call names and module names ('sa'/'cm'/'ch') centralized rather than distributed. This will make adapting to a changing API easier.
parent 794f7c64
package
{
import flash.display.SimpleButton;
import flash.text.TextField;
import flash.events.Event;
import flash.events.ErrorEvent;
import flash.events.MouseEvent;
import Error;
import com.mattism.http.xmlrpc.Connection;
import com.mattism.http.xmlrpc.ConnectionImpl;
import com.mattism.http.xmlrpc.MethodFault;
public class Geni
{
/*
public static function init(newConsole : TextField,
newButton : SimpleButton) : void
{
op = new Operation("", "");
console = newConsole;
button = newButton;
button.addEventListener(MouseEvent.CLICK, methodStart);
credential = null;
leebee = null;
sliceUuid = null;
current = 0;
}
static function methodStart(event : MouseEvent) : void
{
console.appendText("START: " + name[current] + "\n");
start[current]();
button.removeEventListener(MouseEvent.CLICK, methodStart);
button.visible = false;
}
static function methodComplete(code : Number, value : String,
output : String,
response : Object) : void
{
if (code == 0)
{
console.appendText("COMPLETE: " + name[current] + "\n");
if (output != "")
{
console.appendText("Output: " + output + "\n");
}
complete[current](value, response);
button.addEventListener(MouseEvent.CLICK, methodStart);
button.visible = true;
}
else
{
console.appendText("COMPLETE CODE: " + name[current] + ": " + code
+ "\n");
}
++current;
if (current >= name.length)
{
button.visible = false;
button.removeEventListener(MouseEvent.CLICK, methodStart);
}
}
static function methodFailure(event : ErrorEvent, fault : MethodFault) : void
{
if (fault != null)
{
console.appendText("FAILURE: " + name[current] + ": "
+ fault.getFaultString() + "\n");
}
else
{
console.appendText("FAILURE: " + name[current] + ": Fault is null: "
+ event.toString() + "\n");
}
}
static function startCredential() : void
{
op.reset("sa", "GetCredential");
op.addField("uuid", "0b2eb97e-ed30-11db-96cb-001143e453fe");
op.call(methodComplete, methodFailure);
}
static function completeCredential(value : String,
response : Object) : void
{
credential = value;
}
static function startLeigh() : void
{
op.reset("sa", "Resolve");
op.addField("hrn", "stoller");
op.addField("credential", credential);
op.addField("type", "User");
op.call(methodComplete, methodFailure);
}
static function completeNoop(value : String, response : Object) : void
{
}
static function startLeebee() : void
{
op.reset("sa", "Resolve");
op.addField("hrn", "leebee");
op.addField("credential", credential);
op.addField("type", "User");
op.call(methodComplete, methodFailure);
}
static function completeLeebee(value : String, response : Object) : void
{
leebee = value;
}
static function startLookupNode() : void
{
op.reset("cm", "Resolve");
op.addField("hrn", "pc41");
op.addField("credential", credential);
op.addField("type", "Node");
op.setUrl("https://myboss.myelab.testbed.emulab.net:443/protogeni/xmlrpc");
op.call(methodComplete, methodFailure);
}
static function startSliceCheck() : void
{
op.reset("sa", "Resolve");
op.addField("hrn", "myslice1");
op.addField("credential", credential);
op.addField("type", "Slice");
op.call(sliceCheckComplete, methodFailure);
}
static function sliceCheckComplete(code : Number, value : String,
output : String,
response : Object) : void
{
if (code == 0)
{
console.appendText("COMPLETE: Slice exists. We must delete it.\n");
if (output != "")
{
console.appendText("Output: " + output + "\n");
}
var slice : Object = response["value"];
sliceUuid = slice["uuid"];
}
else
{
console.appendText("COMPLETE: Slice does not exist. "
+ "Skipping deletion.\n");
++current;
}
button.addEventListener(MouseEvent.CLICK, methodStart);
button.visible = true;
++current;
if (current >= name.length)
{
button.visible = false;
button.removeEventListener(MouseEvent.CLICK, methodStart);
}
}
public function startSliceDelete() : void
{
op.reset("sa", "Remove");
op.addField("credential", credential);
op.addField("uuid",
op.addField("type", "Slice");
op.call(sliceCheckComplete, methodFailure);
}
static var op : Operation;
static var console : TextField = null;
static var button : SimpleButton = null;
static var credential : String;
static var leebee : String;
static var sliceUuid : String;
static var current : int = 0;
static var name : Array = new Array("Request Credential",
"Lookup Leigh",
"Lookup Leebee",
"Lookup pc41",
"Slice Check",
"Slice Delete");
static var start : Array = new Array(startCredential,
startLeigh,
startLeebee,
startLookupNode,
startSliceCheck,
startSliceDelete);
static var complete : Array = new Array(completeCredential,
completeNoop,
completeLeebee,
completeNoop,
completeNoop,
completeNoop);
static var ch : String = "sa";
static var cm : String = "cm";
public static var getCredential = new Array(ch, "GetCredential");
public static var resolve = new Array(ch, "Resolve");
public static var remove = new Array(ch, "Remove");
public static var register = new Array(ch, "Register");
public static var discoverResources = new Array(cm, "DiscoverResources");
public static var getTicket = new Array(cm, "GetTicket");
public static var redeemTicket = new Array(cm, "RedeemTicket");
public static var deleteSliver = new Array(cm, "DeleteSliver");
public static var startSliver = new Array(cm, "StartSliver");
public static var updateSliver = new Array(cm, "UpdateSliver");
}
*/
}
......@@ -26,7 +26,7 @@ package
clip.addEventListener(Event.ENTER_FRAME, enterFrame);
op = new Operation("", "");
op = new Operation(null);
startCredential();
}
......@@ -71,6 +71,7 @@ package
var before : int = clip.xmlText.scrollV;
clip.xmlText.appendText("\n-----------------------------------------\n");
clip.xmlText.appendText("SEND: " + opName + "\n");
clip.xmlText.appendText("URL: " + op.getUrl() + "\n");
clip.xmlText.appendText("-----------------------------------------\n\n");
clip.xmlText.appendText(op.getSendXml());
clip.xmlText.scrollV = before;
......@@ -91,7 +92,7 @@ package
{
opName = "Acquiring credential";
clip.loadText.text = opName;
op.reset("sa", "GetCredential");
op.reset(Geni.getCredential);
op.addField("uuid", "0b2eb97e-ed30-11db-96cb-001143e453fe");
op.call(completeCredential, failure);
addSend();
......@@ -115,7 +116,7 @@ package
{
opName = "Lookup User";
clip.loadText.text = "Looking up user '" + userName + "'";
op.reset("sa", "Resolve");
op.reset(Geni.resolve);
op.addField("hrn", userName);
op.addField("credential", credential.base);
op.addField("type", "User");
......@@ -141,7 +142,7 @@ package
{
opName = "Lookup Slice";
clip.loadText.text = "Looking up slice name '" + sliceName + "'";
op.reset("sa", "Resolve");
op.reset(Geni.resolve);
op.addField("hrn", sliceName);
op.addField("credential", credential.base);
op.addField("type", "Slice");
......@@ -167,7 +168,7 @@ package
{
opName = "Delete";
clip.loadText.text = "Deleting existing slice";
op.reset("sa", "Remove");
op.reset(Geni.remove);
op.addField("credential", credential.base);
op.addField("uuid", sliceId);
op.addField("type", "Slice");
......@@ -192,7 +193,7 @@ package
{
opName = "Create";
clip.loadText.text = "Creating new slice";
op.reset("sa", "Register");
op.reset(Geni.register);
op.addField("credential", credential.base);
op.addField("hrn", sliceName);
op.addField("type", "Slice");
......@@ -227,7 +228,7 @@ package
"</rspec>";
opName = "Looking up resources";
clip.loadText.text = opName;
op.reset("cm", "DiscoverResources");
op.reset(Geni.discoverResources);
op.addField("credential", credential.slice);
op.addField("rspec", rspec);
op.setUrl("https://myboss.myelab.testbed.emulab.net:443/protogeni/xmlrpc");
......
......@@ -6,16 +6,19 @@ package
class Operation
{
public function Operation(newModule : String, newMethod : String) : void
public function Operation(qualifiedMethod : Array) : void
{
server = null;
reset(newModule, newMethod);
reset(qualifiedMethod);
}
public function reset(newModule : String, newMethod : String) : void
public function reset(qualifiedMethod : Array) : void
{
module = newModule;
method = newMethod;
if (qualifiedMethod != null)
{
module = qualifiedMethod[0];
method = qualifiedMethod[1];
}
clearFields();
resetUrl();
if (server != null)
......@@ -37,6 +40,11 @@ package
url = newUrl + "/" + module;
}
public function getUrl() : String
{
return url;
}
public function addField(key : String, value : Object) : void
{
param[key] = value;
......
......@@ -4,7 +4,7 @@ package
{
public function Request() : void
{
op = new Operation("", "");
op = new Operation(null);
opName = "";
}
......
......@@ -17,7 +17,7 @@ package
override public function start(credential : Credential) : Operation
{
opName = "Requesting Resources";
op.reset("cm", "DiscoverResources");
op.reset(Geni.discoverResources);
op.addField("credential", credential.slice);
op.setUrl(cm.getUrl(cmIndex));
return op;
......
......@@ -23,7 +23,7 @@ package
if (cm.getTicket(cmIndex) == null)
{
opName = "Getting Ticket";
op.reset("cm", "GetTicket");
op.reset(Geni.getTicket);
op.addField("credential", credential.slice);
op.addField("rspec", rspec);
op.addField("impotent", Request.IMPOTENT);
......@@ -32,7 +32,7 @@ package
else
{
opName = "Redeeming Ticket";
op.reset("cm", "RedeemTicket");
op.reset(Geni.redeemTicket);
op.addField("ticket", cm.getTicket(cmIndex));
op.addField("impotent", Request.IMPOTENT);
op.setUrl(cm.getUrl(cmIndex));
......
......@@ -21,7 +21,7 @@ package
// TODO: Check to make sure that credential.slivers[cmIndex]
// exists and perform a no-op if it doesn't.
opName = "Deleting Sliver";
op.reset("cm", "DeleteSliver");
op.reset(Geni.deleteSliver);
op.addField("credential", credential.slivers[cmIndex]);
op.addField("impotent", Request.IMPOTENT);
op.setUrl(url);
......
......@@ -19,7 +19,7 @@ package
override public function start(credential : Credential) : Operation
{
opName = "Booting Sliver";
op.reset("cm", "StartSliver");
op.reset(Geni.startSliver);
op.addField("credential", credential.slivers[cmIndex]);
op.addField("impotent", Request.IMPOTENT);
op.setUrl(url);
......
......@@ -21,7 +21,7 @@ package
override public function start(credential : Credential) : Operation
{
opName = "Updating Sliver";
op.reset("cm", "UpdateSliver");
op.reset(Geni.updateSliver);
op.addField("credential", credential.slivers[cmIndex]);
op.addField("rspec", rspec);
op.addField("impotent", Request.IMPOTENT);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment