Skip to content

Commit

Permalink
Added documentation for all the methods and improvements command-line
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jun 25, 2020
1 parent 29d79a9 commit 70360f2
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 15 deletions.
29 changes: 19 additions & 10 deletions pyjboss/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
import json
import argparse

#Metodo responsible for format output to user
# Metodo responsible for format output to user


def print_pretty(command_return):
transform_json = json.dumps(command_return, indent=2)
print(transform_json)


class main():
from . import PyJboss

# main command
description = 'This package can be used to call the jbossapi by http protocol and return values'
main_parse = argparse.ArgumentParser(prog='jbosspy',
Expand Down Expand Up @@ -38,9 +40,10 @@ class main():
ejb_parse = main_subparse.add_parser(name="ejb",
help='Manage ejb resources',
description="Call the ejb resources")
ejb_parse.add_argument("--thread-pool-name",
required=True,
help="Ejb thread pool name")
ejb_parse.add_argument(
'--list-thread-pools', help="Return a list of thread pools", action="store_true")
ejb_parse.add_argument("--get-thread-pool",
help="Get information about an thread pool")
ejb_parse.set_defaults(command="ejb")

# parse message command
Expand Down Expand Up @@ -90,8 +93,8 @@ class main():

# return main_parse
parse_return = main_parse.parse_args()
#create a PyJboss object

# create a PyJboss object
obJboss = PyJboss(controller=parse_return.controller,
user=parse_return.user,
password=parse_return.password,
Expand All @@ -100,7 +103,12 @@ class main():

# process command ejb
if parse_return.command == 'ejb':
print_pretty(command_return=obJboss.ejb.get_thread_pool(thread_pool_name=parse_return.thread_pool_name))
if parse_return.list_thread_pools:
print_pretty(command_return=obJboss.ejb.list_thread_pools())
else:
print_pretty(command_return=obJboss.ejb.get_thread_pool(
thread_pool_name=parse_return.get_thread_pool))

# process command message
elif parse_return.command == 'message':
if parse_return.queue_name:
Expand All @@ -117,7 +125,8 @@ class main():
# process command datasource
elif parse_return.command == 'datasource':
if parse_return.list:
print_pretty(obJboss.datasource.list(datasource_type=parse_return.list))
print_pretty(obJboss.datasource.list(
datasource_type=parse_return.list))
elif parse_return.datasource:
print_pretty(
obJboss.datasource.get(
Expand Down
22 changes: 22 additions & 0 deletions pyjboss/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@


class PyJboss(object):
'''
Jboss Client API, provides a way to get information about jboss and Wildfly resources by its API.
This instance has the following attributes:
:client.datasource This provides informations about datasources and xa-datasources
:client.ejb This provides informations about ejb thread pools
:client.messages This provides informations about jms-queues and jms-topics
:client.utils This provides general informations like jvm-memory
You can create an object for standole mode like:
>>> objboss = PyJboss(controller='ip_host_controller', user='jboss_admin_user' , password='jboss_admin_password')
or
You can create an object for domain mode like:
>>> objboss = PyJboss(controller='ip_domain_controller', user='jboss_admin_user' , password='jboss_admin_password', host='master', server='server-one')
:param controller: IP or Hostname of jboss host controller or domain controller.
:param user: A jboss user with administrative permissions.
:param password: The password of jboss user.
:param host: This parameter must be used for the domain mode only, this especify the host in domain mode that will be consulted.
:param server: This parameter must be used for the domain mode only, this especify a server from the host that will be consulted.
'''
def __init__(self, controller, user, password, host=None, server=None):
self.controller = controller
self.user = user
Expand Down
36 changes: 33 additions & 3 deletions pyjboss/client/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,32 @@

class DatasourcePy(NamespacedClient):
'''
Class used to management the datasources
Get information about datasources and xa-datasources
'''

def normalize_datasource(self, datasource_type='datasource'):
#Method utilized internaly only, that is reponsible to format output from datasource and xa-datasource
# Method used internaly only, that is reponsible to format output from datasource and xa-datasource
if datasource_type == 'datasource':
datasource_type = 'data-source'
elif datasource_type == 'xa-datasource':
datasource_type = 'xa-data-source'
return datasource_type

def list(self, datasource_type='datasource'):
'''
Get a list of datasources by especific datasource_type
Parameters
----------
param: datasource_type: The type of datasource, that can be datasource or xa-datasource.
if not defined "datasource" is the default value.
Returns
-------
list
A list with the datasources
'''
payload = {
"address": [{
"subsystem": "datasources"
Expand All @@ -28,7 +42,23 @@ def list(self, datasource_type='datasource'):
payload=payload)
return return_data

def get(self, datasource_type, datasource_name):
def get(self, datasource_name, datasource_type='datasource'):
'''
Get information about a datasource
Parameters
----------
param: datasource_name: The name of datasource or xa-datasoruce.
param: datasource_type The type of datasource can be datasource or xa-datasource
if not defined "datasource" is the default value.
Returns
-------
dictionary
Return a dictionary with information about the datasource.
For more information, can be usefull enable statistics in the datasources.
'''
payload = {
"address": [{
"subsystem": "datasources"
Expand Down
27 changes: 26 additions & 1 deletion pyjboss/client/ejb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,42 @@

class EjbPy(NamespacedClient):
'''
Class utilized to get information about ejb resources
Get informations about ejb resources
'''
def list_thread_pools(self):
'''
List thread pools
Parameters
----------
None
Returns
-------
list
A list of thread pools
'''
payload = {"address" : [{ "subsystem" : "ejb3" }], "operation" : "read-children-names", "child-type" : "thread-pool"}
return_data = self.transport.make_request(
method='POST', endpoint=self.transport.controller,
payload=payload)
return return_data

def get_thread_pool(self, thread_pool_name='default'):
'''
Get information about a thread pool
Parameters
----------
param: thread_pool_name: The thread pool that desired get information.
if not defined "default" is the default value.
Returns
-------
dictionary
Return a dictionary with information about the thread pool.
'''
payload = {"address" : [{ "subsystem" : "ejb3" },{ "thread-pool" : thread_pool_name }], "operation" : "read-resource", "include-runtime" : True}

return_data = self.transport.make_request(
Expand Down
31 changes: 31 additions & 0 deletions pyjboss/client/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@


class MessagePy(NamespacedClient):
'''
Get information about queues and topics jms
'''

def list(self, message_server='default', type_message='queue'):
'''
List a type of message queue, the type can be queue or topic
Parameters
----------
param: message_server: The message server definied in jboss/wildfly, by default the name of the message server is "default". Recommend to verify your installation.
param: type_message: The type of message queue, this can be queue or topic, the dafult value is queue.
Returns
-------
list
Return a list with jms-queues ou jms-topics
'''
payload = {
"address": [{
"subsystem": "messaging-activemq"
Expand All @@ -24,6 +41,20 @@ def get(self,
name_resource,
message_server='default',
type_message='queue'):
'''
Get information about a queue or topic jms
Parameters
----------
param: name_resource: queue or topic name
param: message_server: The message server definied in jboss/wildfly, by default the name of the message server is "default". Recommend to verify your installation.
param: type_message: The type of message queue, this can be queue or topic, the dafult value is queue.
Returns
-------
dictionary
Return a dictionary with information about the queue or topic jms.
'''
payload = {
"address": [{
"subsystem": "messaging-activemq"
Expand Down
15 changes: 15 additions & 0 deletions pyjboss/client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@


class UtilsPy(NamespacedClient):
'''
General information that is not provided by a especific jboss subsystem will be here, like jvm memory information.
'''
def get_memory_info(self):
'''
Get memory about jvm memory
Parameters
----------
None
Returns
-------
dictionary
Return a dictionary with information about jvm memory, java heap space, non-heap space and others.
'''
payload = {"address": [{"core-service": "platform-mbean"}, {
"type": "memory"}], "operation": "read-resource", "include-runtime": True}
return_data = self.transport.make_request(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pyjboss",
version="0.0.1",
version="0.0.4",
license="GNU General Public License v3.0",
author="Rafael Benites Gil",
author_email="[email protected]",
Expand Down

0 comments on commit 70360f2

Please sign in to comment.