pip_services3_commons.refer.Descriptor module

pip_services_runtime.refer.Descriptor

Component descriptor implementation

copyright

Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.

license

MIT, see LICENSE for more details.

class pip_services3_commons.refer.Descriptor.Descriptor(group: Optional[str, None], type: Optional[str, None], kind: Optional[str, None], name: Optional[str, None], version: Optional[str, None])

Bases: object

Locator type that most often used in PipServices toolkit. It locates components using several fields:

  • Group: a package or just named group of components like “pip-services”

  • Type: logical component type that defines it’s contract like “persistence”

  • Kind: physical implementation type like “mongodb”

  • Name: unique component name like “default”

  • Version: version of the component contract like “1.0”

The locator matching can be done by all or only few selected fields. The fields that shall be excluded from the matching must be set to “*” or None. That approach allows to implement many interesting scenarios. For instance:

  • Locate all loggers (match by type and version)

  • Locate persistence components for a microservice (match by group and type)

  • Locate specific component by its name (match by name)

Example:

locator1 = Descriptor("mygroup", "connector", "aws", "default", "1.0")
locator2 = Descriptor.from_string("mygroup:connector:*:*:1.0")

locator1.match(locator2);               // Result: true
locator1.eq(locator2);          // Result: true
locator1.exact_match(locator2); // Result: false
equals(value: Any)bool

Compares this descriptor to a args. If args is a Descriptor it tries to match them, otherwise the method returns false.

Parameters

value – the args to match against this descriptor.

Returns

true if the args is matching descriptor and false otherwise.

exact_match(descriptor: pip_services3_commons.refer.Descriptor.Descriptor)bool

Matches this descriptor to another descriptor by all fields. No exceptions are made.

Parameters

descriptor – the descriptor to match this one against.

Returns

true if descriptors match and false otherwise.

static from_string(value: str) → Optional[pip_services3_commons.refer.Descriptor.Descriptor, None]

Parses colon-separated list of descriptor fields and returns them as a Descriptor.

Parameters

value – colon-separated descriptor fields to initialize Descriptor.

Returns

a newly created Descriptor.

get_group()str

Gets the component’s logical group.

Returns

the component’s logical group

get_kind()str

Gets the component’s implementation type.

Returns

the component’s implementation type.

get_name()str

Gets the unique component’s name.

Returns

the unique component’s name.

get_type()str

Gets the component’s logical type.

Returns

the component’s logical type.

get_version()str

Gets the component’s implementation version.

Returns

the component’s implementation version.

is_complete()bool

Checks whether all descriptor fields are set. If descriptor has at least one “*” or null field it is considered “incomplete”

Returns

true if all descriptor fields are defined and false otherwise.

match(descriptor: pip_services3_commons.refer.Descriptor.Descriptor)bool

Partially matches this descriptor to another descriptor. Fields that contain “*” or null are excluded from the match.

Parameters

descriptor – the descriptor to match this one against.

Returns

true if descriptors match and false otherwise

to_string()str

Gets a string representation of the object. The result is a colon-separated list of descriptor fields as “mygroup:connector:aws:default:1.0”

Returns

a string representation of the object.