Project

General

Profile

« Previous | Next » 

Revision 6988

Added by Matt Jones over 12 years ago

Added new methods to generate a default replication policy based on properties from the metacat configuration. This is called during system metadata creation for objects that lack any system metadata.

View differences:

src/edu/ucsb/nceas/metacat/dataone/SystemMetadataFactory.java
61 61
import org.dataone.service.types.v1.Identifier;
62 62
import org.dataone.service.types.v1.NodeReference;
63 63
import org.dataone.service.types.v1.ObjectFormatIdentifier;
64
import org.dataone.service.types.v1.ReplicationPolicy;
64 65
import org.dataone.service.types.v1.Session;
65 66
import org.dataone.service.types.v1.Subject;
66 67
import org.dataone.service.types.v1.SystemMetadata;
......
289 290
		sysMeta.setOriginMemberNode(nr);
290 291
		sysMeta.setAuthoritativeMemberNode(nr);
291 292
		
293
		// Set a default replication policy
294
        ReplicationPolicy rp = getDefaultReplicationPolicy();
295
        if (rp != null) {
296
            sysMeta.setReplicationPolicy(rp);
297
        }
298
		
292 299
		// further parse EML documents to get data object format,
293 300
		// describes and describedBy information
294 301
		if (fmtid == ObjectFormatCache.getInstance().getFormat(
......
556 563

  
557 564
		return sysMeta;
558 565
	}
559
	
560
	/**
566

  
567
    /**
561 568
     * Generate SystemMetadata for any object in the object store that does
562 569
     * not already have it.  SystemMetadata documents themselves, are, of course,
563 570
     * exempt.  This is a utility method for migration of existing object 
......
692 699
		
693 700
		return documentFile;
694 701
	}
702

  
703
	/**
704
	 * Create a default ReplicationPolicy by reading properties from metacat's configuration
705
	 * and using those defaults. If the numReplicas property is not found, malformed, or less
706
	 * than or equal to zero, no policy needs to be set, so return null.
707
	 * @return ReplicationPolicy, or null if no replication policy is needed
708
	 */
709
    private static ReplicationPolicy getDefaultReplicationPolicy() {
710
        ReplicationPolicy rp = null;
711
        int numReplicas = -1;
712
        try {
713
            numReplicas = new Integer(PropertyService.getProperty("dataone.replicationpolicy.default.numreplicas"));
714
        } catch (NumberFormatException e) {
715
            // The property is not a valid integer, so return a null policy
716
            return null;
717
        } catch (PropertyNotFoundException e) {
718
            // The property is not found, so return a null policy
719
            return null;
720
        }
721
        
722
        if (numReplicas > 0) {
723
            rp = new ReplicationPolicy();
724
            rp.setReplicationAllowed(true);
725
            rp.setNumberReplicas(numReplicas);
726
            try {
727
                String preferredNodeList = PropertyService.getProperty("dataone.replicationpolicy.default.preferredNodeList");
728
                if (preferredNodeList != null) {
729
                    List<NodeReference> pNodes = extractNodeReferences(preferredNodeList);
730
                    if (pNodes != null && !pNodes.isEmpty()) {
731
                        rp.setPreferredMemberNodeList(pNodes);
732
                    }
733
                }
734
            } catch (PropertyNotFoundException e) {
735
                // No preferred list found in properties, so just ignore it; no action needed
736
            }
737
            try {
738
                String blockedNodeList = PropertyService.getProperty("dataone.replicationpolicy.default.blockedNodeList");
739
                if (blockedNodeList != null) {
740
                    List<NodeReference> bNodes = extractNodeReferences(blockedNodeList);
741
                    if (bNodes != null && !bNodes.isEmpty()) {
742
                        rp.setPreferredMemberNodeList(bNodes);
743
                    }
744
                }
745
            } catch (PropertyNotFoundException e) {
746
                // No blocked list found in properties, so just ignore it; no action needed
747
            }
748
        }
749
        return rp;
750
    }
751

  
752
    /**
753
     * Extract a List of NodeReferences froma String listing the node identifiers where
754
     * each identifier is separated by whitespace, comma, or semicolon characters.
755
     * @param nodeString the string containing the list of nodes
756
     * @return the List of NodeReference objects parsed fromt he input string
757
     */
758
    private static List<NodeReference> extractNodeReferences(String nodeString) {
759
        List<NodeReference> nodeList = new ArrayList<NodeReference>();
760
        String[] result = nodeString.split("[,;\\s]*");
761
        for (String r : result) {
762
            NodeReference noderef = new NodeReference();
763
            noderef.setValue(r);
764
            nodeList.add(noderef);
765
        }
766
        return nodeList;
767
    }
695 768
}

Also available in: Unified diff