Changeset 26446 for main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java
- Timestamp:
- 2012-11-06T15:27:10+13:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java
r25973 r26446 32 32 import org.greenstone.gsdl3.util.GSPath; 33 33 import org.greenstone.gsdl3.util.GSXML; 34 import org.greenstone.gsdl3.util.SimpleMacroResolver; 34 35 import org.greenstone.gsdl3.util.UserContext; 35 36 import org.greenstone.gsdl3.util.XMLConverter; … … 42 43 * Implements ModuleInterface. Contains a list of services provided by the cluster, along with metadata about the cluster itself. 43 44 * a collection is a special type of cluster 44 * @author <a href="mailto:[email protected]">Katherine Don</a>45 * @version $Revision$46 45 * @see ModuleInterface 47 46 */ … … 61 60 /** The name of the cluster - for a collection, this is the collection name */ 62 61 protected String cluster_name = null; 63 /** collection type : mg, mgpp or lucene */ 64 protected String col_type = ""; 65 /** database type : gdbm, jdbm or sqlite */ 66 protected String db_type = ""; 67 62 68 63 /** a reference to the message router */ 69 64 protected MessageRouter router = null; … … 85 80 /** XML converter for String to DOM and vice versa */ 86 81 protected XMLConverter converter = null; 82 /** a MacroResolver for resolving macros in displayItems */ 83 protected SimpleMacroResolver macro_resolver = null; 87 84 88 85 /** container doc for description elements */ … … 92 89 /** list of metadata - all metadata, regardless of language goes in here */ 93 90 protected Element metadata_list = null; 94 /** language specific stuff*/95 //protected Element lang_specific_metadata_list = null; 91 /** language specific display items */ 92 96 93 protected Element display_item_list = null; 94 /** default values for servlet params */ 95 protected Element library_param_list = null; 97 96 /** the element that will have any descriptions passed back in */ 98 97 protected Element description = null; 99 98 100 99 /** list of plugin */ 101 protected Element plugin_item_list = null;100 //protected Element plugin_item_list = null; 102 101 103 102 protected Element _globalFormat = null; … … 139 138 this.service_name_map = new HashMap<String, String>(); 140 139 this.converter = new XMLConverter(); 140 this.macro_resolver = new SimpleMacroResolver(); 141 141 this.doc = this.converter.newDOM(); 142 142 this.description = this.doc.createElement(GSXML.CLUSTER_ELEM); 143 143 this.display_item_list = this.doc.createElement(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER); 144 144 this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 145 this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER); 145 this.library_param_list = this.doc.createElement("libraryParamList"); 146 this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER); 147 //this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER); 146 148 } 147 149 … … 156 158 * parsed. This method will work with any subclass. 157 159 * 160 * This is called by ServiceCluster itself when asked to do a reconfigure 158 161 * @return true if configure successful, false otherwise. 159 162 */ … … 167 170 } 168 171 logger.info("configuring service cluster"); 172 macro_resolver.addMacro("_httpsite_", this.site_http_address); 169 173 // read the site configuration file 170 174 File config_file = new File(GSFile.siteConfigFile(this.site_home)); … … 187 191 Element sc = GSXML.getNamedElement(cluster_list, GSXML.CLUSTER_ELEM, GSXML.NAME_ATT, this.cluster_name); 188 192 193 // this is probably a reconfigure, so clear all previous info 194 clearServices(); 195 clearLocalData(); 189 196 return this.configure(sc); 190 197 } 191 198 199 /** this is called by configure(), but also by MR when it is loading up all the service clusters */ 192 200 public boolean configure(Element service_cluster_info) 193 201 { 194 202 configureLocalData(service_cluster_info); 203 // //get the plugin info 204 // Element import_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.IMPORT_ELEM); 205 // if (import_list != null) 206 // { 207 // Element plugin_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER); 208 // if (plugin_list != null) 209 // { 210 // if (!addPlugins(plugin_list)) 211 // { 212 213 // logger.error("couldn't configure the plugins"); 214 // } 215 // } 216 // } 217 218 // do the service racks 219 // empty the service map in case this is a reconfigure 220 //clearServices(); 221 Element service_rack_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.SERVICE_CLASS_ELEM + GSXML.LIST_MODIFIER); 222 logger.error("cluster service rack list ="); 223 logger.error(GSXML.xmlNodeToString(service_rack_list)); 224 if (service_rack_list == null) 225 { 226 // is this an error? could you ever have a service cluster 227 // without service racks??? 228 logger.error(cluster_name+" has no service racks!!"); 229 } 230 else 231 { 232 233 if (!configureServiceRackList(service_rack_list, null)) 234 { 235 logger.error("couldn't configure "+cluster_name+" service racks!!"); 236 return false; 237 } 238 } 239 240 return true; 241 } 242 243 protected void configureLocalData(Element service_cluster_info) { 195 244 // get the metadata - for now just add it to the list 196 245 Element meta_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); … … 208 257 if (display_list != null) 209 258 { 259 resolveMacros(display_list); 210 260 if (!addDisplayItems(display_list)) 211 261 { … … 215 265 } 216 266 217 //get the plugin info 218 Element import_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.IMPORT_ELEM); 219 if (import_list != null) 220 { 221 Element plugin_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER); 222 if (plugin_list != null) 223 { 224 if (!addPlugins(plugin_list)) 225 { 226 227 logger.error("couldn't configure the plugins"); 228 } 229 } 230 } 231 232 // do the service racks 233 // empty the service map in case this is a reconfigure 234 clearServices(); 235 Element service_rack_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.SERVICE_CLASS_ELEM + GSXML.LIST_MODIFIER); 236 if (service_rack_list == null) 237 { 238 // is this an error? could you ever have a service cluster 239 // without service racks??? 240 logger.error("cluster has no service racks!!"); 241 } 242 else 243 { 244 245 if (!configureServiceRackList(service_rack_list, null)) 246 { 247 logger.error("couldn't configure the service racks!!"); 248 return false; 249 } 250 } 251 252 return true; 253 } 254 267 // get the servlet params 268 Element param_list = (Element) GSXML.getChildByTagName(service_cluster_info, "libraryParamList"); 269 if (param_list != null) { 270 if (!addLibraryParams(param_list)) { 271 logger.error("couldn't configure the library param list"); 272 } 273 } 274 275 } 255 276 /** 256 277 * adds metadata from a metadataList into the metadata_list xml … … 271 292 return true; 272 293 } 273 294 /** adds an individual metadata element into the list */ 295 protected boolean addMetadata(String name, String value) { 296 return GSXML.addMetadata(this.doc, this.metadata_list, name, value); 297 } 298 299 /** in displayItemList, end up with the following for each named displayItem 300 <displayItem name=""> 301 <displayItem name="" lang="">value</displayItem> 302 <displayItem name="" lang="">value</displayItem> 303 </displayItem> 304 */ 274 305 protected boolean addDisplayItems(Element display_list) 275 306 { … … 305 336 } 306 337 307 protected boolean addPlugins(Element plugin_list) 308 { 309 if (plugin_list == null) 310 return false; 311 NodeList pluginNodes = plugin_list.getElementsByTagName(GSXML.PLUGIN_ELEM); 312 if (pluginNodes.getLength() > 0) 313 { 314 for (int k = 0; k < pluginNodes.getLength(); k++) 315 { 316 this.plugin_item_list.appendChild(this.doc.importNode(pluginNodes.item(k), true)); 317 } 318 } 319 338 // protected boolean addPlugins(Element plugin_list) 339 // { 340 // if (plugin_list == null) 341 // return false; 342 // NodeList pluginNodes = plugin_list.getElementsByTagName(GSXML.PLUGIN_ELEM); 343 // if (pluginNodes.getLength() > 0) 344 // { 345 // for (int k = 0; k < pluginNodes.getLength(); k++) 346 // { 347 // this.plugin_item_list.appendChild(this.doc.importNode(pluginNodes.item(k), true)); 348 // } 349 // } 350 351 // return true; 352 // } 353 protected boolean resolveMacros(Element display_list) 354 { 355 if (display_list == null) 356 return false; 357 NodeList displaynodes = display_list.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM); 358 if (displaynodes.getLength() > 0) 359 { 360 //String http_site = this.site_http_address; 361 //String http_collection = this.site_http_address + "/collect/" + this.cluster_name; 362 for (int k = 0; k < displaynodes.getLength(); k++) 363 { 364 Element d = (Element) displaynodes.item(k); 365 String text = GSXML.getNodeText(d); 366 text= macro_resolver.resolve(text); 367 //text = StringUtils.replace(text, "_httpsite_", http_site); 368 //text = StringUtils.replace(text, "_httpcollection_", http_collection); 369 GSXML.setNodeText(d, text); 370 } 371 } 320 372 return true; 321 373 } 322 374 375 /** 376 * adds library params from libraryParamList into library_param_list xml 377 */ 378 protected boolean addLibraryParams(Element param_list) 379 { 380 if (param_list == null) 381 return false; 382 NodeList paramnodes = param_list.getElementsByTagName(GSXML.PARAM_ELEM); 383 if (paramnodes.getLength() > 0) 384 { 385 for (int k = 0; k < paramnodes.getLength(); k++) 386 { 387 this.library_param_list.appendChild(this.doc.importNode(paramnodes.item(k), true)); 388 } 389 } 390 391 return true; 392 } 323 393 protected void clearServices() 324 394 { 395 cleanUp(); 325 396 service_map.clear(); 397 service_name_map.clear(); 326 398 this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER); 327 399 } 328 400 401 protected void clearLocalData() { 402 this.description = this.doc.createElement(GSXML.CLUSTER_ELEM); 403 this.display_item_list = this.doc.createElement(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER); 404 this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 405 this.library_param_list = this.doc.createElement("libraryParamList"); 406 407 } 329 408 /** 330 409 * creates and configures all the services - extra_info is some more xml … … 555 634 Element description = (Element) this.description.cloneNode(false); 556 635 // set collection type : mg, mgpp, lucene or solr 557 description.setAttribute(GSXML.TYPE_ATT, col_type);558 description.setAttribute(GSXML.DB_TYPE_ATT, db_type);636 //description.setAttribute(GSXML.TYPE_ATT, col_type); 637 //description.setAttribute(GSXML.DB_TYPE_ATT, db_type); 559 638 560 639 response.appendChild(description); … … 566 645 description.appendChild(this.service_list); 567 646 description.appendChild(this.metadata_list); 568 description.appendChild(this.plugin_item_list); 647 description.appendChild(this.library_param_list); 648 //description.appendChild(this.plugin_item_list); 569 649 return response; 570 650 } … … 586 666 else if (info.equals(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER)) 587 667 { 588 description.appendChild( metadata_list);668 description.appendChild(this.metadata_list); 589 669 } 590 670 else if (info.equals(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER)) … … 592 672 addAllDisplayInfo(description, lang); 593 673 } 594 else if (info.equals( GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER))674 else if (info.equals("libraryParamlist")) 595 675 { 596 description.appendChild(plugin_item_list);676 description.appendChild(this.library_param_list); 597 677 } 598 678 } … … 820 900 return addMetadata(metadata_list); 821 901 } 822 else if (subset.equals(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER))823 {824 this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER);825 Element import_list = (Element) GSXML.getChildByTagName(cluster_config_elem, GSXML.IMPORT_ELEM);826 if (import_list != null)827 {828 Element plugin_item_list = (Element) GSXML.getChildByTagName(cluster_config_elem, GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER);829 return addPlugins(plugin_item_list);830 }831 else832 return false;833 }902 // else if (subset.equals(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER)) 903 // { 904 // this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER); 905 // Element import_list = (Element) GSXML.getChildByTagName(cluster_config_elem, GSXML.IMPORT_ELEM); 906 // if (import_list != null) 907 // { 908 // Element plugin_item_list = (Element) GSXML.getChildByTagName(cluster_config_elem, GSXML.PLUGIN_ELEM + GSXML.LIST_MODIFIER); 909 // return addPlugins(plugin_item_list); 910 // } 911 // else 912 // return false; 913 // } 834 914 else 835 915 { … … 847 927 { // for each key 848 928 Element m = (Element) items.item(i); 849 // find 929 // findthe child with the correct language 850 930 Element new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang); 851 931 if (new_m == null && lang != DEFAULT_LANG)
Note:
See TracChangeset
for help on using the changeset viewer.