- Timestamp:
- 2003-04-07T16:52:08+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/collection/Collection.java
r4086 r4097 44 44 extends ServiceCluster { 45 45 46 protected XMLTransformer transformer _= null;46 protected XMLTransformer transformer = null; 47 47 /** same as setClusterName */ 48 48 public void setCollectionName(String name) { … … 51 51 52 52 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); 62 58 63 59 } … … 75 71 public boolean configure() { 76 72 77 if ( site_home_ == null || cluster_name_== null) {73 if (this.site_home == null || this.cluster_name== null) { 78 74 System.err.println("site_home and collection_name must be set before configure called!"); 79 75 return false; 80 76 } 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 85 182 if (!coll_config_file.exists()) { 86 183 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)); 91 197 if (!build_config_file.exists()) { 92 198 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); 102 212 Element meta_list = (Element)GSXML.getChildByTagName(coll_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 103 configureMetadata(meta_list);213 addMetadata(meta_list); 104 214 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); 116 220 return true; 117 221 118 222 } 119 223
Note:
See TracChangeset
for help on using the changeset viewer.