Changeset 4097


Ignore:
Timestamp:
2003-04-07T16:52:08+12:00 (21 years ago)
Author:
kjdon
Message:

I am rearranging stuff so that you can reconfigure all the bits individually without having to restart tomcat - I am part of the way through

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/collection
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/Collection.java

    r4086 r4097  
    4444    extends ServiceCluster {
    4545
    46     protected XMLTransformer transformer_ = null;
     46    protected XMLTransformer transformer = null;
    4747    /** same as setClusterName */
    4848    public void setCollectionName(String name) {
     
    5151
    5252    public Collection() {
    53     service_map_ = new HashMap();
    54     converter_ = new XMLConverter();
    55     transformer_ = new XMLTransformer();
    56     doc_ = converter_.newDOM();
    57     description_ = doc_.createElement(GSXML.COLLECTION_ELEM);
    58     service_info_ = doc_.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
    59     meta_info_ = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    60     description_.appendChild(meta_info_);
    61     description_.appendChild(service_info_);
     53    this.service_map = new HashMap();
     54    this.converter = new XMLConverter();
     55    this.transformer = new XMLTransformer();
     56    this.doc = this.converter.newDOM();
     57    this.description = this.doc.createElement(GSXML.COLLECTION_ELEM);
    6258   
    6359    }
     
    7571    public boolean configure() {
    7672   
    77     if (site_home_ == null || cluster_name_== null) {
     73    if (this.site_home == null || this.cluster_name== null) {
    7874        System.err.println("site_home and collection_name must be set before configure called!");
    7975        return false;
    8076    }
    81     // read the collection build configuration file
    82     File build_config_file = new File(GSFile.collectionBuildConfigFile(site_home_, cluster_name_));
    83     File coll_config_file = new File(GSFile.collectionConfigFile(site_home_, cluster_name_));
    84 
     77   
     78    Element coll_config_xml = loadCollConfigFile();
     79    Element build_config_xml = loadBuildConfigFile();
     80   
     81    if (coll_config_xml==null||build_config_xml==null) {
     82        return false;
     83    }
     84    // process the metadata
     85    findAndLoadMetadata(coll_config_xml, build_config_xml);
     86
     87    // now do the services 
     88    Element service_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
     89    configureServiceRack(service_list, coll_config_xml);
     90   
     91    return true;
     92   
     93    }
     94
     95    /**
     96     * overwrite the serviceCluster one cos we use diff config files
     97     */
     98    protected Element processSystemRequest(Element request) {
     99    Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     100    response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
     101    response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_SYSTEM);
     102
     103    // a list of system requests - should put any error messages
     104    // or success messages into response
     105    NodeList commands = request.getElementsByTagName(GSXML.SYSTEM_ELEM);
     106    Element coll_config_elem = null;
     107    Element build_config_elem = null;
     108    for (int i=0; i<commands.getLength(); i++) {
     109        // all the commands should be Elements
     110        Element elem = (Element)commands.item(i);
     111        String action = elem.getAttribute(GSXML.TYPE_ATT);
     112        if (action.equals("configure")) {
     113        String subset = elem.getAttribute("subset");
     114        if (subset.equals("")) {
     115            // need to reconfigure the collection
     116            if (this.configure()) {
     117            Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " collection reconfigured");
     118            response.appendChild(s);
     119            continue;
     120            }
     121           
     122            Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " collection could not  be reconfigured");
     123            response.appendChild(s);
     124            return response; // wont be able to process any more if we cant do this one
     125           
     126        }
     127        // else its a specific request
     128       
     129        // need the coll config files
     130        if (coll_config_elem==null) {
     131            coll_config_elem = loadCollConfigFile();
     132            build_config_elem = loadBuildConfigFile();
     133            if (coll_config_elem == null||build_config_elem == null) {
     134            // wont be able to do any of teh requests
     135            return response;
     136            }   
     137        }
     138       
     139        boolean success = false;
     140        if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
     141            Element service_rack_list = (Element)GSXML.getChildByTagName(build_config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
     142           
     143            success = configureServiceRack(service_rack_list, coll_config_elem);
     144        } else if (subset.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
     145            success = findAndLoadMetadata(coll_config_elem, build_config_elem);
     146           
     147        } else {
     148            System.err.println("ServiceCluster: cant process system request, configure "+subset);
     149        }
     150       
     151        String message=null;
     152        if (success) {
     153            message = "ServiceCluster: "+ subset + " reconfigured successfully";
     154        } else {
     155            message = "ServiceCluster: Error in reconfiguring "+subset;
     156        }
     157        Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message);
     158        response.appendChild(s);
     159        } else {
     160        String module_name = elem.getAttribute(GSXML.SYSTEM_MODULE_NAME_ATT);
     161        String module_type = elem.getAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT);
     162        if (action.equals("activate")) {
     163            Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type+": "+module_name+" activated -- not yet implemented");
     164            response.appendChild(s);
     165        } else if (action.equals("deactivate")) {
     166            Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type+": "+module_name+" deactivated -- not yet implemented");
     167            response.appendChild(s);
     168        } else {
     169            System.err.println("Collection: cant process system request, action "+action);
     170            continue;
     171        }
     172       
     173        }
     174    } // for each command
     175    return response;
     176    }
     177   
     178    protected Element loadCollConfigFile() {
     179
     180    File coll_config_file = new File(GSFile.collectionConfigFile(this.site_home, this.cluster_name));
     181   
    85182    if (!coll_config_file.exists()) {
    86183        System.err.println(coll_config_file+" does not exist");
    87         System.err.println("couldn't configure collection: "+cluster_name_);
    88         return false;
    89     }
    90    
     184        System.err.println("couldn't configure collection: "+this.cluster_name);
     185        return null;
     186    }
     187    // get the xml for both files
     188    Element coll_config_elem = this.converter.getDOM(coll_config_file, CONFIG_ENCODING).getDocumentElement();
     189    return coll_config_elem;
     190
     191    }
     192   
     193   
     194    protected Element loadBuildConfigFile() {
     195   
     196    File build_config_file = new File(GSFile.collectionBuildConfigFile(this.site_home, this.cluster_name));
    91197    if (!build_config_file.exists()) {
    92198        System.err.println(build_config_file+" does not exist");
    93         System.err.println("couldn't configure collection: "+cluster_name_);
    94         return false;
    95     }
    96    
    97     // get the xml for both files
    98     Element coll_config_xml = converter_.getDOM(coll_config_file, CONFIG_ENCODING).getDocumentElement();
    99     Element build_config_xml = converter_.getDOM(build_config_file, CONFIG_ENCODING).getDocumentElement();
    100    
    101     // process the metadata
     199        System.err.println("couldn't configure collection: "+this.cluster_name);
     200        return null;
     201    }
     202    Element build_config_elem = this.converter.getDOM(build_config_file, CONFIG_ENCODING).getDocumentElement();
     203
     204    return build_config_elem;
     205    }
     206
     207   
     208    protected boolean findAndLoadMetadata(Element coll_config_xml,
     209                      Element build_config_xml){
     210
     211    this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    102212    Element meta_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    103     configureMetadata(meta_list);
     213    addMetadata(meta_list);
    104214    meta_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    105     configureMetadata(meta_list);
    106 
    107     meta_list = doc_.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
    108     GSXML.addMetadata(doc_, meta_list, "httpPath", site_http_address_+"/collect/"+cluster_name_);
    109     configureMetadata(meta_list);
    110    
    111     // now do the services
    112    
    113     Element service_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
    114     configureServiceRack(service_list, coll_config_xml);
    115    
     215    addMetadata(meta_list);
     216
     217    meta_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
     218    GSXML.addMetadata(this.doc, meta_list, "httpPath", this.site_http_address+"/collect/"+this.cluster_name);
     219    addMetadata(meta_list);
    116220    return true;
    117    
     221
    118222    }
    119223
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java

    r4086 r4097  
    4848
    4949    /** base directory for the site that this cluster belongs to*/
    50     protected String site_home_ = null;
     50    protected String site_home = null;
    5151    /** http address of the site that this cluster belongs to */
    52     protected String site_http_address_ = null;
     52    protected String site_http_address = null;
    5353    /** The name of the cluster - for a collection, this is the collection name*/
    54     protected String cluster_name_ = null;
     54    protected String cluster_name = null;
    5555
    5656    /** a reference to the message router */
    57     protected MessageRouter router_ = null;
     57    protected MessageRouter router = null;
    5858    /** The map of services.
    5959     *
     
    6262     *
    6363     */
    64     protected HashMap service_map_=null;
     64    protected HashMap service_map=null;
    6565
    6666    /** XML converter for String to DOM and vice versa */
    67     protected XMLConverter converter_=null;
     67    protected XMLConverter converter=null;
    6868
    6969    /** container doc for description elements */
    70     protected Document doc_ = null;
     70    protected Document doc = null;
    7171    /** list of services */
    72     protected Element service_info_ = null;
     72    protected Element service_list = null;
    7373    /** list of Metadata */
    74     protected Element meta_info_ = null;
    75     /** full description */
    76     protected Element description_ = null;
     74    protected Element metadata_list = null;
     75    /** the element that will have any descriptions passed back in */
     76    protected Element description = null;
    7777
    7878    public void setSiteHome(String home) {
    79     site_home_ = home;
     79    this.site_home = home;
    8080    }
    8181
    8282    public void setSiteAddress(String address) {
    83     site_http_address_ = address;
     83    this.site_http_address = address;
    8484    }
    8585
    8686    public void setClusterName(String name) {
    87     cluster_name_ = name;   
    88     description_.setAttribute(GSXML.NAME_ATT, name);
     87    this.cluster_name = name;   
     88    this.description.setAttribute(GSXML.NAME_ATT, name);
    8989    } 
    9090
    9191    public void setMessageRouter(MessageRouter m) {
    92     router_ = m;
     92    this.router = m;
    9393    }
    9494
    9595    public ServiceCluster() {
    96     service_map_ = new HashMap();
    97     converter_ = new XMLConverter();
    98     doc_ = converter_.newDOM();
    99     description_ = doc_.createElement(GSXML.CLUSTER_ELEM);
    100     service_info_ = doc_.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
    101     meta_info_ = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    102     description_.appendChild(meta_info_);
    103     description_.appendChild(service_info_);
     96    this.service_map = new HashMap();
     97    this.converter = new XMLConverter();
     98    this.doc = this.converter.newDOM();
     99    this.description = this.doc.createElement(GSXML.CLUSTER_ELEM);
    104100   
    105101    }
     
    120116    public boolean configure() {
    121117
    122     if (site_home_ == null || cluster_name_== null) {
    123         System.err.println("site_home_ and cluster_name_ must be set before configure called!");
     118    if (this.site_home == null || this.cluster_name== null) {
     119        System.err.println("this.site_home and cluster_name_ must be set before configure called!");
    124120        return false;
    125121    }
    126122    System.out.println("configuring service cluster");
    127123    // read the site configuration file
    128     File config_file_ = new File(GSFile.siteConfigFile(site_home_));
    129 
    130     if (!config_file_.exists()) {
    131         System.err.println(config_file_+" does not exist");
    132         System.err.println("couldn't configure cluster: "+cluster_name_);
     124    File config_file = new File(GSFile.siteConfigFile(this.site_home));
     125
     126    if (!config_file.exists()) {
     127        System.err.println(config_file+" does not exist");
     128        System.err.println("couldn't configure cluster: "+this.cluster_name);
    133129        return false;
    134130    }
    135131
    136     Document doc = converter_.getDOM(config_file_, CONFIG_ENCODING);
     132    Document doc = this.converter.getDOM(config_file, CONFIG_ENCODING);
    137133   
    138134    // get the appropriate service cluster element
    139135    Element cluster_list = (Element)GSXML.getChildByTagName(doc.getDocumentElement(), GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);
    140136    Element sc = GSXML.getNamedElement(cluster_list, GSXML.CLUSTER_ELEM,
    141                        GSXML.NAME_ATT, cluster_name_);
     137                       GSXML.NAME_ATT, this.cluster_name);
    142138   
    143139    return this.configure(sc);
     
    148144   
    149145    // do the metadata
    150    
     146    this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    151147    // get the metadata - for now just add it to the list
    152148    Element meta_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    153149    if (meta_list !=null) {
    154         if (!configureMetadata(meta_list)) {
     150        if (!addMetadata(meta_list)) {
    155151       
    156152        System.err.println("couldn't configure the metadata");
     
    176172    }
    177173   
    178     /** adds metadata from a metadataList into the meta_info_ xml */
    179     protected boolean configureMetadata(Element metadata_list) {
     174    /** adds metadata from a metadataList into the metadata_list xml */
     175    protected boolean addMetadata(Element metadata_list) {
    180176    NodeList metanodes = metadata_list.getElementsByTagName(GSXML.METADATA_ELEM);
    181177    if (metanodes.getLength()>0) { 
    182178        for(int k=0; k<metanodes.getLength(); k++) {
    183         meta_info_.appendChild(doc_.importNode(metanodes.item(k),true));
     179        this.metadata_list.appendChild(this.doc.importNode(metanodes.item(k),true));
    184180        }
    185181    }       
     
    192188    protected boolean configureServiceRack(Element service_rack_list,
    193189                       Element extra_info) {
    194    
     190
     191    // empty the service map in case this is a reconfigure
     192    service_map.clear();
     193    this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
     194
    195195    // create all the services
    196196    NodeList nodes = service_rack_list.getElementsByTagName(GSXML.SERVICE_CLASS_ELEM);
    197197    if (nodes.getLength()==0) {
    198         System.err.println("Cluster configuration error: cluster "+cluster_name_+" has no service modules!");
     198        System.err.println("Cluster configuration error: cluster "+this.cluster_name+" has no service modules!");
    199199        return false;
    200200    }
     
    204204        // the xml request to send to the serviceRack to query what
    205205        // services it provides
    206         Element message = doc_.createElement(GSXML.MESSAGE_ELEM);
    207         Element request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_DESCRIBE, "", "");
     206        Element message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     207        Element request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", "");
    208208        message.appendChild(request);
    209209        request.setAttribute(GSXML.INFO_ATT, GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
     
    216216        ServiceRack s = (ServiceRack)Class.forName("org.greenstone.gsdl3.service."+servicetype).newInstance();
    217217
    218         s.setSiteHome(site_home_);
    219         s.setSiteAddress(site_http_address_);
    220         s.setClusterName(cluster_name_);
    221         s.setMessageRouter(router_);
     218        s.setSiteHome(this.site_home);
     219        s.setSiteAddress(this.site_http_address);
     220        s.setClusterName(this.cluster_name);
     221        s.setMessageRouter(this.router);
    222222        // pass the xml node to the service for configuration
    223223        s.configure(n, extra_info);
     
    229229        for (int j=0; j<typenodes.getLength();j++) {
    230230            String service = ((Element) typenodes.item(j)).getAttribute(GSXML.NAME_ATT);       
    231             service_map_.put(service, s);
     231            this.service_map.put(service, s);
    232232           
    233233            // also add info to the ServiceInfo XML element
    234             service_info_.appendChild(doc_.importNode(typenodes.item(j), true));
     234            this.service_list.appendChild(this.doc.importNode(typenodes.item(j), true));
    235235        }
    236236        } catch (Exception e) {
     
    241241       
    242242    }
    243     // add elements to description
    244     description_.appendChild(service_info_);
    245243    return true;
    246244   
     
    259257    public String process(String in) {
    260258
    261     Document doc = converter_.getDOM(in);
     259    Document doc = this.converter.getDOM(in);
    262260    Element e = doc.getDocumentElement();
    263261   
    264262    Element res = process(e);
    265     return converter_.getString(res);
     263    return this.converter.getString(res);
    266264   
    267265    }
     
    274272    NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM);
    275273    Document mess_doc = message.getOwnerDocument();
    276     Element mainResult = doc_.createElement(GSXML.MESSAGE_ELEM);
     274    Element mainResult = this.doc.createElement(GSXML.MESSAGE_ELEM);
    277275    if (requests.getLength()==0) {
    278         System.err.println("ServiceCluster.process: no requests for cluster:"+cluster_name_);
     276        System.err.println("ServiceCluster.process: no requests for cluster:"+this.cluster_name);
    279277        // no requests
    280278        return mainResult; // for now
     
    286284        // the cluster name should be first, check, then remove
    287285        String clustername = GSPath.getFirstLink(to);
    288         if (!clustername.equals(cluster_name_)){
    289         System.err.println("ServiceCluster Error: cluster name wrong! was "+clustername+" should have been "+cluster_name_);
     286        if (!clustername.equals(this.cluster_name)){
     287        System.err.println("ServiceCluster Error: cluster name wrong! was "+clustername+" should have been "+this.cluster_name);
    290288        continue; // ignore this request
    291289        }
     
    294292       
    295293        if (to.equals("")) { // this command is for me
    296         String type = request.getAttribute(GSXML.TYPE_ATT);
    297         if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE)) {
    298             // create a response with the description inside it
    299             Element response = doc_.createElement(GSXML.RESPONSE_ELEM);
    300             response.setAttribute(GSXML.FROM_ATT, cluster_name_);
    301             response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);
    302             response.appendChild(description_);
    303             mainResult.appendChild(response);
    304        
    305         } else {
    306             System.err.println("ServiceCluster Error: cant handle request of type "+ type);
    307            
    308         }
    309        
     294        Element response = processMessage(request);
     295        mainResult.appendChild(response);
     296       
    310297        } else { // the request is for one of my services
    311298        String service = GSPath.getFirstLink(to);
    312299       
    313         if (!service_map_.containsKey(service)) {
     300        if (!this.service_map.containsKey(service)) {
    314301            System.err.println("ServiceCluster Error: non-existant service, "+service+", specified!");
    315302            continue;
     
    318305        Element single_message = mess_doc.createElement(GSXML.MESSAGE_ELEM);
    319306        single_message.appendChild(request);
    320         Element response_message = ((ModuleInterface)service_map_.get(service)).process(single_message);
     307        Element response_message = ((ModuleInterface)this.service_map.get(service)).process(single_message);
    321308        if (response_message != null) {
    322309            Element response = (Element) GSXML.getChildByTagName(response_message, GSXML.RESPONSE_ELEM);
    323310            String from = response.getAttribute(GSXML.FROM_ATT);
    324             from = GSPath.prependLink(from, cluster_name_);
     311            from = GSPath.prependLink(from, this.cluster_name);
    325312            response.setAttribute(GSXML.FROM_ATT, from);
    326             mainResult.appendChild(doc_.importNode(response, true));
     313            mainResult.appendChild(this.doc.importNode(response, true));
    327314        }
    328315         
     
    333320    return mainResult;
    334321    }
    335    
     322
     323    /** handles requests made to the ServiceCluster itself
     324     *
     325     * @param req - the request Element- <request>
     326     * @return the result Element - should be <response>
     327     */
     328    protected Element processMessage(Element request) {
     329
     330    Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     331    response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
     332    String type = request.getAttribute(GSXML.TYPE_ATT);
     333    response.setAttribute(GSXML.TYPE_ATT, type);
     334   
     335    if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE)) {
     336        // create the collection element
     337        Element description = (Element)this.description.cloneNode(false);
     338        response.appendChild(description);
     339        // check the param list
     340        Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     341        if (param_list == null) {
     342        description.appendChild(this.service_list);
     343        description.appendChild(this.metadata_list);
     344        return response;
     345        }
     346       
     347        // go through the param list and see what components are wanted
     348        NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM);
     349        for (int i=0; i<params.getLength(); i++) {
     350       
     351        Element param = (Element)params.item(i);
     352        // Identify the structure information desired
     353        if (param.getAttribute(GSXML.NAME_ATT) == GSXML.INFO_PARAM ) {
     354            String info = param.getAttribute(GSXML.VALUE_ATT);
     355            if (info.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
     356            description.appendChild(this.service_list);
     357            } else if (info.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
     358            description.appendChild(this.metadata_list);
     359            }
     360        }
     361        }
     362        return response;
     363    }
     364   
     365    if (type.equals(GSXML.REQUEST_TYPE_SYSTEM)) {
     366        response = processSystemRequest(request);
     367    } else { // unknown type
     368        System.err.println("ServiceCluster Error: cant handle request of type "+ type);
     369       
     370    }
     371    return response;
     372    }
     373
     374    protected Element processSystemRequest(Element request) {
     375
     376    Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     377    response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
     378    response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_SYSTEM);
     379
     380    // a list of system requests - should put any error messages
     381    // or success messages into response
     382    NodeList commands = request.getElementsByTagName(GSXML.SYSTEM_ELEM);
     383    Element cluster_config_elem = null;
     384    for (int i=0; i<commands.getLength(); i++) {
     385        // all the commands should be Elements
     386        Element elem = (Element)commands.item(i);
     387        String action = elem.getAttribute(GSXML.TYPE_ATT);
     388        if (action.equals("configure")) {
     389        String subset = elem.getAttribute(GSXML.SYSTEM_SUBSET_ATT);
     390        if (subset.equals("")) {
     391            // need to reconfigure the service cluster
     392           
     393            if (this.configure()) {
     394            Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " cluster reconfigured");
     395            response.appendChild(s);
     396            continue;
     397            }
     398           
     399            Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " cluster could not  be reconfigured");
     400            response.appendChild(s);
     401            return response; // wont be able to process any more if we cant do this one
     402           
     403        }
     404        // else its a specific request
     405       
     406        // need the site config file
     407        if (cluster_config_elem==null) {
     408           
     409            File configFile = new File(GSFile.siteConfigFile(this.site_home));
     410            if (!configFile.exists() ) {
     411            System.err.println("ServiceCluster: site config file: "+configFile.getPath()+" not found!");
     412                // wont be able to do any of teh requests
     413            return response;
     414           
     415            }
     416            Element site_config_elem  = this.converter.getDOM(configFile).getDocumentElement();
     417            cluster_config_elem = GSXML.getNamedElement((Element)GSXML.getChildByTagName(site_config_elem, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER), GSXML.CLUSTER_ELEM, GSXML.NAME_ATT, this.cluster_name);
     418            if (cluster_config_elem == null) {
     419            System.err.println("ServiceCluster: site config file: "+configFile.getPath()+" has no element for cluster "+this.cluster_name);
     420                // wont be able to do any of teh requests
     421            return response;
     422           
     423            }
     424        }
     425       
     426        boolean success = false;
     427        if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
     428            Element service_rack_list = (Element)GSXML.getChildByTagName(cluster_config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
     429           
     430            success = configureServiceRack(service_rack_list, null);
     431        } else if (subset.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
     432            this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
     433            Element metadata_list = (Element)GSXML.getChildByTagName(cluster_config_elem, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
     434            success = addMetadata(metadata_list);
     435        } else {
     436            System.err.println("ServiceCluster: cant process system request, configure "+subset);
     437        }
     438       
     439        String message=null;
     440        if (success) {
     441            message = "ServiceCluster: "+ subset + "reconfigured successfully";
     442        } else {
     443            message = "ServiceCluster: Error in reconfiguring "+subset;
     444        }
     445        Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message);
     446        response.appendChild(s);
     447        } else {
     448        String module_name = elem.getAttribute(GSXML.SYSTEM_MODULE_NAME_ATT);
     449        String module_type = elem.getAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT);
     450        if (action.equals("activate")) {
     451            Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type+": "+module_name+" activated -- not yet implemented");
     452            response.appendChild(s);
     453        } else if (action.equals("deactivate")) {
     454            Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type+": "+module_name+" deactivated -- not yet implemented");
     455            response.appendChild(s);
     456        } else {
     457            System.err.println("ServiceCluster: cant process system request, action "+action);
     458            continue;
     459        }
     460       
     461        }
     462       
     463    } // for each command
     464    return response;
     465    }
     466   
    336467}
    337468
Note: See TracChangeset for help on using the changeset viewer.