Project

General

Profile

« Previous | Next » 

Revision 6657

Changes to setReplicationStatus and isNodeAuthorized(), working out minor bugs in replication.

View differences:

src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
80 80
import edu.ucsb.nceas.metacat.IdentifierManager;
81 81
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
82 82
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService;
83
import edu.ucsb.nceas.utilities.Log;
83 84

  
84 85
/**
85 86
 * Represents Metacat's implementation of the DataONE Coordinating Node 
......
214 215
      try {      
215 216
          HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
216 217
          systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
217
          
218

  
219
          if ( systemMetadata == null ) {
220
              logMetacat.debug("systemMetadata is null for " + pid.getValue());
221
              
222
          }
218 223
          replicas = systemMetadata.getReplicaList();
219 224
          int count = 0;
220 225
          
226
          if ( replicas == null || replicas.size() < 1 ) {
227
              logMetacat.debug("no replicas to evaluate");
228
              
229
          }
230

  
221 231
          // find the target replica index in the replica list
222 232
          for (Replica replica: replicas) {
223
              if (replica.getReplicaMemberNode().getValue().equals(targetNode.getValue())) {
233
              String replicaNodeStr = replica.getReplicaMemberNode().getValue();
234
              String targetNodeStr = targetNode.getValue();
235
              logMetacat.debug("Comparing " + replicaNodeStr + " to " + targetNodeStr);
236
              
237
              if (replicaNodeStr.equals(targetNodeStr)) {
224 238
                  replicaEntryIndex = count;
239
                  logMetacat.debug("replica entry index is: " + replicaEntryIndex);
225 240
                  break;
226 241
              }
227 242
              count++;
......
841 856
      CNode cn = D1Client.getCN();
842 857
      List<Node> nodes = cn.listNodes().getNodeList();
843 858

  
844
      for ( Node node : nodes ) {
845
          Subject nodeSubject = node.getSubject(0);
846
          if (nodeSubject.getValue().equals(targetNodeSubject)) {
847
              targetNode = node.getIdentifier();
848
              
849
          }
859
      if ( nodes != null ) {
860
        for (Node node : nodes) {
861
            for (Subject nodeSubject : node.getSubjectList()) {
862
                if (nodeSubject.getValue().equals(targetNodeSubject.getValue())) {
863
                    targetNode = node.getIdentifier();
864
                    logMetacat.debug("targetNode is : " + targetNode.getValue());
865
                    break;
866
                }
867

  
868
            }
869
            
870
            if ( targetNode != null ) {
871
                break;
872
            }
873
        }
874
        
875
      } else {
876
          String msg = "Couldn't get the node list from the CN";
877
          logMetacat.debug(msg);
878
          throw new ServiceFailure("4872", msg);
879
          
850 880
      }
851
      
852

  
853 881
      //lock, get, and unlock the pid
854 882
      HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
883
      logMetacat.debug("Getting system metadata for identifier " + pid.getValue());
884
      
855 885
      sysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
856
      List<Replica> replicaList = sysmeta.getReplicaList();
857
      
858
      // find the replica with the status set to 'requested'
859
      for (Replica replica : replicaList) {
860
          ReplicationStatus status = replica.getReplicationStatus();
861
          NodeReference listedNode = replica.getReplicaMemberNode();
862
          if (listedNode.equals(targetNode)
863
                  && status.equals(ReplicationStatus.REQUESTED)) {
864
              isAllowed = true;
865
              break;
866 886

  
887
      if ( sysmeta != null ) {
888
          
889
          List<Replica> replicaList = sysmeta.getReplicaList();
890
          
891
          if ( replicaList != null ) {
892
              
893
              logMetacat.debug("Replica list for identifier " + pid.getValue() +
894
                  " is " + replicaList.size());
895
              // find the replica with the status set to 'requested'
896
              for (Replica replica : replicaList) {
897
                  ReplicationStatus status = replica.getReplicationStatus();
898
                  NodeReference listedNode = replica.getReplicaMemberNode();
899
                  logMetacat.debug("Comparing " + listedNode.getValue() + " to " + 
900
                      targetNode.getValue());
901
                  if (listedNode.getValue().equals(targetNode.getValue())
902
                          && status.equals(ReplicationStatus.REQUESTED)) {
903
                      isAllowed = true;
904
                      break;
905

  
906
                  }
907
              }
867 908
          }
909
          
910
          
911
      } else {
912
          logMetacat.debug("System metadata for identifier " + pid.getValue() +
913
          " is null.");          
914
          
868 915
      }
869
      
870 916
      HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
871 917

  
918
    } catch(RuntimeException e) {
919
        // Catch Hazelcast RuntimeExceptions
920
        throw new ServiceFailure("4872", 
921
            "RuntimeException: Couldn't determine if node is allowed.");  
922
        
872 923
    } catch(Exception e) {
873
    	ServiceFailure sf = new ServiceFailure("4872", 
874
                "Couldn't determine if node is allowed: " + 
924
        throw new ServiceFailure("4872", 
925
                "General Exception: Couldn't determine if node is allowed: " + 
875 926
                e.getMessage());
876
    	sf.initCause(e);
877
        throw sf;
878 927
        
879 928
    } finally {
880 929
      // always unlock the pid
......
1149 1198

  
1150 1199
        return objectList;
1151 1200
  }
1201
    
1152 1202
}

Also available in: Unified diff