Search This Blog

Sunday, August 19, 2018

Configuration of GEOCODE Datasource for Oracle MapViewer

Couple of years back in the same blog I've posted how we can configure a generic datasource in WebLogic domain using WLST. Working in today's trend continuous deployment(CD) automation development I've worked on similar task that is GEOCODE datasource configuration. GEOCODE datasource is the basic configuration requirement for running Oracle MapViewer.

In Oracle Utilities Mobile Workforce Management runs on WebLogic server.

Pre-requisites
Oracle native WebLogic domain configured and the Admin Server must be up and running because our automation will be going to work online WLST.

How does it works?

In the Oracle Utilities products have a file ENVIRON.INI, that will having all connection related parameters available such as: ADMIN HOST, ADMIN PORT, UserStoreConfig files userConfigFile
userKeyFile path. By reading this file as properties we can get connected to the  running WebLogic Admin Server.

We will need the GEOCODE data source parameters, this can be passed as properties file ConfigGEOCODE.properties. To create a data source we need the following :
  1. Name of the datasoruce as GEOCODE
  2. JNDI Name as NAVTEQ_UTIL
  3. Select the database as Oracle
Connection pool configuration in the JDBC System Resource
  1. Enter your database hostname
  2. Database port
  3. Database name
  4. Database user credentials
  5. Test Connection Pool
###################****##############****################################################
# Generic Datasource configuration script applicable on any Operating Environments (Unix, Windows)
# ScriptName    : ConfigGEOCODE.py
# Properties    : ConfigGEOCODE.properties
# Updated by    : Pavan Devarakonda
# Date creation : 9th Aug 2018
###############     Connecting to Start     ################################################
def connectAdmin() :
 try:
  import os
  splebase=os.environ['SPLEBASE']
  loadProperties(splebase+"/etc/ENVIRON.INI")
  userconfig = splebase+"/etc/.wlsuserconfig"
  userkey = splebase+"/etc/.wlsuserkey"
  adminurl="t3s://"+WEB_ADMIN_SERVER+":"+WLS_ADMIN_PORT
  printline('Connectiong to adminurl: '+adminurl)
  connect(userConfigFile=userconfig,userKeyFile=userkey, url=adminurl)
  printline('Successfully connected')
 except:
  printline('Unable to find admin server...')
  exit()

#================== Printing line =====================================
def printline(msg):
        print 45*'#'
        print msg
        print 45*'#'

################### Configuring Connection Pool #############################
def connPool(DSnam) :
 DRVPARM='/JDBCSystemResources/'+DSnam+'/JDBCResource/'+DSnam+'/JDBCDriverParams/'+DSnam
 cd(DRVPARM)
 set('Url',DBURL)
 set('DriverName',DBDRV)
 cmo.setPassword('XXXXXX')

 cd(DRVPARM+'/Properties/'+DSnam)
 cmo.createProperty('user')
 cd(DRVPARM+'/Properties/'+DSnam+'/Properties/user')
 set('Value',DBUSR)

############         Creating Data source    ###############################
def createDS() :
 DSnam = DSName
 printline('Creating datasource :'+DSnam)
 cmo.createJDBCSystemResource(DSnam)
 RESOURCE='/JDBCSystemResources/'+DSnam+'/JDBCResource/'+DSnam
 cd(RESOURCE)
 set('Name',DSnam)
 #Setting JNDI name
 cd(RESOURCE+'/JDBCDataSourceParams/'+DSnam)
 print RESOURCE+'/JDBCDataSourceParams/'+DSnam
 set('JNDINames',jarray.array([String(JNDIname)], String))

 connPool(DSnam)

 #Set Connection Pool specific parameters
 cd(RESOURCE+'/JDBCConnectionPoolParams/'+DSnam)
 cmo.setTestConnectionsOnReserve(true)
 cmo.setTestTableName('SQL SELECT 1 FROM DUAL\r\n\r\n')
 #cmo.setTestTableName('SQL ISVALID')
 cmo.setConnectionReserveTimeoutSeconds(25)
 cmo.setMaxCapacity(15)
 cmo.setConnectionReserveTimeoutSeconds(10)
 cmo.setTestFrequencySeconds(120)

 cd(RESOURCE+'/JDBCDataSourceParams/'+DSnam)
 cmo.setGlobalTransactionsProtocol('TwoPhaseCommit')

 # targets the GEOCODE DataSource to utilities_cluster1
 cd('/SystemResources/'+DSnam)
 set('Targets',jarray.array([ObjectName('com.bea:Name='+clstrNam+',Type=Cluster')], ObjectName))

###########################  Main Module   #####################################
if __name__== "main":
 connectAdmin()
 edit()
 startEdit()
 # Create a new JDBC resource)
 try:
  cd('/')
  createDS()

 except BeanAlreadyExistsException:
  printline('Error: GEOCODE Datasource already exist')
  cancelEdit('y'); exit()
 save()
 activate()
 printline('Successfully created GEOCODE datasource')
 disconnect()

The properties file look like this:
#=========================================
DBURL=jdbc:oracle:thin:@mydb.server.com:1521:M1DBMAPS
DBDRV=oracle.jdbc.xa.client.OracleXADataSource
DBPASS=XXXXXXX
DBUSR=NAVTEQ_UTIL
DSName=GEOCODE
JNDIname=NAVTEQ_UTIL
clstrNam=utilities_cluster1
The script execution goes as follows:

Now prepare for execution of WLST script, setup the environment and also define proper SSL related options to include in JAVA_OPTIONS which will be considered when wlst.sh execution time.

wlst -loadProperties ConfigGEOCODE.properties ConfigGEOCODE.py

This script execution was tested successful and ready to use. You need to enter properties file corresponding to your database values.


Friday, July 13, 2018

Setting Keystore and SSL for a WebLogic Server using WLST

Configuring Custom SSL for WebLogic server                     

Working on the Oracle Utilities project, where our Environment requirement is that Mobile runtimes will communicates with secure servers. So we need to make the WebLogic server SSL Enabled with  Custom SSL certificates configuration.

WLST keystore SSL for Admin Server, Managed Server


Assumptions:

  • WebLogic 12.2.1.3 domain configured
  • Each WebLogic server SSL enabled already
  • AdminServer up and running


Here in this example I am using CA provided certificates but to publish in this post giving dummy paths and file names. The prerequisites you must have the Custom Identity and Custom Trust store


#!/usr/bin/python
# Author    : Pavan Devarakonda
# Save Script as  : set_keystoreSSL.py
# Initial drafted : 12/07/2018
#==========================================

import re

# Get location of the properties file.
execfile('/opt/MWM/scripts/set_keystore.properties')
def connectAdmin():
        # Connect to the AdminServer.
        try:
                connect(admin_username, admin_password, admin_url)
        except:
                print 'Unable to connect to AdminServer'
                exit()

def setKSnSSL4server(serverName, ksIdentityPath,ksIdentityPassword,ksTrustPath,ksTrustPassword,privateKeyAlias,keyPhrase):
        # Set keystore information.
        print "==============================="
        print "set keystore to "+serverName
        print "==============================="
        cd('/Servers/' + serverName)
        cmo.setKeyStores('CustomIdentityAndCustomTrust')

        cmo.setCustomIdentityKeyStoreFileName(ksIdentityPath)
        cmo.setCustomIdentityKeyStoreType('JKS')
        set('CustomIdentityKeyStorePassPhrase', ksIdentityPassword)
        cmo.setCustomTrustKeyStoreFileName(ksTrustPath)
        cmo.setCustomTrustKeyStoreType('JKS')
        set('CustomTrustKeyStorePassPhrase', ksTrustPassword)
        print "set SSL to "+serverName
        print "==============================="
        cd('/Servers/' + serverName + '/SSL/' + serverName)
        cmo.setServerPrivateKeyAlias(privateKeyAlias)
        set('ServerPrivateKeyPassPhrase', keyPhrase)

def main():
        connectAdmin()
        print servers
        edit()
        startEdit()
        print "========================================================================="
        print "AdminServer, utilities_server1 server set keystore, SSL custom keystore"
        print "========================================================================="
  setKSnSSL4server(adm['name'], adm['identity.path'], adm['identity.password'],adm['trust.path'],adm['trust.password'],adm['privateKeyAlias'],adm['keyPhrase'])
  setKSnSSL4server(ms1['name'], ms1['identity.path'], ms1['identity.password'],ms1['trust.path'],ms1['trust.password'],ms1['privateKeyAlias'],ms1['keyPhrase'])
        save()
        activate()
        disconnect()
        exit()

main()

This time the properties file is also python script to use the dictionary capabilities of Python to refer to the Weblogic server and its corresponding server'S keystore, SSL details to store together.


# AdminServer connection details.
admin_username='system'
admin_password='welcome1'
admin_url='t3://test.server.com:7001'

#Dictionaries for AdminServer, utilities_server1 keystore, SSL values

adm = { 'name':'AdminServer','identity.path':'/opt/myalias_cert/myIdentity.jks', 'identity.password':'welcome1', \
'trust.path':'/opt/myalias_cert/myTrustStore.jks', 'trust.password':'welcome1', \
'keyPhrase':'welcome1', 'privateKeyAlias':'myalias'}

ms1 = { 'name':'utilities_server1','identity.path':'/opt/myalias_cert/myIdentity.jks', 'identity.password':'welcome1', \
'trust.path':'/opt/myalias_cert/myTrustStore.jks', 'trust.password':'welcome1', \
'keyPhrase':'welcome1', 'privateKeyAlias':'myalias'}




 The execution or the above script output looks as below: You can execute.

Saturday, February 3, 2018

Remotely domain extension using WLST

WebLogic latest version 12.2.x come up with different WebLogic domain templates and their usage methods in WLST. Usually WebLogic domain can be created with base domain template using wls.jar. Then after that domain need to be customized as the projects where we need the extended domain.

  1. When the domain spread across multiple machines/nodes
  2. One successful configuration domain reuse to create new domains
Here is small experiment with the domain template, here we have two nodes associated with  192.168.33.100 - Machine100 and 192.168.33101 - Machine101 IP addresses and machine. The admin server configured in the Machine100 and also two web servers in webcluster, two app servers in appcluster. The whole configuration we need in Machine101.

Earlier to WebLogic 12.2 version we have pack and unpack option only for the domain expansion in the remote machine otherwise copy the domain folder need to copy. 

In the latest versions of WebLogic 12.2.x above are having different WLST methods that relates to template usage.
Remotely extension of WebLogic Domain using WLST and pack-unpack
Lets explore options available in WLST

selectTemplate() in WLST

There are multiple domain templates, extension templates for domains are available in Oracle WebLogic installation media pack it self. Some of the application specific templates also available with the media pack.

selectCustomTemplate() in WLST

We can create our own WebLogic domain template using writeTemplate() that will be containing the project specific configurations such as - servers, cluster, JDBC, JMS are pre-configured and reusable. The select custom template method followed by loadTemplate command.

loadTemplates() in WLST

The loadTemplates(0 is the command always used after selectTemplate or selectCustomTemplate commands.

Automation solution: Create domain template and configure domain


Like here we need to create extension domain in the Machine101, you may need to to do for multiple machines in production environments.

The process is simplified into few steps
  1. connect to the existing domain
  2. Read the domain and generate the custom domain template
  3. Create the extended domain enter the same domain name and path or fresh domain can be configured with the new domain name, listen address modification as required

#======================================
# 
# File: remoteDomain.py
# Applicable WebLogic version: 12.2.x
# This will solve pack and unpack strange issues
#
#===============================================
def printline(s):
    print "-"*10 + s
 
def createDomainTemplate(templateLocation):
    
    ''' Generate the custom domain template  '''
    connect(admuser,admpass,admurl)
    
    print ("Writing Custom Template...")
    writeTemplate(templateLocation)
    print ("Writing Template...: Completed")
    disconnect()
    
def create_Domain(templateLocation, domainPath):
 ''' Creating extended domain remotely 
 selectCustomTemplate, loadTemplates will get the inputs
 then writeDomain will create the domain '''
 
 selectCustomTemplate(templateLocation)
 loadTemplates()
 print ("Creating extended domain...")
 writeDomain (domainPath)
 closeTemplate()
 print ("Creating domain...: Completed")
       
       
def main():
 '''
 Change the following values according to your domain
 user security better to use storeuserconfig
 and domain template 
 you can move these variables into properties file
 '''
 templateLocation ='/u01/app/oracle/prod_domain_template.jar'
 domainPath='/u01/app/oracle/prod_domain'
 admuser='weblogic'
 admpass='welcome1'
 admurl='192.168.33.100:8001'
 
 createDomainTemplate(templateLocation)
 create_Domain(templateLocation, domainPath)
    
if __name__ == "__main__":
    printline()
    print("SCRIPT BEING RUN DIRECTLY")
    printline()
    main()
 printline()

Remotely execution of script

WLST SCRIPT

Popular Posts