Project

General

Profile

Revision 6448

do not send <systemMetadata> with the <docInfo> replication information - this is handled by the Hazelcast shared map

View differences:

src/edu/ucsb/nceas/metacat/util/ReplicationUtil.java
27 27
package edu.ucsb.nceas.metacat.util;
28 28

  
29 29
/**
30
 * A suite of utility classes for the metadata replication functions
30
 * A suite of utility classes for the system metadata replication functions
31
 * @deprecated
31 32
 */
32 33
public class ReplicationUtil {
33 34
	  
src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java
26 26

  
27 27
package edu.ucsb.nceas.metacat.replication;
28 28

  
29
import java.io.ByteArrayInputStream;
30
import java.io.InputStream;
31
import java.io.StringReader;
32
import java.net.InetAddress;
33
import java.net.URL;
34
import java.net.UnknownHostException;
35
import java.sql.PreparedStatement;
36
import java.sql.ResultSet;
37
import java.sql.SQLException;
38
import java.text.DateFormat;
39
import java.text.ParseException;
40
import java.util.Date;
41
import java.util.Hashtable;
42
import java.util.TimerTask;
43
import java.util.Vector;
44

  
45
import org.apache.log4j.Logger;
46
import org.dataone.service.types.v1.SystemMetadata;
47
import org.dataone.service.util.TypeMarshaller;
48
import org.xml.sax.ContentHandler;
49
import org.xml.sax.ErrorHandler;
50
import org.xml.sax.InputSource;
51
import org.xml.sax.SAXException;
52
import org.xml.sax.XMLReader;
53
import org.xml.sax.helpers.DefaultHandler;
54
import org.xml.sax.helpers.XMLReaderFactory;
55

  
29 56
import edu.ucsb.nceas.metacat.CatalogMessageHandler;
30 57
import edu.ucsb.nceas.metacat.DBUtil;
31 58
import edu.ucsb.nceas.metacat.DocInfoHandler;
......
43 70
import edu.ucsb.nceas.metacat.properties.PropertyService;
44 71
import edu.ucsb.nceas.metacat.shared.HandlerException;
45 72
import edu.ucsb.nceas.metacat.util.MetacatUtil;
46
import edu.ucsb.nceas.metacat.util.ReplicationUtil;
47
import edu.ucsb.nceas.metacat.IdentifierManager;
48 73
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
49 74

  
50
import java.sql.*;
51
import java.util.*;
52
import java.util.Date;
53
import java.io.*;
54
import java.net.*;
55
import java.text.*;
56 75

  
57
import org.apache.log4j.Logger;
58
import org.dataone.service.types.v1.SystemMetadata;
59
import org.dataone.service.util.TypeMarshaller;
60
import org.xml.sax.ContentHandler;
61
import org.xml.sax.ErrorHandler;
62
import org.xml.sax.InputSource;
63
import org.xml.sax.SAXException;
64
import org.xml.sax.XMLReader;
65
import org.xml.sax.helpers.XMLReaderFactory;
66
import org.xml.sax.helpers.DefaultHandler;
67 76

  
68

  
69

  
70 77
/**
71 78
 * This class handles deltaT replication checking.  Whenever this TimerTask
72 79
 * is fired it checks each server in xml_replication for updates and updates
......
373 380
      logReplication.info("ReplicationHandler.handleSingleXMLDocument - Sending message: " + docinfoUrl.toString());
374 381
      String docInfoStr = ReplicationService.getURLContent(docinfoUrl);
375 382
      
376
      // strip out the system metadata portion
377
      String systemMetadataXML = ReplicationUtil.getSystemMetadataContent(docInfoStr);
378
   	  docInfoStr = ReplicationUtil.getContentWithoutSystemMetadata(docInfoStr);
379
      
380 383
      docinfoParser.parse(new InputSource(new StringReader(docInfoStr)));
381 384
      Hashtable<String, String> docinfoHash = dih.getDocInfo();
382 385
      // Get home server of the docid
......
440 443
          }
441 444
      }
442 445
      
443
      // process system metadata
444
      if (systemMetadataXML != null) {
445
    	  SystemMetadata sysMeta = 
446
    		  TypeMarshaller.unmarshalTypeFromStream(
447
    				  SystemMetadata.class, 
448
    				  new ByteArrayInputStream(systemMetadataXML.getBytes("UTF-8")));
449
    	  HazelcastService.getInstance().getSystemMetadataMap().put(sysMeta.getIdentifier(), sysMeta);
450
      }
451
      
452 446
      logReplication.info("ReplicationHandler.handleSingleXMLDocument - Successfully replicated doc " + accNumber);
453 447
      if (tableName.equals(DocumentImpl.DOCUMENTTABLE))
454 448
      {
......
529 523

  
530 524
      String docInfoStr = ReplicationService.getURLContent(docinfoUrl);
531 525
      
532
      // strip out the system metadata portion
533
      String systemMetadataXML = ReplicationUtil.getSystemMetadataContent(docInfoStr);
534
   	  docInfoStr = ReplicationUtil.getContentWithoutSystemMetadata(docInfoStr);  
535
   	  
536 526
      docinfoParser.parse(new InputSource(new StringReader(docInfoStr)));
537 527
      Hashtable<String, String> docinfoHash = dih.getDocInfo();
538 528
      
......
589 579
            }
590 580
        }
591 581
        
592
        //process guid
593
     // process system metadata
594
        if (systemMetadataXML != null) {
595
      	  SystemMetadata sysMeta = 
596
      		TypeMarshaller.unmarshalTypeFromStream(
597
      				  SystemMetadata.class, 
598
      				  new ByteArrayInputStream(systemMetadataXML.getBytes("UTF-8")));
599
      	  HazelcastService.getInstance().getSystemMetadataMap().put(sysMeta.getIdentifier(), sysMeta);
600
        }
601
        
602 582
        logReplication.info("ReplicationHandler.handleSingleDataFile - Successfully to write datafile " + accNumber);
603 583
        /*MetacatReplication.replLog("wrote datafile " + accNumber + " from " +
604 584
                                    remote server);*/
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java
47 47
import java.sql.SQLException;
48 48
import java.text.SimpleDateFormat;
49 49
import java.util.Date;
50
import java.util.Enumeration;
51 50
import java.util.Hashtable;
52 51
import java.util.List;
53 52
import java.util.Timer;
......
85 84
import edu.ucsb.nceas.metacat.shared.ServiceException;
86 85
import edu.ucsb.nceas.metacat.util.DocumentUtil;
87 86
import edu.ucsb.nceas.metacat.util.MetacatUtil;
88
import edu.ucsb.nceas.metacat.util.ReplicationUtil;
89 87
import edu.ucsb.nceas.metacat.util.SystemUtil;
90 88
import edu.ucsb.nceas.utilities.FileUtil;
91 89
import edu.ucsb.nceas.utilities.GeneralPropertyException;
......
570 568
			
571 569

  
572 570
			String docInfoStr = ReplicationService.getURLContent(docinfourl);
573
			// strip out the system metadata portion
574
			String systemMetadataXML = ReplicationUtil.getSystemMetadataContent(docInfoStr);
575
			docInfoStr = ReplicationUtil.getContentWithoutSystemMetadata(docInfoStr);
576
		   	  
571

  
577 572
			//dih is the parser for the docinfo xml format
578 573
			DocInfoHandler dih = new DocInfoHandler();
579 574
			XMLReader docinfoParser = ReplicationHandler.initParser(dih);
......
583 578
			
584 579
			// Get home server of this docid
585 580
			String homeServer = (String) docinfoHash.get("home_server");
586
			
587
			// process system metadata
588
			if (systemMetadataXML != null) {
589
				SystemMetadata sysMeta = 
590
					TypeMarshaller.unmarshalTypeFromStream(
591
							SystemMetadata.class,
592
							new ByteArrayInputStream(systemMetadataXML.getBytes("UTF-8")));
593
				HazelcastService.getInstance().getSystemMetadataMap().put(sysMeta.getIdentifier(), sysMeta);
594
			}
595 581
      
596 582
        	// replicate doc contents
597 583
			String createdDate = (String) docinfoHash.get("date_created");
......
788 774

  
789 775
			String docInfoStr = ReplicationService.getURLContent(docinfourl);
790 776
			
791
			// strip out the system metadata portion
792
		    String systemMetadataXML = ReplicationUtil.getSystemMetadataContent(docInfoStr);
793
		   	docInfoStr = ReplicationUtil.getContentWithoutSystemMetadata(docInfoStr);
794

  
795 777
			//dih is the parser for the docinfo xml format
796 778
			DocInfoHandler dih = new DocInfoHandler();
797 779
			XMLReader docinfoParser = ReplicationHandler.initParser(dih);
......
850 832
		        		}
851 833
		            }
852 834
		        }
853
		        
854
		        // process system metadata
855
		        if (systemMetadataXML != null) {
856
		      	  SystemMetadata sysMeta = 
857
		      		TypeMarshaller.unmarshalTypeFromStream(
858
		      				  SystemMetadata.class, 
859
		      				  new ByteArrayInputStream(systemMetadataXML.getBytes("UTF-8")));
860
		      	  HazelcastService.getInstance().getSystemMetadataMap().put(sysMeta.getIdentifier(), sysMeta);
861
		        }
862 835

  
863 836
				if (writeException != null) {
864 837
					throw writeException;
......
949 922
			DocumentImpl doc = new DocumentImpl(docid);
950 923
			sb.append("<documentinfo><docid>").append(docid);
951 924
			sb.append("</docid>");
952
			
953
			try {
954
				// serialize the System Metadata as XML for docinfo
955
				String guid = IdentifierManager.getInstance().getGUID(doc.getDocID(), doc.getRev());
956
				SystemMetadata systemMetadata = IdentifierManager.getInstance().getSystemMetadata(guid);
957
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
958
				TypeMarshaller.marshalTypeToOutputStream(systemMetadata, baos);
959
				String systemMetadataXML = baos.toString("UTF-8");
960
				sb.append("<systemMetadata>");
961
				sb.append(systemMetadataXML);
962
				sb.append("</systemMetadata>");
963
			} catch(McdbDocNotFoundException e) {
964
			  logMetacat.warn("No SystemMetadata found for: " + docid);
965
			}
966 925
			sb.append("<docname>").append(doc.getDocname());
967 926
			sb.append("</docname><doctype>").append(doc.getDoctype());
968 927
			sb.append("</doctype>");

Also available in: Unified diff