Project

General

Profile

« Previous | Next » 

Revision 8323

Added by Jing Tao about 11 years ago

Add code the display the SchemaModification exception.

View differences:

src/edu/ucsb/nceas/metacat/admin/upgrade/solr/SolrSchemaUpgrader.java
152 152
                        String error1 = "SolrSchemaUpdator.update - couldn't determine if the schema.xml in the "+solrHomePath+"/conf"+
153 153
                                        " was modified or not. If you did modify it, please manually merge the change to the file "+metacatIndexSolrHome+SCHEMAFILERELATIVEPATH +" and copy it to "+
154 154
                                        solrHomePath+"/conf; otherwise, just copy the file "+metacatIndexSolrHome+SCHEMAFILERELATIVEPATH +" to "+solrHomePath+"/conf.";
155
                        String error2 ="\nAfter copying the schema file, you have to issue a 'reindexall' action as an administrator.";
156
                        String error3 = "SolrSchemaUpdator.update - Metacat determined the schema.xml in the "+solrHomePath+"/conf"+
157
                                        " was modified. Please manually merge the change to the file "+metacatIndexSolrHome+SCHEMAFILERELATIVEPATH +" and copy it to overwrite "+
158
                                        solrHomePath+"/conf/schema.xml.";
155
                        //String error2 ="After configuring Metacat and restarting Tomcat, you have to issue a 'reindexall' action as an administrator to rebuild the Solr index.";
156
                        String error3 = "Metacat determined the schema.xml in the "+solrHomePath+"/conf"+
157
                                        " was customized. You have to manually fix the issue - merge the change to the file "+metacatIndexSolrHome+SCHEMAFILERELATIVEPATH +" and copy it to overwrite the schema.xml in the "+
158
                                        solrHomePath+"/conf. You may click the OK button When you finish the merging. ";
159 159
                        if(checkSum != null) {
160 160
                            String checksumValue = checkSum.getValue();
161 161
                            //System.out.println("the existing schema.xml in the solr home has the checksum ================== "+checksumValue);
......
183 183
                                        
184 184
                                    } else {
185 185
                                        //users changed the schema, we have to throw an exception to ask the administrator to manually merge and overwrite.
186
                                        throw new SolrSchemaModificationException(error3+error2);
186
                                        throw new SolrSchemaModificationException(error3);
187 187
                                    }
188 188
                                }
189 189
                            } else {
190
                                throw new SolrSchemaModificationException(error1+error2);
190
                                throw new SolrSchemaModificationException(error1);
191 191
                            }
192 192
                        } else {
193
                            throw new SolrSchemaModificationException(error1+error2);
193
                            throw new SolrSchemaModificationException(error1);
194 194
                        }
195 195
                    }
196 196
                }
src/edu/ucsb/nceas/metacat/admin/DBAdmin.java
51 51

  
52 52
import edu.ucsb.nceas.metacat.MetacatVersion;
53 53
import edu.ucsb.nceas.metacat.admin.upgrade.UpgradeUtilityInterface;
54
import edu.ucsb.nceas.metacat.admin.upgrade.solr.SolrSchemaModificationException;
54 55
import edu.ucsb.nceas.metacat.database.DBConnection;
55 56
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
56 57
import edu.ucsb.nceas.metacat.database.DBVersion;
......
90 91
	private HashSet<String> sqlCommandSet = new HashSet<String>();
91 92
	private Map<String, String> scriptSuffixMap = new HashMap<String, String>();
92 93
	private static DBVersion databaseVersion = null;
94
	private SolrSchemaModificationException solrSchemaException = null;
93 95

  
94 96
	/**
95 97
	 * private constructor since this is a singleton
......
145 147
		String processForm = request.getParameter("processForm");
146 148
		String formErrors = (String) request.getAttribute("formErrors");
147 149
		HttpSession session = request.getSession();
150
		String supportEmail = null;
148 151

  
149 152
		if (processForm == null || !processForm.equals("true") || formErrors != null) {
150 153
			// The servlet configuration parameters have not been set, or there
......
174 177
				request.setAttribute("databaseVersion", dbVersionString);
175 178
				Vector<String> updateScriptList = getUpdateScripts();
176 179
				request.setAttribute("updateScriptList", updateScriptList);
177
				String supportEmail = PropertyService.getProperty("email.recipient");
180
				supportEmail = PropertyService.getProperty("email.recipient");
178 181
				request.setAttribute("supportEmail", supportEmail);
179 182

  
180 183
				// Forward the request to the JSP page
......
204 207
				// there is no other easy way to go back to the configure form
205 208
				// and
206 209
				// preserve their entries.
210
			    supportEmail = PropertyService.getProperty("email.recipient");
207 211
				validationErrors.addAll(validateOptions(request));
208

  
212
				
213
				
209 214
				upgradeDatabase();
215
				
216
				
210 217

  
211 218
				// Now that the options have been set, change the
212 219
				// 'databaseConfigured' option to 'true' so that normal metacat
213 220
				// requests will go through
214 221
				PropertyService.setProperty("configutil.databaseConfigured",
215 222
						PropertyService.CONFIGURED);
223
				PropertyService.persistMainBackupProperties();
224
                if(solrSchemaException != null) {
225
                    //Show the warning message
226
                    Vector<String> errorVector = new Vector<String>();
227
                    errorVector.add(solrSchemaException.getMessage());
228
                    RequestUtil.clearRequestMessages(request);
229
                    request.setAttribute("supportEmail", supportEmail);
230
                    RequestUtil.setRequestErrors(request, errorVector);
231
                    RequestUtil.forwardRequest(request, response,
232
                                    "/admin/solr-schema-warn.jsp", null);
233
                } else {
234
                    // Reload the main metacat configuration page
235
                    processingSuccess.add("Database successfully upgraded");
236
                    RequestUtil.clearRequestMessages(request);
237
                    RequestUtil.setRequestSuccess(request, processingSuccess);
238
                    RequestUtil.forwardRequest(request, response,
239
                            "/admin?configureType=configure&processForm=false", null);
240
                    // Write out the configurable properties to a backup file
241
                    // outside the install directory.
216 242

  
217
				// Reload the main metacat configuration page
218
				processingSuccess.add("Database successfully upgraded");
219
				RequestUtil.clearRequestMessages(request);
220
				RequestUtil.setRequestSuccess(request, processingSuccess);
221
				RequestUtil.forwardRequest(request, response,
222
						"/admin?configureType=configure&processForm=false", null);
223
				// Write out the configurable properties to a backup file
224
				// outside the install directory.
225

  
226
				PropertyService.persistMainBackupProperties();
243
                    
244
                }
245
			
227 246
			} catch (GeneralPropertyException gpe) {
228 247
				throw new AdminException("DBAdmin.configureDatabase - Problem getting or setting " +
229 248
						"property while upgrading database: " + gpe.getMessage());
......
803 822
				try {
804 823
					utility = (UpgradeUtilityInterface) Class.forName(className).newInstance();
805 824
					utility.upgrade();
825
				} catch (SolrSchemaModificationException e) {
826
				    //don't throw the exception and continue 
827
				    solrSchemaException = e;
828
				    continue;
806 829
				} catch (Exception e) {
807 830
					throw new AdminException("DBAdmin.upgradeDatabase - error getting utility class: " 
808 831
							+ className + ". Error message: "

Also available in: Unified diff