Commit 7b355473 authored by Jonathon Duerig's avatar Jonathon Duerig

Robustness improvements. Merging with other changes.

parent 729b7fe7
...@@ -316,16 +316,38 @@ package ...@@ -316,16 +316,38 @@ package
return result; return result;
} }
public function changeState(cmIndex : int, newState : int) : void public function changeState(cmIndex : int, oldState : int,
newState : int) : void
{ {
var i : int = 0; var i : int = 0;
for (; i < nodes.length; ++i) for (; i < nodes.length; ++i)
{ {
nodes[i].changeState(cmIndex, newState); if (nodes[i].calculateState() == oldState)
{
nodes[i].changeState(cmIndex, newState);
}
} }
updateSelectText(); updateSelectText();
} }
public function revertState(cmIndex : int) : void
{
var i : int = 0;
for (; i < nodes.length; ++i)
{
nodes[i].revertState(cmIndex);
}
}
public function commitState(cmIndex : int) : void
{
var i : int = 0;
for (; i < nodes.length; ++i)
{
nodes[i].commitState(cmIndex);
}
}
public function existsState(cmIndex : int, newState : int) : Boolean public function existsState(cmIndex : int, newState : int) : Boolean
{ {
var result : Boolean = false; var result : Boolean = false;
...@@ -354,15 +376,13 @@ package ...@@ -354,15 +376,13 @@ package
static var NO_SELECTION : int = -1; static var NO_SELECTION : int = -1;
public static var PLANNED : int = 0; public static var PLANNED : int = 0;
public static var PENDING : int = 1; public static var CREATED : int = 1;
public static var CREATED : int = 2; public static var BOOTED : int = 2;
public static var BOOTED : int = 3; public static var PENDING : int = 3;
public static var FAILED : int = 4;
public static var statusText = new Array("Planned", public static var statusText = new Array("Planned",
"Pending",
"Created", "Created",
"Booted", "Booted",
"Failed"); "Pending");
} }
} }
...@@ -104,7 +104,7 @@ package ...@@ -104,7 +104,7 @@ package
if (newRequest != null) if (newRequest != null)
{ {
queue.push(newRequest); queue.push(newRequest);
nodes.changeState(i, ActiveNodes.PENDING); // nodes.changeState(i, ActiveNodes.PENDING);
if (! working) if (! working)
{ {
start(); start();
......
...@@ -49,7 +49,9 @@ package ...@@ -49,7 +49,9 @@ package
renumber(newNumber); renumber(newNumber);
links = new Array(); links = new Array();
changeState(cmIndex, ActiveNodes.PLANNED); oldState = ActiveNodes.PLANNED;
newState = ActiveNodes.PLANNED;
updateState();
} }
public function cleanup() : void public function cleanup() : void
...@@ -140,15 +142,50 @@ package ...@@ -140,15 +142,50 @@ package
return cmIndex; return cmIndex;
} }
public function changeState(index : int, newState : int) : void public function changeState(index : int, state : int) : void
{ {
if (index == cmIndex) if (index == cmIndex)
{ {
clip.node.nameField.backgroundColor = stateColor[newState]; newState = state;
state = newState; updateState();
} }
} }
public function commitState(index : int) : void
{
if (index == cmIndex)
{
oldState = newState;
updateState();
}
}
public function revertState(index : int) : void
{
if (index == cmIndex)
{
newState = oldState;
updateState();
}
}
public function calculateState() : int
{
var state : int = newState;
if (newState != oldState)
{
state = ActiveNodes.PENDING;
}
return state;
}
public function updateState() : void
{
var state : int = calculateState();
clip.node.nameField.backgroundColor = stateColor[state];
}
public function getXml(targetIndex : int) : XML public function getXml(targetIndex : int) : XML
{ {
var result : XML = null; var result : XML = null;
...@@ -165,11 +202,13 @@ package ...@@ -165,11 +202,13 @@ package
public function isState(index : int, exemplar : int) : Boolean public function isState(index : int, exemplar : int) : Boolean
{ {
var state : int = calculateState();
return index == cmIndex && state == exemplar; return index == cmIndex && state == exemplar;
} }
public function getStatusText() : String public function getStatusText() : String
{ {
var state : int = calculateState();
var result : String = ""; var result : String = "";
result += "<font color=\"#7777ff\">Name:</font> " + name + "\n"; result += "<font color=\"#7777ff\">Name:</font> " + name + "\n";
result += "<font color=\"#7777ff\">UUID:</font> " + id + "\n"; result += "<font color=\"#7777ff\">UUID:</font> " + id + "\n";
...@@ -179,6 +218,11 @@ package ...@@ -179,6 +218,11 @@ package
{ {
result += "<font color=\"#7777ff\">Status:</font> " result += "<font color=\"#7777ff\">Status:</font> "
+ ActiveNodes.statusText[state]; + ActiveNodes.statusText[state];
if (state == ActiveNodes.PENDING)
{
result += ": " + ActiveNodes.statusText[oldState] + " -> "
+ ActiveNodes.statusText[newState];
}
} }
return result; return result;
} }
...@@ -192,7 +236,8 @@ package ...@@ -192,7 +236,8 @@ package
var links : Array; var links : Array;
var mouseDownNode : Function; var mouseDownNode : Function;
var mouseDownLink : Function; var mouseDownLink : Function;
var state : int; var oldState : int;
var newState : int;
static var virtType = "emulab-vnode"; static var virtType = "emulab-vnode";
...@@ -203,9 +248,9 @@ package ...@@ -203,9 +248,9 @@ package
public static var CENTER_Y : int = Math.floor(HEIGHT/2); public static var CENTER_Y : int = Math.floor(HEIGHT/2);
static var stateColor = new Array(0xaaaaff, static var stateColor = new Array(0xaaaaff,
0xaaaaaa,
0xaaffaa, 0xaaffaa,
0xaaffff, 0xaaffff,
0xffaaaa); 0xaaaaaa);
// 0xffaaaa);
} }
} }
...@@ -36,6 +36,7 @@ package ...@@ -36,6 +36,7 @@ package
{ {
if (cm.getTicket(cmIndex) == null) if (cm.getTicket(cmIndex) == null)
{ {
nodes.changeState(cmIndex, ActiveNodes.PLANNED, ActiveNodes.CREATED);
opName = "Getting Ticket"; opName = "Getting Ticket";
op.reset(Geni.getTicket); op.reset(Geni.getTicket);
op.addField("credential", credential.slice); op.addField("credential", credential.slice);
...@@ -68,21 +69,26 @@ package ...@@ -68,21 +69,26 @@ package
} }
else else
{ {
nodes.changeState(cmIndex, ActiveNodes.CREATED); nodes.commitState(cmIndex);
credential.slivers[cmIndex] = response.value; credential.slivers[cmIndex] = response.value;
cm.setTicket(cmIndex, null); cm.setTicket(cmIndex, null);
} }
} }
else else
{ {
nodes.changeState(cmIndex, ActiveNodes.FAILED); if (cm.getTicket(cmIndex) != null)
{
// TODO: DeleteTicket
}
nodes.revertState(cmIndex);
} }
return result; return result;
} }
override public function fail() : void override public function fail() : void
{ {
nodes.changeState(cmIndex, ActiveNodes.FAILED); // TODO: DeleteTicket
nodes.revertState(cmIndex);
} }
var cmIndex : int; var cmIndex : int;
......
...@@ -34,6 +34,8 @@ package ...@@ -34,6 +34,8 @@ package
{ {
// TODO: Check to make sure that credential.slivers[cmIndex] // TODO: Check to make sure that credential.slivers[cmIndex]
// exists and perform a no-op if it doesn't. // exists and perform a no-op if it doesn't.
nodes.changeState(cmIndex, ActiveNodes.CREATED, ActiveNodes.PLANNED);
nodes.changeState(cmIndex, ActiveNodes.BOOTED, ActiveNodes.PLANNED);
opName = "Deleting Sliver"; opName = "Deleting Sliver";
op.reset(Geni.deleteSliver); op.reset(Geni.deleteSliver);
op.addField("credential", credential.slivers[cmIndex]); op.addField("credential", credential.slivers[cmIndex]);
...@@ -47,11 +49,11 @@ package ...@@ -47,11 +49,11 @@ package
{ {
if (code == 0) if (code == 0)
{ {
nodes.changeState(cmIndex, ActiveNodes.PLANNED); nodes.commitState(cmIndex);
} }
else else
{ {
nodes.changeState(cmIndex, ActiveNodes.FAILED); nodes.revertState(cmIndex);
} }
credential.slivers[cmIndex] = null; credential.slivers[cmIndex] = null;
return null; return null;
......
...@@ -32,6 +32,7 @@ package ...@@ -32,6 +32,7 @@ package
override public function start(credential : Credential) : Operation override public function start(credential : Credential) : Operation
{ {
nodes.changeState(cmIndex, ActiveNodes.CREATED, ActiveNodes.BOOTED);
opName = "Booting Sliver"; opName = "Booting Sliver";
op.reset(Geni.startSliver); op.reset(Geni.startSliver);
op.addField("credential", credential.slivers[cmIndex]); op.addField("credential", credential.slivers[cmIndex]);
...@@ -45,11 +46,11 @@ package ...@@ -45,11 +46,11 @@ package
{ {
if (code == 0) if (code == 0)
{ {
nodes.changeState(cmIndex, ActiveNodes.BOOTED); nodes.commitState(cmIndex);
} }
else else
{ {
nodes.changeState(cmIndex, ActiveNodes.FAILED); nodes.revertState(cmIndex);
} }
return null; return null;
} }
......
...@@ -34,6 +34,7 @@ package ...@@ -34,6 +34,7 @@ package
override public function start(credential : Credential) : Operation override public function start(credential : Credential) : Operation
{ {
nodes.changeState(cmIndex, ActiveNodes.PLANNED, ActiveNodes.CREATED);
opName = "Updating Sliver"; opName = "Updating Sliver";
op.reset(Geni.updateSliver); op.reset(Geni.updateSliver);
op.addField("credential", credential.slivers[cmIndex]); op.addField("credential", credential.slivers[cmIndex]);
...@@ -48,11 +49,11 @@ package ...@@ -48,11 +49,11 @@ package
{ {
if (code == 0) if (code == 0)
{ {
nodes.changeState(cmIndex, ActiveNodes.CREATED); nodes.commitState(cmIndex);
} }
else else
{ {
nodes.changeState(cmIndex, ActiveNodes.FAILED); nodes.revertState(cmIndex);
} }
return null; return null;
} }
......
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