>From b466858d677c12d033621376d47dbca057e75d81 Mon Sep 17 00:00:00 2001
From: Luca Foppiano <lfoppiano@sboing.byte-code.lan>
Date: Wed, 5 Nov 2008 11:01:03 +0100
Subject: [PATCH] updated jboss module

---
 func/minion/modules/jboss.py |  159 +++++++++++++-----------------------------
 1 files changed, 50 insertions(+), 109 deletions(-)

diff --git a/func/minion/modules/jboss.py b/func/minion/modules/jboss.py
index dc09091..20d64eb 100644
--- a/func/minion/modules/jboss.py
+++ b/func/minion/modules/jboss.py
@@ -13,18 +13,22 @@
 
 
 import func_module
-from func.minion import sub_process
-from func.minion import codes
+import sub_process
+import codes
+import copyfile
 import process
 import networktest
 import command
+import ConfigParser
+from certmaster.config import BaseConfig
+from certmaster.config import Option
 from func import logger
 
 class JBoss(func_module.FuncModule):
-    version = "0.0.1"
-    api_version = "0.0.1"
+    version = "0.0.3"
+    api_version = "0.0.2"
     description = "JBoss monitoring and control module"
-
+    
     def status(self):
         """
             Get jboss information
@@ -33,7 +37,7 @@ class JBoss(func_module.FuncModule):
         processo = process.ProcessModule()
         results = processo.info("ax") 
 		
-	logging = logger.Logger().logger
+        logging = logger.Logger().logger
         output = []
         for items in results:
             if "-Dprogram.name=run.sh" in items:
@@ -45,21 +49,20 @@ class JBoss(func_module.FuncModule):
                     if items.__contains__("-c"):
                         instance = items[items.index("-c")+1]
                     else:
-                        instance = ""
+                        instance = None
 
                     if items.__contains__("-b"):
                         address = items[items.index("-b")+1]
                     else:
-                        address = ""
+                        address = None
 
                     output.append((int(items[0]),instance,address,[]))
 
         # Retrieve information about network (netstat -tupln)
-
 	net_status = networktest.NetworkTest()
 	results = net_status.netstat("-tupln")
 
-        for string in results:#netstat_list:
+        for string in results:
             address = None
             port = None
             pid = None
@@ -174,86 +177,24 @@ class JBoss(func_module.FuncModule):
         
         return founded
 
-    def register_method_args(self):
-        """
-        Implementin the method argument getter part
-        """
+    def static_configuration(self):
+        '''
+            Return configuration values, read from
+            configuration file.
+        '''
+        return (self.options.jboss_home, self.options.jboss_address, self.options.jboss_instance)
+ 
+    def start(self):
+        '''
+           Start a jboss instance 
+	'''
+        logging = logger.Logger().logger
+
+        address=self.options.jboss_address
+        instance=self.options.jboss_instance
+
+        jboss_run_path=self.options.jboss_home+"/bin/run.sh"
 
-        return {
-                'status':{
-                    'args':{},
-                    'description':"Get jboss information"
-                    },
-                'check':{
-                    'args':{
-                        'status':{
-                            'type':'string',
-                            'optional':True,
-                            'description':"The status of instance to check (optional)"
-                            }
-                        },
-                    'description':"Check if jboss instances works"
-                    },
-                'search_by_port':{
-                    'args':{
-                        'port':{
-                            'type':'int',
-                            'optional':False,
-                            'min':0,
-                            'max':65535,
-                            'description':'The port to search for'
-                            },
-                        'status':{
-                            'type':'string',
-                            'optional':True,
-                            'description':"The status of instance to check (optional)"
-                            }
-                        },
-                    'description':"Search instance by listening port"
-                    },
-                'search_by_instance':{
-                    'args':{
-                        'instance':{
-                            'type':'string',
-                            'optional':False,
-                            'description':"The name of the instance"
-                            },
-                        'status':{
-                            'type':'string',
-                            'optional':True,
-                            'description':"The status of the instance to search (optional)"
-                            }
-                        },
-                    'description':"Search instance by instance name"
-                    },
-                'search_by_address':{
-                    'args':{
-                        'address':{
-                            'type':'string',
-                            'optional':False,
-                            'description':"The bind adress to check"
-                            },
-                        'status':{
-                            'type':'string',
-                            'optional':True,
-                            'description':"The status of the instance to search (optional)"
-                            }
-                        },
-                    'description':"Search instance by bind address"
-
-                    }
-                }
-
-'''
-    def start(self, address="127.0.0.1", instance="default"):
-        """
-            Start a jboss instance, you must specify couple 
-	    address/instance_name. ATM __call__() in server.py 
-	    doesn't support keywords.
-        """
-	# TODO: move outside this two variables
-        jboss_path="/var/lib/jboss-4.2.2.GA"
-        jboss_run_path=jboss_path+"/bin/run.sh"
         status=self.status()
 		
         if len(self.search_by_address(address=address, status=status)) != 0:
@@ -262,43 +203,43 @@ class JBoss(func_module.FuncModule):
        	if len(self.search_by_instance(instance=instance, status=status)) != 0:
             return (-1,"This instances is just instanced")
 
-        launcher ="sh "+str(jboss_run_path)+" -c "+instance+" -b "+address
+        launcher ="sh "+str(jboss_run_path)+" -c "+instance+" -b "+address+" &"
+        logging.info(launcher)
 
 	comm = command.Command()
 	comm.run(launcher)
         
-	return "OK, instance "+ instance +"started on address "+address
+	return "OK, instance "+ instance +" started on address "+address
 
 
-    def stop(self, address="127.0.0.1"):
-        """
+    def stop(self):
+        '''
             Stop a jboss instance, It suppose you are using 
 	    use standard JNDI port 1099. 
- 	    By default stop che localhost bind instance
-            TODO: give more flexibility
-        """
-        jboss_path="/var/lib/jboss-4.2.2.GA"
-        jboss_sd_path=jboss_path+"/bin/shutdown.sh"
+        '''
+        logging = logger.Logger().logger
+
+        address=self.options.jboss_address
+        instance=self.options.jboss_instance
+
+        jboss_sd_path=self.options.jboss_home+"/bin/shutdown.sh"
         data = self.search_by_address(address)
 
         if len(data) == 0:
             return (-1, "Istance on "+ address +" not running")
     
-	launcher ="sh "+str(jboss_sd_path)+" -s jnp://"+address+":1099"
+	launcher ="sh "+str(jboss_sd_path)+" -s jnp://"+address+":1099 &"
+        logging.info(launcher)
 
         comm = command.Command()
 	comm.run(launcher)
 
         return "OK, stopped instance listening address "+address
- 
-   def version(self):
-        """
-            Return jboss version
-            TODO: implementation, is necessary to 
-		find a way to get jboss version (maybe
-		by parse log files)
-        """
 
-	return "version"
 
-'''
+    class Config(BaseConfig):
+        jboss_home=Option('/var/lib/jboss')
+        jboss_instance=Option('default')
+        jboss_address=Option('127.0.0.1') 
+
+
-- 
1.5.6.5

