Weblogic work manager Stuck Thread Action wlst.sh - weblogic

In Weblogic, how can I change Work Manager's Stuck-Thread-Action using WLST and python.

WLST uses Jython not Python. You can use the below script to change the stuck thread action.
admin_user = "weblogic"
admin_pass = "password"
admin_server_url = "t3://localhost:7001"
managed_server_name = "myserver"
connect(admin_user,admin_pass,admin_server_url)
edit()
startEdit()
cd('/Servers/'+managed_server_name+'/OverloadProtection/'+managed_server_name)
cmo.setPanicAction('no-action')
# cmo.setPanicAction('force-shutdown')
# cmo.setPanicAction('admin-state')
cmo.setFailureAction('no-action')
# cmo.setFailureAction('force-shutdown')
# cmo.setFailureAction('admin-state')
save()
activate()
For editing other attributes for Stuck Thread use below :
cd('/Servers/'+managed_server_name)
cmo.setStuckThreadMaxTime(300)
For more information you can read documentation for OverloadProtectionMBean from this link.

I solved it as I share below.
cd('edit:/SelfTuning/' + domainName + '/WorkManagers/' + workManagerName) cmo.setIgnoreStuckThreads(true)

Related

Renaming an Amazon CloudWatch Alarm

I'm trying to organize a large number of CloudWatch alarms for maintainability, and the web console grays out the name field on an edit. Is there another method (preferably something scriptable) for updating the name of CloudWatch alarms? I would prefer a solution that does not require any programming beyond simple executable scripts.
Here's a script we use to do this for the time being:
import sys
import boto
def rename_alarm(alarm_name, new_alarm_name):
conn = boto.connect_cloudwatch()
def get_alarm():
alarms = conn.describe_alarms(alarm_names=[alarm_name])
if not alarms:
raise Exception("Alarm '%s' not found" % alarm_name)
return alarms[0]
alarm = get_alarm()
# work around boto comparison serialization issue
# https://github.com/boto/boto/issues/1311
alarm.comparison = alarm._cmp_map.get(alarm.comparison)
alarm.name = new_alarm_name
conn.update_alarm(alarm)
# update actually creates a new alarm because the name has changed, so
# we have to manually delete the old one
get_alarm().delete()
if __name__ == '__main__':
alarm_name, new_alarm_name = sys.argv[1:3]
rename_alarm(alarm_name, new_alarm_name)
It assumes you're either on an ec2 instance with a role that allows this, or you've got a ~/.boto file with your credentials. It's easy enough to manually add yours.
Unfortunately it looks like this is not currently possible.
I looked around for the same solution but it seems neither console nor cloudwatch API provides that feature.
Note:
But we can copy the existing alram with the same parameter and can save on new name
.

How can I interact with the user inside a CasperJS/PhantomJS script?

Imagine a script like
system = require "system"
system.stdout.write "What's your name? "
name = system.stdin.readLine()
system.stdout.writeLine "Hello, #{name}"
To be run via
casperjs name.coffee
I'd like to be able to interact with the user in the terminal used to run the script, but I get stuck in the readLine() call.
As GarethOwen pointed out, it is indeed possible.
Here is a very basic CasperJS implementation of the Unix command cat:
var system = require('system'),
casper = require('casper').create();
while (!system.stdin.atEnd()) {
var line = system.stdin.readLine();
casper.log(line);
}
casper.exit();
Note that this module is mostly implemented in C++:
https://github.com/ariya/phantomjs/blob/master/src/system.h
And that stdin / stdout / stderr are instances of the PhantomJs class File :
https://github.com/ariya/phantomjs/blob/master/src/filesystem.h
According to the documentation, phantomJS can communicate with standard input. See this example:
https://github.com/ariya/phantomjs/blob/master/examples/stdin-stdout-stderr.js
Documentation regarding inter-process communication is here:
https://github.com/ariya/phantomjs/wiki/Inter-Process-Communication
But I've never tried it myself.

How to write a Python script that uses the OpenERP ORM to directly upload to Postgres Database

I need to write a "standalone" script in Python to upload sales taxes to the account_tax table in the database using ONLY the ORM module of OpenERP. What I would like to do is something like the pseudo code below.
Can someone provide me a more details on the following:
1) what sys.path's do I need to set
2) what modules do I need to import before importing the "account" module. Currently when I import the "account" module I get the following error:
AssertionError: The report "report.custom" already exists!
3) What is the proper way to get my database cursor. In the code below I am simply calling psycopg2 directly to get a cursor.
If this approach cannot work, can anyone suggest an alternative approach other than writing XML files to load the data from the OpenERP application itself. This process needs to run outside of the the standard OpenERP application.
PSEUDO CODE:
import sys
# set Python paths to access openerp modules
sys.path.append("./openerp")
sys.path.append("./openerp/addons")
# import OpenERP
import openerp
# import the account addon modules that contains the tables
# to be populated.
import account
# define connection string
conn_string2 = "dbname='test2' user='xyz' password='password'"
# get a db connection
conn = psycopg2.connect(conn_string2)
# conn.cursor() will return a cursor object
cursor = conn.cursor()
# and finally use the ORM to insert data into table.
If you wanna do it via web service then have look at the OpenERP XML-RPC Web services
Example code top work with OpenERP Web Services :
import xmlrpclib
username = 'admin' #the user
pwd = 'admin' #the password of the user
dbname = 'test' #the database
# OpenERP Common login Service proxy object
sock_common = xmlrpclib.ServerProxy ('http://localhost:8069/xmlrpc/common')
uid = sock_common.login(dbname, username, pwd)
#replace localhost with the address of the server
# OpenERP Object manipulation service
sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
partner = {
'name': 'Fabien Pinckaers',
'lang': 'fr_FR',
}
#calling remote ORM create method to create a record
partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create', partner)
More clearly you can also use the OpenERP Client lib
Example Code with client lib :
import openerplib
connection = openerplib.get_connection(hostname="localhost", database="test", \
login="admin", password="admin")
user_model = connection.get_model("res.users")
ids = user_model.search([("login", "=", "admin")])
user_info = user_model.read(ids[0], ["name"])
print user_info["name"]
You see both way are good but when you use the client lib, code is less and easy to understand while using xmlrpc proxy is lower level calls that you will handle
Hope this will help you.
As per my view one must go for XMLRPC or NETSVC services provided by Open ERP for such needs.
You don't need to import accounts module of Open ERP, there are possibilities that other modules have inherited accounts.tax object and had altered its behaviour as per your business needs.
Eventually if you feed data by calling those methods manually without using Open ERP Web service its possible you'll get undesired result / unexpected failures / inconsistent database state.
You can use Erppeek to browse data, but not sure if you can really upload data to DB, personally I use/prefer XMLRPC
Why don't you use the xmlrpc call of openerp.
it will not need to import account or openerp . and even you can have all orm functionality.
You can use python library to access openerp server using xmlrpc service.
Please check https://github.com/OpenERP/openerp-client-lib
It is officially supported by OpenERP SA.
If you want to interacti directly with the DB, you could just import psycopg2 and:
conn = psycopg2.connect(dbname='dbname', user='dbuser', password='dbpassword', host='dbhost')
cur = conn.cursor()
cur.execute('select * from table where id = %d' % table_id)
cur.execute('insert into table(column1, column2) values(%d, %d)' % (value1, value2))
cur.close()
conn.close()
Why you want to fix it like that?! You should create a localization module and define data in XML files. This is the standard way to fix such a problem in OpenERP.
You want to insert sales taxes for which country? Explain more plz.
from openerp.modules.registry import RegistryManager
registry = RegistryManager.get("databasename")
with registry.cursor() as cr:
user = registry.get('res.users').browse(cr, userid, listids)
print user

Alfresco Share: accessing bpm_comment in Activiti workflow

In Activiti workflow, how can I access variable bpm_comment for each comment that's input by user?
If I'm using bpm_comment in every task, it shows the same comment (the first one).
I've solved it!
In each userTask I used the following code to retrieve bpm:comment.
var taskId = "activiti$" + task.getId();
var taskComment = workflow.getTask(taskId).getProperties()["bpm:comment"];

How to check if application was deployed on a specific managed server?

I use following wlst command in order to check if application was already deployed before:
oldApplication = find(name=d['name'], type='AppDeployment')
But it does not show that application was deployed on a specific server.
How can I find that application was deployed on a specific managed server?
oldApplication will be an AppDeployment MBean, which has the "targets" attribute.
http://download.oracle.com/docs/cd/E17904_01/apirefs.1111/e13951/mbeans/AppDeploymentMBean.html
oldApplication.targets will return an array of "TargetMBean", which will be the list of servers on which the application is targeted/deployed.
It works for me and might help you:
print 'stopping and undeploying ...'
try:
stopApplication('WebApplication')
undeploy('WebApplication')
print 'Redeploying...'
except Exception:
print 'Deploy...'
deploy('WebApplication', '/home/saeed/project/test/WebApplication/dist/WebApplication.war')
startApplication('WebApplication2')