How to find the NodeManager Running from WLST?
Found three alternative solutions.
- Use jps command to find the NodeManager Pid exist or not
- Connect the Nodemanager if it is succeeds then NM Reachable otherwise not.
- Use a simple socket module to create the socket object on the host, port
NodeManager Check with jps commandJDK provides jps command to show the list of Java Pids with name of the Java program. provided your JAVA_HOME must be available in os environment variables. So conditions applied here!! anyways lets see the solution :
def nm_status(): NMstatus=os.system('jps |grep -i nodemanager|grep -v grep') if NMstatus==0: return 'Reachable' else: return 'Inactive'Note: Please check indentations after copying to your editor.
The disadvantage of this method is it is going to work on Linux/Unix environments only, No Windows.
Connect to NodeMnager get State
WLST Command nmConnect() is going to connect if the machine have a Node Manager running, but here it does not returns the output to a variable. The output normally redirecting to standard output stdout. If we can redirect that to a file and check that contians "Connected"word then you can confirm Nodemanager is 'Reachable' otherwise 'Inactive' state.
def NM_status(nmUser, nmPassword, nmHost, nmPort, dName, domainPath,nmTYPE): """ This option nmConnect will give that it is reachable or not from stdout """ redirect('/tmp/mywlst.out') nmConnect(nmUser, nmPassword, nmHost, nmPort, dName, domainPath,nmTYPE) stopRedirect() flag=0 for line in open("/tmp/mywlst.out"): if "Connected" in line: flag=1 break nmDisconnect() if flag==1: return "Reachable" else: return "Inactive"
Here we met the purpose of knowing about the status of Node manager. Still looking for better alternative than this!
Node manager status by Socket moduleIn Python we have Socket object and its related methods to check weather a port is available or not. On a machine if we try to create socket object with Node manager ip address, port then it is going to check the port availability that gives us status!
def is_available(address, port): import socket try: s = socket.socket() s.connect((address, int(port))) return true except: return false def nmStatus(machinesList): """ This will create global string with Node manager status" machine_port=5556 machine_host=localhost global g_str g_str+="NM "+machine+ " - " if is_available(machine_host, machine_port): g_str+="Reachable"+"\n" else: g_str+="Inactive"+"\n"In you main script you could call nmStatus to know about the nodemanager status. Do you have any new thoughts, ideas or suggestions are welcome, Thanks for being with me.