streamsx.rest module

class streamsx.rest.ConfigParams

Bases: object

Configuration options which may be used as keys in the config parameter of the StreamsContext constructor.

VCAP_SERVICES - a json object containing the VCAP information used to submit to Bluemix SERVICE_NAME - the name of the streaming analytics service to use from VCAP_SERVICES.

SERVICE_NAME = 'topology.service.name'
VCAP_SERVICES = 'topology.service.vcap'
class streamsx.rest.StreamsConnection(username=None, password=None, resource_url=None, config=None, instance_id=None)

Bases: object

Creates a connection to a running Streams instance and exposes methods to retrieve the state of that instance.

Streams maintains information regarding the state of its resources. For example, these resources could include the currently running Jobs, Views, PEs, Operators, and Domains. The StreamsConnection provides methods to retrieve that information.

Example

>>> _resource_url = "https://streamsqse.localdomain:8443/streams/rest/resources"
>>> sc = StreamsConnection(username="streamsadmin", password="passw0rd", resource_url=_resource_url)
>>> instances = sc.get_instances()
>>> jobs_count = 0
>>> for instance in instances:
...    jobs_count += len(instance.get_jobs())
>>> print("There are " + jobs_count + " jobs across all instances.")
get_domains(id=None)

Retrieves a list of all Domain resources across all known streams installations.

Returns:Returns a list of all Domain resources.
get_installations()

Retrieves a list of all known streams Installations.

Returns:Returns a list of all Installation resources.
get_instances(id=None)

Retrieves a list of all Instance resources across all known streams installations.

Returns:Returns a list of all Instance resources.
get_resources()
get_streaming_analytics()

Get a ref:StreamingAnalyticsService to allow interaction with the Streaming Analytics service this object is connected to.

This connection must be configured for a Streaming Analytics service. :returns: Object to interact with service.

Return type:StreamingAnalyticsService
get_view(name)

Gets a view with the specified name. If there are multiple views with the same name, it will return the first one encountered.

Parameters:name – The name of the View resource.
Returns:The view resource with the specified name.
get_views()

Gets a list of all View resources across all known streams installations.

Returns:Returns a list of all View resources.
class streamsx.rest.VcapUtils

Bases: object

Contains convenience methods for retrieving the VCAP Services, credentials, and REST API URL from a provided config dictionary.

static get_credentials(config, vcap_services)

Retrieves the credentials of the VCAP Service specified by the ConfigParams.SERVICE_NAME field in config.

Parameters:
  • config (dict.) – Connection information for Bluemix.
  • vcap_services (dict.) – A dict representation of the VCAP Services information.
Returns:

A dict representation of the credentials.

static get_rest_api_url_from_creds(credentials)

Retrieves the Streams REST API URL from the provided credentials.

Parameters:credentials (dict.) – A dict representation of the credentials.
Returns:The remote Streams REST API URL.
static get_vcap_services(config)

Retrieves the VCAP Services information from the ConfigParams.VCAP_SERVICES field in the config object. If the field is a string, it attempts to parse it as a dict. If the field is a file, it reads the file and attempts to parse the contents as a dict.

Parameters:config (dict.) – Connection information for Bluemix.
Returns:A dict representation of the VCAP Services information.