Skip to content

Commit

Permalink
Merge pull request #79 from jonbinney/start-capability-response
Browse files Browse the repository at this point in the history
Return an error if start_capability requested for a capability that is already running
  • Loading branch information
wjwwood committed Aug 28, 2014
2 parents 93bd4a2 + 5a24d95 commit 6152591
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/capabilities/server.py
Expand Up @@ -689,11 +689,30 @@ def __start_capability(self, capability, preferred_provider):
provider = providers[preferred_provider]
instances = self.__get_capability_instances_from_provider(provider)
with self.__graph_lock:
# If the requested capability has an existing instance, we don't start it
# again. Return a result that lets the callee know this happened.
requested_instance = instances[0]
if requested_instance.interface in self.__capability_instances:
requested_instance_state = self.__capability_instances[
requested_instance.interface].state
if requested_instance_state in ['running']:
# Current instance is running (or will be soon)
return StartCapabilityResponse.RESULT_CURRENTLY_RUNNING
elif requested_instance_state in ['waiting', 'launching']:
return StartCapabilityResponse.RESULT_CURRENTLY_STARTING
elif state in ['stopped', 'terminated']:
# Current instance is in the process of stopping
return StartCapabilityResponse.RESULT_CURRENTLY_STOPPING
else:
raise RuntimeError(
"Instance for capability '{0}' has improper state '{1}'"
.format(capability, requested_instance_state))

for x in instances:
if x.interface not in self.__capability_instances:
self.__capability_instances[x.interface] = x
self.__update_graph()
return True
return StartCapabilityResponse.RESULT_SUCCESS

def handle_get_capability_specs(self, req):
return self.__catch_and_log(self._handle_get_capability_specs, req)
Expand Down
7 changes: 6 additions & 1 deletion srv/StartCapability.srv
@@ -1,4 +1,9 @@
string capability
string preferred_provider
---
bool successful
uint8 result
uint8 RESULT_SUCCESS=0
uint8 RESULT_CURRENTLY_STARTING=1 # Cannot start because capability is currently starting
uint8 RESULT_CURRENTLY_RUNNING=2 # Cannot start because capability is currently running
uint8 RESULT_CURRENTLY_STOPPING=3 # Cannot start because capability is currently stopping

0 comments on commit 6152591

Please sign in to comment.