Revision 6786
Added by Chris Jones about 13 years ago
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java | ||
---|---|---|
419 | 419 |
* @throws InvalidRequest |
420 | 420 |
*/ |
421 | 421 |
@Override |
422 |
public boolean replicate(Session session, SystemMetadata sysmeta, NodeReference sourceNode) |
|
423 |
throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest, |
|
424 |
InsufficientResources, UnsupportedType { |
|
425 |
|
|
426 |
// cannot be called by public |
|
422 |
public boolean replicate(Session session, SystemMetadata sysmeta, |
|
423 |
NodeReference sourceNode) throws NotImplemented, ServiceFailure, |
|
424 |
NotAuthorized, InvalidRequest, InsufficientResources, |
|
425 |
UnsupportedType { |
|
426 |
|
|
427 |
// cannot be called by public |
|
427 | 428 |
if (session == null) { |
428 |
throw new NotAuthorized("2152", "No session was provided.");
|
|
429 |
throw new NotAuthorized("2152", "No session was provided.");
|
|
429 | 430 |
} |
430 | 431 |
|
431 |
logMetacat.info("MNodeService.replicate() called with parameters: \n" +
|
|
432 |
"\tSession.Subject = " + session.getSubject().getValue() + "\n" +
|
|
433 |
"\tSystemMetadata = " + sysmeta.toString() + "\n" +
|
|
434 |
"\tSource NodeReference =" + sourceNode.getValue());
|
|
435 |
|
|
432 |
logMetacat.info("MNodeService.replicate() called with parameters: \n" |
|
433 |
+ "\tSession.Subject = " + session.getSubject().getValue()
|
|
434 |
+ "\n" + "\tSystemMetadata = " + sysmeta.toString()
|
|
435 |
+ "\n" + "\tSource NodeReference =" + sourceNode.getValue());
|
|
436 |
|
|
436 | 437 |
boolean result = false; |
437 |
String nodeIdStr = null;
|
|
438 |
String nodeIdStr = null; |
|
438 | 439 |
NodeReference nodeId = null; |
439 |
|
|
440 |
|
|
440 | 441 |
// get the local node id |
441 | 442 |
try { |
442 | 443 |
nodeIdStr = PropertyService.getProperty("dataone.memberNodeId"); |
443 | 444 |
nodeId = new NodeReference(); |
444 | 445 |
nodeId.setValue(nodeIdStr); |
445 |
|
|
446 |
|
|
446 | 447 |
} catch (PropertyNotFoundException e1) { |
447 |
logMetacat.error("Couldn't get dataone.memberNodeId property: " +
|
|
448 |
e1.getMessage()); |
|
449 |
|
|
448 |
logMetacat.error("Couldn't get dataone.memberNodeId property: " |
|
449 |
+ e1.getMessage());
|
|
450 |
|
|
450 | 451 |
} |
451 | 452 |
// TODO: check credentials |
452 | 453 |
|
... | ... | |
460 | 461 |
long serialVersion = sysmeta.getSerialVersion().longValue(); |
461 | 462 |
InputStream object = null; |
462 | 463 |
Session thisNodeSession = null; |
463 |
|
|
464 |
Identifier localPid = null; |
|
465 |
SystemMetadata localSystemMetadata = null; |
|
466 |
|
|
464 | 467 |
try { |
465 |
// session should be null to use the default certificate location set in the Certificate manager |
|
466 |
object = mn.getReplica(thisNodeSession, pid); |
|
467 |
logMetacat.info("MNodeService.replicate() called for identifier " + pid.getValue()); |
|
468 |
// do we already have a replica? |
|
469 |
try { |
|
470 |
localSystemMetadata = |
|
471 |
HazelcastService.getInstance().getSystemMetadataMap().get(pid); |
|
472 |
object = getReplica(thisNodeSession, pid); |
|
473 |
|
|
474 |
} catch (RuntimeException e) { |
|
475 |
logMetacat.info("An error occurred getting system metadata for " |
|
476 |
+ pid.getValue()); |
|
468 | 477 |
|
478 |
} |
|
479 |
|
|
480 |
// no local replica, get a replica |
|
481 |
if (localSystemMetadata == null) { |
|
482 |
// session should be null to use the default certificate |
|
483 |
// location set in the Certificate manager |
|
484 |
object = mn.getReplica(thisNodeSession, pid); |
|
485 |
logMetacat.info("MNodeService.replicate() called for identifier " |
|
486 |
+ pid.getValue()); |
|
487 |
|
|
488 |
} |
|
489 |
|
|
469 | 490 |
} catch (InvalidToken e) { |
470 |
e.printStackTrace(); |
|
471 |
throw new ServiceFailure("2151", "Could not retrieve object to replicate (InvalidToken): " + e.getMessage()); |
|
491 |
throw new ServiceFailure("2151", |
|
492 |
"Could not retrieve object to replicate (InvalidToken): " |
|
493 |
+ e.getMessage()); |
|
494 |
|
|
472 | 495 |
} catch (NotFound e) { |
473 |
e.printStackTrace(); |
|
474 |
throw new ServiceFailure("2151", "Could not retrieve object to replicate (NotFound): " + e.getMessage()); |
|
496 |
throw new ServiceFailure("2151", |
|
497 |
"Could not retrieve object to replicate (NotFound): " |
|
498 |
+ e.getMessage()); |
|
499 |
|
|
475 | 500 |
} |
476 | 501 |
|
477 | 502 |
// verify checksum on the object, if supported |
478 | 503 |
if (object.markSupported()) { |
479 |
Checksum givenChecksum = sysmeta.getChecksum(); |
|
480 |
Checksum computedChecksum = null; |
|
481 |
try { |
|
482 |
computedChecksum = ChecksumUtil.checksum(object, givenChecksum.getAlgorithm()); |
|
483 |
object.reset(); |
|
484 |
} catch (Exception e) { |
|
485 |
String msg = "Error computing checksum on replica: " + e.getMessage(); |
|
486 |
ServiceFailure sf = new ServiceFailure("2151", msg); |
|
487 |
sf.initCause(e); |
|
488 |
throw sf; |
|
489 |
} |
|
490 |
if (!givenChecksum.getValue().equals(computedChecksum)) { |
|
491 |
throw new ServiceFailure("2151", "Computed checksum does not match declared checksum"); |
|
492 |
} |
|
504 |
Checksum givenChecksum = sysmeta.getChecksum(); |
|
505 |
Checksum computedChecksum = null; |
|
506 |
try { |
|
507 |
computedChecksum = ChecksumUtil.checksum(object, |
|
508 |
givenChecksum.getAlgorithm()); |
|
509 |
object.reset(); |
|
510 |
} catch (Exception e) { |
|
511 |
String msg = "Error computing checksum on replica: " |
|
512 |
+ e.getMessage(); |
|
513 |
ServiceFailure sf = new ServiceFailure("2151", msg); |
|
514 |
sf.initCause(e); |
|
515 |
throw sf; |
|
516 |
} |
|
517 |
if (!givenChecksum.getValue().equals(computedChecksum)) { |
|
518 |
throw new ServiceFailure("2151", |
|
519 |
"Computed checksum does not match declared checksum"); |
|
520 |
} |
|
493 | 521 |
} |
494 |
|
|
522 |
|
|
495 | 523 |
// add it to local store |
496 | 524 |
Identifier retPid; |
497 | 525 |
try { |
498 |
// skip the MN.create -- this mutates the system metadata and we dont want it to |
|
526 |
// skip the MN.create -- this mutates the system metadata and we |
|
527 |
// dont want it to |
|
499 | 528 |
retPid = super.create(session, pid, object, sysmeta); |
500 | 529 |
result = (retPid.getValue().equals(pid.getValue())); |
501 | 530 |
} catch (InvalidToken e) { |
502 | 531 |
e.printStackTrace(); |
503 |
throw new ServiceFailure("2151", "Could not save object to local store (InvalidToken): " + e.getMessage()); |
|
532 |
throw new ServiceFailure("2151", |
|
533 |
"Could not save object to local store (InvalidToken): " |
|
534 |
+ e.getMessage()); |
|
504 | 535 |
} catch (IdentifierNotUnique e) { |
505 | 536 |
e.printStackTrace(); |
506 |
throw new ServiceFailure("2151", "Could not save object to local store (IdentifierNotUnique): " + e.getMessage()); |
|
537 |
throw new ServiceFailure("2151", |
|
538 |
"Could not save object to local store (IdentifierNotUnique): " |
|
539 |
+ e.getMessage()); |
|
507 | 540 |
} catch (InvalidSystemMetadata e) { |
508 | 541 |
e.printStackTrace(); |
509 |
throw new ServiceFailure("2151", "Could not save object to local store (InvalidSystemMetadata): " + e.getMessage()); |
|
542 |
throw new ServiceFailure("2151", |
|
543 |
"Could not save object to local store (InvalidSystemMetadata): " |
|
544 |
+ e.getMessage()); |
|
510 | 545 |
} |
511 | 546 |
|
512 | 547 |
try { |
513 |
// call the CN as the MN to set the replication status |
|
514 |
cn.setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.COMPLETED, serialVersion); |
|
515 |
|
|
548 |
// call the CN as the MN to set the replication status |
|
549 |
cn.setReplicationStatus(thisNodeSession, pid, nodeId, |
|
550 |
ReplicationStatus.COMPLETED, serialVersion); |
|
551 |
|
|
516 | 552 |
} catch (InvalidToken e) { |
517 | 553 |
// TODO Auto-generated catch block |
518 | 554 |
e.printStackTrace(); |
... | ... | |
520 | 556 |
// TODO Auto-generated catch block |
521 | 557 |
e.printStackTrace(); |
522 | 558 |
} catch (VersionMismatch e) { |
523 |
// TODO Auto-generated catch block
|
|
524 |
e.printStackTrace();
|
|
525 |
}
|
|
559 |
// TODO Auto-generated catch block
|
|
560 |
e.printStackTrace();
|
|
561 |
}
|
|
526 | 562 |
return result; |
527 | 563 |
|
528 | 564 |
} |
Also available in: Unified diff
In MNodeService.replicate(), check to see if we have a replica (via an out of band channel) before we call sourceMN.getReplica().