Project

General

Profile

« Previous | Next » 

Revision 6484

Don't use the hzNodes map yet (as a hazelcast client). Use D1Client instead to get the node list in isNodeAuthorized().

View differences:

src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
28 28
import java.util.Set;
29 29

  
30 30
import org.apache.log4j.Logger;
31
import org.dataone.client.CNode;
32
import org.dataone.client.D1Client;
31 33
import org.dataone.service.cn.v1.CNAuthorization;
32 34
import org.dataone.service.cn.v1.CNCore;
33 35
import org.dataone.service.cn.v1.CNRead;
......
775 777

  
776 778
	  boolean isAllowed = false;
777 779
	  SystemMetadata sysmeta = null;
778
    String query = "subject = '" + targetNodeSubject + "'";
779 780
    NodeReference targetNode = null;
780 781
    
781 782
	  try {
782
	    // get the target node reference from the hzNodes map
783
	    Set<Node> nodeList = (Set<Node>) 
784
	      HazelcastService.getInstance().getNodesMap().values(new SqlPredicate(query));
783
	    // get the target node reference from the nodes list
784
	    CNode cn = D1Client.getCN();
785
	    List<Node> nodes = (List<Node>) cn.listNodes();
786

  
787
	    for ( Node node : nodes ) {
788
	        Subject nodeSubject = node.getSubject(0);
789
	        if (nodeSubject.getValue().equals(targetNodeSubject)) {
790
	            targetNode = node.getIdentifier();
791
	            
792
	        }
793
	    }
785 794
	    
786
	    // we should only have one subject DN per node
787
	    for (Node node : nodeList) {      
788
	      targetNode = node.getIdentifier();
789
	      break;
790
	        
791
      }
795

  
792 796
	    //lock, get, and unlock the pid
793 797
	    HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
794 798
	    sysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
795 799
	    HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
796 800
	    List<Replica> replicaList = sysmeta.getReplicaList();
797 801
	    
798
	    // find the replica with the status set to 'requested'
799
	    for(Replica replica : replicaList) {
800
	      ReplicationStatus status = replica.getReplicationStatus();
801
	      NodeReference listedNode = replica.getReplicaMemberNode();
802
	      if ( listedNode.equals(targetNode) && 
803
	           status.equals(ReplicationStatus.REQUESTED)) {
804
	        isAllowed = true;
805
	        break;
806
	        
807
	      }
808
	    }
802
        // find the replica with the status set to 'requested'
803
        for (Replica replica : replicaList) {
804
            ReplicationStatus status = replica.getReplicationStatus();
805
            NodeReference listedNode = replica.getReplicaMemberNode();
806
            if (listedNode.equals(targetNode)
807
                    && status.equals(ReplicationStatus.REQUESTED)) {
808
                isAllowed = true;
809
                break;
809 810

  
811
            }
812
        }
813

  
810 814
	  } catch(Exception e) {
811 815
	    // Catch Hazelcast RuntimeExceptions
812 816
	    

Also available in: Unified diff