Changeset 4105
- Timestamp:
- 2003-04-08T14:41:46+12:00 (21 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/Collection.java
r4097 r4105 92 92 93 93 } 94 95 94 /** 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 95 * load in the collection config file into a DOM Element 96 */ 178 97 protected Element loadCollConfigFile() { 179 98 … … 191 110 } 192 111 193 112 /** 113 * load in the collection build config file into a DOM Element 114 */ 194 115 protected Element loadBuildConfigFile() { 195 116 … … 205 126 } 206 127 207 128 /** 129 * find the metadata from the two config files and add it to a new 130 * metadata list 131 */ 208 132 protected boolean findAndLoadMetadata(Element coll_config_xml, 209 133 Element build_config_xml){ … … 221 145 222 146 } 147 /** 148 * do a configure on only part of the collection 149 */ 150 protected boolean configureSubset(String subset) { 151 152 // need the coll config files 153 Element coll_config_elem = loadCollConfigFile(); 154 Element build_config_elem = loadBuildConfigFile(); 155 if (coll_config_elem == null||build_config_elem == null) { 156 // wont be able to do any of teh requests 157 return false; 158 } 159 160 if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) { 161 Element service_rack_list = (Element)GSXML.getChildByTagName(build_config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER); 162 163 return configureServiceRack(service_rack_list, coll_config_elem); 164 } 165 166 if (subset.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) { 167 return findAndLoadMetadata(coll_config_elem, build_config_elem); 168 169 } 170 171 System.err.println("ServiceCluster: cant process system request, configure "+subset); 172 return false; 173 } 223 174 224 175 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java
r4097 r4105 381 381 // or success messages into response 382 382 NodeList commands = request.getElementsByTagName(GSXML.SYSTEM_ELEM); 383 Element cluster_config_elem = null;383 String message=null; 384 384 for (int i=0; i<commands.getLength(); i++) { 385 385 // all the commands should be Elements … … 392 392 393 393 if (this.configure()) { 394 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " clusterreconfigured");394 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " reconfigured"); 395 395 response.appendChild(s); 396 continue; 397 } 396 397 } else { 398 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " could not be reconfigured"); 399 response.appendChild(s); 400 } 401 } else if (this.configureSubset(subset)) { 402 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " "+subset+" reconfigured"); 403 response.appendChild(s); 404 } else { 405 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " "+subset + " could not be reconfigured"); 406 response.appendChild(s); 407 } 408 continue; 409 } // configure action 410 411 String module_name = elem.getAttribute(GSXML.SYSTEM_MODULE_NAME_ATT); 412 String module_type = elem.getAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT); 413 if (action.equals("activate")) { 414 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, "activate action not yet implemented - does it even make sense in this context??"); 415 response.appendChild(s); 416 } else if (action.equals("deactivate")) { 417 if (module_type.equals(GSXML.SERVICE_ELEM)) { 418 // deactivate the service 419 // remove from service_map 420 this.service_map.remove(module_name); 421 Element service_elem = GSXML.getNamedElement(this.service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, module_name); 422 System.out.println("service list before: "+this.converter.getPrettyString(service_list)); 423 service_list.removeChild(service_elem); 424 System.out.println("service list after: "+this.converter.getPrettyString(service_list)); 398 425 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); 426 message = module_type+": "+module_name+" deactivated"; 435 427 } 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 } 428 message = "can't deactivate "+module_type+" type modules!";} 445 429 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message); 446 430 response.appendChild(s); 447 431 } 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 432 System.err.println("ServiceCluster: cant process system request, action "+action); 433 continue; 434 } 463 435 } // for each command 464 436 return response; 465 437 } 466 438 439 /** 440 * do a configure on only part of the collection 441 */ 442 protected boolean configureSubset(String subset) { 443 444 File configFile = new File(GSFile.siteConfigFile(this.site_home)); 445 if (!configFile.exists() ) { 446 System.err.println("ServiceCluster: site config file: "+configFile.getPath()+" not found!"); 447 // wont be able to do any of teh requests 448 return false; 449 450 } 451 452 Element site_config_elem = this.converter.getDOM(configFile).getDocumentElement(); 453 Element 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); 454 if (cluster_config_elem == null) { 455 System.err.println("ServiceCluster: site config file: "+configFile.getPath()+" has no element for cluster "+this.cluster_name); 456 // wont be able to do any of teh requests 457 return false; 458 459 } 460 if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) { 461 Element service_rack_list = (Element)GSXML.getChildByTagName(cluster_config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER); 462 463 return configureServiceRack(service_rack_list, null); 464 } else if (subset.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) { 465 this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 466 Element metadata_list = (Element)GSXML.getChildByTagName(cluster_config_elem, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 467 return addMetadata(metadata_list); 468 } else { 469 System.err.println("ServiceCluster: cant process system request, configure "+subset); 470 return false; 471 } 472 473 } 467 474 } 468 475 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/core/MessageRouter.java
r4096 r4105 73 73 protected Document doc=null; 74 74 /** the full description of this site */ 75 //protected Element description = null;76 75 77 76 // should these things be separated into local and remote?? … … 402 401 this.site_list.appendChild(this.doc.importNode(s, true)); 403 402 // need to get collection list and service 404 // list from here- this may introduce a 405 // configure problem - leave as is for now, 406 // but fix up later - kjdon 403 // list from here- if the site isn't up yet, the site will 404 // have to be added later 407 405 if (!getRemoteSiteInfo(comm, name)) { 408 406 System.err.println("couldn't get info from site "+name); … … 508 506 } 509 507 System.out.println("params found, getting subset"); 508 NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM); 510 509 511 510 // go through the param list and see what components are wanted 512 Element param = (Element) param_list.getFirstChild(); 513 while (param != null) { 514 if (!param.getNodeName().equals(GSXML.PARAM_ELEM)) { 515 System.err.println("Warning: Non-param in paramList (ignored)."); 516 continue; 517 } 511 for (int i=0; i<params.getLength(); i++) { 512 513 Element param = (Element)params.item(i); 518 514 // Identify the structure information desired 519 515 if (param.getAttribute(GSXML.NAME_ATT) == GSXML.INFO_PARAM ) { … … 531 527 } 532 528 } 533 param = (Element)param.getNextSibling();534 529 } 535 530 return response; 536 531 537 532 } 538 533 534 // the old way, should all be using system now 539 535 if (type.equals(GSXML.REQUEST_TYPE_CONFIGURE)) { 540 536 … … 573 569 // a list of system requests - should put any error messages 574 570 // or success messages into response 575 NodeList commands = req.getElementsByTagName( "system");//GSXML.SYSTEM_ELEM);571 NodeList commands = req.getElementsByTagName(GSXML.SYSTEM_ELEM); 576 572 Element site_config_elem = null; 573 boolean success = false; 574 577 575 for (int i=0; i<commands.getLength(); i++) { 578 576 // all the commands should be Elements … … 580 578 String action = elem.getAttribute(GSXML.TYPE_ATT); 581 579 if (action.equals("configure")) { 582 String subset = elem.getAttribute( "subset");580 String subset = elem.getAttribute(GSXML.SYSTEM_SUBSET_ATT); 583 581 if (subset.equals("")) { 584 582 // need to reconfigure the MR 585 583 this.configure(); 586 Element s = GSXML.createTextElement(this.doc, "status","mr reconfigured");584 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, "mr reconfigured"); 587 585 response.appendChild(s); 588 586 589 587 } else { 590 588 // else it a specific request 591 boolean success = false;592 589 if (subset.equals(GSXML.COLLECTION_ELEM+GSXML.LIST_MODIFIER)) { 593 590 success = configureCollections(); … … 623 620 message = "Error in reconfiguring "+subset; 624 621 } 625 Element s = GSXML.createTextElement(this.doc, "status", message);622 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message); 626 623 response.appendChild(s); 627 624 } … … 629 626 630 627 } else { 631 String module_name = elem.getAttribute( "moduleName");632 String module_type = elem.getAttribute( "moduleType");628 String module_name = elem.getAttribute(GSXML.SYSTEM_MODULE_NAME_ATT); 629 String module_type = elem.getAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT); 633 630 634 631 if (action.equals("deactivate")) { 635 632 deactivateModule(module_type, module_name); 636 Element s = GSXML.createTextElement(this.doc, "status", module_type+": "+module_name+" deactivated");633 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type+": "+module_name+" deactivated"); 637 634 response.appendChild(s); 635 } else if (action.equals("activate")) { 636 if (module_type.equals(GSXML.COLLECTION_ELEM)) { 637 success = activateCollection(module_name); 638 } else if (module_type.equals(GSXML.SITE_ELEM)) { 639 success = activateSite(module_name); 640 } else if (module_type.equals(GSXML.CLUSTER_ELEM)) { 641 success = activateServiceCluster(module_name); 642 } 643 if (success) { 644 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type+": "+module_name+" activated"); 645 response.appendChild(s); 646 } else { 647 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type+": "+module_name+" could not be activated"); 648 response.appendChild(s); 649 } 638 650 } 639 } 651 } // else not a configure action 640 652 } // for all commands 641 653 return response; 642 654 643 655 644 } 656 } // system type request 657 645 658 // if get here something has gone wrong 646 659 System.err.println("MessageRouter: cant process request:"); … … 685 698 } 686 699 700 protected boolean activateSite(String site_name) { 701 System.out.println("MessageRouter:Activating site: "+site_name+"."); 702 703 // just in case this is a reactivation, deactivate this site first 704 deactivateModule(GSXML.SITE_ELEM, site_name); 705 File configFile = new File(GSFile.siteConfigFile(this.site_home)); 706 707 if (!configFile.exists() ) { 708 System.err.println("MessageRouter: site config file: "+configFile.getPath()+" not found!"); 709 return false; 710 } 711 Element config = this.converter.getDOM(configFile).getDocumentElement(); 712 713 Element site_list = (Element)GSXML.getChildByTagName(config, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER); 714 if (site_list ==null ) { 715 System.out.println("MessageRouter:activateSite, no sites found"); 716 return false; 717 } 718 Element this_site_elem = GSXML.getNamedElement(site_list, GSXML.SITE_ELEM, GSXML.NAME_ATT, site_name); 719 if (this_site_elem == null) { 720 System.out.println("MessageRouter:activateSite, site "+site_name+" not found"); 721 return false; 722 } 723 724 Communicator comm=null; 725 String type = this_site_elem.getAttribute(GSXML.TYPE_ATT); 726 if (type.equals(GSXML.COMM_TYPE_SOAP_JAVA)) { 727 comm = new SOAPCommunicator(); 728 if (comm.configure(this_site_elem)) { 729 comm.setLocalSiteName(this.global_site_name); 730 731 // add to map of modules 732 this.module_map.put(site_name, comm); 733 this.site_list.appendChild(this.doc.importNode(this_site_elem, true)); 734 // need to get collection list and service 735 // list from here- if the site isn't up yet, the site will 736 // have to be added later 737 if (!getRemoteSiteInfo(comm, site_name)) { 738 System.err.println("couldn't get info from site "+site_name); 739 } 740 } else { 741 System.err.println("couldn't configure soap site:"+site_name); 742 return false; 743 } 744 745 } else { 746 System.err.print("cant talk to server of type:"+type); 747 System.err.println(", so not making a connection to "+site_name); 748 return false; 749 } 750 return true; 751 752 } 753 687 754 protected boolean activateServiceCluster(String cluster_name) { 688 755 return false; … … 724 791 if (this_site != null) { 725 792 this.site_list.removeChild(this_site); 726 727 // also need to remove from the other lists any 728 // services/clusters/collections that belong to this site 793 794 // also remove this sites colls, services, clusters etc 795 removeRemoteSiteInfo(this.collection_list, GSXML.COLLECTION_ELEM, name); 796 removeRemoteSiteInfo(this.cluster_list, GSXML.CLUSTER_ELEM, name); 797 removeRemoteSiteInfo(this.service_list, GSXML.SERVICE_ELEM, name); 729 798 } 730 799 } else { … … 738 807 739 808 } 809 810 /** 811 * this looks through a list (module_list) of elements named module_name, 812 * and removes any whose names start with site_name 813 */ 814 protected void removeRemoteSiteInfo(Element module_list, 815 String module_name, 816 String site_name) { 817 818 NodeList modules = module_list.getElementsByTagName(module_name); 819 // will this work?? 820 for (int i=0; i<modules.getLength(); i++) { 821 822 String name = ((Element)modules.item(i)).getAttribute(GSXML.NAME_ATT); 823 if (GSPath.getFirstLink(name).equals(site_name)) { 824 module_list.removeChild(modules.item(i)); 825 i--; // move the pointer back 826 } 827 } 828 } 829 830 740 831 } 741 832
Note:
See TracChangeset
for help on using the changeset viewer.