Example: Using a script package to retrieve details about a shared service
The example gets registry information about a deployed sample shared service.
Based on the registry information, the IP address is used to interact with the shared service.
Note: This example script
package works only on virtual systems that are deployed with WebSphere® Application Server.
cbscript.json
[
{
"name": "Sample Shared Service Interaction",
"version": "1.0.0",
"description": "This script package interacts with a deployed Sample Shared Service",
"command": "/opt/IBM/WebSphere/AppServer/bin/wsadmin.sh",
"log": "/opt/sp_sample/log.log",
"location": "/opt/sp_sample",
"timeout": "0",
"commandargs": "-lang jython -f /opt/sp_sample/sample_interaction.jy"
}
]sample_interaction.jy
import sys # needed to point Python towards the shared service client
import os
import re
ssc_path = '/0config/nodepkgs/helper/scripts'
if not ssc_path in sys.path:
sys.path.append(ssc_path)
import sharedserviceclient
def find_IP(reg_info):
"""
Finds the Sample Shared Service IP address in the registry information.
"""
str_info = str(reg_info)
pat = r"\d+\.\d+\.\d+\.\d+"
match = re.search(pat, reg)
if (match):
return match.group(0)
else:
return None
reg = sharedserviceclient.getRegistry("sample", "1.0")
if (reg == '{}'):
print "Sample Shared Service not found (may not be deployed)"
os.system('echo "Sample Shared Service not found (may not be deployed)" >> /opt/sp_sample/log.log')
sys.exit("Sample Shared Service not found (may not be deployed)")
# sample shared service is in place
sip = find_IP(reg)
if (sip is None):
print "Unable to find IP address in response"
os.system('echo "Unable to find IP address in response" >> /opt/sp_sample/log.log')
sys.exit("Unable to find IP address in response")
print "Found Sample Shared Service - IP address = '" + sip + "'"
os.system('echo "Found Sample Shared Service - IP address = \'"' + sip + '"\'" >> /opt/sp_sample/log.log')
response = sharedserviceclient.restapi("https://" + sip + ":9999/sharedservice/sample/test/foobar", "GET", "")
if (response.find('"result":"SUCCESS"') >= 0):
print "Successfully interacted with the Sample Shared Service"
os.system('echo "Successfully interacted with the Sample Shared Service" >> /opt/sp_sample/log.log')
else:
print "Failed to interact with the Sample Shared Service"
os.system('echo "Failed to interact with the Sample Shared Service" >> /opt/sp_sample/log.log')