Project

General

Profile

« Previous | Next » 

Revision 6593

Update CNodeService to use the serialVersion parameter and compare it to the current serialVersion of the system metadata found in the hzSystemMetadata map. Throw an InvalidRequest exception if they are not equal. This affects updateReplicationMetadata(), setReplicationStatus(), setReplicationPolicy(), setAccessPolicy(), and setOwner().

View differences:

src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
126 126
   */
127 127
  @Override
128 128
  public boolean setReplicationPolicy(Session session, Identifier pid,
129
      ReplicationPolicy policy) 
129
      ReplicationPolicy policy, long serialVersion) 
130 130
      throws NotImplemented, NotFound, NotAuthorized, ServiceFailure, 
131 131
      InvalidRequest, InvalidToken {
132 132
      
......
144 144
          HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
145 145
          systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
146 146
        
147

  
148
          // does the request have the most current system metadata?
149
          if ( systemMetadata.getSerialVersion().longValue() != serialVersion ) {
150
             String msg = "The requested system metadata version number " + 
151
                 serialVersion + "differs from the current version at " +
152
                 systemMetadata.getSerialVersion().longValue() +
153
                 " Please get the latest copy in order to modify it.";
154
             throw new InvalidRequest("4883", msg);
155
          }
156
          
147 157
      } catch (Exception e) { // Catch is generic since HZ throws RuntimeException
148 158
        throw new NotFound("4884", "No record found for: " + pid.getValue());
149 159
        
......
189 199
   */
190 200
  @Override
191 201
  public boolean setReplicationStatus(Session session, Identifier pid,
192
    NodeReference targetNode, ReplicationStatus status) 
202
    NodeReference targetNode, ReplicationStatus status, long serialVersion) 
193 203
    throws ServiceFailure, NotImplemented, InvalidToken, NotAuthorized, 
194 204
    InvalidRequest, NotFound {
195 205

  
......
207 217
        HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
208 218
        systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
209 219

  
220

  
221
        // does the request have the most current system metadata?
222
        if ( systemMetadata.getSerialVersion().longValue() != serialVersion ) {
223
           String msg = "The requested system metadata version number " + 
224
               serialVersion + "differs from the current version at " +
225
               systemMetadata.getSerialVersion().longValue() +
226
               " Please get the latest copy in order to modify it.";
227
           throw new InvalidRequest("4730", msg);
228
        }
229
        
210 230
    } catch (Exception e) { // Catch is generic since HZ throws RuntimeException
211 231
      throw new NotFound("4740", "No record found for: " + pid.getValue() +
212 232
          " : " + e.getMessage());
......
791 811
   * @throws InvalidRequest
792 812
   */  
793 813
  @Override
794
  public Identifier setOwner(Session session, Identifier pid, Subject userId)
795
    throws InvalidToken, ServiceFailure, NotFound, NotAuthorized,
796
    NotImplemented, InvalidRequest {
797
    
798
    // get the subject
799
    Subject subject = session.getSubject();
800
    
801
    // are we allowed to do this?
802
    if (!isAuthorized(session, pid, Permission.CHANGE_PERMISSION)) {
803
      throw new NotAuthorized("4440", "not allowed by " + subject.getValue() + " on " + pid.getValue());  
804
    }
805
    
806
    SystemMetadata systemMetadata = null;
807
    try {
808
        HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
809
        systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
810
        
811
    } catch (Exception e) { // Catch is generic since HZ throws RuntimeException
812
        throw new NotFound("4460", "No record found for: " + pid.getValue());
813
        
814
    }
815
        
816
    // set the new rights holder
817
    systemMetadata.setRightsHolder(userId);
818
    
819
    // update the metadata
820
    try {
821
        systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
822
        systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
823
	      HazelcastService.getInstance().getSystemMetadataMap().put(pid, systemMetadata);
824
	      HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
825
	      
826
    } catch (Exception e) {
827
		throw new ServiceFailure("4490", e.getMessage());
828
		
829
	  } finally {
830
	      HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
831
	  }
832
    
833
    return pid;
814
  public Identifier setOwner(Session session, Identifier pid, Subject userId,
815
      long serialVersion)
816
      throws InvalidToken, ServiceFailure, NotFound, NotAuthorized,
817
      NotImplemented, InvalidRequest {
818
      
819
      // get the subject
820
      Subject subject = session.getSubject();
821
      
822
      // are we allowed to do this?
823
      if (!isAuthorized(session, pid, Permission.CHANGE_PERMISSION)) {
824
        throw new NotAuthorized("4440", "not allowed by " + subject.getValue() + " on " + pid.getValue());  
825
      }
826
      
827
      SystemMetadata systemMetadata = null;
828
      try {
829
          HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
830
          systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
831
          
832
          // does the request have the most current system metadata?
833
          if ( systemMetadata.getSerialVersion().longValue() != serialVersion ) {
834
             String msg = "The requested system metadata version number " + 
835
                 serialVersion + "differs from the current version at " +
836
                 systemMetadata.getSerialVersion().longValue() +
837
                 " Please get the latest copy in order to modify it.";
838
             throw new InvalidRequest("4442", msg);
839
          }
840
          
841
      } catch (Exception e) { // Catch is generic since HZ throws RuntimeException
842
          throw new NotFound("4460", "No record found for: " + pid.getValue());
843
          
844
      }
845
          
846
      // set the new rights holder
847
      systemMetadata.setRightsHolder(userId);
848
      
849
      // update the metadata
850
      try {
851
          systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
852
          systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
853
	        HazelcastService.getInstance().getSystemMetadataMap().put(pid, systemMetadata);
854
	        HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
855
	        
856
      } catch (Exception e) {
857
		  throw new ServiceFailure("4490", e.getMessage());
858
		  
859
	    } finally {
860
	        HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
861
	    }
862
      
863
      return pid;
834 864
  }
835 865

  
836 866
  /**
......
1002 1032
   * @throws InvalidRequest
1003 1033
   */
1004 1034
  public boolean setAccessPolicy(Session session, Identifier pid, 
1005
      AccessPolicy accessPolicy) 
1035
      AccessPolicy accessPolicy, long serialVersion) 
1006 1036
      throws InvalidToken, ServiceFailure, NotFound, NotAuthorized, 
1007 1037
      NotImplemented, InvalidRequest {
1008 1038
      
......
1018 1048
      }
1019 1049
      
1020 1050
      SystemMetadata systemMetadata = null;
1021
      
1022 1051
      try {
1023 1052
          HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
1024 1053
          systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
1025 1054

  
1055
          // does the request have the most current system metadata?
1056
          if ( systemMetadata.getSerialVersion().longValue() != serialVersion ) {
1057
             String msg = "The requested system metadata version number " + 
1058
                 serialVersion + "differs from the current version at " +
1059
                 systemMetadata.getSerialVersion().longValue() +
1060
                 " Please get the latest copy in order to modify it.";
1061
             throw new InvalidRequest("4402", msg);
1062
          }
1063
          
1026 1064
      } catch (Exception e) {
1027 1065
          // convert Hazelcast RuntimeException to NotFound
1028 1066
          throw new NotFound("4400", "No record found for: " + pid);
......
1034 1072
      
1035 1073
      // update the system metadata
1036 1074
      try {
1037
          // TODO: consult authoritative MN on current sysmeta serial version?
1038 1075
          systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
1039 1076
          systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
1040 1077
          HazelcastService.getInstance().getSystemMetadataMap().put(systemMetadata.getIdentifier(), systemMetadata);
......
1070 1107
   * @throws NotFound
1071 1108
   */
1072 1109
  public boolean updateReplicationMetadata(Session session, Identifier pid,
1073
      Replica replica) 
1110
      Replica replica, long serialVersion) 
1074 1111
      throws NotImplemented, NotAuthorized, ServiceFailure, InvalidRequest,
1075 1112
      NotFound {
1076 1113
      
......
1096 1133
          HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
1097 1134
          systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
1098 1135

  
1136
          // does the request have the most current system metadata?
1137
          if ( systemMetadata.getSerialVersion().longValue() != serialVersion ) {
1138
             String msg = "The requested system metadata version number " + 
1139
                 serialVersion + "differs from the current version at " +
1140
                 systemMetadata.getSerialVersion().longValue() +
1141
                 " Please get the latest copy in order to modify it.";
1142
             throw new InvalidRequest("4853", msg);
1143
          }
1144
          
1099 1145
      } catch (Exception e) { // Catch is generic since HZ throws RuntimeException
1100 1146
        throw new NotFound("4854", "No record found for: " + pid.getValue() +
1101 1147
            " : " + e.getMessage());

Also available in: Unified diff