Tuesday, 22 April 2014

Jython

How to execute Jython scripts?

Execute the script using below wsadmin command
Windows:
Go to DMGR BIN directory

 wsadmin.bat -f example.py -lang jython -port -conntype SOAP -user -password  

Unix :-
Go to DMGR BIN directory


 ./wsadmin.sh -f example.py -lang jython -port -conntype SOAP -user -password  


JYTHON SCRIPT TO CREATE SERVER

Copy the Below Code and create a file create_server.py and place the file in Deployment Manager Bin Directory  :-
#-------------------------------------------#
import sys,java
from java.util import Properties
from java.io import FileInputStream
from org.python.modules import time
lineSep = java.lang.System.getProperty('line.separator')

def server_create(node,server):
 node=AdminConfig.getid('/Node:'+node+'/')
 attr=[['name', server]]
 print "creating server .."
 AdminConfig.create('Server',node,attr)
 print "server created .."
 AdminConfig.save()
 print "saving config .."


arglen=len(sys.argv)
number_of_argument=2
if ( arglen != number_of_argument):
 print "pass 2 arguments .."
 sys.exit(-1)

server=sys.argv[0]
node=sys.argv[1]
server_create(node,server)


Example :

 ./wsadmin.sh -f create_server.py -lang jython -port 8879 -conntype SOAP -user wasadmin -password wasadmin test_server test_node

Wednesday, 20 March 2013

Information on Subversion

Information on Subversion

I have tried few of the following, not all of it but found these information very useful while learning and doing my project to get SVN working:

Creating the Repository
Subversion has two kinds of repository type: Berkeley DB Repository and FSFS Repository. Default is FSFS Repository.
svnadmin create D:/svn_repository/repos
svn mkdir --parents file:///D:/svn_repository/repos/myproject/trunk file:///D:/svn_repository/repos/myproject/branches file:///D:/svn_repository/repos/myproject/tags -m "creating initial repository layout"
svn list file:///D:/svn_repository/repos/myproject/
Populating the Repository
svn import D:/ws/myproject file:///D:/svn_repository/repos/myproject/trunk -m "importing my project"
Checking Out a Working Copy
svn checkout file:///D:/svn_repository/repos/myproject/trunk D:/ws/svnprojetcs/myproject
Optional arguments:
-r or --revision argument, which allows to indicate what revision to check out. Default is the HEAD revision of the repository.
Getting Information about Working Copy
svn status (-v) print out the current status of working copy
svn info find information about items in working copy.
Adding, Copying, Renaming, and Removing Files
svn mkdir --parents src\java\org\kenny
svn add src\java\org\kenny\Hello.java
svn commit -m "commit messgae"
svn log -r BASE:HEAD
svn update
Copying and Moving Versioned Items
svn move Hello.java HelloWorld.java
svn copy HelloWorld.java HelloWorldCpoy.java
Deleting Versioned Items
svn delete HelloWorld.java

Although the file has been removed from the HEAD revision of the repository, it still exists in the previous revisions, and you can easily get the file back either by using svn copy to copy the file from the previous revision into your working copy.

svn copy --revision 10 file:///D:/svn_repository/repos/myproject/trunk/src/java/org/kenny/HelloWorld.java HelloWorld.java
Working with Branches and Tags
The difference between Branches and Tags:
Tags are used to mark a particular version or release of project so we can easily refer back to it later, normally they are just a copy of project at particular time and left them here.
A tag is intended to never be modified again (this may be enforced by various means).

Branches are different; they can be modified, and are used for further development. for example, we don't want our modification in the main development(trunk), maybe they are experimental code, and might never be committed to the mainline version.or maybe this is a branch we want to make a release from and only want to allow bug fixes.
In cases like these we might want to create a new development branch by making a separate
copy of the trunk and then commit our changes to the branch. If we later decide that the
changes are ready, they can be merged into the version of the project in the trunk and com-
mitted so that everyone can see them.
Creating Branches and Tags
svn copy file:///D:/svn_repository/repos/myproject/trunk file:///D:/svn_repository/repos/myproject/tags/0.9-release -m "tagging 0.9 release"
svn diff file:///D:/svn_repository/repos/myproject/trunk file:///D:/svn_repository/repos/myproject/tags/0.9-release
Merging Changes between Branches
The merge command has three modes of operation.
In the first, you give the command two source URLs (with optional revisions specified with @REVNUM at the end of the URL), and it will merge the differences between the two sources
into your current working directory (or another directory if it’s specified on the command line).
svn merge file:///D:/svn_repository/repos/myproject/tags/0.9-release file:///D:/svn_repository/repos/myproject/tags/1.0-release D:\ws\svnprojetcs\0.9-branch
Merge a particular change or set of changes from one branch into another
svn merge -r 12:13 file:///D:/svn_repository/repos/myproject/branches/0.9-branch D:/ws/svnprojetcs/myproject_trunk
Use “SVN MERGE” to Revert a Change
svn merge -r 9:8 HelloWorld.java
Apply the change needed to go from revision 9 of HelloWorld.java to revision 8 of HelloWorld.java to the version of HelloWorld.java
Switching to another Branch
svn switch can move checked-out working copy to another branch in the repository. Standard use is either to migrate an entire working copy from one branch to another or, more commonly, to move specific parts of your working copy to another branch.
svn switch file:///D:/svn_repository/repos/myproject/trunk D:\ws\svnprojetcs\0.9-release
svn switch file:///D:/svn_repository/repos/myproject/tags/0.9-release D:\ws\svnprojetcs\0.9-release
Changing a Repository URL with svn switch --relocate
This would happen when the URL you use to access your Subversion repository has changed.
svn switch --relocate file:///D:/svn_repository/repos/myproject http://localhost/svn/myproject/
Removing Old Branches
svn list file:///D:/svn_repository/repos/myproject/branches/
svn delete file:///D:/svn_repository/repos/myproject/branches/0.9-branch/

Working with Locks
This often happens when working with binary files which don’t work in a nonlocking model.
svn lock logo.jpg –message “Working on drawing for the next hour”
svn unlock logo.jpg
svn unlock –force http://example/repos/trunk/logo.jpg
Properties
Associate arbitrary metadata with files, directories, and even revisions in the repository.

svn proplist
Tell what properties have been set on a particular versioned resource.
svn proplist index.html
svn propget command prints out the value of a given property.
svn propget svn:mime-type index.html

svn propset and svn propedit commands set and change he value of a given property.
svn propset svn:mime-type image/png logo.png

Special Properties
svn:mime-type, svn:ignore,
svn:needs-lock
Specify which files should be locked before editing them. When this property is set on a file it will be read-only until svn lock is called on the file. This is useful in order to ensure that locking of unmergable files occurs before they are edited.
svn:keywords
/* $URL$
* $Rev$
* $Author$
* $Date$
* $Id$
*/
svn:executable
svn blame
Output in each line the version that line originates from, and the username of author of that line.
svn blame D:\ws\svnprojetcs\0.9-release\src\src\java\org\kenny\HelloWorld.java
svn cleanup
Return everything to working order, by finishing up all unfinished work and removing stray locks.
svn export
The export command is useful when you need to release a version of your software and don’t want to include all the administrative directories from a working copy.
svn export file:///D:/svn_repository/repos/myproject/tags/1.0-release D:\ws\svnprojetcs\release-1.0
Choosing a Repository Type
Subversion has two kinds of repository: FSFS or Berkeley DB, default is FSFS. and it is highly recommended we go with the FSFS default repository type.
svnadmin create --fs-type bdb D:/svn_repository/repos-bdb
svnadmin create --fs-type fsfs D:/svn_repository/repos-fsfs
Tools for Working with the Repository
svnadmin
svnadmin create
Using svnadmin to Manipulate Transactions
Use svnadmin lstxns to find old, abandoned transactions, and use svnadmin rmtxns to remove them
svnadmin lstxns /path/to/repository
svnadmin rmtxns /path/to/repository 2
svnlook
A safer way to work with the repository
svnlook uuid prints the UUID of a repository.
svnlook youngest prints the current HEAD revision number of the repository
Backups
svnadmin hotcopy D:/svn_repository/repos D:/repos-backups/repos0714
Optional arguments:--clean-logs
Dumping and Loading Repository Contents
svnadmin create D:/svn_repository/new-repos0714
svnadmin dump D:/svn_repository/repos > D:/repos-backups/repos0714.dump
svnadmin load D:/svn_repository/new-repos0714 < D:/repos-backups/repos0714.dump
The above step is equivalent as followings:
svnadmin create D:/svn_repository/new-repos0714
svnadmin dump D:/svn_repository/repos | svnadmin load D:/svn_repository/new-repos0714

svnadmin dump can be used in conjunction with the svndumpfilter tool to migrate
portions of a repository from one repository to another or to remove specific portions of
a repository if data that can’t be allowed to exist in the repository at all has been accidentally
committed.
svnadmin dump D:/svn_repository/repos| svndumpfilter include trunk | svnadmin load D:/svn_repository/new-repos0714

svnadmin dump --incremental -r 0:5 D:/svn_repository/repos > D:/repos-backups/dump-0-5
svnadmin dump --incremental -r 6:10 D:/svn_repository/repos > D:/repos-backups/dump-6-10

svnadmin create D:/svn_repository/repos-incremental
svnadmin load D:/svn_repository/repos-incremental < D:/repos-backups/dump-0-5
svnadmin load D:/svn_repository/repos-incremental < D:/repos-backups/dump-6-10

Networking with ra_dav
Integration Subversion with Apache Server
Add the following to httpd.conf:
LoadModule dav_module modules/mod_dav.so
LoadModule dav_svn_module modules/mod_dav_svn.so
<Location /svn>
DAV svn
SVNPathAuthz off
SVNPath D:/svn_repository/repos
AuthType basic
AuthName "Kenny Subversion Repository"
AuthUserFile "D:/Program Files/Apache Software Foundation/Apache2.2.6/bin/svn-passwd"
<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
</LimitExcept>
</Location>
Create and Modify user/pass
htpasswd -c svn-passwd kenny
htpasswd svn-passwd kenny
SVNParentPath
This indicates that a single parent directory contains several Subversion repositories, so we don’t have to list them each in their own individual Location block.
SVNListParentPath option enables a web browser accessing SVNParentPath to display a list of repositories
And these options are exclusive with SVNPath.
Networking with ra_svn
svnserve --daemon --root D:/svn_repository/repos
Configuration file: conf/svnserve.conf in each Subversion repository.
Optional flags: --listen-host, --threads
svn checkout svn://localhost/myproject/trunk D:/ws/svnprojetcs/myproject-svn
mod_auth
Use Apache htpasswd command to create file including username and password
htpasswd -c svn-passwd kenny
Read-only access available without an account
<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
</LimitExcept>
Restricting User Actions with mod_authz_svn
mod_authz_svn allows to define authorization rules in a simple text file.
LoadModule authz_svn_module modules/mod_authz_svn.so

And add the following line to <Location /svn> section.
AuthzSVNAccessFile D: /svn_repository/repos/conf/authzSVNAccessFile

Combining "Satisfy Any" and "Require valid-user" together allows anonymous users access to the repository for anything that’s allowed for all users (specified as an * in the AuthzSVNAccessFile), but for anything that requires a specific user or group the client will be required to authenticate.
AuthzSVNAccessFile config file
It contains several sections, one special section named [groups] that contains definitions for groups of users, and a number of other sections, each of which has a path specification for a name and contains users or groups and their access rights. To distinguish groups from users in the permission specifications, groups are prefixed with an @. An * can be used in the place of a user or a group as a wildcard that indicates all users have that kind of access. Access rights can be specified as r for read, w for write, rw for read-write, or nothing for no access at all.
[groups]
committers = tom,dick,harry,michelle,tracey,jessica,mark,dave
documenters = phil,fred,rob,james
[/]
# give everyone read access to the whole repository
* = r
@committers = rw
[/trunk/docs]
# documentation people have read-write access
@documenters = rw
[/tags]
# phil is the release manager, so he lays down the tags
phil = rw
[/private]
# default to denying access in this section
* =
# but give committers read-write and documenters read access
@committers = rw
@documenters = r
If combining mod_authz_svn with the SVNParentPath directive, you need to be a bit careful. If you just specify raw paths such as the previous AuthzSVNAccessFile, those rules will be applied to all of the repositories under the SVNParentPath directory. If you want to limit the rule to a particular repository, you prefix the path with the repository name and a colon, like this:
[groups]
javacommitters = tom,dick,harry,michelle,tracey,jessica,mark,dave
perlcommitters = simon,casey,larry,chip
[java:/]
# give everyone read access to the whole java repository
* = r
@javacommitters = rw
[perl:/]
# everyone has read access to the perl repository
* = r
@perlcommitters = rw
Encrypting Traffic with mod_ssl
Use mod_ssl to provide access to repository via https instead of http.
1. Create a self-signed certificate
cd D:\OpenSSL\bin
openssl genrsa help
openssl genrsa -des3 -out "D:\Program Files\Apache Software Foundation\Apache2.2.6\bin\server-svn.key" 4096
2. Then create a certificate signing request
openssl req -new -key server-svn.key -out server-svn.csr
3. Sign the certificate signing request
openssl x509 -req -days 365 -in server-svn.csr -signkey server-svn.key -out server-svn.crt
4. Add following lints to httpd.conf
LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf
Require clients always access the repository via SSL, add following lines to Location section:
<IfDefine SSL>
SSLRequireSSL
</IfDefine>
Compression
Use apache module mod_deflate to compress HTTPtraffic
1.Uncooment "LoadModule deflate_module modules/mod_deflate.so" in httpd.conf.
2.Add a SetOutputFilter DEFLATE directive to repository’s Location block in httpd.conf
SetOutputFilter DEFLATE
Logging
CustomLog logs/svn_logfile "%t %{SVN-ACTION}e %u" env=SVN-ACTION
log a time-stamp, an SVN action, and a username to a log file named logs/svn_logfile
Choosing a Repository Layout
For single projects, the standard trunk/branches/tags repository layout works great.
branches
tags
trunk
For multiple projects, there are two basic schools of thought on the subject, the first being to do the following:
branches
project1
project2
tags
project1
project2
trunk
project1
project2
The second is to do this:
project1
branches
tags
trunk
project2
branches
tags
trunk
Best Practices
Avoid Locking Mergeable Files
Committing Changes:
Commit Early, Commit Often
Make Small, Atomic Changes
Use Meaningful Log Messages
Don’t Break the Tree
Use svn switch to only branch small portions of the tree, instead of something as large as the entire trunk.
Releases
Making a Release Branch
A release branch is a branch created from development trunk once you determine that all the goals for your release have been reached. After the release branch has been created, all testing of the release should be done on the branch, and development work can continue on the trunk. The majority of the developers can turn their attention to working on the next phase of the project, while those who are tasked with making the release can feel free to take their time testing the branch without worrying about holding up development work.
svn copy svn://example.org/repos/trunk
svn://example.org/repos/branches/release-1.0 -m "create release branch"
Merge fixes in Release Branch’s working copy, and then commit to Release Branch
svn merge -r 2070:2071 svn://example.org/repos/trunk .
svn commit -m "merge fix for issue #175 into the release branch."
Finalizing the Release
svn cp svn://example.org/repos/branches/release-1.0 svn://example.org/repos/tags/1.0 -m "tag version 1.0"
Once the tag is created, the release is finalized, and if a problem is found, a new release needs to be created if you want to fix it.
Use "svn export" to roll out distribution
Integration Subversion with CruiseControl to automate test
Integrating Subversion with Other Tools
Ant Integration:svnant
Download svnant from http://subclipse.tigris.org/svnant.html.
The next step is to tell Ant how to find SVNAnt task by adding the following to build.xml file:
<path id= "svnant.classpath" >
<fileset dir= "D:/kenny/software/Subversion/svnant-1.0.0/lib" >
<include name= "*.jar" />
</fileset>
</path>
<typedef resource="svntask.properties" classpathref="svnant.classpath" />
Then we can use svn task in ant:
<target name="svn-checkout">
<svn>
<checkout url="http://localhost/svn/dms/trunk/"
destPath="dms" />
</svn>
</target>
Eclipse Integration: http://subclipse.tigris.org/
TortoiseSVN http://tortoisesvn.net

Access via custom protocol (svn://)
svnserve -d -r /usr/local/repositories
-d|--daemon, -r|--root

edit $repos/conf/svnserve.conf:
[general]
anon-access = read
auth-access = write
password-db = passwd
authz-db = authz
realm = My First Repository

in passwd:
[users]
harry = foopassword
sally = barpassword
Access via custom protocol with SSL encryption (svn+ssh://)
 $ svn co svn+ssh://hostname/home/svn/myproject myproject --username user_name
NOTE: You must use full path (/home/svn/myproject) to access SVN repository using this access method.

Start svnserve at bootup
cd /etc/init.d/
sudo vi svnserve
svnserve -d -r /usr/local/svn/repository_name
or we can download this init script and to start it manually, run sudo /etc/init.d/svnserve start.
sudo chmod +x /etc/init.d/svnserve
Add the script to the boot sequence
sudo update-rc.d svnserve defaults

Creating Branches and Tags
svn copy file://path/to/repos/branches/my-development-branch \
file:///path/to/repos/tags/0.9-release \
-m "create development branch from version 0.9 tag"
List Repository
svn list -R file:///path/to/repos

Thursday, 7 March 2013

Why JMS over Database?

Why JMS over Database?
 
1)      If there is no need to store the messages permanently then do NOT use a database.

2)      The main difference is a JMS message queue is a high performance highly concurrent load balancer designed for huge throughput; you can send usually tens of thousands of messages per second too many concurrent consumers in many processes and threads.

3)      One could say that just enable row level locking and grab next row using database for this instead of using JMS (a new abstraction layer). The reason database overkill is that this gets stored on hardware, so in case of a power failure your messages will be there with tx guarantee. This is overkill for a simple pipe operation.

4)      If you are looking for Asynchronous communications, Reliability and Loose coupling:
a)      Asynchronous communications : An application need to notify another that an event has occurred with no need to wait for a response.
b)      Reliability: Ensure once-and-only-once message delivery. With your DB approach you have to "reinvent the wheel", specially if you have several clients reading the messages.
c)       Loose coupling: Not all systems can communicate using a database. So JMS is pretty good to be used in heterogeneous environments with decoupled systems that can communicate over system boundaries.

5)      The JMS implementation is "push", in the sense that you don't have to poll the queue to discover new messages, but you register a callback that gets called as soon as a new message arrives.

6)      You don't need to write the code yourself (and possibly screw up the logic so that it's not quite as persistent as you think it is). also, third-party impl might be more scalable than simple database approach.

7)      You are not tied to a specific implementation, and can swap it out if your needs change in the future, w/out messing w/ your java code.

8)      The consumer of the message can be in a remote location. Exposing database for remote access is dangerous. You can workaround this by providing additional service for reading messages from database, that requires more effort.

9)      In general implementation via JMS will be simpler and take less effort than database route.