Changeset 36869


Ignore:
Timestamp:
2022-11-01T16:40:14+13:00 (4 weeks ago)
Author:
anupama
Message:

Finished up Kathy's bugfix to central method MessageRouter.processMessage() upon activating and deactivating: existing code always removed a specified module upon deactivation, without checking the moduletype matched the instance of the module in the moduleMap that we're removing. But we don't want to allow action=system, subaction=deactivate, moduletype=service (should be collection) and modulename=demo (collection-name). The demo collection should not be removed as it's not a service. It's a meaningless command. Further, the code is ready to cast the module to Collection which used to result in a type cast error. This commit tidies that part up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java

    r36638 r36869  
    12901290                    String module_type = elem.getAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT);
    12911291
     1292                    if (!moduleTypeMatchesModuleInstance(module_name, module_type)) {
     1293                        logger.error(module_name + "is not a module of type " + module_type + ", not (de)activating it");
     1294                        success = false;
     1295
     1296                        Element s = null;
     1297                       
     1298                        if (action.equals(GSXML.SYSTEM_TYPE_DEACTIVATE)) {
     1299                        s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " could not be deactivated (module type and instance mismatch)", GSXML.SYSTEM_TYPE_DEACTIVATE, GSXML.ERROR);
     1300                        } else {
     1301                        s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " could not be activated (module type and instance mismatch)", GSXML.SYSTEM_TYPE_ACTIVATE, GSXML.ERROR);
     1302                        }
     1303                        response.appendChild(s);
     1304                        return response;
     1305                    }
     1306                   
     1307
    12921308                    if (action.equals(GSXML.SYSTEM_TYPE_DEACTIVATE))
    12931309                    {
     
    13471363
    13481364    }
     1365
     1366    protected boolean moduleTypeMatchesModuleInstance(String module_name, String module_type)
     1367    {
     1368    ModuleInterface m = this.module_map.get(module_name);
     1369    if(m == null) {
     1370        return true; // no module also means no conflict between module_type and module_name
     1371    }
     1372
     1373    boolean moduleTypeMatchesInstance = false;
     1374    if (module_type.equals(GSXML.COLLECTION_ELEM) && m instanceof Collection) {
     1375        moduleTypeMatchesInstance = true;
     1376    } else if(module_type.equals(GSXML.SERVICE_ELEM) && m instanceof ServiceRack) {
     1377        moduleTypeMatchesInstance = true;
     1378    } else if(module_type.equals(GSXML.CLUSTER_ELEM) && m instanceof ServiceCluster) {
     1379        moduleTypeMatchesInstance = true;
     1380    } else if(module_type.equals(GSXML.SITE_ELEM) && m instanceof Communicator) {
     1381        moduleTypeMatchesInstance = true;       
     1382    }
     1383
     1384    return moduleTypeMatchesInstance;
     1385    }
    13491386
    13501387    //* Used to copy nodes from one message to another. E.g. copy a response node to the next request. Not sure if this is actually used anywhere yet... */
Note: See TracChangeset for help on using the changeset viewer.