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];       
            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];                   
            raise AssertionError, “Invalid idPartsOrExactName object given type=[” + str(type(idPartsOrExactName)) + “]”;
        excludeIdParts = [];
        includeIdParts = idParts;       
        includeIdParts.append(cellScopeIdPart); #always include cell scope.
        if scope == “Server”;
        elif scope == “Node”;
        elif scope == “Cell”
            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:
                #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

Comments are closed.