Sie können Jython-basierte Scripts verwenden, um eine JMX-MBean-Liberty-Serververbindung
(Java™ Management Extensions) zu erstellen.
Vorbereitende Schritte
Sie müssen die Jython-Version Ihrer Wahl
abrufen und installieren, um diese Prozedur auszuführen.
Ohne eine Jython-Laufzeit werden die Anweisungen fehlschlagen.
Vorgehensweise
- Konfigurieren Sie die Umgebung.
Die Dateien, die Sie benötigen, befinden sich im Verzeichnis Liberty-Ausgangsverzeichnis/clients/jython.
- Kopieren Sie die Datei lib/restConnector.py in das Verzeichnis
Jython-Ausgangsverzeichnis/Lib.
- Definieren Sie den Klassenpfad (Variable CLASSPATH) für die Datei restConnector.jar
im Verzeichnis Liberty-Ausgangsverzeichnis/clients.
set CLASSPATH=%CLASSPATH%;c:\wlp\clients\restConnector.jar
- Führen Sie das Dienstprogramm aus.
Beispiel 1: Eine einfache Verbindung mit
connector.connect(host,port,user,password) abrufen
from restConnector import JMXRESTConnector
JMXRESTConnector.trustStore = "c:/key.jks"
JMXRESTConnector.trustStorePassword = "Liberty"
connector = JMXRESTConnector()
connector.connect("foo.bar.com",9443,"theUser","thePassword")
mconnection = connector.getMBeanServerConnection()
# mconnection.invoke(...)
connector.disconnect()
Beispiel 2: Eine erweiterte Verbindung mit
connector.connect(host,port,map) und benutzerdefinierten Eigenschaften abrufen
import java
import javax
import jarray
import com.ibm.websphere.jmx.connector.rest
import com.ibm.ws.jmx.connector.client.rest
map=java.util.HashMap()
map.put("jmx.remote.provider.pkgs","com.ibm.ws.jmx.connector.client")
map.put(javax.management.remote.JMXConnector.CREDENTIALS,jarray.array(["theUser","thePassword"],java.lang.String))
map.put(com.ibm.ws.jmx.connector.client.rest.ClientProvider.READ_TIMEOUT,2*60*1000)
map.put(com.ibm.websphere.jmx.connector.rest.ConnectorSettings.DISABLE_HOSTNAME_VERIFICATION, True)
connector = JMXRESTConnector()
connector.connect("foo.bar.com",9443,map)
mconnection = connector.getMBeanServerConnection()
# mconnection.invoke(...)
connector.disconnect()
Beispiel 3: Listener für Benachrichtigungen registrieren
import java
import javax
from restConnector import JMXRESTConnector
from restConnector import BaseNotificationListener
class SampleNotificationListener(BaseNotificationListener):
def __init__(self):
pass
def handleNotification(self,notification,handback):
print "Notification received:"
print " Source: " + notification.getSource().toString()
print " Type: " + notification.getType()
print " Message: " + notification.getMessage()
# main starts here
JMXRESTConnector.trustStore = "c:/key.jks"
JMXRESTConnector.trustStorePassword = "Liberty"
connector=JMXRESTConnector()
connector.connect("foo.bar.com",9443,"theUser","thePassword")
mconnection=connector.getMBeanServerConnection()
listener=SampleNotificationListener()
handback=java.lang.Object()
notifier1=javax.management.ObjectName("web:name=Notifier1")
mconnection.addNotificationListener(notifier1,listener,None,handback)
- JMXRESTConnector.trustStore
- Legt den Pfad fest, unter dem die SSL-Schlüsseldatei gespeichert wird.
- JMXRESTConnector.trustStorePassword
- Legt das Kennwort für den Schlüssel fest.
- JMXRESTConnector.connect(Host,Port,Benutzer,Kennwort)
- Erstellt einen Connector für einen Server.
- JMXRESTConnector.connect(Host,Port,Zuordnung)
- Erstellt eine Verbindung mit Benutzereigenschaften.
- JMXRESTConnector.getMBeanServerConnection
- Ruft eine Verbindung zum MBean-Server ab.
- JMXRESTConnector.disconnect()
- Schließt die Verbindung.
Nächste Schritte
Nachdem eine Verbindung zum MBean-Server hergestellt ist, können Sie mit der Methode invoke(...)
Aufrufe an den MBean-Server absetzen.
Anmerkung: Sie können eine Bibliothek von Jython-Scripts aus dem
Liberty-Repository
herunterladen.