Reported state of nodes from NoteMetadata#getState

37 views
Skip to first unread message

Chris Strand

unread,
Sep 21, 2011, 1:06:27 PM9/21/11
to jclouds
Hey guys,

Long post - sorry!

I expect I'm using jclouds a bit differently to most people - when I
launch nodes I don't block until they are ready but instead just try
and connect to them at some point in the future. The way I get that to
work is to have a startup script on node that just sends a short
message back to my app that launched the node. This means I don't have
to keep polling to see when the node is ready.

My problem is that even after getting that message from the node for a
short amount of time (usually a few seconds) I can't SSH in with
jclouds due to a thrown IllegalStateException, example:
Exception in thread "pool-2-thread-1" java.lang.IllegalStateException:
node 10052116 needs to be running before executing a script on it.
current state: PENDING
at
org.jclouds.compute.internal.BaseComputeService.runScriptOnNode(BaseComputeService.java:
607)
at
org.jclouds.compute.internal.BaseComputeService.runScriptOnNode(BaseComputeService.java:
595)
at
my.app.CloudServerHandler.doSshStuff(CloudServerHandler.java:441)
at java.util.concurrent.ThreadPoolExecutor
$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

So thinking that I could just wait for jclouds to do its stuff and
update the state I wrote something along the lines of:
NodeMetadata node = mynode;
while(node.getState() != ServerState.ACTIVE) { ... } // Twiddle thumbs
computeService.runScriptOnNode(node.getId(), "echo bacon");

However the #getState method does not seem to update the state so the
above code doesn't work. I could not see a convenient way of re-
checking the state to see if it has changed, is there something I
missed?

My preference would be for the #getState to actually check the state
of the node each time it is called rather than simply returning the
value currently stored in the Object. Or alternatively have a method
called something like #updateState which can be called when you
actually need to check for a change - this may be a bit more
inconvenient but better for performance reasons.

Calling #runScriptOnNode(...) actually checks for a change in state
and throws the exception above if the node is not ACTIVE. So I managed
to get around the #getState issue by just trying to run the script
until no exception is thrown.


I also have another (potentially more Rackspace specific) related
problem. I think - couldn't find the relevant part of the source code
- the state is updated to ACTIVE by querying the API rather than
pinging/polling the actual server? I ran into a problem with this
because a node of mine booted up fine and was running etc., but for
several minutes after the API and control panel from Rackspace was
stuck on reporting the status as:
Status: Build Complete - Configuring
Current Action: Running Post-Build Configurations

At this point I was still getting IllegalStateExceptions thrown when
trying to SSH via jclouds, despite the fact that I had manually SSH'ed
in to the node while this was going on. Perhaps jclouds should check
to see if SSH is possible when methods such as #runScriptOnNode are
called rather than querying the API?

Summary of points/suggestions:
Have NoteMetadata#getState check for changes in the state or implement
a method such as #updateState to do this.
Have jclouds state changed to ACTIVE by checking if SSH is up and
running rather than querying the providers API in certain situations.

Hopefully I haven't misunderstood anything too badly! I'd be
interested to hear other peoples thoughts on this.

Chris

Chris Strand

unread,
Sep 21, 2011, 1:41:12 PM9/21/11
to jclouds
Note got the enum wrong:
replace ServerState with NodeState and ACTIVE with RUNNING, woops!
Reply all
Reply to author
Forward
0 new messages