Thursday, July 30, 2015

Getting Started with Boto and AWS

In this article, I’ll demonstrate the simplest way to managed AWS using Boto – a Python SDK for AWS. It is very necessary to have some kind of scripting in order to manage infrastructure on AWS. Boto is the best SDK for Systems Administrators. You can use packages and libraries of Python to take additional advantages. Boto supports most of the frequently used AWS services.
First thing you need to do is to configure Boto Config file for AWS Access keys and Secret keys, otherwise you’ll have to provide these keys every time you try to connect with AWS.
If you are using Linux, then you can configure Boto Config file at any of the below locations.
1. At /etc/boto.cfg – For site-wide or system wide settings
2. At ~/.boto ( ~ means home directory) – For user-specific settings
In Windows OS, you can place boto.config file user home directory of your Windows account.
A sample Boto config file looks like this:
[Boto]
ec2_region_name = us-east-1
ec2_region_endpoint = ec2.us-east-1.amazonaws.com
[Credentials]
aws_access_key_id=YOUR AWS ACCESS KEY
aws_secret_access_key=YOUR AWS SECRET ACCESS KEY
Now we can start working with Boto and get connected with AWS
1. Establishing a connection with AWS (Multiple ways to do it)
It can be done in more than one way. There is no impact of using one or the other method. Only thing to consider is what you are importing in Python. If you import complete Boto module, it means it needs more resources since every component Boto supports will be imported in Python. The other way is to import only specific module, e.g. only EC2 module if you are working with only EC2 instances.
a. Import Boto in Python (Importing all modules)
>>> import boto
>>> boto.Version
‘2.38.0’
b. Connect with AWS default region (us-east-1)
>>> ec2_conn=boto.connect_ec2()
>>> print ec2_conn
EC2Connection:ec2.us-east-1.amazonaws.com
c. Importing only EC2 module in Boto (Specific module only)
>>> from boto.ec2 import EC2Connection
>>> conn=EC2Connection()
>>> print conn
EC2Connection:ec2.us-east-1.amazonaws.com
As you can see, there is no change in the end result using both ways. However, it is preferred to import only specific module if you are going to work only on one particular AWS service.
2. List all servers in your account.
Now we’ll talk about listing all the servers configured in your account along with state. By default, there is no direct way to get list of all the servers. Although there is a function called ‘get_all_instances’ but it does not provide information about all the configured instances. Instead it provides reservation ids of all servers which can further help in getting instances ids and health state.
Let’s see how it works.
a. Get reservation ids of all servers.
>>> res=conn.get_all_instances()
>>> print res
[Reservation:r-0ad52ce3]
Since I have only one server running, it returned only one reservation id.
b. Get instance ID and instance state manually. Just to understand how it works.
>>> res[0].instances[0].id
u’i-98d45571′
>>> res[0].instances[0].state
u’running’
c. As you can see, returned reservation output is an array in itself, which further contains sub-array that contains information of instances.
d. Let’s automate it so that instance information can be obtained for all the instances.
>>> for r in res:
for i in r.instances:
print r.id, i.id, i.state
r-0ad52ce3 i-98d45571 running
The last line is the output which provides information on reservation ID, instance ID and instance state. If you have multiple instances configured, then all the instances will be listed in the output.

Monday, May 19, 2014

Manage SOA Composites with WLST


Here are some useful WLST commands for managing SOA composites.

Use the scripts located at:
(UNIX) MIDDLEWARE_HOME/ORACLE_SOA1/common/bin/wlst.sh

Retiring a Composite
wls:/soa_domain/serverConfig> sca_retireComposite(“nysolutionsltd.com”,”8400″,”weblogic”,”weblogicpassword”,”CompositeName”,”1.01″,partition=”SOA_Partition”)

host = localhost
port = 8400
user = weblogic
partition = SOA_Partition
compositeName = CompositeName
revision = 0.01
label = None
compositeDN =SOA_Partition/CompositeName!0.01
Connecting to: service:jmx:t3://localhost:8400/jndi/weblogic.management.mbeanservers.runtime
Composite (SOA_Partition/CompositeName!0.01) is successfully retired.

Stop/Shutdown a composite

wls:/soa_domain/serverConfig> sca_stopComposite(“localhost”,”8400″,”weblogic”,”mypassword”,”MYCompositeName”,”0.01″,partition=”SOA_Partition”)

host = localhost
port = 8400
user = weblogic
partition = SOA_Partition
compositeName = MYCompositeName
revision = 0.01
label = None
compositeDN =SOA_Partition/MYCompositeName!0.01

Connecting to: service:jmx:t3://localhost:8400/jndi/weblogic.management.mbeanservers.runtime
Composite (SOA_Partition/MYCompositeName!0.01) is successfully stopped.
wls:/soa_domain/serverConfig>

Starting a composite

wls:/soa_domain/serverConfig> sca_startComposite(“localhost”,”8400″,”weblogic”,”mypassword”,”MYCompositeName”,”0.01″,partition=”SOA_Partition”)

host = localhost
port = 8400
user = weblogic
partition = SOA_Partition
compositeName = MYCompositeName
revision = 0.01
label = None
compositeDN =SOA_Partition/MYCompositeName!0.01

Connecting to: service:jmx:t3://localhost:8400/jndi/weblogic.management.mbeanservers.runtime
Composite (SOA_Partition/MYCompositeName!0.01) is successfully started..

Activating a Composite

wls:/soa_domain/serverConfig> sca_activateComposite(“localhost”,”8400″,”weblogic”,”mypassword”,”MYCompositeName”,”0.01″,partition=”SOA_Partition”)

host = localhost
port = 8400
user = weblogic
partition = SOA_Partition
compositeName = MYCompositeName
revision = 0.01
label = None
compositeDN =SOA_Partition/MYCompositeName!0.01

Connecting to: service:jmx:t3://localhost:8400/jndi/weblogic.management.mbeanservers.runtime
Composite (SOA_Partition/MYCompositeName!0.01) is successfully activated.

List all Composites

wls:/soa_domain/serverConfig> sca_listDeployedComposites(‘localhost’,’8400′,’weblogic’,'mypassword’)

host = localhost
port = 8400
user = weblogic

Connecting to: service:jmx:t3://localhost:8400/jndi/weblogic.management.mbeanservers.runtime

Following 2 composites are currently deployed to the platform:

1. MYCompositeNameABCS[1.04], partition=SOA_Partition, mode=retired, state=off, isDefault=false, deployedTime=2014-04-25T15:51:19.116+01:00

2. MYCompositeNameABCS[1.05], partition=SOA_Partition, mode=active, state=on, isDefault=true, deployedTime=2014-04-21T09:51:34.818+01:00

Fusion SOA BEA-110486 Transaction xxxx cannot complete commit processing because resource is unavailable (Doc ID 1385959.1)

Issue - BEA-110486 Transaction xxxx cannot complete commit processing because resource is unavailable (Doc ID 1385959.1)

Solution - 
 To make the warnings disappear in the Server logs, implement below steps. Below is the workaround to make the warnings disappear:
  •  Stop your server.
  •  Go to [your domain]\servers\AdminServer\data\store\default.
  •  Delete * _WLS_ADMINSERVER_[random number].DAT. Make sure to take a backup of the DAT file before deleting it.
  •  Restart server.