WebSphere Application Server & Liberty

WebSphere Application Server & Liberty

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

WAS ND, change Data sources in resources.xml

  • 1.  WAS ND, change Data sources in resources.xml

    Posted Wed July 12, 2023 11:41 AM

    Hi everyone,

    I have a WAS ND environment that has more than a hundred Data Sources that connect to an Oracle database.

    Now the databases will be moved to a new server, so the Data sources' URL has to change.

    I thought of changing all Data source entries in the resources.xml.

    I just want to make sure that I only have to change the data sources in the resources.xml in the Dmgr profile at the Cell level.

    Then restart Dmgr, and all servers, or just restart Dmgr and Sync all nodes?

    I would like some input on this.

    BR

    Christos



    ------------------------------
    Christos Chorattides
    Datatech
    ------------------------------


  • 2.  RE: WAS ND, change Data sources in resources.xml

    Posted Thu July 13, 2023 12:36 AM

    Hello Christos,

    first of all and needless to say that 'hacking" the resources.xml is not supported. The supported way of doing such mass updates would be running a wsadmin script.

    If I'd like to try the hack that's how I'd do it:

    • Go to the WAS Admin Console and ensure that all nodes are in sync (run a full resync and check nodeagent logs in case of doubts)
    • Stop all servers except the nodeagents
    • Stop the Dmgr
    • Create a backup of the existing resources.xml (on all scopes as there could be multiple ones due to the different scope of the datasource resources). Or run a backup of the Dmgr profile directory
    • Hack the changes into resources.xml (make sure that you edit them on all scopes)
    • Start the Dmgr
    • Run a full resync for each node and verify that the changes are synced
    • Restart the nodeagents
    • Perform a DS connectivityt test for those with the scope above the server level
    • Start the servers
    • Test the applications to make sure they connect to the correct database

    Hope there are some interesting thoughts added.



    ------------------------------
    Hermann Huebler
    2innovate IT Consulting GmbH
    Vienna
    Austria

    #IBMChampion
    ------------------------------



  • 3.  RE: WAS ND, change Data sources in resources.xml

    Posted Thu July 13, 2023 03:00 AM

    Hi Hermann,

    thank you very much for your detailed answer.

    I thought that editing configuration .xlm files was ok, I believe this it what basically WAS Console does. Anyway.

    I understand the risk of messing the xml structure if you miss a character, but this is just a URL change which will happen as a find-and-replace in a proper text editor. Existing resouces.xml will be backed-up, so we minimize the risk.

    It is impossible to do these changes using the WAS Console, it will take ages, URL field is too short so you cannot view the entire URL and the biggest problem is that I can easily miss a data source from the list.

    I took a quick look at wsadmin but it can be a complicated task to get all Data sources, iterate through, find the URLs you want  to replace and then replace with the new value, and I frankly do not have the skills.

    In our case all Data sources are all created at the Cell level, no Data sources are defined in other scopes. So, I believe that editing resources.xml at the Cell level will be fine.

    I cannot thank you enough for sharing your expertise with me.

    BR

    Christos

     



    ------------------------------
    Christos Chorattides
    Datatech
    ------------------------------



  • 4.  RE: WAS ND, change Data sources in resources.xml

    Posted Thu July 13, 2023 02:44 AM

    Hi Christos

      My suggestion is to make tha change using properties file base management.
      
      https://www.ibm.com/docs/en/was-nd/8.5.5?topic=wsadmin-using-properties-files-manage-system-configuration
      
      1. Extract all datasources information to file.
      2. Replace URL
      3. Apply changes.
      4. Synchronice the cell
      
      Hope this helps. Tell us if you need more support.
      
    Regards



    ------------------------------
    Gabriel Aberasturi
    Versia Sistemas TI
    ------------------------------



  • 5.  RE: WAS ND, change Data sources in resources.xml

    Posted Thu July 13, 2023 03:16 AM

    Hi Gabriel,

    thank you for your input.

    This is a wsadmin approach and as it is fully supported, I am tempted to try it.

    I need some clarifications as I am not very experienced with WebSphere.

    1. When starting wasadmin, how do I make sure, that it will connect to Dmgr and not a server?
    2. Is there an option to extract Datasources only, or do I get the entire configuration?
    3. "Apply changes" means using applyConfigProperties?

    BR



    ------------------------------
    Christos Chorattides
    Datatech
    ------------------------------



  • 6.  RE: WAS ND, change Data sources in resources.xml

    Posted Thu July 13, 2023 03:22 AM

    Christos,

    Open a command prompt or terminal and navigate to the <WAS_HOME>/bin directory. Replace <WAS_HOME> with the actual installation directory of your WebSphere Application Server.

    Start the wsadmin tool by running the following command:

    On Windows:


    wsadmin.bat -lang jython

    On Unix/Linux:


    ./wsadmin.sh -lang jython

    Once the wsadmin prompt appears, execute the following commands to connect to the WebSphere Application Server profile:


    # Connect to the WebSphere Application Server profile
    host = '<hostname>'
    port = '<admin_console_port>'
    username = '<username>'
    password = '<password>'
    connectionType = '<SOAP|SOAP_SSL|SSL|NONE>'
    securityEnabled = '<true|false>'

    AdminTask.createAdminTask()
    AdminTask.validate()
    AdminTask.getDatabaseConfiguration(['-type', 'JDBCProvider', '-scope', 'Node=<node_name>,Server=<server_name>'])


    Replace the placeholders within angle brackets (< >) with the appropriate values specific to your environment:

    <hostname>: The hostname or IP address of the WebSphere Application Server.
    <admin_console_port>: The port number of the WebSphere Application Server administrative console.
    <username>: The username of an administrative user.
    <password>: The password of the administrative user.
    <SOAP|SOAP_SSL|SSL|NONE>: The connection type for the administrative connection.
    <true|false>: Indicates whether security is enabled or not.
    <node_name> and <server_name> in the -scope parameter specify the target node and server where the JDBC provider is configured. Replace them with the appropriate values for your environment.

    To save the output to a file, you can redirect the output of the AdminTask.getDatabaseConfiguration command to a file. For example:


    AdminTask.getDatabaseConfiguration(['-type', 'JDBCProvider', '-scope', 'Cell=<cell_name>']) > 'datasource_config.txt'

    Replace 'datasource_config.txt' with the desired file path and name.

    Open the extracted properties file in a text editor and make the necessary changes to the datasource configuration.

    Save the modified properties file.



    AdminTask.applyConfigProperties('[-propertiesFileName "<file_path>"]')

    Replace <file_path> with the path to the modified properties file.

    Save the changes and synchronize the nodes by executing the following commands:


    AdminConfig.save()
    AdminNodeManagement.syncActiveNodes()

    This command saves the configuration changes and synchronizes the changes across the active nodes in the cell.

    Finally, execute the command to disconnect from the WebSphere Application Server:


    AdminConfig.reset()
    AdminTask.clearTaskLists()

    This command resets the configuration and clears the administrative task lists.

    Hope this helps.

    Regards.



    ------------------------------
    Gabriel Aberasturi
    Versia Sistemas TI
    ------------------------------



  • 7.  RE: WAS ND, change Data sources in resources.xml

    Posted Thu July 13, 2023 03:49 AM

    Hi Gabriel,

    I was expecting a higher level reply. :) 

    But, a detailed one is most welcome!

    Thank you for spending so much time to provide such comprehensive guide!

    I will try it on a test server asap.

    Thank you so much!

    BR



    ------------------------------
    Christos Chorattides
    Datatech
    ------------------------------



  • 8.  RE: WAS ND, change Data sources in resources.xml

    Posted Thu July 13, 2023 06:06 AM
    Edited by Hermann Huebler Thu July 13, 2023 08:45 AM

    Hello Christos,

    as you are obviously trying to use properties export / import (which makes perfectly sense) maybe the follwing function helps (using that on one of my scripts):

    def rtvWmInfo(wcvObjType, wcvObjNamesList, wcvOutDir, wcvCompareAttribute="name"):
    	wmInfoList=AdminConfig.list(wcvObjType)
    	wmInfoList = wmInfoList.replace("\r\n", "\n").split("\n")
    	for wmInfo in wmInfoList:
    		if (wmInfo != ''):
    			wmName = AdminConfig.showAttribute(wmInfo, wcvCompareAttribute)
    			if ((wmName in wcvObjNamesList) or ((len(wcvObjNamesList) == 1) and (wcvObjNamesList[0] == "*"))):
    				print "Exporting %s object  %s" % (wcvObjType, wmName)
    				fileName = os.path.join(wcvOutDir, wcvObjType + "_" + wmName + ".props")
    				AdminTask.extractConfigProperties(wmInfo, ['-propertiesFileName', fileName, "-options", [["PortablePropertiesFile", "true"]]])
    

    You should be able to call that like: `rtvWmInfo("DataSource", "*", "/tmp")`. This should create .props files in /tmp with the exported DataSources which you can modify and then import again. 



    ------------------------------
    Hermann Huebler
    2innovate IT Consulting GmbH
    Vienna
    Austria

    #IBMChampion
    ------------------------------



  • 9.  RE: WAS ND, change Data sources in resources.xml

    Posted Thu July 13, 2023 02:10 PM

    Hi Hermann,

    thank you for the script. This approach requires more knowledge on WAS scripting, (which I don't have).

    I created a script file and named it rtvWmInfo. I then tried to run it at wsadmin prompt but I got error at the last parameter.

    I hope that the backticks don't mean that I have to run it at Unix prompt.

    BR



    ------------------------------
    Christos Chorattides
    Datatech
    ------------------------------



  • 10.  RE: WAS ND, change Data sources in resources.xml

    Posted Thu July 13, 2023 02:16 PM

    Hello Christos,

    Nope .. the back-ticks should just indicate that this is a command you have to run in the wsadmin script which calls the function to export the DataSource properties.



    ------------------------------
    Hermann Huebler
    2innovate IT Consulting GmbH
    Vienna
    Austria

    #IBMChampion
    ------------------------------



  • 11.  RE: WAS ND, change Data sources in resources.xml

    Posted Thu July 13, 2023 05:53 AM
    Edited by Christos Chorattides Thu July 13, 2023 05:54 AM

    Hi Gabriel,

    sorry to bother you again, but I get an error at the very beginning of the process, which is a bit strange.

    I don't know if there is a syntax error somewhere, a typo, or we are missing a command that must be previously executed.

    When issuing the createAdminTask(), I get this error.

    wsadmin>AdminTask.createAdminTask()
    WASX7015E: Exception running command: "AdminTask.createAdminTask()"; exception information:
    com.ibm.bsf.BSFException: exception from Jython:
    Traceback (most recent call last):
      File "<input>", line 1, in <module>


    AttributeError: 'com.ibm.ws.scripting.adminCommand.AdminTask' object has no attribute 'createAdminTask'

    BR


    ------------------------------
    Christos Chorattides
    Datatech
    ------------------------------



  • 12.  RE: WAS ND, change Data sources in resources.xml

    Posted Thu July 13, 2023 09:59 AM

    Christos,

    What version of WAS ND do you have?

    try writing an space between wasadmin> AdminTask.CreateAdminTask()

    Regards



    ------------------------------
    Gabriel Aberasturi
    Versia Sistemas TI
    ------------------------------



  • 13.  RE: WAS ND, change Data sources in resources.xml

    Posted Thu July 13, 2023 01:12 PM

    Hi Gabriel,

    I tried the  AdminTask.CreateAdminTask() on a ND 8.5.5 on AIX and on a 9.0.x on Windows. Got the same error.

    When placing a space, I got a syntax error at space.

    I think I will go ahead and "hack" the resources.xml.

    Thank you for your time.

    BR



    ------------------------------
    Christos Chorattides
    Datatech
    ------------------------------



  • 14.  RE: WAS ND, change Data sources in resources.xml

    Posted Thu July 13, 2023 04:09 AM

    Usually the recommendation is to do the changes using wsadmin script or admin console, not editing the files, but I believe that if you change the resources.xml, it will work. Yes, it is only there, you just need to check the scope to find out which resources.xml file to change (node or server level). After that try to sync and go to one of the nodes node agent log and see if it has changed the file. After changing a datasource you need to restart the servers. 

    You can also use the syncNode.sh in each node.



    ------------------------------
    JOAO PEDRO ALEXANDRE
    ------------------------------



  • 15.  RE: WAS ND, change Data sources in resources.xml

    Posted Thu July 13, 2023 01:59 PM

    Thank you Joao Pedro!



    ------------------------------
    Christos Chorattides
    Datatech
    ------------------------------