Using Jython to extract business data from the WebSphere Failed Event Manager - jython

I normally work with shellscript, but I'm dabbling in Jython for my current client. I need to extract and display business data from a failed event in WebSphere, and I can't figure out how to do it.
The code I have so far is
green='\033[0;32m'
cyan='\033[0;36m'
clear='\033[0m'
##########################################################################
import time
today=time.asctime().split(' ')
objstr = AdminControl.completeObjectName('WebSphere:*,type=FailedEventManager')
obj = AdminControl.makeObjectName(objstr)
fecount = AdminControl.invoke(objstr,"getFailedEventCount")
msglist = AdminControl.invoke_jmx(obj,'getAllFailedEvents',[0],['int'])
i=0
for fe in msglist:
i+=1
ftd=str(fe.getFailureDateTime()).split(' ')
if ftd[1]==today[1] and ftd[2]==today[2] and ftd[5]==today[4]:
col=green
else:
col=cyan
fstr="%4d: %-46s "+col+"%s"+clear
print fstr % (i, fe.getMsgId(), fe.getFailureDateTime() )
Which displays the message ID and the timestamp of the event. But I've looked around the net, and can't figure out how to get from what I've got to actually extracting specific parameters from the business data for each failed event.
I'd appreciate if somebody with greater knowledge of Jython than I have could point me in the right direction.
Thanks
Douglas

Not sure if you got your answer.
Posting what I know to help who is looking for:
You can use getFailedEventParameters to get business data of failed events.
scaDetail = AdminControl.invoke_jmx(obj,'getEventDetailForSCA',[event], ['com.ibm.wbiserver.manualrecovery.FailedEvent'])
eventDetailParameter = scaDetail.getFailedEventParameters()
for failedParameter in eventDetailParameter:
print failedParameter.getName()
print failedParameter.getType()
print failedParameter.getValue()

Related

How to close a QInputDialog with after a defined amount of time

I'm currently working on an application that run in the background and sometime create an input dialog for the user to answer. If the user doesn't interact, I'd like to close the dialog after 30 seconds. I made a QThread that act like a timer and the "finished" signal should close the dialog. I unfortunately cannot find a way to close it.
At this point I'm pretty much lost. I completely new to QThread and a beginner in PyQt5
Here is a simplified version of the code (we are inside a class running a UI):
def Myfunction(self,q):
# q : [q1,q2,q3]
self.popup = counter_thread()
self.popup.start()
self.dial = QInputDialog
self.popup.finished.connect(self.dial.close)
text, ok = self.dial.getText(self, 'Time to compute !', '%s %s %s = ?'%(q[0], q[2], q[1]))
#[...]
I tried ".close()" and others but i got this error message:
TypeError: close(self): first argument of unbound method must have type 'QWidget'
I did it in a separated function but got the same problem...
You cannot close it because the self.dial you created is just an alias (another reference) to a class, not an instance.
Also, getText() is a static function that internally creates the dialog instance, and you have no access to it.
While it is possible to get that dialog through some tricks (installing an event filter on the QApplication), there's no point in complicating things: instead of using the static function, create a full instance of QInputDialog.
def Myfunction(self,q):
# q : [q1,q2,q3]
self.popup = counter_thread()
self.dial = QInputDialog(self) # <- this is an instance!
self.dial.setInputMode(QInputDialog.TextInput)
self.dial.setWindowTitle('Time to compute !')
self.dial.setLabelText('%s %s %s = ?'%(q[0], q[2], q[1]))
self.popup.finished.connect(self.dial.reject)
self.popup.start()
if self.dial.exec():
text = self.dial.textValue()
Note that I started the thread just before showing the dialog, in the rare case it may return immediately, and also because, for the same reason, the signal should be connected before starting it.

Object of type 'closure' is not subsettable topic modeling

I am attempting some data analysis via topic modeling. I have followed the guide posted here: https://bookdown.org/joone/ComputationalMethods/topicmodeling.html
The code works fine until the last step. Here is my code snippet for your reference:
LePen_top <- tibble(topic = terms$topicnums, prob = apply(terms$prob, 1, paste, collapse = ", "),
frex = apply(terms$frex, 1, paste, collapse = ", "))
When I run it, the following message pops up: Error in terms$topicnums : object of type 'closure' is not subsettable
I have looked around the forums, but I have not been able to solve it due to my inexperience. I would greatly appreciate your help, and if you could explain what have I done wrong.
Best regards,
MRizak

Why isn't Entrez NCBI API error handling working?

from Bio import Entrez, __version__
print('Biopython version : ', __version__)
id_list = ["NC_045512.2", "ON248099.1", "ON248101.1", "ON248104.1", "ON248107.1", "ON248108.1", "ON248109.1", "ON248110.1", "ON248114.1", "ON247234.1", "ON247236.1", "ON247240.1", "ON247242.1", "ON247243.1", "ON247244.1", "ON247245.1", "ON247246.1", "ON247247.1", "ON247248.1"]
try:
print ("Downloading "+str(id_list[ax]))
net_handle = Entrez.efetch(db="nucleotide", id=id_list[ax], rettype="fasta", retmode="text")
net_handle_gb = Entrez.efetch(db="nucleotide", id=id_list[ax], rettype="gbwithparts", retmode="text")
except (IOError):
print ("Waiting")
sleep (30)
tell.app( 'Terminal', 'do script "' + command+ ' && ' + "python3 'All Covid SSR.py'" +'"')
I'm using this try block to download files from NCBI API. Up to this point, the try block was working and the exception was handled as given here. Now it isn't. The code gets stuck in the try section. Returns no errors or exceptions, so it doesn't trigger the exception handler.
I've set max_tries = 1, sleep_between_tries = 1 and got the personal API_Key too.
For context, I'm using the exceptions block to restart the downloading code on Mac Terminal.
I need the try and except section to automatically restart the script when Entrez.efetch returns an error. There isn't any error. The code just gets stuck after
print ("Downloading "+str(id_list[ax]))
Any suggestions are welcome.
P.S. I thought of changing the default timeout for requests.get because that's the module Entrez uses to access the NCBI API. Haven't found a way to do that. (There is no timeout variable that you can set in the efetch module.)
An explanation would be great!

WebSphere wsadmin testConnection error message

I'm trying to write a script to test all DataSources of a WebSphere Cell/Node/Cluster. While this is possible from the Admin Console a script is better for certain audiences.
So I found the following article from IBM https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/txml_testconnection.html which looks promising as it describles exactly what I need.
After having a basic script like:
ds_ids = AdminConfig.list("DataSource").splitlines()
for ds_id in ds_ids:
AdminControl.testConnection(ds_id)
I experienced some undocumented behavior. Contrary to the article above the testConnection function does not always return a String, but may also throw a exception.
So I simply use a try-catch block:
try:
AdminControl.testConnection(ds_id)
except: # it actually is a com.ibm.ws.scripting.ScriptingException
exc_type, exc_value, exc_traceback = sys.exc_info()
now when I print the exc_value this is what one gets:
com.ibm.ws.scripting.ScriptingException: com.ibm.websphere.management.exception.AdminException: javax.management.MBeanException: Exception thrown in RequiredModelMBean while trying to invoke operation testConnection
Now this error message is always the same no matter what's wrong. I tested authentication errors, missing WebSphere Variables and missing driver classes.
While the Admin Console prints reasonable messages, the script keeps printing the same meaningless message.
The very weird thing is, as long as I don't catch the exception and the script just exits by error, a descriptive error message is shown.
Accessing the Java-Exceptions cause exc_value.getCause() gives None.
I've also had a look at the DataSource MBeans, but as they only exist if the servers are started, I quickly gave up on them.
I hope someone knows how to access the error messages I see when not catching the Exception.
thanks in advance
After all the research and testing AdminControl seems to be nothing more than a convinience facade to some of the commonly used MBeans.
So I tried issuing the Test Connection Service (like in the java example here https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/cdat_testcon.html
) directly:
ds_id = AdminConfig.list("DataSource").splitlines()[0]
# other queries may be 'process=server1' or 'process=dmgr'
ds_cfg_helpers = __wat.AdminControl.queryNames("WebSphere:process=nodeagent,type=DataSourceCfgHelper,*").splitlines()
try:
# invoke MBean method directly
warning_cnt = __wat.AdminControl.invoke(ds_cfg_helpers[0], "testConnection", ds_id)
if warning_cnt == "0":
print = "success"
else:
print "%s warning(s)" % warning_cnt
except ScriptingException as exc:
# get to the root of all evil ignoring exception wrappers
exc_cause = exc
while exc_cause.getCause():
exc_cause = exc_cause.getCause()
print exc_cause
This works the way I hoped for. The downside is that the code gets much more complicated if one needs to test DataSources that are defined on all kinds of scopes (Cell/Node/Cluster/Server/Application).
I don't need this so I left it out, but I still hope the example is useful to others too.

Juliaopt JuMP CbcSolver how to print progress

I coding in julia using JuMP of Juliopt.
I would like to know how to print the solve progress using CbcSolver?
I already used the log level parameter:
m = Model(solver = CbcSolver(log=1))
it works and you can choose between 0 to 3, higher more details.
but my problem is that the log level only prints after the solver finish, i already put the the time limit parameter "sec" but when it is set for higher values never stops and i don't know why!!
m = Model(solver = CbcSolver(sec=90,log=1))
I was going to try callbacks but Cbc does not support callback.
I am positive that there is a way to print because when i use the opensolver in excel a set Cbc to solve it shows the progress.I just dont know how to do this!!