Revision 8811
Added by ben leinfelder over 10 years ago
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java | ||
---|---|---|
1862 | 1862 |
throw new NotImplemented("0000", "The CN capabilities are not stored in Metacat."); |
1863 | 1863 |
} |
1864 | 1864 |
|
1865 |
/** |
|
1866 |
* A method to notify the Coordinating Node that the authoritative copy of |
|
1867 |
* system metadata on the Authoritative Member Node has changed. |
|
1868 |
* |
|
1869 |
* @param session Session information that contains the identity of the |
|
1870 |
* calling user as retrieved from the X.509 certificate |
|
1871 |
* which must be traceable to the CILogon service. |
|
1872 |
* @param serialVersion The serialVersion of the system metadata |
|
1873 |
* @param dateSysMetaLastModified The time stamp for when the system metadata was changed |
|
1874 |
* @throws NotImplemented |
|
1875 |
* @throws ServiceFailure |
|
1876 |
* @throws NotAuthorized |
|
1877 |
* @throws InvalidRequest |
|
1878 |
* @throws InvalidToken |
|
1879 |
*/ |
|
1880 |
@Override |
|
1881 |
public boolean systemMetadataChanged(Session session, Identifier pid, |
|
1882 |
long serialVersion, Date dateSysMetaLastModified) |
|
1883 |
throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest, |
|
1884 |
InvalidToken { |
|
1885 |
|
|
1886 |
// cannot be called by public |
|
1887 |
if (session == null) { |
|
1888 |
throw new InvalidToken("2183", "No session was provided."); |
|
1889 |
} |
|
1890 |
|
|
1891 |
SystemMetadata currentLocalSysMeta = null; |
|
1892 |
SystemMetadata newSysMeta = null; |
|
1893 |
boolean allowed = false; |
|
1894 |
|
|
1895 |
// are we allowed to call this? |
|
1896 |
allowed = super.isAuthoritativeMNodeAdmin(session, pid); |
|
1897 |
|
|
1898 |
if (!allowed ) { |
|
1899 |
String msg = "The subject identified by " + session.getSubject().getValue() + |
|
1900 |
" is not authorized to call this service."; |
|
1901 |
throw new NotAuthorized("1331", msg); |
|
1902 |
|
|
1903 |
} |
|
1904 |
|
|
1905 |
// compare what we have locally to what is sent in the change notification |
|
1906 |
try { |
|
1907 |
currentLocalSysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid); |
|
1908 |
|
|
1909 |
} catch (RuntimeException e) { |
|
1910 |
String msg = "SystemMetadata for pid " + pid.getValue() + |
|
1911 |
" couldn't be updated because it couldn't be found locally: " + |
|
1912 |
e.getMessage(); |
|
1913 |
logMetacat.error(msg); |
|
1914 |
ServiceFailure sf = new ServiceFailure("1333", msg); |
|
1915 |
sf.initCause(e); |
|
1916 |
throw sf; |
|
1917 |
} |
|
1918 |
|
|
1919 |
if (currentLocalSysMeta.getSerialVersion().longValue() < serialVersion ) { |
|
1920 |
try { |
|
1921 |
|
|
1922 |
MNode mn = D1Client.getMN(currentLocalSysMeta.getAuthoritativeMemberNode()); |
|
1923 |
newSysMeta = mn .getSystemMetadata(null, pid); |
|
1924 |
} catch (NotFound e) { |
|
1925 |
// huh? you just said you had it |
|
1926 |
String msg = "On updating the local copy of system metadata " + |
|
1927 |
"for pid " + pid.getValue() +", the AuthMN reports it is not found." + |
|
1928 |
" The error message was: " + e.getMessage(); |
|
1929 |
logMetacat.error(msg); |
|
1930 |
ServiceFailure sf = new ServiceFailure("1333", msg); |
|
1931 |
sf.initCause(e); |
|
1932 |
throw sf; |
|
1933 |
} |
|
1934 |
|
|
1935 |
// update the local copy of system metadata for the pid |
|
1936 |
try { |
|
1937 |
HazelcastService.getInstance().getSystemMetadataMap().put(newSysMeta.getIdentifier(), newSysMeta); |
|
1938 |
logMetacat.info("Updated local copy of system metadata for pid " + |
|
1939 |
pid.getValue() + " after change notification from the CN."); |
|
1940 |
|
|
1941 |
// TODO: consider inspecting the change for archive |
|
1942 |
// see: https://projects.ecoinformatics.org/ecoinfo/issues/6417 |
|
1943 |
|
|
1944 |
} catch (RuntimeException e) { |
|
1945 |
String msg = "SystemMetadata for pid " + pid.getValue() + |
|
1946 |
" couldn't be updated: " + |
|
1947 |
e.getMessage(); |
|
1948 |
logMetacat.error(msg); |
|
1949 |
ServiceFailure sf = new ServiceFailure("1333", msg); |
|
1950 |
sf.initCause(e); |
|
1951 |
throw sf; |
|
1952 |
} |
|
1953 |
|
|
1954 |
// submit for indexing |
|
1955 |
try { |
|
1956 |
MetacatSolrIndex.getInstance().submit(newSysMeta.getIdentifier(), newSysMeta, null, true); |
|
1957 |
} catch (Exception e) { |
|
1958 |
logMetacat.error("Could not submit changed systemMetadata for indexing, pid: " + newSysMeta.getIdentifier().getValue(), e); |
|
1959 |
} |
|
1960 |
} |
|
1961 |
|
|
1962 |
return true; |
|
1963 |
|
|
1964 |
} |
|
1965 | 1865 |
|
1966 | 1866 |
} |
Also available in: Unified diff
remove CN.systemMetadataChanged in favor of the CN.updateSystemMetadata method. Otherwise there's no good way to know where to fetch the auth copy from since the SM change might be to switch the authMN!