Scripting Websphere 6.1 configurations, Part 2

Finding your server parameters

One of the problems with scripting your configuration is usually the scripts you use to define your development Websphere environment cannot be used in your QA or production servers. Usually you will have a standalone Websphere instance on your local machine and your QA environment will host other application or might be in a cluster. Your production environment is usually in a cluster. The problem arises when you create configuration parameters you have to pass in server/node/cell parameters. Those will be different for each environment. Take that in to consideration when creating your scripts.

The anemic example scripts you can find on IBM’s site have you passing in the parameters when you run the script (I bet if you hired an IBM consultant at $500 an hour, they just *might* be able to write better scripts for you) but that is not a best practice. Here are some examples finding those parameters automatically.

    # Gets the Cell ID
    def getCellId(self):
        return self.findConfigId(“Cell”, self.cellName, “Cell”);
               
    # Gets the Node ID
    def getNodeId(self):
        return self.findConfigId(“Node”, self.nodeName, “Node”);

    # Gets the Server ID
    def getServerId(self):
        return self.findConfigId(“Server”, self.serverName);

    #return 1 configId that matches the given criteria: see findConfigIdAll.
    #Throws an error if more than 1 exist.
    def findConfigId(self, configType, idPartsOrExactName=[], scope=WASConfigType.SERVER):
        ids = self.findConfigIdAll(configType, idPartsOrExactName, scope);   
       
        if len(ids) > 1:
            raise AssertionError, “Too many [” + str(len(ids)) + “] configuration items of [” + str(idPartsOrExactName) + “]”;
        elif len(ids) == 1:
            return ids[0];       
        else:
            return None;

    #finds all config ids of given WASConfigType configType with
    #     the given idParts as substrings (as a list of 0 or more elements) e.g [‘sony’].
    #     or an exactName (as a string) – overloaded on same parameter e.g. ‘sony’.   
    #Uses AdminConfig.list(type) and finds the id that matches the criteria.               
    def findConfigIdAll(self, configType, idPartsOrExactName=[], scope=”Server”):
        cellScopeIdPart = “cells/” + self.cellName;
        nodeScopeIdPart = “nodes/” + self.nodeName;
        serverScopeIdPart = “servers/” + self.serverName;
           
        #determine if a list of idParts substrings or an exactName.
        if type(idPartsOrExactName) == type([]):
            idParts = idPartsOrExactName;
            exactName = None;
        elif type(idPartsOrExactName) == type(“”):
            exactName = idPartsOrExactName;
            idParts = [exactName];                   
        else:
            raise AssertionError, “Invalid idPartsOrExactName object given type=[” + str(type(idPartsOrExactName)) + “]”;
               
        excludeIdParts = [];
        includeIdParts = idParts;       
           
        includeIdParts.append(cellScopeIdPart); #always include cell scope.
        if scope == “Server”;
            includeIdParts.append(nodeScopeIdPart);
            includeIdParts.append(serverScopeIdPart);
        elif scope == “Node”;
            includeIdParts.append(nodeScopeIdPart);
            excludeIdParts.append(serverScopeIdPart);
        elif scope == “Cell”
            excludeIdParts.append(nodeScopeIdPart);
            excludeIdParts.append(serverScopeIdPart);
        else:
            raise AssertionError, “Invalid config scope specified [” + scope + “]”;           

        # You will have to create this ListAsString helper method
        ids = ListAsString(AdminConfig.list(configType)).asList();       
               
        # You will have to create the below helper methods
        for includeIdPart in includeIdParts:
            ids = findStringItems(ids, includeIdPart);
        for excludeIdPart in excludeIdParts:
            ids = findStringItemsExclude(ids, excludeIdPart);
       
        #if exactName given then do a regexp match to ‘exactName(…)”.
        if exactName != None:   
            exactIds = [];
            for configId in ids:
                if self.getConfigName(configId) == exactName:
                    exactIds.append(configId);
                #alternative way by using regexp.
                #pattern = exactName+”\(.*\)”;
                #if re.match(pattern, configId) or re.match(‘”‘+pattern+'”‘, configId):
                #    exactIds.append(configId);                   
            ids = exactIds;
                               
        return ids;
       

These Jython methods for scripting Websphere were written by a teammate of mine, Sony Mathew.

5 thoughts on “Scripting Websphere 6.1 configurations, Part 2

  1. I am working through this. So i’m going to help by providing some implementations that are missing from this.

    Here’s one
    # You will have to create this ListAsString helper method
    idString = AdminConfig.list(configType)
    ids = idString.splitlines()

    At least I was getting them back as \r\n delimited list so the splitlines worked.

  2. Is there any chance you can describe what findStringItems and fidnStringItemsExclude, as well as what self.getConfigName does?

    I’m guessing findStringItems/Exclude simply throw out those items that we don’t care about (i.e. if i our scope doesn’t include the server, then we get rid of them. If it does include the server, we better include it. but the getConfigName is more elusive, though I have yet to look everywhere at your examples.

  3. Here are the implementations for those methods:

    #return an array list of items in the given list that matches the given stringItem as an exact string or substring.
    def findStringItems(listOfStrings, stringItem):
    items = [];
    for s in listOfStrings:
    if s.find(stringItem) >= 0:
    items.append(s);
    return items;

    #return an array list of items in the given list that excludes the given stringItem as an exact string or substring.
    def findStringItemsExclude(listOfStrings, stringItem):
    items = [];
    for s in listOfStrings:
    if s.find(stringItem) < 0:
    items.append(s);
    return items;

    I will be back in a min.

  4. Here is the wrapper that gets the config name:

    #Extracts the Config Name from the given configId returns None if unnamed or unobtainable.

    def getConfigName(self, configId):

    return AdminConfig.showAttribute(configId, “name”);

  5. I did code approx the same implementation for those first two but would not have guessed at the showAttribute for the last one.

    Thank you immensely for the time it must have taken you to write up these descriptions and code samples, they are a great way to approach this. I am glad your GFI saved you that you might be here to write this. If I’m ever out in MN I’ll buy you a beer (or non alcoholic beverage of your choice).

Comments are closed.