Revision 9354
Added by Jing Tao about 9 years ago
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java | ||
---|---|---|
595 | 595 |
HazelcastService.getInstance().getSystemMetadataMap().lock(pid); |
596 | 596 |
logMetacat.debug("CNodeService.archive - lock the system metadata for "+pid.getValue()); |
597 | 597 |
SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid); |
598 |
boolean notifyReplica = true;
|
|
599 |
archiveCNObject(session, pid, sysMeta, notifyReplica);
|
|
598 |
boolean needModifyDate = true;
|
|
599 |
archiveCNObjectWithNotificationReplica(session, pid, sysMeta, needModifyDate);
|
|
600 | 600 |
|
601 | 601 |
} finally { |
602 | 602 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid); |
... | ... | |
609 | 609 |
|
610 | 610 |
|
611 | 611 |
/** |
612 |
* Archive a object on cn. This method doesn't lock the system metadata map. The caller should lock it. |
|
612 |
* Archive a object on cn and notify the replica. This method doesn't lock the system metadata map. The caller should lock it.
|
|
613 | 613 |
* This method doesn't check the authorization; this method only accept a pid. |
614 | 614 |
* @param session |
615 | 615 |
* @param pid |
... | ... | |
622 | 622 |
* @throws NotFound |
623 | 623 |
* @throws NotImplemented |
624 | 624 |
*/ |
625 |
public Identifier archiveCNObject(Session session, Identifier pid, SystemMetadata sysMeta, boolean notifyReplica) |
|
626 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
|
627 |
|
|
628 |
String localId = null; // The corresponding docid for this pid |
|
629 |
|
|
630 |
// Check for the existing identifier |
|
631 |
try { |
|
632 |
localId = IdentifierManager.getInstance().getLocalId(pid.getValue()); |
|
633 |
super.archiveObject(session, pid, sysMeta); |
|
634 |
|
|
635 |
} catch (McdbDocNotFoundException e) { |
|
636 |
// This object is not registered in the identifier table. Assume it is of formatType DATA, |
|
637 |
// and set the archive flag. (i.e. the *object* doesn't exist on the CN) |
|
638 |
|
|
639 |
try { |
|
640 |
if ( sysMeta != null ) { |
|
641 |
sysMeta.setSerialVersion(sysMeta.getSerialVersion().add(BigInteger.ONE)); |
|
642 |
sysMeta.setArchived(true); |
|
643 |
sysMeta.setDateSysMetadataModified(Calendar.getInstance().getTime()); |
|
644 |
HazelcastService.getInstance().getSystemMetadataMap().put(pid, sysMeta); |
|
645 |
|
|
646 |
} else { |
|
647 |
throw new ServiceFailure("4972", "Couldn't archive the object " + pid.getValue() + |
|
648 |
". Couldn't obtain the system metadata record."); |
|
649 |
|
|
650 |
} |
|
651 |
|
|
652 |
} catch (RuntimeException re) { |
|
653 |
throw new ServiceFailure("4972", "Couldn't archive " + pid.getValue() + |
|
654 |
". The error message was: " + re.getMessage()); |
|
655 |
|
|
656 |
} |
|
657 |
|
|
658 |
} catch (SQLException e) { |
|
659 |
throw new ServiceFailure("4972", "Couldn't archive the object " + pid.getValue() + |
|
660 |
". The local id of the object with the identifier can't be identified since "+e.getMessage()); |
|
661 |
} |
|
662 |
if(notifyReplica) { |
|
663 |
// notify the replicas |
|
664 |
notifyReplicaNodes(sysMeta); |
|
665 |
} |
|
625 |
private Identifier archiveCNObjectWithNotificationReplica(Session session, Identifier pid, SystemMetadata sysMeta, boolean needModifyDate) |
|
626 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
|
627 |
archiveCNObject(session, pid, sysMeta, needModifyDate); |
|
628 |
// notify the replicas |
|
629 |
notifyReplicaNodes(sysMeta); |
|
666 | 630 |
return pid; |
667 |
|
|
668 | 631 |
} |
669 | 632 |
|
670 | 633 |
|
... | ... | |
2270 | 2233 |
List<Replica> replicas = currentSysmeta.getReplicaList(); |
2271 | 2234 |
sysmeta.setReplicaList(replicas); |
2272 | 2235 |
boolean needUpdateModificationDate = false;//cn doesn't need to change the modification date. |
2273 |
success = updateSystemMetadata(session, pid, sysmeta, needUpdateModificationDate, currentSysmeta); |
|
2236 |
boolean fromCN = true; |
|
2237 |
success = updateSystemMetadata(session, pid, sysmeta, needUpdateModificationDate, currentSysmeta, fromCN); |
|
2274 | 2238 |
} finally { |
2275 | 2239 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid); |
2276 | 2240 |
} |
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java | ||
---|---|---|
1717 | 1717 |
* @throws InvalidToken |
1718 | 1718 |
*/ |
1719 | 1719 |
protected boolean updateSystemMetadata(Session session, Identifier pid, |
1720 |
SystemMetadata sysmeta, boolean needUpdateModificationDate, SystemMetadata currentSysmeta) throws NotImplemented, NotAuthorized, |
|
1720 |
SystemMetadata sysmeta, boolean needUpdateModificationDate, SystemMetadata currentSysmeta, boolean fromCN) throws NotImplemented, NotAuthorized,
|
|
1721 | 1721 |
ServiceFailure, InvalidRequest, InvalidSystemMetadata, InvalidToken { |
1722 | 1722 |
|
1723 | 1723 |
// The lock to be used for this identifier |
... | ... | |
1801 | 1801 |
} |
1802 | 1802 |
|
1803 | 1803 |
// do the actual update |
1804 |
updateSystemMetadataWithoutLock(sysmeta, needUpdateModificationDate); |
|
1805 |
|
|
1804 |
if(sysmeta.getArchived() != null && sysmeta.getArchived() == true && |
|
1805 |
((currentSysmeta.getArchived() != null && currentSysmeta.getArchived() == false ) || currentSysmeta.getArchived() == null)) { |
|
1806 |
if(fromCN) { |
|
1807 |
logMetacat.debug("D1Node.update - this is to archive a cn object "+pid.getValue()); |
|
1808 |
try { |
|
1809 |
archiveCNObject(session, pid, sysmeta, needUpdateModificationDate); |
|
1810 |
} catch (NotFound e) { |
|
1811 |
throw new InvalidRequest("4869", "Can't find the pid "+pid.getValue()+" for archive."); |
|
1812 |
} |
|
1813 |
} else { |
|
1814 |
logMetacat.debug("D1Node.update - this is to archive a MN object "+pid.getValue()); |
|
1815 |
try { |
|
1816 |
archiveObject(session, pid, sysmeta, needUpdateModificationDate); |
|
1817 |
} catch (NotFound e) { |
|
1818 |
throw new InvalidRequest("4869", "Can't find the pid "+pid.getValue()+" for archive."); |
|
1819 |
} |
|
1820 |
} |
|
1821 |
} else { |
|
1822 |
logMetacat.debug("D1Node.update - regularly update the system metadata of the pid "+pid.getValue()); |
|
1823 |
updateSystemMetadataWithoutLock(sysmeta, needUpdateModificationDate); |
|
1824 |
} |
|
1825 |
|
|
1806 | 1826 |
try { |
1807 | 1827 |
String localId = IdentifierManager.getInstance().getLocalId(pid.getValue()); |
1808 | 1828 |
EventLog.getInstance().log(request.getRemoteAddr(), |
... | ... | |
2012 | 2032 |
* @throws NotImplemented |
2013 | 2033 |
* @throws InvalidRequest |
2014 | 2034 |
*/ |
2015 |
protected Identifier archiveObject(Session session, Identifier pid, SystemMetadata sysMeta) |
|
2035 |
protected Identifier archiveObject(Session session, Identifier pid, SystemMetadata sysMeta, boolean needModifyDate)
|
|
2016 | 2036 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
2017 | 2037 |
|
2018 | 2038 |
String localId = null; |
... | ... | |
2053 | 2073 |
|
2054 | 2074 |
// archive it |
2055 | 2075 |
sysMeta.setArchived(true); |
2056 |
sysMeta.setDateSysMetadataModified(Calendar.getInstance().getTime()); |
|
2057 |
sysMeta.setSerialVersion(sysMeta.getSerialVersion().add(BigInteger.ONE)); |
|
2076 |
if(needModifyDate) { |
|
2077 |
sysMeta.setDateSysMetadataModified(Calendar.getInstance().getTime()); |
|
2078 |
sysMeta.setSerialVersion(sysMeta.getSerialVersion().add(BigInteger.ONE)); |
|
2079 |
} |
|
2058 | 2080 |
HazelcastService.getInstance().getSystemMetadataMap().put(pid, sysMeta); |
2059 | 2081 |
|
2060 | 2082 |
// submit for indexing |
... | ... | |
2079 | 2101 |
return pid; |
2080 | 2102 |
} |
2081 | 2103 |
|
2104 |
/** |
|
2105 |
* Archive a object on cn and notify the replica. This method doesn't lock the system metadata map. The caller should lock it. |
|
2106 |
* This method doesn't check the authorization; this method only accept a pid. |
|
2107 |
* It wouldn't notify the replca that the system metadata has been changed. |
|
2108 |
* @param session |
|
2109 |
* @param pid |
|
2110 |
* @param sysMeta |
|
2111 |
* @param notifyReplica |
|
2112 |
* @return |
|
2113 |
* @throws InvalidToken |
|
2114 |
* @throws ServiceFailure |
|
2115 |
* @throws NotAuthorized |
|
2116 |
* @throws NotFound |
|
2117 |
* @throws NotImplemented |
|
2118 |
*/ |
|
2119 |
protected void archiveCNObject(Session session, Identifier pid, SystemMetadata sysMeta, boolean needModifyDate) |
|
2120 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
|
2121 |
|
|
2122 |
String localId = null; // The corresponding docid for this pid |
|
2123 |
|
|
2124 |
// Check for the existing identifier |
|
2125 |
try { |
|
2126 |
localId = IdentifierManager.getInstance().getLocalId(pid.getValue()); |
|
2127 |
archiveObject(session, pid, sysMeta, needModifyDate); |
|
2128 |
|
|
2129 |
} catch (McdbDocNotFoundException e) { |
|
2130 |
// This object is not registered in the identifier table. Assume it is of formatType DATA, |
|
2131 |
// and set the archive flag. (i.e. the *object* doesn't exist on the CN) |
|
2132 |
|
|
2133 |
try { |
|
2134 |
if ( sysMeta != null ) { |
|
2135 |
sysMeta.setArchived(true); |
|
2136 |
if (needModifyDate) { |
|
2137 |
sysMeta.setSerialVersion(sysMeta.getSerialVersion().add(BigInteger.ONE)); |
|
2138 |
sysMeta.setDateSysMetadataModified(Calendar.getInstance().getTime()); |
|
2139 |
} |
|
2140 |
HazelcastService.getInstance().getSystemMetadataMap().put(pid, sysMeta); |
|
2141 |
|
|
2142 |
} else { |
|
2143 |
throw new ServiceFailure("4972", "Couldn't archive the object " + pid.getValue() + |
|
2144 |
". Couldn't obtain the system metadata record."); |
|
2145 |
|
|
2146 |
} |
|
2147 |
|
|
2148 |
} catch (RuntimeException re) { |
|
2149 |
throw new ServiceFailure("4972", "Couldn't archive " + pid.getValue() + |
|
2150 |
". The error message was: " + re.getMessage()); |
|
2151 |
|
|
2152 |
} |
|
2153 |
|
|
2154 |
} catch (SQLException e) { |
|
2155 |
throw new ServiceFailure("4972", "Couldn't archive the object " + pid.getValue() + |
|
2156 |
". The local id of the object with the identifier can't be identified since "+e.getMessage()); |
|
2157 |
} |
|
2158 |
|
|
2159 |
} |
|
2082 | 2160 |
|
2161 |
|
|
2083 | 2162 |
/** |
2084 | 2163 |
* A utility method for v1 api to check the specified identifier exists as a pid |
2085 | 2164 |
* @param identifier the specified identifier |
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java | ||
---|---|---|
2355 | 2355 |
HazelcastService.getInstance().getSystemMetadataMap().lock(pid); |
2356 | 2356 |
logMetacat.debug("MNodeService.archive - lock the identifier "+pid.getValue()+" in the system metadata map."); |
2357 | 2357 |
SystemMetadata sysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid); |
2358 |
super.archiveObject(session, pid, sysmeta); |
|
2358 |
boolean needModifyDate = true; |
|
2359 |
super.archiveObject(session, pid, sysmeta, needModifyDate); |
|
2359 | 2360 |
} finally { |
2360 | 2361 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid); |
2361 | 2362 |
logMetacat.debug("MNodeService.archive - unlock the identifier "+pid.getValue()+" in the system metadata map."); |
... | ... | |
2428 | 2429 |
". Please check if you have got the newest version of the system metadata before the modification."); |
2429 | 2430 |
} |
2430 | 2431 |
boolean needUpdateModificationDate = true; |
2431 |
success = updateSystemMetadata(session, pid, sysmeta, needUpdateModificationDate, currentSysmeta); |
|
2432 |
boolean fromCN = false; |
|
2433 |
success = updateSystemMetadata(session, pid, sysmeta, needUpdateModificationDate, currentSysmeta, fromCN); |
|
2432 | 2434 |
} finally { |
2433 | 2435 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid); |
2434 | 2436 |
} |
Also available in: Unified diff
Add the case the mn.updateSystemMetadata and cn.updateSystemMetadata will call the archive method internally.