Showing posts with label wsadmin. Show all posts
Showing posts with label wsadmin. Show all posts

Friday, November 11, 2016

Jython operators and sequences in wsadmin

Welcome back to Jython learning blog again. today I have explored different categories of operators how they can be used in Jython for wsadmin. prerequisites for this is you must have a Jython for WebSphere installed on your VM and you are on wsadmin prompt.

Types of operators (inherited from Python):
  • Arithmetic operators
  • Comparison operators
  • Relational operators 
These simple experiments would give you a base for building automation scripts in your projects.

Basic understanding of Jython Operators
Jython Operators on wsadmin


 

How can Jython deals with Arithmetic operators

Every language supports the Arthematic operators and in Jython same operators as in C or Python languages.

wsadmin>x,y = 10, 20
wsadmin>print x, y
10 20
wsadmin>x+y
30
wsadmin>x+y+30
60
wsadmin>y-x
10
wsadmin>x-y
-10
wsadmin>x*y
200
wsadmin>x**2
100
wsadmin>y/x
2
wsadmin>y%x
0

How to use Jython Comparison operators?

The comparing operators mostly used in the 'if-else' or 'while' blocks which returns either True or False value. For each data type it will be different so see the examples executed at the wsadmin prompt.

Numeric comparison in Jython
 wsadmin>10>1
1
wsadmin>20<34 1="" wsadmin="">20<2 0="" wsadmin="">10<10 0="" wsadmin="">10<=10
1



Tuple comparison in Jython
wsadmin>'app_server1' in ('app_server1','app_server2','ejb_server1','ejb_server2')
1
wsadmin>servers_list=('app_server1','app_server2','ejb_server1','ejb_server2')
wsadmin>'appserver1' in servers_list
0


String comparison in Jython
wsadmin>'dmgr'=='dmgr'
1




Char comparison in Jython
wsadmin>'t'=='t'
1
wsadmin>'t'=='T'
0



List comparison in Jython
wsadmin>['dev_cell01',20]==['dev_cell01',20]
1
wsadmin>['dev_cell01',20]==[20,'dev_cell01']
0


Dictionaries comparison in Jython
wsadmin>{'appserver1':8001}=={'appserver1':8001}
1
wsadmin>server_dict={'appserver1':8001}
wsadmin>{'appserver1':8001}==server_dict
1
wsadmin>server_dict=={'appserver2':8001}
0

How can Jython Relational operators simplify your scripts?

Here is the set of releational operators usage examples
wsadmin>x>=10
1
wsadmin>x>=10 and y==20
1
wsadmin>x>10 or y==20
1
wsadmin>x>10
0
wsadmin>not x>10
1
wsadmin>not x>=10
0


Hope you enjoyed this short learning about operators. Please share your experiance with your friends and teams. Comment your expectations we will keep updating this blog frequently.

Friday, August 29, 2014

Getting Node id, Cell ID, Server ID of Mbean in wsadmin

Basic understanding of wsadmin objects
  • Node – an individual system, either physical or virtual
  • Node Manager – the process controlling the individual node and all servers in all cells, it executes the commands of the Deployment Manager
  • Profile – a WebSphere entity similar to a node concept wise
  • Application Server – a Java Virtual Machine (JVM) process
  • Application – a Java enterprise application it could be .ear file with some modules
  • Cluster – a group of Servers, all running the same applications
  • Cell – an administrative domain of one or more servers
  • Deployment Manager (DM) – the administration application for a cell
How do all these pieces work together? 
 “Multiple Nodes in a Cell run Servers that contain Applications. All pieces are controlled via the Deployment Manager”
 

How to retrieving  Node ID in wsadmin?

This task is very much required for most of the create method executions. When you create servers, when you construct Cluster Member servers your script need Node id. Ofcourse if you wish to Sync the differe!!nt members of a node also requird the Node id.

wsadmin>AdminConfig.getid('/Node:DmgrNode05')
'DmgrNode05(cells/DmgrCell05/nodes/DmgrNode05|node.xml#Node_1)'

How to retrieving Cell Name in wsadmin?

wsadmin>CellName=AdminControl.getCell()

What is the command to Retrieving Cell ID in wsadmin?

wsadmin>AdminConfig.getid('/Cell:'+CellName)
'DmgrCell05(cells/DmgrCell05|cell.xml#Cell_1)'

How can I retrieving the Servers list in wsadmin?

wsadmin>AdminTask.listServers('[-serverType APPLICATION_SERVER]')
'server1(cells/DmgrCell05/nodes/AppSrvNode/servers/server1|server.xml)'

How to fetch the Server ID on wsadmin?

wsadmin>AdminConfig.getid('/Server:server1')
'server1(cells/DmgrCell05/nodes/AppSrvNode/servers/server1|server.xml#Server_1407376951191)'
wsadmin>

Different automation scripts requires the wsadmin provided MBean values. so that we can store in the Jython variables like list and use them.

Hoping this post helped you in doing simple command exections on your wsadmin prompt. Keep writing your comments and thoughts on this blog 

Tuesday, August 12, 2014

Jython variables in wsadmin

A warm Welcome to my jython4wsadmin blog!!

Variables in programming languages we need to declare on the top of the function or program. When we declare it we need to tell about what type of data we would like to store in the variable. Where as in Scripting languages you don't need to do so. Jython is a scripting language so you don't need to declare the variable.

Like any programming language Jython also support variables but these variables looks like scripting variables, they are dynamic.
The value that assigned to a variable is going to have an id and label internally it is one of the Python Object type as well.

Let me experiment with my simple Jython script to understand more how the variables can be created and used in multi variants. Here the values can be integer, float, long types in numeric data types.

Jython Variable inside wsadmin

	# This program will illustrate the variables of jython.
	# Integer variable
	x=5
	print 'x=', x, type(x), id(x)

	# Multiple Variables can be assigned with multiple values respectively
	y, z=10, 30
	print 'y=',y, 'z=',z

	# Float number
	f=10.45
	print "f=", f, type(f), id(f)

	# Boolean value
	b=10<40 and="" assert="" b=",b, type(b), id(b)

	# String value
	cellName=" cellname:="" cellname="" democell="" pre="" print="" t="">
The script execution can be done using execfile function that takes the path for the Jython script.<br /> Better to have the all Jython scripts at one common place, I"> Output of the above script looks like this...

Best practice: Avoid the keyword in the namespaces

How do I know what all the keywords available in Jython? It is easy to determine that, from the keyword module you can get keyword list as shown below:
wsadmin>import keyword
wsadmin>keyword.kwlist
['and', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while']

Note: Don't use any of these keywords in the function names, class name or variable names.

How the type Casting works in Jython?

Unlike any other programming languages we have typecasting allowed in Jython script. What do you mean by casting? It is simple converting from one type of data to another type. Following illustrates a float value casting to int type.
	wsadmin>f=10/3.0
	wsadmin>print f
	3.3333333333333335
	wsadmin>cast2int = int(f)
	wsadmin>print cast2int
	3

Casting a int value to str type
	wsadmin>str(cast2int)
	'3'

Converting a int value to chr type
	wsadmin>chr(65)
	'A'

Hope you enjoyed this post please write your comment where did you use the post. Information is wealth!! keep sharing this knowledge article.

Containerization with Docker

Containerization with Docker
Learn modern microservices containers grow