Revision 6578
Added by Chris Jones about 13 years ago
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java | ||
---|---|---|
1055 | 1055 |
return success; |
1056 | 1056 |
} |
1057 | 1057 |
|
1058 |
/** |
|
1059 |
* Full replacement of replication metadata in the system metadata for the |
|
1060 |
* specified object, changes date system metadata modified |
|
1061 |
* |
|
1062 |
* @param session - the Session object containing the credentials for the Subject |
|
1063 |
* @param pid - the object identifier for the given object to apply the policy |
|
1064 |
* @param replica - the replica to be updated |
|
1065 |
* @return |
|
1066 |
* @throws NotImplemented |
|
1067 |
* @throws NotAuthorized |
|
1068 |
* @throws ServiceFailure |
|
1069 |
* @throws InvalidRequest |
|
1070 |
* @throws NotFound |
|
1071 |
*/ |
|
1072 |
public boolean updateReplicationMetadata(Session session, Identifier pid, |
|
1073 |
Replica replica) |
|
1074 |
throws NotImplemented, NotAuthorized, ServiceFailure, InvalidRequest, |
|
1075 |
NotFound { |
|
1076 |
|
|
1077 |
// get the subject |
|
1078 |
Subject subject = session.getSubject(); |
|
1079 |
|
|
1080 |
// are we allowed to do this? |
|
1081 |
try { |
|
1082 |
// what is the controlling permission? |
|
1083 |
if (!isAuthorized(session, pid, Permission.WRITE)) { |
|
1084 |
throw new NotAuthorized("4851", "not allowed by " + subject.getValue() + |
|
1085 |
" on " + pid.getValue()); |
|
1086 |
} |
|
1087 |
|
|
1088 |
} catch (InvalidToken e) { |
|
1089 |
throw new NotAuthorized("4851", "not allowed by " + subject.getValue() + |
|
1090 |
" on " + pid.getValue()); |
|
1091 |
|
|
1092 |
} |
|
1093 |
|
|
1094 |
SystemMetadata systemMetadata = null; |
|
1095 |
try { |
|
1096 |
HazelcastService.getInstance().getSystemMetadataMap().lock(pid); |
|
1097 |
systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid); |
|
1098 |
|
|
1099 |
} catch (Exception e) { // Catch is generic since HZ throws RuntimeException |
|
1100 |
throw new NotFound("4854", "No record found for: " + pid.getValue() + |
|
1101 |
" : " + e.getMessage()); |
|
1102 |
|
|
1103 |
} |
|
1104 |
|
|
1105 |
// set the status for the replica |
|
1106 |
List<Replica> replicas = systemMetadata.getReplicaList(); |
|
1107 |
NodeReference replicaNode = replica.getReplicaMemberNode(); |
|
1108 |
int index = 0; |
|
1109 |
for (Replica listedReplica: replicas) { |
|
1110 |
|
|
1111 |
// remove the replica that we are replacing |
|
1112 |
if ( replicaNode.getValue().equals(listedReplica.getReplicaMemberNode().getValue())) { |
|
1113 |
replicas.remove(index); |
|
1114 |
break; |
|
1115 |
|
|
1116 |
} |
|
1117 |
index++; |
|
1118 |
} |
|
1119 |
|
|
1120 |
// add the new replica item |
|
1121 |
replicas.add(replica); |
|
1122 |
systemMetadata.setReplicaList(replicas); |
|
1123 |
|
|
1124 |
// update the metadata |
|
1125 |
try { |
|
1126 |
systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE)); |
|
1127 |
systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime()); |
|
1128 |
HazelcastService.getInstance().getSystemMetadataMap().put(systemMetadata.getIdentifier(), systemMetadata); |
|
1129 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(systemMetadata.getIdentifier()); |
|
1130 |
|
|
1131 |
} catch (Exception e) { |
|
1132 |
throw new ServiceFailure("4852", e.getMessage()); |
|
1133 |
|
|
1134 |
} finally { |
|
1135 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(systemMetadata.getIdentifier()); |
|
1136 |
|
|
1137 |
} |
|
1138 |
|
|
1139 |
return true; |
|
1140 |
|
|
1141 |
} |
|
1058 | 1142 |
} |
Also available in: Unified diff
Add updateReplicationMetadata() to the CN service implementation. This was missing from the API, and likely never called. It fully replaces the given replica item in the list of replicas in system metadata.