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
  • 1.  WSADMIN-Script for enable autostartup in websphere

    Posted Tue April 17, 2018 08:54 PM
    Team,

    Joined your Group.

    Now I have an new request from client,as below.
    In websphere,by clicking application, and then click on application ( war or ear) file,then go to target modules,there are 2 options, one is enable startup and disable startup.
    Enable star up:- if it is enabled,then when JVM will start by the time ear also up
    And
    Disable startup:- if it is enabled,then when JVM will start by the time ear will not start,we need to do it manually.
    For both the cases,we need to restart JVM post update.
    Now requirements is that,we need create a script either Python or shell script to update the startups by selecting option when required ,not from console.
    Step1:- option to select JVM
    Step2:- option to see status of JVM is up and running or not
    Step3:- option to select enable autostart , disable autostart up, status,...Here to select one and check the status.
    Step4:- final verification post doing auto startup enabled or disabled 
    Can you look and send me script.
    PMR raised,IBM said it can be automated.

    Thanks,
    'Satish'


  • 2.  RE: WSADMIN-Script for enable autostartup in websphere

    Posted Wed April 18, 2018 02:32 AM

    Hello Satish,

    from you description I'm not 100% sure what you want to change but I assume it is the attribute marked in the attaches screen copy.

    Regarding you scripting requirements you asked for you have two requirements namely

    1. Get the status about the application Servers
    2. Set the autostart for the applications

    Disclaimer: All code written here is for demonstration purposes only and was neither tested nor production ready! So usage is totally at your own risk!

    The prototype code for the first requirement should be something like that:

    cellName = AdminControl.getCell()
    queryString='WebSphere:type=Server,cell=' + cellName + ',*'
    serverMBeans = AdminControl.queryNames(queryString).split('\n')
    for serverMBean in serverMBeans:
      serverName = AdminControl.getAttribute(serverMBean, 'name')
      serverState = AdminControl.getAttribute(serverMBean, 'state')
      print "Server: %20s ; State: %10s" % (serverName, serverState)

    For the second requirement you need to use ApplicationDeployment objects. Here I found a problem you might check with support. The problems is the following:

    print AdminConfig.attributes('ApplicationDeployment')

    Contains a name attribute .. however when retrieving the objects this attribute is always None. So you need to find another way to identify. But assuming the name is returned correctly the prototype should be similar to:

    appDeployments = AdminConfig.list('ApplicationDeployment').split('\n')
    ## appDeployment = appDeployments[0]
    for appDeployment in appDeployments:
        ## print AdminConfig.showall(appDeployment)
        deploymentTargetMappings = AdminConfig.showAttribute(appDeployment, 'targetMappings').split('\n')
        ## deploymentTargetMappings = AdminConfig.list('DeploymentTargetMapping').split('\n')
        ## deploymentTargetMapping = deploymentTargetMappings[0]
        for deploymentTargetMapping in deploymentTargetMappings:
          singleDeploymentTargetMappings = deploymentTargetMapping[1:-1].split(" ")
          ## singleDeploymentTargetMapping = singleDeploymentTargetMappings[0]
          for singleDeploymentTargetMapping in singleDeploymentTargetMappings:
                deployedObject = AdminConfig.showAttribute(singleDeploymentTargetMapping, 'DeployedObject')
                appName = AdminConfig.showAttribute(appDeployment, 'name')
                binariesURL = AdminConfig.showAttribute(deployedObject, 'binariesURL')
                appIsEnabled = AdminConfig.showAttribute(singleDeploymentTargetMapping, 'enable')
                print "AppName: %20s; binariesURL: %s; appIsEnabled: %5s" % (appName, binariesURL, appIsEnabled)
                ##
                ## Enable the application if it is the selected application
                if (appName == appNameToModify):
                    AdminConfig.modify(deploymentTargetMapping, [['enable', 'true']])

    if (AdminConfig.hasChanges()):
        AdminConfig.save()
    else:
      print "No changes ... not saved!"


  • 3.  WSADMIN-Script for enable autostartup in websphere

    Posted Wed April 18, 2018 03:12 AM
    Hi Herman,

    Thanks for giving script,let me check and get back to you.

    Appreciate your quick response.

    Thanks,
    Satish

    On Wed, Apr 18, 2018, 15:02 Hermann Huebler <
    applicationserver-ws@lists.imwuc.org> wrote:

    > Hello Satish,
    >
    > from you description I'm not 100% sure what you want to change but I
    > assume it is the attribute marked in the attaches screen copy.
    >
    > Regarding you scripting requirements you asked for you have two
    > requirements namely
    >
    > 1. Get the status about the application Servers
    > 2. Set the autostart for the applications
    >
    > *Disclaimer: All code written here is for demonstration purposes only and
    > was neither tested nor production ready! So usage is totally at your own
    > risk!*
    >
    > The prototype code for the first requirement should be something like that:
    >
    > cellName = AdminControl.getCell()
    > queryString='WebSphere:type=Server,cell=' + cellName + ',*'
    > serverMBeans = AdminControl.queryNames(queryString).split('\n')
    > for serverMBean in serverMBeans:
    > serverName = AdminControl.getAttribute(serverMBean, 'name')
    > serverState = AdminControl.getAttribute(serverMBean, 'state')
    > print "Server: %20s ; State: %10s" % (serverName, serverState)
    >
    > For the second requirement you need to use ApplicationDeployment objects.
    > Here I found a problem you might check with support. The problems is the
    > following:
    >
    > print AdminConfig.attributes('ApplicationDeployment')
    >
    > Contains a *name* attribute .. however when retrieving the objects this
    > attribute is always None. So you need to find another way to identify. But
    > assuming the name is returned correctly the prototype should be similar to:
    >
    > appDeployments = AdminConfig.list('ApplicationDeployment').split('\n')
    > ## appDeployment = appDeployments[0]
    > for appDeployment in appDeployments:
    > ## print AdminConfig.showall(appDeployment)
    > deploymentTargetMappings = AdminConfig.showAttribute(appDeployment, 'targetMappings').split('\n')
    > ## deploymentTargetMappings = AdminConfig.list('DeploymentTargetMapping').split('\n')
    > ## deploymentTargetMapping = deploymentTargetMappings[0]
    > for deploymentTargetMapping in deploymentTargetMappings:
    > singleDeploymentTargetMappings = deploymentTargetMapping[1:-1].split(" ")
    > ## singleDeploymentTargetMapping = singleDeploymentTargetMappings[0]
    > for singleDeploymentTargetMapping in singleDeploymentTargetMappings:
    > deployedObject = AdminConfig.showAttribute(singleDeploymentTargetMapping, 'DeployedObject')
    > appName = AdminConfig.showAttribute(appDeployment, 'name')
    > binariesURL = AdminConfig.showAttribute(deployedObject, 'binariesURL')
    > appIsEnabled = AdminConfig.showAttribute(singleDeploymentTargetMapping, 'enable')
    > print "AppName: %20s; binariesURL: %s; appIsEnabled: %5s" % (appName, binariesURL, appIsEnabled)
    > ##
    > ## Enable the application if it is the selected application
    > if (appName == appNameToModify):
    > AdminConfig.modify(deploymentTargetMapping, [['enable', 'true']])
    >
    > if (AdminConfig.hasChanges()):
    > AdminConfig.save()
    > else:
    > print "No changes ... not saved!"
    >
    >
    > -----End Original Message-----
    >