Revision 6568
Added by Chris Jones about 13 years ago
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java | ||
---|---|---|
256 | 256 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, |
257 | 257 |
InvalidRequest, NotImplemented { |
258 | 258 |
|
259 |
|
|
260 |
// get the system metadata |
|
261 |
String guid1 = pidOfSubject.getValue(); |
|
259 |
boolean asserted = false; |
|
260 |
|
|
262 | 261 |
// are we allowed to do this? |
263 | 262 |
if (!isAuthorized(session, pidOfSubject, Permission.READ)) { |
264 |
throw new NotAuthorized("4881", Permission.READ + " not allowed on " + guid1);
|
|
263 |
throw new NotAuthorized("4881", Permission.READ + " not allowed on " + pidOfSubject.getValue());
|
|
265 | 264 |
} |
266 | 265 |
|
267 | 266 |
SystemMetadata systemMetadata = null; |
268 | 267 |
try { |
269 |
systemMetadata = IdentifierManager.getInstance().getSystemMetadata(guid1); |
|
270 |
} catch (McdbDocNotFoundException e) { |
|
271 |
throw new NotFound("4884", "No record found for: " + guid1); |
|
272 |
} |
|
268 |
HazelcastService.getInstance().getSystemMetadataMap().lock(pidOfSubject); |
|
269 |
systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pidOfSubject); |
|
273 | 270 |
|
274 |
// check relationships |
|
275 |
// TODO: use ORE map |
|
276 |
if (relationship.equalsIgnoreCase("describes")) { |
|
271 |
|
|
272 |
// check relationships |
|
273 |
// TODO: use ORE map |
|
274 |
if (relationship.equalsIgnoreCase("describes")) { |
|
275 |
|
|
276 |
} |
|
277 |
|
|
278 |
if (relationship.equalsIgnoreCase("describedBy")) { |
|
279 |
|
|
280 |
} |
|
281 |
|
|
282 |
if (relationship.equalsIgnoreCase("derivedFrom")) { |
|
283 |
|
|
284 |
} |
|
285 |
|
|
286 |
if (relationship.equalsIgnoreCase("obsoletes")) { |
|
287 |
Identifier pid = systemMetadata.getObsoletes(); |
|
288 |
if (pid.getValue().equals(pidOfObject.getValue())) { |
|
289 |
asserted = true; |
|
290 |
|
|
291 |
} |
|
292 |
//return systemMetadata.getObsoleteList().contains(pidOfObject); |
|
293 |
} |
|
294 |
if (relationship.equalsIgnoreCase("obsoletedBy")) { |
|
295 |
Identifier pid = systemMetadata.getObsoletedBy(); |
|
296 |
if (pid.getValue().equals(pidOfObject.getValue())) { |
|
297 |
asserted = true; |
|
298 |
|
|
299 |
} |
|
300 |
//return systemMetadata.getObsoletedByList().contains(pidOfObject); |
|
301 |
} |
|
302 |
|
|
303 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(pidOfSubject); |
|
277 | 304 |
|
278 |
} |
|
279 |
if (relationship.equalsIgnoreCase("describedBy")) { |
|
305 |
} catch (Exception e) { |
|
306 |
throw new ServiceFailure("4270", "Could not assert relation for: " + |
|
307 |
pidOfSubject.getValue() + |
|
308 |
". The error message was: " + e.getMessage()); |
|
280 | 309 |
|
310 |
} finally { |
|
311 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(pidOfSubject); |
|
312 |
|
|
281 | 313 |
} |
282 |
if (relationship.equalsIgnoreCase("derivedFrom")) { |
|
283 |
|
|
284 |
} |
|
285 |
if (relationship.equalsIgnoreCase("obsoletes")) { |
|
286 |
Identifier pid = systemMetadata.getObsoletes(); |
|
287 |
if (pid.getValue().equals(pidOfObject.getValue())) { |
|
288 |
return true; |
|
289 |
} |
|
290 |
//return systemMetadata.getObsoleteList().contains(pidOfObject); |
|
291 |
} |
|
292 |
if (relationship.equalsIgnoreCase("obsoletedBy")) { |
|
293 |
Identifier pid = systemMetadata.getObsoletedBy(); |
|
294 |
if (pid.getValue().equals(pidOfObject.getValue())) { |
|
295 |
return true; |
|
296 |
} |
|
297 |
//return systemMetadata.getObsoletedByList().contains(pidOfObject); |
|
298 |
} |
|
299 |
|
|
300 |
return false; |
|
314 |
|
|
315 |
return asserted; |
|
301 | 316 |
} |
302 | 317 |
|
303 | 318 |
/** |
... | ... | |
319 | 334 |
public Checksum getChecksum(Session session, Identifier pid) |
320 | 335 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, |
321 | 336 |
InvalidRequest, NotImplemented { |
322 |
|
|
337 |
|
|
323 | 338 |
if (!isAuthorized(session, pid, Permission.READ)) { |
324 |
throw new NotAuthorized("1400", Permission.READ + " not allowed on " + pid.getValue()); |
|
339 |
throw new NotAuthorized("1400", Permission.READ + " not allowed on " + pid.getValue());
|
|
325 | 340 |
} |
341 |
|
|
326 | 342 |
SystemMetadata systemMetadata = null; |
343 |
Checksum checksum = null; |
|
344 |
|
|
327 | 345 |
try { |
328 |
systemMetadata = IdentifierManager.getInstance().getSystemMetadata(pid.getValue()); |
|
329 |
} catch (McdbDocNotFoundException e) { |
|
330 |
throw new NotFound("1420", "No record found for: " + pid.getValue()); |
|
346 |
HazelcastService.getInstance().getSystemMetadataMap().lock(pid); |
|
347 |
systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid); |
|
348 |
checksum = systemMetadata.getChecksum(); |
|
349 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid); |
|
350 |
|
|
351 |
} catch (Exception e) { |
|
352 |
throw new ServiceFailure("1410", "An error occurred getting the checksum for " + |
|
353 |
pid.getValue() + ". The error message was: " + e.getMessage()); |
|
354 |
|
|
355 |
} finally { |
|
356 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid); |
|
357 |
|
|
331 | 358 |
} |
332 |
Checksum checksum = systemMetadata.getChecksum(); |
|
333 | 359 |
|
334 | 360 |
return checksum; |
335 | 361 |
} |
... | ... | |
539 | 565 |
} |
540 | 566 |
|
541 | 567 |
// verify that guid == SystemMetadata.getIdentifier() |
542 |
logMetacat.debug("Comparing guid|sysmeta_guid: " + guid.getValue() + "|" + sysmeta.getIdentifier().getValue()); |
|
568 |
logMetacat.debug("Comparing guid|sysmeta_guid: " + guid.getValue() + |
|
569 |
"|" + sysmeta.getIdentifier().getValue()); |
|
543 | 570 |
if (!guid.getValue().equals(sysmeta.getIdentifier().getValue())) { |
544 | 571 |
throw new InvalidRequest("4863", |
545 |
"GUID in method call (" + guid.getValue() + ") does not match GUID in system metadata (" + |
|
572 |
"The identifier in method call (" + guid.getValue() + |
|
573 |
") does not match identifier in system metadata (" + |
|
546 | 574 |
sysmeta.getIdentifier().getValue() + ")."); |
547 | 575 |
} |
548 | 576 |
|
549 | 577 |
logMetacat.debug("Checking if identifier exists..."); |
550 | 578 |
// Check that the identifier does not already exist |
551 |
if (IdentifierManager.getInstance().identifierExists(guid.getValue())) {
|
|
579 |
if (HazelcastService.getInstance().getSystemMetadataMap().containsKey(guid)) {
|
|
552 | 580 |
throw new InvalidRequest("4863", |
553 |
"GUID is already in use by an existing object.");
|
|
581 |
"The identifier is already in use by an existing object.");
|
|
554 | 582 |
|
555 | 583 |
} |
556 |
|
|
584 |
|
|
557 | 585 |
// insert the system metadata into the object store |
558 | 586 |
logMetacat.debug("Starting to insert SystemMetadata..."); |
559 |
sysmeta.setDateSysMetadataModified(new Date()); |
|
560 | 587 |
try { |
561 |
HazelcastService.getInstance().getSystemMetadataMap().lock(sysmeta.getIdentifier()); |
|
562 |
HazelcastService.getInstance().getSystemMetadataMap().put(sysmeta.getIdentifier(), sysmeta); |
|
563 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(sysmeta.getIdentifier()); |
|
588 |
HazelcastService.getInstance().getSystemMetadataMap().lock(sysmeta.getIdentifier()); |
|
589 |
sysmeta.setSerialVersion(BigInteger.ONE); |
|
590 |
sysmeta.setDateSysMetadataModified(Calendar.getInstance().getTime()); |
|
591 |
HazelcastService.getInstance().getSystemMetadataMap().put(sysmeta.getIdentifier(), sysmeta); |
|
592 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(sysmeta.getIdentifier()); |
|
593 |
|
|
564 | 594 |
} catch (Exception e) { |
565 | 595 |
logMetacat.error("Problem registering system metadata: " + guid.getValue(), e); |
566 |
throw new ServiceFailure("4862", "Error inserting system metadata: " + e.getClass() + ": " + e.getMessage()); |
|
596 |
throw new ServiceFailure("4862", "Error inserting system metadata: " + |
|
597 |
e.getClass() + ": " + e.getMessage()); |
|
598 |
|
|
567 | 599 |
} finally { |
568 | 600 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(sysmeta.getIdentifier()); |
569 | 601 |
|
... | ... | |
823 | 855 |
//lock, get, and unlock the pid |
824 | 856 |
HazelcastService.getInstance().getSystemMetadataMap().lock(pid); |
825 | 857 |
sysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid); |
826 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid); |
|
827 | 858 |
List<Replica> replicaList = sysmeta.getReplicaList(); |
828 | 859 |
|
829 |
// find the replica with the status set to 'requested'
|
|
830 |
for (Replica replica : replicaList) {
|
|
831 |
ReplicationStatus status = replica.getReplicationStatus();
|
|
832 |
NodeReference listedNode = replica.getReplicaMemberNode();
|
|
833 |
if (listedNode.equals(targetNode)
|
|
834 |
&& status.equals(ReplicationStatus.REQUESTED)) {
|
|
835 |
isAllowed = true;
|
|
836 |
break;
|
|
860 |
// find the replica with the status set to 'requested' |
|
861 |
for (Replica replica : replicaList) { |
|
862 |
ReplicationStatus status = replica.getReplicationStatus(); |
|
863 |
NodeReference listedNode = replica.getReplicaMemberNode(); |
|
864 |
if (listedNode.equals(targetNode) |
|
865 |
&& status.equals(ReplicationStatus.REQUESTED)) { |
|
866 |
isAllowed = true; |
|
867 |
break; |
|
837 | 868 |
|
838 |
} |
|
839 |
} |
|
869 |
} |
|
870 |
} |
|
871 |
|
|
872 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid); |
|
840 | 873 |
|
841 | 874 |
} catch(Exception e) { |
842 |
// Catch Hazelcast RuntimeExceptions |
|
875 |
// Catch Hazelcast RuntimeExceptions |
|
876 |
throw new ServiceFailure("4872", |
|
877 |
"Couldn't determine if node is allowed: " + e.getMessage()); |
|
843 | 878 |
|
844 | 879 |
} finally { |
845 | 880 |
// always unlock the pid |
Also available in: Unified diff
Modify CNodeService's registerSystemMetadata() with support for SystemMetadata's serialVersion field. Also, use the hzSystemMetadata map for all system metadata reads using a lock on the pid in order to get the very latest version. This affected isNodeAuthorized(), getChecksum(), and assertRelation(). Since we're using Hazelcast, exceptions are masked as RuntimeException, so throw a ServiceFailure with the underlying message.