Project

General

Profile

« Previous | Next » 

Revision 6119

include System Metadata forced replication - just need to figure out when to call it!

View differences:

src/edu/ucsb/nceas/metacat/replication/ReplicationService.java
1040 1040
		}
1041 1041

  
1042 1042
	}
1043
	
1044
	/**
1045
	 * when a forcereplication request comes in, local host sends a read request
1046
	 * to the requesting server (remote server) for the specified docid. Then
1047
	 * store it in local database.
1048
	 */
1049
	protected static void handleForceReplicateSystemMetadataRequest(
1050
			Hashtable<String, String[]> params, HttpServletResponse response,
1051
			HttpServletRequest request) {
1052
		String server = ((String[]) params.get("server"))[0]; // the server that
1053
		String guid = ((String[]) params.get("guid"))[0]; // sent the document
1054
		
1055
		try {
1056
			logReplication.info("ReplicationService.handleForceReplicateSystemMetadataRequest - Force replication system metadata request from: " + server);
1057
			// get the system metadata from server
1058
			URL docinfourl = new URL("https://" + server + "?server="
1059
					+ MetacatUtil.getLocalReplicationServerName()
1060
					+ "&action=getsystemmetadata&guid=" + guid);
1061
			
1062
			String systemMetadataXML = ReplicationService.getURLContent(docinfourl);
1063
						
1064
			// process system metadata
1065
			if (systemMetadataXML != null) {
1066
				SystemMetadata sysMeta = 
1067
					(SystemMetadata) ServiceTypeUtil.deserializeServiceType(
1068
							SystemMetadata.class,
1069
							new ByteArrayInputStream(systemMetadataXML.getBytes("UTF-8")));
1070
				if (!IdentifierManager.getInstance().identifierExists(guid)) {
1071
					logReplication.debug("Creating system metadata for guid: " + guid);
1072
					IdentifierManager.getInstance().createSystemMetadata(sysMeta);
1073
				}
1074
				IdentifierManager.getInstance().updateSystemMetadata(sysMeta);
1075
			}
1076
      
1077
			logReplication.info("ReplicationService.handleForceReplicateSystemMetadataRequest - processed guid: " + guid);
1078
			EventLog.getInstance().log(request.getRemoteAddr(), REPLICATIONUSER, guid, "systemMetadata");
1043 1079

  
1080
		} catch (Exception e) {
1081
			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG, e);                         
1082
			logReplication.error("ReplicationService.handleForceReplicateRequest - General error when processing guid: " + guid, e);
1083
		}
1084
	}
1085

  
1044 1086
	/**
1045 1087
	 * Sends a datafile to a remote host
1046 1088
	 */
src/edu/ucsb/nceas/metacat/replication/ForceReplicationSystemMetadataHandler.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A class to asyncronously force the replication of each server
4
 *             that has an entry in the xml_replication table.  When run,
5
 *             this thread communicates with each server in the list and
6
 *             solicites a read of an updated or newly inserted document
7
 *             with a certain docid.
8
 *  Copyright: 2000 Regents of the University of California and the
9
 *             National Center for Ecological Analysis and Synthesis
10
 *    Authors: Chad Berkley
11
 *
12
 *   '$Author: daigle $'
13
 *     '$Date: 2009-08-24 13:34:17 -0800 (Mon, 24 Aug 2009) $'
14
 * '$Revision: 5030 $'
15
 *
16
 * This program is free software; you can redistribute it and/or modify
17
 * it under the terms of the GNU General Public License as published by
18
 * the Free Software Foundation; either version 2 of the License, or
19
 * (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29
 */
30

  
31
package edu.ucsb.nceas.metacat.replication;
32

  
33
import java.net.URL;
34

  
35
import org.apache.log4j.Logger;
36

  
37
import edu.ucsb.nceas.metacat.properties.PropertyService;
38
import edu.ucsb.nceas.metacat.util.MetacatUtil;
39
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
40

  
41
/**
42
 * A class to asyncronously force the replication of each server
43
 * that has an entry in the xml_replication table.  When run,
44
 * this thread communicates with each server in the list and
45
 * forces replication of system metadata
46
 */
47
public class ForceReplicationSystemMetadataHandler implements Runnable
48
{
49
  private Thread btThread;
50
  private String guid;
51
    
52
  private ReplicationServerList serverLists = null;
53

  
54
  private String notificationServer = null;
55
  private static Logger logReplication = Logger.getLogger("ReplicationLogging");
56
  private static Logger logMetacat = Logger.getLogger(ForceReplicationSystemMetadataHandler.class);
57
 
58
  /**
59
   * Use this constructor when the action is implied.
60
   */
61
  public ForceReplicationSystemMetadataHandler(String docid, boolean xml,
62
                                                String myNotificationServer )
63
  {
64
    this.guid = docid;
65
    // Build a severLists from xml_replication table
66
    this.serverLists = new ReplicationServerList();
67
   
68
    // Get notification server
69
    this.notificationServer = myNotificationServer;
70
    btThread = new Thread(this);
71
    btThread.setPriority(Thread.MIN_PRIORITY);
72
    btThread.start();
73
  }
74

  
75
  /**
76
   * Method to send force replication command to other server to get
77
   * a new or updated docid
78
   */
79
  public void run()
80
  {
81

  
82
    
83
	    // URL for notification
84
	    URL comeAndGetIt = null;
85
		// If no server in xml_replication table we are done
86
		if (serverLists.isEmpty()) {
87
			return;
88
		}
89

  
90
		// Thread sleeping for some seconds to make sure the document was insert
91
		// into the database before we send force replication request
92
		int sleepTime;
93
		try {
94
			sleepTime = Integer.parseInt(PropertyService.getProperty("replication.forcereplicationwaitingtime"));
95
			Thread.sleep(sleepTime);
96
		} catch (PropertyNotFoundException pnfe) {
97
	    	logMetacat.error(ReplicationService.METACAT_REPL_ERROR_MSG);
98
			logReplication.error("Property error: " + pnfe.getMessage());
99
		} catch (InterruptedException ie) {
100
	    	logMetacat.error(ReplicationService.METACAT_REPL_ERROR_MSG);
101
			logReplication.error("Thread sleep error: " + ie.getMessage());
102
		}
103
		logReplication.info("Notification server:" + notificationServer);
104
		// Check every server in the serverlists
105
		for (int i = 0; i < serverLists.size(); i++) {
106
			//Set comeAndGetIt null
107
			comeAndGetIt = null;
108
			// Get ReplicationServer object in index i
109
			ReplicationServer replicationServer = serverLists.serverAt(i);
110
			// Get this ReplicationServer 's name
111
			String server = replicationServer.getServerName();
112
			try {
113

  
114
				// If the server is the notification server, we don't notify it back
115
				// again, if server is null we don't replicate to
116
				if (server != null && !server.equals(notificationServer)) {
117

  
118
					comeAndGetIt = new URL("https://" + server
119
							+ "?action=forcereplicatesystemmetadata"
120
							+ "&guid=" + guid + "&server="
121
							+ MetacatUtil.getLocalReplicationServerName());
122

  
123
					// Make sure comeAndGetIt is not empty
124
					if (comeAndGetIt != null && !comeAndGetIt.equals("")) {
125
						logReplication.warn("Sending message: " + comeAndGetIt.toString());
126
						String message = ReplicationService.getURLContent(comeAndGetIt);
127
					}
128
				}
129
			} catch (Exception e) {
130
		    	logMetacat.error(ReplicationService.METACAT_REPL_ERROR_MSG, e);
131
				logReplication.error("Error forcing System Metadata replication");
132
			}
133
			
134
		}
135

  
136
		logReplication.warn("Exiting Forced System Metadata Thread");
137
	}
138
}
src/edu/ucsb/nceas/metacat/replication/ReplicationServlet.java
190 190
				// local host
191 191
				ReplicationService.handleForceReplicateRequest(params, response,
192 192
						request);
193
			} else if (action.equals("forcereplicatesystemmetadata")) {
194
				ReplicationService.handleForceReplicateSystemMetadataRequest(params, response,
195
						request);
193 196
			} else if (action.equals("forcereplicatedelete")) {
194 197
				// read a specific docid from remote host, and store it into
195 198
				// local host

Also available in: Unified diff