1

The problem is that if the application is "stopped" this will return nothing. But i still want to uninstall it anyway. I don't know the application name, i'm getting all applications installed on a Server and then uninstalling them all.

apps = AdminControl.queryNames('type=Application,node=' + nodeName + ',process=' + serverName + ',*').split()

Here is my code.

serverObj = AdminControl.completeObjectName('type=Server,node=%s,name=%s,*' % (nodeName, serverName))
serverID = AdminConfig.getid('/Node:%s/Server:%s/' % (nodeName, serverName))

if serverID == "": 
    print "Can't find the server, exiting..."
    sys.exit(1)
else:
    cellName = AdminControl.getAttribute(serverObj, 'cellName')

#Uninstall Apps
apps = AdminControl.queryNames('type=Application,node=' + nodeName + ',process=' + serverName + ',*').split()
appManager=AdminControl.queryNames('type=ApplicationManager,node=' + nodeName + ',process=,*')
if len(apps) > 0:
    for app in apps:
        appName = AdminControl.getAttribute(app, 'name')
        AdminControl.invoke(appManager,'stopApplication', appName)
        print "Uninstalling application: " + appName
        AdminApp.uninstall(appName)
else:
    print "No applications to uninstall"
leSourCil
  • 13
  • 2
  • When you said "this will return nothing." What is "this". The code snippet where you get the list of apps? The mbean invocation to uninstall it? – F Rowe Mar 07 '19 at 22:48
  • i mean, if I run AdminControl.queryNames('type=Application,node=' + nodeName + ',process=' + serverName + ',*').split(), apps will = "" – leSourCil Mar 11 '19 at 15:21

2 Answers2

1

You can use the below snippet to uninstall all Apps deployed on the target server:

#Get the list of all Apps deployed in target server
installedApps=AdminApp.list("WebSphere:cell=%s,node=%s,server=%s" % (cellName, nodeName, serverName))

#Check if there are any installed Apps on the server
if len (installedApps) > 0:
    #if there are installed Apps, iterate through the list and uninstall Apps one by one
    for app in installedApps.splitlines():
        print "uninstalling "+ app +" ...."
        AdminApp.uninstall(app)
    #Save the changes
    AdminConfig.save()
else:
    #if there are no installed Apps, do nothing
    print "No applications to uninstall"

M I P
  • 867
  • 10
  • 25
0

You can use AdminApp.list() to obtain the list of apps for a target scope. So for server scope:

AdminApp.list("WebSphere:cell=yourCellName,node=yourNodeName,servers=yourServerName”)

With that information, you can then use AdminApp.uninstall() to uninstall the app, for example:

AdminApp.uninstall('NameOfApp')
Dan Belina
  • 11
  • 1