resource_pool

This module tracks all known resources managed by the scheduler. The scheduler_msgs/Resource ROS message describes resources used by the Robotics in Concert (ROCON) project.

exception concert_resource_pool.resource_pool.InvalidRequestError[source]

Request cannot be satisfied as specified.

exception concert_resource_pool.resource_pool.ResourceNotAvailableError[source]

Error exception: resource not available.

exception concert_resource_pool.resource_pool.ResourceNotOwnedError[source]

Error exception: resource not owned.

class concert_resource_pool.resource_pool.PoolResource(msg)[source]

Base class for tracking the status of a single ROCON resource.

Parameters:msg (ConcertClient, CurrentStatus or Resource) – ROCON scheduler resource description message.
hash(res)
Returns:Hash key for this resource.
res == other
Returns:True if this PoolResource equals the other.
res != other
Returns:True if this PoolResource differs from the other.
str(res)
Returns:Human-readable string representation of this PoolResource.

These attributes are also provided:

uri = None

Fully-resolved canonical ROCON resource name.

status = None

Current status of this resource.

owner = None

uuid.UUID of request to which this resource is currently assigned, or None.

priority = None

Priority of request to which this resource is currently assigned.

allocate(request)[source]

Allocate this resource.

Parameters:request (ActiveRequest) – New owner of this resource.
Raises:ResourceNotAvailableError if not available
current_status()[source]
Returns:scheduler_msgs/CurrentStatus for this resource.
match(res)[source]

Match this resource to a requested one.

Parameters:res (scheduler_msgs/Resource or PoolResource) – Resource request to match.
Returns:True if this specific resource matches.

To match, the res.rapp must be one of the rapps advertised by this ROCON resource. The res.uri may include Python regular expression syntax for matching multiple resource names.

If the res.uri is not a canonical ROCON name starting with ‘rocon:’, it will be converted from shell wildcard syntax into an equivalent Python regular expression.

match_pattern(pattern, rapp)[source]

Match this resource to a ROCON name and application.

Parameters:
  • pattern (str) – Canonical ROCON name to match, maybe a regular expression.
  • rapp (str) – ROCON application name.
Returns:

True if this specific resource matches.

Raises:

RoconURIValueError if pattern invalid.

The rapp must be one of those advertised by this ROCON resource. The pattern may be a ROCON pattern matching multiple resource names.

release(request_id=None)[source]

Release this resource.

Parameters:request_id (uuid.UUID or None) – Optional owning request.
Raises:ResourceNotOwnedError if request_id is specified and is not the owner.
class concert_resource_pool.resource_pool.ResourcePool(msg=None, pool_resource=<class 'concert_resource_pool.resource_pool.PoolResource'>)[source]

This class manages a pool of PoolResource objects known to the scheduler.

Parameters:
  • msg – An optional scheduler_msgs/KnownResources or scheduler_msgs/Request message or a list of CurrentStatus or Resource messages, like the resources component of one of those messages.
  • pool_resource – a possibly-derived class providing a compatible ResourcePool interface.

ResourcePool supports these standard container operations:

len(pool)
Returns:The number of resources in the pool.
pool[uri]
Param uri:(str) The Uniform Resource Identifier of a resource in the pool.
Returns:The actual pool resource corresponding to uri.
Raises:KeyError if uri not in the pool.
uri in pool
Returns:True if pool contains uri, else False.
uri not in pool

Equivalent to not uri in pool.

str(pool)
Returns:Human-readable string representation of this ResourcePool.
pool = None

Dictionary of known pool_resource objects, indexed by the fully-resolved ROCON resource name.

changed = None

True, if resource pool has changed since the previous known_resources() call.

pool_resource = None

The ResourcePool class this pool contains.

allocate(request)[source]

Try to allocate all resources for a request.

Parameters:request (ActiveRequest) – Scheduler request object, some resources may include regular expression syntax.
Returns:List of scheduler_msgs/Resource messages allocated, in requested order with platform info fully resolved; or [] if not everything is available.
Raises:InvalidRequestError if the request is not valid.

If successful, matching ROCON resources are allocated to this request. Otherwise, the request remains unchanged.

_allocate_permutation(perm, request, matches)[source]

Try to allocate some permutation of resources for a request.

Parameters:
  • perm – List of permuted resource indices for this request, like [0, 1, 2] or [1, 2, 0].
  • request (ActiveRequest) – Scheduler request object, some resources may include regular expression syntax.
  • matches – List containing sets of the available resources matching each element of request.msg.resources.
Returns:

List of scheduler_msgs/Resource messages allocated, in requested order with platform info fully resolved; or [] if not everything is available.

If successful, matching ROCON resources are allocated to this request. Otherwise, the request remains unchanged.

get(resource_name, default=None)[source]

Get named pool resource, if known.

Parameters:
  • resource_name (str) – Name of desired resource.
  • default – value to return if no such resource.
Returns:

named pool resource if successful, else default.

known_resources()[source]

Convert resource pool to scheduler_msgs/KnownResources.

match_list(resources, criteria)[source]

Make a list containing sets of the available resources matching each item in resources.

Parameters:
  • resources – List of Resource messages to match.
  • criteriaset of resource status values allowed.
Returns:

List of set containing names of matching resources, empty if any item cannot be satisfied, or there are not enough resources, or the original resources list was empty.

_match_subset(resource_msg, criteria)[source]

Make a set of names of all available resources matching resource_msg.

Parameters:
  • resource_msg (scheduler_msgs/Resource) – Resource message from a scheduler Request.
  • criteriaset of resource status values allowed.
Returns:

set containing matching resource names.

release_request(request)[source]

Release all the resources owned by this request.

Parameters:request (ActiveRequest) – Current owner of resources to release.

Only appropriate when this request is being closed.

release_resources(resources, request_id=None)[source]

Release a list of resources.

Parameters:
  • resources – List of scheduler_msgs/Resource messages.
  • request_id (uuid.UUID or None) – Optional owning request.

This makes newly allocated resources available again when they cannot be assigned to a request for some reason.

update(client_list)[source]

Update resource pool from a new concert clients list.

Parameters:client_list – current list of ConcertClient messages.

Previous topic

Overview

Next topic

scheduler_clients

This Page