Revision 6575
Added by Chris Jones about 13 years ago
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java | ||
---|---|---|
253 | 253 |
* @throws InvalidRequest |
254 | 254 |
*/ |
255 | 255 |
@Override |
256 |
public Identifier update(Session session, Identifier pid, InputStream object, Identifier newPid, SystemMetadata sysmeta) throws InvalidToken, |
|
257 |
ServiceFailure, NotAuthorized, IdentifierNotUnique, UnsupportedType, InsufficientResources, NotFound, InvalidSystemMetadata, NotImplemented, |
|
258 |
InvalidRequest { |
|
256 |
public Identifier update(Session session, Identifier pid, InputStream object, |
|
257 |
Identifier newPid, SystemMetadata sysmeta) |
|
258 |
throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, |
|
259 |
UnsupportedType, InsufficientResources, NotFound, |
|
260 |
InvalidSystemMetadata, NotImplemented, InvalidRequest { |
|
259 | 261 |
|
260 | 262 |
String localId = null; |
261 | 263 |
boolean allowed = false; |
... | ... | |
265 | 267 |
// do we have a valid pid? |
266 | 268 |
if (pid == null || pid.getValue().trim().equals("")) { |
267 | 269 |
throw new InvalidRequest("1202", "The provided identifier was invalid."); |
270 |
|
|
268 | 271 |
} |
269 | 272 |
|
270 | 273 |
// check for the existing identifier |
271 | 274 |
try { |
272 | 275 |
localId = IdentifierManager.getInstance().getLocalId(pid.getValue()); |
276 |
|
|
273 | 277 |
} catch (McdbDocNotFoundException e) { |
274 |
throw new InvalidRequest("1202", "The object with the provided " + "identifier was not found."); |
|
278 |
throw new InvalidRequest("1202", "The object with the provided " + |
|
279 |
"identifier was not found."); |
|
280 |
|
|
275 | 281 |
} |
276 | 282 |
|
277 | 283 |
// set the originating node |
... | ... | |
282 | 288 |
sysmeta.setSubmitter(subject); |
283 | 289 |
// set the dates |
284 | 290 |
Date now = Calendar.getInstance().getTime(); |
285 |
sysmeta.setDateSysMetadataModified(now);
|
|
286 |
sysmeta.setDateUploaded(now);
|
|
291 |
sysmeta.setDateSysMetadataModified(now);
|
|
292 |
sysmeta.setDateUploaded(now);
|
|
287 | 293 |
|
288 | 294 |
// does the subject have WRITE ( == update) priveleges on the pid? |
289 | 295 |
allowed = isAuthorized(session, pid, Permission.WRITE); |
... | ... | |
352 | 358 |
public Identifier create(Session session, Identifier pid, InputStream object, SystemMetadata sysmeta) throws InvalidToken, ServiceFailure, NotAuthorized, |
353 | 359 |
IdentifierNotUnique, UnsupportedType, InsufficientResources, InvalidSystemMetadata, NotImplemented, InvalidRequest { |
354 | 360 |
|
355 |
// check for null session
|
|
361 |
// check for null session
|
|
356 | 362 |
if (session == null) { |
357 |
throw new InvalidToken("1110", "Session is required to WRITE to the Node.");
|
|
363 |
throw new InvalidToken("1110", "Session is required to WRITE to the Node.");
|
|
358 | 364 |
} |
359 | 365 |
// set the submitter to match the certificate |
360 | 366 |
sysmeta.setSubmitter(session.getSubject()); |
... | ... | |
363 | 369 |
sysmeta.setOriginMemberNode(originMemberNode); |
364 | 370 |
// set the dates |
365 | 371 |
Date now = Calendar.getInstance().getTime(); |
366 |
sysmeta.setDateSysMetadataModified(now);
|
|
367 |
sysmeta.setDateUploaded(now);
|
|
372 |
sysmeta.setDateSysMetadataModified(now);
|
|
373 |
sysmeta.setDateUploaded(now);
|
|
368 | 374 |
// call the shared impl |
369 | 375 |
return super.create(session, pid, object, sysmeta); |
370 | 376 |
} |
... | ... | |
415 | 421 |
InputStream object = null; |
416 | 422 |
|
417 | 423 |
try { |
418 |
// session should be null to use the default certificate location set in the Certificate manager
|
|
424 |
// session should be null to use the default certificate location set in the Certificate manager
|
|
419 | 425 |
object = mn.getReplica(null, pid); |
420 | 426 |
logMetacat.info("MNodeService.replicate() called for identifier " + pid.getValue()); |
421 | 427 |
|
... | ... | |
430 | 436 |
// add it to local store |
431 | 437 |
Identifier retPid; |
432 | 438 |
try { |
433 |
// skip the MN.create -- this mutates the system metadata and we dont want it to
|
|
439 |
// skip the MN.create -- this mutates the system metadata and we dont want it to
|
|
434 | 440 |
retPid = super.create(session, pid, object, sysmeta); |
435 | 441 |
result = (retPid.getValue().equals(pid.getValue())); |
436 | 442 |
} catch (InvalidToken e) { |
... | ... | |
445 | 451 |
} |
446 | 452 |
|
447 | 453 |
try { |
448 |
// call the CN as the MN to set the replication status
|
|
454 |
// call the CN as the MN to set the replication status
|
|
449 | 455 |
cn.setReplicationStatus(null, pid, sourceNode, ReplicationStatus.COMPLETED); |
450 | 456 |
|
451 | 457 |
} catch (InvalidToken e) { |
... | ... | |
481 | 487 |
public DescribeResponse describe(Session session, Identifier pid) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented, |
482 | 488 |
InvalidRequest { |
483 | 489 |
|
484 |
// get system metadata and construct the describe response
|
|
490 |
// get system metadata and construct the describe response
|
|
485 | 491 |
SystemMetadata sysmeta = getSystemMetadata(session, pid); |
486 | 492 |
DescribeResponse describeResponse = new DescribeResponse(sysmeta.getFormatId(), sysmeta.getSize(), sysmeta.getDateSysMetadataModified(), |
487 | 493 |
sysmeta.getChecksum()); |
... | ... | |
887 | 893 |
// TODO: use the event type enum when the SYNCHRONIZATION_FAILED event is added |
888 | 894 |
String principal = Constants.SUBJECT_PUBLIC; |
889 | 895 |
if (session != null && session.getSubject() != null) { |
890 |
principal = session.getSubject().getValue();
|
|
896 |
principal = session.getSubject().getValue();
|
|
891 | 897 |
} |
892 | 898 |
try { |
893 |
EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), principal, localId, "synchronization_failed");
|
|
899 |
EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), principal, localId, "synchronization_failed");
|
|
894 | 900 |
} catch (Exception e) { |
895 | 901 |
throw new ServiceFailure("2161", "Could not log the error for: " + syncFailed.getPid()); |
896 |
}
|
|
902 |
}
|
|
897 | 903 |
//EventLog.getInstance().log("CN URL WILL GO HERE", |
898 | 904 |
// session.getSubject().getValue(), localId, Event.SYNCHRONIZATION_FAILED); |
899 | 905 |
|
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java | ||
---|---|---|
559 | 559 |
* @throws InvalidSystemMetadata |
560 | 560 |
*/ |
561 | 561 |
@Override |
562 |
public Identifier registerSystemMetadata(Session session, Identifier guid,
|
|
563 |
SystemMetadata sysmeta) |
|
564 |
throws NotImplemented, NotAuthorized, ServiceFailure, InvalidRequest, |
|
565 |
InvalidSystemMetadata { |
|
562 |
public Identifier registerSystemMetadata(Session session, Identifier pid,
|
|
563 |
SystemMetadata sysmeta)
|
|
564 |
throws NotImplemented, NotAuthorized, ServiceFailure, InvalidRequest,
|
|
565 |
InvalidSystemMetadata {
|
|
566 | 566 |
|
567 |
// TODO: control who can call this? |
|
568 |
if (session == null) {
|
|
569 |
//TODO: many of the thrown exceptions do not use the correct error codes
|
|
570 |
//check these against the docs and correct them
|
|
571 |
throw new NotAuthorized("4861", "No Session - could not authorize for registration." +
|
|
572 |
" If you are not logged in, please do so and retry the request.");
|
|
573 |
}
|
|
574 |
|
|
575 |
// verify that guid == SystemMetadata.getIdentifier()
|
|
576 |
logMetacat.debug("Comparing guid|sysmeta_guid: " + guid.getValue() +
|
|
577 |
"|" + sysmeta.getIdentifier().getValue());
|
|
578 |
if (!guid.getValue().equals(sysmeta.getIdentifier().getValue())) {
|
|
579 |
throw new InvalidRequest("4863",
|
|
580 |
"The identifier in method call (" + guid.getValue() +
|
|
581 |
") does not match identifier in system metadata (" +
|
|
582 |
sysmeta.getIdentifier().getValue() + ").");
|
|
583 |
}
|
|
567 |
// TODO: control who can call this?
|
|
568 |
if (session == null) { |
|
569 |
//TODO: many of the thrown exceptions do not use the correct error codes |
|
570 |
//check these against the docs and correct them |
|
571 |
throw new NotAuthorized("4861", "No Session - could not authorize for registration." + |
|
572 |
" If you are not logged in, please do so and retry the request."); |
|
573 |
} |
|
574 |
|
|
575 |
// verify that guid == SystemMetadata.getIdentifier() |
|
576 |
logMetacat.debug("Comparing guid|sysmeta_guid: " + pid.getValue() +
|
|
577 |
"|" + sysmeta.getIdentifier().getValue()); |
|
578 |
if (!pid.getValue().equals(sysmeta.getIdentifier().getValue())) {
|
|
579 |
throw new InvalidRequest("4863", |
|
580 |
"The identifier in method call (" + pid.getValue() +
|
|
581 |
") does not match identifier in system metadata (" + |
|
582 |
sysmeta.getIdentifier().getValue() + ")."); |
|
583 |
} |
|
584 | 584 |
|
585 |
logMetacat.debug("Checking if identifier exists...");
|
|
586 |
// Check that the identifier does not already exist
|
|
587 |
if (HazelcastService.getInstance().getSystemMetadataMap().containsKey(guid)) {
|
|
588 |
throw new InvalidRequest("4863",
|
|
589 |
"The identifier is already in use by an existing object.");
|
|
585 |
logMetacat.debug("Checking if identifier exists..."); |
|
586 |
// Check that the identifier does not already exist |
|
587 |
if (HazelcastService.getInstance().getSystemMetadataMap().containsKey(pid)) {
|
|
588 |
throw new InvalidRequest("4863", |
|
589 |
"The identifier is already in use by an existing object."); |
|
590 | 590 |
|
591 |
} |
|
592 |
|
|
593 |
// insert the system metadata into the object store |
|
594 |
logMetacat.debug("Starting to insert SystemMetadata..."); |
|
595 |
try { |
|
596 |
HazelcastService.getInstance().getSystemMetadataMap().lock(sysmeta.getIdentifier()); |
|
597 |
sysmeta.setSerialVersion(BigInteger.ONE); |
|
598 |
sysmeta.setDateSysMetadataModified(Calendar.getInstance().getTime()); |
|
599 |
HazelcastService.getInstance().getSystemMetadataMap().put(sysmeta.getIdentifier(), sysmeta); |
|
600 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(sysmeta.getIdentifier()); |
|
601 |
|
|
602 |
} catch (Exception e) { |
|
603 |
logMetacat.error("Problem registering system metadata: " + guid.getValue(), e); |
|
604 |
throw new ServiceFailure("4862", "Error inserting system metadata: " + |
|
605 |
e.getClass() + ": " + e.getMessage()); |
|
606 |
|
|
607 |
} finally { |
|
591 |
} |
|
592 |
|
|
593 |
// insert the system metadata into the object store |
|
594 |
logMetacat.debug("Starting to insert SystemMetadata..."); |
|
595 |
try { |
|
596 |
HazelcastService.getInstance().getSystemMetadataMap().lock(sysmeta.getIdentifier()); |
|
597 |
sysmeta.setSerialVersion(BigInteger.ONE); |
|
598 |
sysmeta.setDateSysMetadataModified(Calendar.getInstance().getTime()); |
|
599 |
HazelcastService.getInstance().getSystemMetadataMap().put(sysmeta.getIdentifier(), sysmeta); |
|
608 | 600 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(sysmeta.getIdentifier()); |
601 |
|
|
602 |
} catch (Exception e) { |
|
603 |
logMetacat.error("Problem registering system metadata: " + pid.getValue(), e); |
|
604 |
throw new ServiceFailure("4862", "Error inserting system metadata: " + |
|
605 |
e.getClass() + ": " + e.getMessage()); |
|
606 |
|
|
607 |
} finally { |
|
608 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(sysmeta.getIdentifier()); |
|
609 | 609 |
|
610 |
} |
|
611 |
|
|
612 |
logMetacat.debug("Returning from registerSystemMetadata"); |
|
613 |
EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), session.getSubject().getValue(), guid.getValue(), "registerSystemMetadata"); |
|
614 |
return guid; |
|
610 |
} |
|
611 |
|
|
612 |
logMetacat.debug("Returning from registerSystemMetadata"); |
|
613 |
EventLog.getInstance().log(request.getRemoteAddr(), |
|
614 |
request.getHeader("User-Agent"), session.getSubject().getValue(), |
|
615 |
pid.getValue(), "registerSystemMetadata"); |
|
616 |
return pid; |
|
615 | 617 |
} |
616 | 618 |
|
617 | 619 |
/** |
Also available in: Unified diff
Minor indentation cleanup.