Welcome to Brewtils’s documentation!¶
Contents:
Brewtils¶
Brewtils is the Python library for interfacing with Beergarden systems. If you are planning on writing beer-garden plugins, this is the correct library for you. In addition to writing plugins, it provides simple ways to query the API and is officially supported by the beer-garden team.
Features¶
Brewtils helps you interact with beer-garden.
- Easy way to create beer-garden plugins
- Full support of the entire Beer-Garden API
- Officially supported by the beer-garden team
Installation¶
To install brewtils, run this command in your terminal:
$ pip install brewtils
Or add it to your requirements.txt
$ cat brewtils >> requirements.txt
$ pip install -r requirements.txt
Quick Start¶
You can create your own beer-garden plugins without much problem at all. To start, we’ll create the obligatory hello-world plugin. Creating a plugin is as simple as:
from brewtils.decorators import system, parameter, command
from brewtils.plugin import RemotePlugin
@system
class HelloWorld(object):
@parameter(key="message", description="The message to echo", type="String")
def say_hello(self, message="World!"):
print("Hello, %s!" % message)
return "Hello, %s!" % message
if __name__ == "__main__":
client = HelloWorld()
plugin = RemotePlugin(client,
name="hello",
version="0.0.1",
bg_host='127.0.0.1',
bg_port=2337)
plugin.run()
Assuming you have a Beer Garden running on port 2337 on localhost, running this will register and
start your plugin! You now have your first plugin running in beer-garden. Let’s use another part
of the brewtils
library to exercise your plugin from python.
The SystemClient
is designed to help you interact with registered Systems as if they were native
Python objects.
from brewtils.rest.system_client import SystemClient
hello_client = SystemClient('localhost', 2337, 'hello')
request = hello_client.say_hello(message="from system client")
print(request.status) # 'SUCCESS'
print(request.output) # Hello, from system client!
In the background, the SystemClient
has executed an HTTP POST with the payload required to get
beer-garden to execute your command. The SystemClient
is how most people interact with
beer-garden when they are in the context of python and want to be making requests.
Of course, the rest of the API is accessible through the brewtils
package. The EasyClient
provides simple convenient methods to call the API and auto-serialize the responses. Suppose you
want to get a list of all the commands on all systems:
from brewtils.rest.easy_client import EasyClient
client = EasyClient('localhost', 2337)
systems = client.find_systems()
for system in systems:
for command in system.commands:
print(command.name)
This is just a small taste of what is possible with the EasyClient
. Feel free to explore all the
methods that are exposed.
For more detailed information and better walkthroughs, checkout the full documentation!
Documentation¶
- Full Beer Garden documentation is available at https://beer-garden.io
- Brewtils Documentation is available at https://brewtils.readthedocs.io
Installation¶
Stable release¶
To install Brewtils, run this command in your terminal:
$ pip install brewtils
This is the preferred method to install Brewtils, as it will always install the most recent stable release.
If you don’t have pip installed, this Python installation guide can guide you through the process.
From sources¶
The sources for Brewtils can be downloaded from the Github repo.
You can either clone the public repository:
$ git clone git@github.com/beer-garden/brewtils.git
Or download the tarball:
$ curl -OL https://github.com/beer-garden/brewtils/tarball/master
Once you have a copy of the source, you can install it with:
$ python setup.py install
Usage¶
Brewtils¶
Brewtils is the Python library for interfacing with Beergarden systems. If you are planning on writing beer-garden plugins, this is the correct library for you. In addition to writing plugins, it provides simple ways to query the API and is officially supported by the beer-garden team.
Features¶
Brewtils helps you interact with beer-garden.
- Easy way to create beer-garden plugins
- Full support of the entire Beer-Garden API
- Officially supported by the beer-garden team
Installation¶
To install brewtils, run this command in your terminal:
$ pip install brewtils
Or add it to your requirements.txt
$ cat brewtils >> requirements.txt
$ pip install -r requirements.txt
Quick Start¶
You can create your own beer-garden plugins without much problem at all. To start, we’ll create the obligatory hello-world plugin. Creating a plugin is as simple as:
from brewtils.decorators import system, parameter, command
from brewtils.plugin import RemotePlugin
@system
class HelloWorld(object):
@parameter(key="message", description="The message to echo", type="String")
def say_hello(self, message="World!"):
print("Hello, %s!" % message)
return "Hello, %s!" % message
if __name__ == "__main__":
client = HelloWorld()
plugin = RemotePlugin(client,
name="hello",
version="0.0.1",
bg_host='127.0.0.1',
bg_port=2337)
plugin.run()
Assuming you have a Beer Garden running on port 2337 on localhost, running this will register and
start your plugin! You now have your first plugin running in beer-garden. Let’s use another part
of the brewtils
library to exercise your plugin from python.
The SystemClient
is designed to help you interact with registered Systems as if they were native
Python objects.
from brewtils.rest.system_client import SystemClient
hello_client = SystemClient('localhost', 2337, 'hello')
request = hello_client.say_hello(message="from system client")
print(request.status) # 'SUCCESS'
print(request.output) # Hello, from system client!
In the background, the SystemClient
has executed an HTTP POST with the payload required to get
beer-garden to execute your command. The SystemClient
is how most people interact with
beer-garden when they are in the context of python and want to be making requests.
Of course, the rest of the API is accessible through the brewtils
package. The EasyClient
provides simple convenient methods to call the API and auto-serialize the responses. Suppose you
want to get a list of all the commands on all systems:
from brewtils.rest.easy_client import EasyClient
client = EasyClient('localhost', 2337)
systems = client.find_systems()
for system in systems:
for command in system.commands:
print(command.name)
This is just a small taste of what is possible with the EasyClient
. Feel free to explore all the
methods that are exposed.
For more detailed information and better walkthroughs, checkout the full documentation!
Documentation¶
- Full Beer Garden documentation is available at https://beer-garden.io
- Brewtils Documentation is available at https://brewtils.readthedocs.io
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/beer-garden/brewtils/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.
Write Documentation¶
Brewtils could always use more documentation, whether as part of the official Brewtils docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/beer-garden/brewtils/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up brewtils
for local development.
Fork the
brewtils
repo on GitHub.Clone your fork locally:
$ git clone git@github.com:your_name_here/brewtils.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv brewtils $ cd brewtils/ $ python setup.py develop
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 brewtils test $ nosetests $ tox
To get flake8 and tox, just pip install them into your virtualenv.
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
- The pull request should work for Python 2.7, 3.5, and 3.6. Check https://travis-ci.org/beer-garden/brewtils/pull_requests and make sure that the tests pass for all supported Python versions.
Credits¶
Development Leads¶
- Logan Asher Jones <loganasherjones@gmail.com>
- Matt Patrick
Contributors¶
None yet. Why not be the first?
Brewtils Changelog¶
2.3.4¶
Date: 4/5/18
New Features¶
- Python 3.4 is now supported (#43)
- Now using Yapconf for configuration parsing (#34)
- Parameter types can now be specified as native Python types (#29)
- Added flag to raise an exception if a request created with
SystemClient
completes with an ‘ERROR’ status (#28)
Other Changes¶
- All exceptions now inherit from
BrewtilsException
(#45) - Removed references to
Brewmaster
exception classes (#44) - Requests with JSON
command_type
are smarter about formatting exceptions (#27) - Decorators,
RemotePlugin
, andSystemClient
can now be imported directly from thebrewtils
package
2.3.2¶
Date: 3/7/18
Bug Fixes¶
- Fixed issue with multi-instance remote plugins failing to initialize (#35)
2.3.0¶
Date: 1/26/18
New Features¶
- Added methods for interacting with the Queue API to RestClient and EasyClient
- Clients and Plugins can now be configured to skip server certificate verification when making HTTPS requests
- Timestamps now have true millisecond precision on platforms that support it
- Added
form_input_type
to Parameter model - Plugins can now be stopped correctly by calling their
_stop
method - Added Event model
Bug Fixes¶
- Plugins now additionally look for
ca_cert
andclient_cert
inBG_CA_CERT
andBG_CLIENT_CERT
Other Changes¶
- Better data integrity by only allowing certain Request status transitions
2.2.1¶
Date: 1/11/18
Bug Fixes¶
- Nested requests that reference a different beer-garden no longer fail
2.2.0¶
Date: 10/23/17
New Features¶
- Command descriptions can now be changed without updating the System version
- Standardized Remote Plugin logging configuration
- Added domain-specific language for dynamic choices configuration
- Added
metadata
field to Instance model
Bug Fixes¶
- Removed some default values from model
__init__
functions - System descriptors (description, display name, icon name, metadata) now always updated during startup
- Requests with output type ‘JSON’ will now have JSON error messages
Other changes¶
- Added license file
2.1.1¶
Date: 8/25/17
New Features¶
- Added
updated_at
field toRequest
model SystemClient
now allows specifying aclient_cert
RestClient
now reuses the same session for subsequent connectionsSystemClient
can now make non-blocking requestsRestClient
andEasyClient
now support PATCHing aSystem
Deprecations / Removals¶
multithreaded
argument toPluginBase
has been superseded bymax_concurrent
- These decorators are now deprecated
-
@command_registrar
, instead use@system
-@plugin_param
, instead use@parameter
-@register
, instead use@command
- These classes are now deprecated
-
BrewmasterSchemaParser
, instead useSchemaParser
-BrewmasterRestClient
, instead useRestClient
-BrewmasterEasyClient
, instead useEasyClient
-BrewmasterSystemClient
, instead useSystemClient
Bug Fixes¶
- Reworked message processing to remove the possibility of a failed request being stuck in
IN_PROGRESS
- Correctly handle custom form definitions with a top-level array
- Smarter reconnect logic when the RabbitMQ connection fails
Other changes¶
- Removed dependency on
pyopenssl
so there’s need to compile any Python extensions - Request processing now occurs inside of a
ThreadPoolExecutor
thread - Better serialization handling for epoch fields