Re: jboss module controller

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2008-03-17 at 17:09 +0100, Luca Foppiano wrote:

> I've upgrade and add some stuff (search by address, port and istance
> name) and check istance without listening ports.

last update, I call networktest and process module directly  :)

do you think is possible to put it on git repository? After, I can open
a new page on wiki. :)

bye
Luca
-- 
Today is Prickle-Prickle, the 11st day of Discord in the YOLD 3174

#
# Copyright 2008 
# Luca Foppiano <lfoppiano@xxxxxxxxxxxxx>
# Simone Pucci <spucci@xxxxxxxxxxxxx>
# Byte-code srl www.byte-code.com
#
# This software may be freely redistributed under the terms of the GNU
# general public license.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


import func_module
import sub_process
import codes 
import process
import networktest

class JBoss(func_module.FuncModule):
    version = "0.0.1"
    api_version = "0.0.1"
    description = "JBoss monitoring and control module"


    def version(self):
        """
            Return jboss version
            TODO: implementation 
        """

	return "version"


    def status(self):
        """
            Get jboss information
            (istance name, ports, bind address, pid)
        """  
        processo = process.ProcessModule()
        results = processo.info("ax") 

        output = []
        for items in results:
            if "-Dprogram.name=run.sh" in items:
                for item in items:
                    if "java" in item:
                        java = True

                if java == True:
                    if items.__contains__("-c"):
                        istance = items[items.index("-c")+1]
                    else:
                        istance = None

                    if items.__contains__("-b"):
                        address = items[items.index("-b")+1]
                    else:
                        address = None

                    output.append((int(items[0]),istance,address,[]))

        # Retrieve information about network (netstat -tupln)

	net_status = networktest.NetworkTest()
	results = net_status.netstat("-tupln")

        debug = []
        for string in results:#netstat_list:
            address = None
            port = None
            pid = None

            try:
                address_port = string[3]
                pid_name = string[6]
            except:
                address_port = None
                pid_name = None

            if address_port != None:
                try:
                    address = string[3].split(":")[0]
                    port =  int(string[3].split(":")[1])
                except:
                    address = None
                    port = None

            if pid_name != None:
                try:
                    pid = int(pid_name.split("/")[0])
                except:
                    pid = None
            
            if pid != None:
                for data in output:
                    debug.append(data)
                    if data[0] == pid:
                        #verify address
                        if address != None:
                            if data[2] == address:
                                data[3].append(port)

    
        return output


    def check(self, status=None):
        """
            Check if jboss istances works, controls:
                * check if istance listen on ports

            Return values:
                - istance up but not listen = (-1, istances with problem)
                - OK = (0, [])                
        """     
        if(status == None):
            data = self.status()
        else:
            data = status

        result = []
        code = 0
        for item in data:
            if len(item[3]) == 0:
                code = -1
                result.append(item)
        
        return (code, result)


    def search_by_port(self, port, status=None):
        """
            Search istance by listening port
        """
        if(status == None):
            data = self.status()
        else:
            data = status

        founded = []

        for item in data:
            for ports in item[3]:
                if port == ports:
                    founded.append(item)
        
        return founded


    def search_by_istance(self, istance, status=None):
        """
            Search istance by istance name
        """
        if(status == None):
            data = self.status()
        else:
            data = status

        founded = []

        for item in data:
            if item[1] == istance:
                founded.append(item)
        
        return founded

    def search_by_address(self, address, status=None):
        """
            Search istance by bind address
        """
        if(status == None):
            data = self.status()
        else:
            data = status

        founded = []

        for item in data:
            if item[2] == address:
                founded.append(item)
        
        return founded

'''
    def start(self, address="127.0.0.1", istance="default"):
        """
            Start a jboss istance
        """
        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:
            return "Another istances listening on this address, "

        if len(self.search_by_istance(istance=istance, status=status)) != 0:
            return result + str("This istances is just istanced")
    
        arguments = boss_run_path+" -c "+istance+" -b "+address
        cmd = sub_process.Popen(["/bin/sh", arguments], executable="/bin/sh", 
                                stdout=sub_process.PIPE, 
                                stderr=sub_process.PIPE,
                                shell=False)

        data, error = cmd.communicate()

        if error and error[:7] != "Warning":
            raise codes.FuncException(error.split('\n')[0])

        return "OK, instance "+ istance +"started on address "+address

    def stop(self, address="127.0.0.1"):
        """
            Stop a jboss istance, now use a standarda JNDI port
            1099. By default stop che localhost bind istance
            TODO: give more flexibility
        """
        jboss_path="/var/lib/jboss-4.2.2.GA"
        jboss_sd_path=jboss_path+"/bin/shutdown.sh"
        data = self.search_by_address("127.0.0.1")

        if len(data) == 0:
            return "Istance on "+ address +" not running"
    
        arguments = " -s jnp://"+address+":1099"
        exe = "/bin/sh "+jboss_sd_path

        cmd = sub_process.Popen([exe, arguments], executable=exe, 
                            stdout=sub_process.PIPE, 
                            stderr=sub_process.PIPE,
                            shell=False)

        data, error = cmd.communicate()

        if error and error[:7] != "Warning":
            raise codes.FuncException(error.split('\n')[0])

        return "OK, stopped istance listening address "+address

'''   

_______________________________________________
Func-list mailing list
Func-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/func-list

[Index of Archives]     [Fedora Users]     [Linux Networking]     [Fedora Legacy List]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux