Revision 8810
Added by ben leinfelder almost 10 years ago
CNodeService.java | ||
---|---|---|
34 | 34 |
import javax.servlet.http.HttpServletRequest; |
35 | 35 |
|
36 | 36 |
import org.apache.log4j.Logger; |
37 |
import org.dataone.client.CNode; |
|
38 |
import org.dataone.client.D1Client; |
|
39 |
import org.dataone.client.MNode; |
|
40 |
import org.dataone.service.cn.v1.CNAuthorization;
|
|
41 |
import org.dataone.service.cn.v1.CNCore;
|
|
42 |
import org.dataone.service.cn.v1.CNRead;
|
|
43 |
import org.dataone.service.cn.v1.CNReplication;
|
|
37 |
import org.dataone.client.v2.CNode;
|
|
38 |
import org.dataone.client.v2.itk.D1Client;
|
|
39 |
import org.dataone.client.v2.MNode;
|
|
40 |
import org.dataone.service.cn.v2.CNAuthorization;
|
|
41 |
import org.dataone.service.cn.v2.CNCore;
|
|
42 |
import org.dataone.service.cn.v2.CNRead;
|
|
43 |
import org.dataone.service.cn.v2.CNReplication;
|
|
44 | 44 |
import org.dataone.service.exceptions.BaseException; |
45 | 45 |
import org.dataone.service.exceptions.IdentifierNotUnique; |
46 | 46 |
import org.dataone.service.exceptions.InsufficientResources; |
... | ... | |
59 | 59 |
import org.dataone.service.types.v1.DescribeResponse; |
60 | 60 |
import org.dataone.service.types.v1.Event; |
61 | 61 |
import org.dataone.service.types.v1.Identifier; |
62 |
import org.dataone.service.types.v1.Log;
|
|
63 |
import org.dataone.service.types.v1.Node;
|
|
64 |
import org.dataone.service.types.v1.NodeList;
|
|
62 |
import org.dataone.service.types.v2.Log;
|
|
63 |
import org.dataone.service.types.v2.Node;
|
|
64 |
import org.dataone.service.types.v2.NodeList;
|
|
65 | 65 |
import org.dataone.service.types.v1.NodeReference; |
66 | 66 |
import org.dataone.service.types.v1.NodeType; |
67 |
import org.dataone.service.types.v1.ObjectFormat;
|
|
67 |
import org.dataone.service.types.v2.ObjectFormat;
|
|
68 | 68 |
import org.dataone.service.types.v1.ObjectFormatIdentifier; |
69 |
import org.dataone.service.types.v1.ObjectFormatList;
|
|
69 |
import org.dataone.service.types.v2.ObjectFormatList;
|
|
70 | 70 |
import org.dataone.service.types.v1.ObjectList; |
71 | 71 |
import org.dataone.service.types.v1.ObjectLocationList; |
72 | 72 |
import org.dataone.service.types.v1.Permission; |
... | ... | |
75 | 75 |
import org.dataone.service.types.v1.ReplicationStatus; |
76 | 76 |
import org.dataone.service.types.v1.Session; |
77 | 77 |
import org.dataone.service.types.v1.Subject; |
78 |
import org.dataone.service.types.v1.SystemMetadata;
|
|
79 |
import org.dataone.service.types.v1.util.ServiceMethodRestrictionUtil;
|
|
78 |
import org.dataone.service.types.v2.SystemMetadata;
|
|
79 |
import org.dataone.service.types.v2.util.ServiceMethodRestrictionUtil;
|
|
80 | 80 |
import org.dataone.service.types.v1_1.QueryEngineDescription; |
81 | 81 |
import org.dataone.service.types.v1_1.QueryEngineList; |
82 | 82 |
|
... | ... | |
84 | 84 |
import edu.ucsb.nceas.metacat.IdentifierManager; |
85 | 85 |
import edu.ucsb.nceas.metacat.McdbDocNotFoundException; |
86 | 86 |
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService; |
87 |
import edu.ucsb.nceas.metacat.index.MetacatSolrIndex; |
|
87 | 88 |
|
88 | 89 |
/** |
89 | 90 |
* Represents Metacat's implementation of the DataONE Coordinating Node |
... | ... | |
1729 | 1730 |
*/ |
1730 | 1731 |
@Override |
1731 | 1732 |
public ObjectList listObjects(Session session, Date startTime, |
1732 |
Date endTime, ObjectFormatIdentifier formatid, Boolean replicaStatus, |
|
1733 |
Date endTime, ObjectFormatIdentifier formatid, Identifier identifier, Boolean replicaStatus,
|
|
1733 | 1734 |
Integer start, Integer count) |
1734 | 1735 |
throws InvalidRequest, InvalidToken, NotAuthorized, NotImplemented, |
1735 | 1736 |
ServiceFailure { |
... | ... | |
1834 | 1835 |
} |
1835 | 1836 |
|
1836 | 1837 |
@Override |
1837 |
public boolean isAuthorized(Identifier pid, Permission permission) |
|
1838 |
throws ServiceFailure, InvalidToken, NotFound, NotAuthorized, |
|
1839 |
NotImplemented, InvalidRequest { |
|
1840 |
|
|
1841 |
return isAuthorized(null, pid, permission); |
|
1842 |
} |
|
1843 |
|
|
1844 |
@Override |
|
1845 |
public boolean setAccessPolicy(Identifier pid, AccessPolicy accessPolicy, long serialVersion) |
|
1846 |
throws InvalidToken, NotFound, NotImplemented, NotAuthorized, |
|
1847 |
ServiceFailure, InvalidRequest, VersionMismatch { |
|
1848 |
|
|
1849 |
return setAccessPolicy(null, pid, accessPolicy, serialVersion); |
|
1850 |
} |
|
1851 |
|
|
1852 |
@Override |
|
1853 |
public Identifier setRightsHolder(Identifier pid, Subject userId, long serialVersion) |
|
1854 |
throws InvalidToken, ServiceFailure, NotFound, NotAuthorized, |
|
1855 |
NotImplemented, InvalidRequest, VersionMismatch { |
|
1856 |
|
|
1857 |
return setRightsHolder(null, pid, userId, serialVersion); |
|
1858 |
} |
|
1859 |
|
|
1860 |
@Override |
|
1861 |
public Identifier create(Identifier pid, InputStream object, SystemMetadata sysmeta) |
|
1862 |
throws InvalidToken, ServiceFailure, NotAuthorized, |
|
1863 |
IdentifierNotUnique, UnsupportedType, InsufficientResources, |
|
1864 |
InvalidSystemMetadata, NotImplemented, InvalidRequest { |
|
1838 |
public QueryEngineDescription getQueryEngineDescription(Session session, |
|
1839 |
String queryEngine) throws InvalidToken, ServiceFailure, NotAuthorized, |
|
1840 |
NotImplemented, NotFound { |
|
1841 |
throw new NotImplemented("0000", "CN query services are not implemented in Metacat."); |
|
1865 | 1842 |
|
1866 |
return create(null, pid, object, sysmeta); |
|
1867 | 1843 |
} |
1868 | 1844 |
|
1869 | 1845 |
@Override |
1870 |
public Identifier delete(Identifier pid) throws InvalidToken, ServiceFailure, |
|
1871 |
NotAuthorized, NotFound, NotImplemented { |
|
1846 |
public QueryEngineList listQueryEngines(Session session) throws InvalidToken, |
|
1847 |
ServiceFailure, NotAuthorized, NotImplemented { |
|
1848 |
throw new NotImplemented("0000", "CN query services are not implemented in Metacat."); |
|
1872 | 1849 |
|
1873 |
return delete(null, pid); |
|
1874 | 1850 |
} |
1875 | 1851 |
|
1876 | 1852 |
@Override |
1877 |
public Identifier generateIdentifier(String scheme, String fragment) |
|
1878 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented, |
|
1879 |
InvalidRequest { |
|
1853 |
public InputStream query(Session session, String queryEngine, String query) |
|
1854 |
throws InvalidToken, ServiceFailure, NotAuthorized, InvalidRequest, |
|
1855 |
NotImplemented, NotFound { |
|
1856 |
throw new NotImplemented("0000", "CN query services are not implemented in Metacat."); |
|
1880 | 1857 |
|
1881 |
return generateIdentifier(null, scheme, fragment); |
|
1882 | 1858 |
} |
1883 | 1859 |
|
1884 | 1860 |
@Override |
1885 |
public Log getLogRecords(Date fromDate, Date toDate, Event event, String pidFilter, |
|
1886 |
Integer start, Integer count) throws InvalidToken, InvalidRequest, |
|
1887 |
ServiceFailure, NotAuthorized, NotImplemented, InsufficientResources { |
|
1888 |
|
|
1889 |
return getLogRecords(null, fromDate, toDate, event, pidFilter, start, count); |
|
1861 |
public Node getCapabilities() throws NotImplemented, ServiceFailure { |
|
1862 |
throw new NotImplemented("0000", "The CN capabilities are not stored in Metacat."); |
|
1890 | 1863 |
} |
1891 | 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 |
*/ |
|
1892 | 1880 |
@Override |
1893 |
public boolean hasReservation(Subject subject, Identifier pid) |
|
1894 |
throws InvalidToken, ServiceFailure, NotFound, NotAuthorized, |
|
1895 |
NotImplemented, InvalidRequest, IdentifierNotUnique { |
|
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 |
} |
|
1896 | 1890 |
|
1897 |
return hasReservation(null, subject, pid); |
|
1898 |
} |
|
1899 |
|
|
1900 |
@Override |
|
1901 |
public Identifier registerSystemMetadata(Identifier pid, SystemMetadata sysmeta) |
|
1902 |
throws NotImplemented, NotAuthorized, ServiceFailure, InvalidRequest, |
|
1903 |
InvalidSystemMetadata, InvalidToken { |
|
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 |
|
1904 | 1943 |
|
1905 |
return registerSystemMetadata(null, pid, sysmeta); |
|
1906 |
} |
|
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 |
} |
|
1907 | 1965 |
|
1908 |
@Override |
|
1909 |
public Identifier reserveIdentifier(Identifier pid) throws InvalidToken, |
|
1910 |
ServiceFailure, NotAuthorized, IdentifierNotUnique, NotImplemented, |
|
1911 |
InvalidRequest { |
|
1912 |
|
|
1913 |
return reserveIdentifier(null, pid); |
|
1914 |
} |
|
1915 |
|
|
1916 |
@Override |
|
1917 |
public boolean setObsoletedBy(Identifier pid, Identifier obsoletedByPid, long serialVersion) |
|
1918 |
throws NotImplemented, NotFound, NotAuthorized, ServiceFailure, |
|
1919 |
InvalidRequest, InvalidToken, VersionMismatch { |
|
1920 |
|
|
1921 |
return setObsoletedBy(null, pid, obsoletedByPid, serialVersion); |
|
1922 |
} |
|
1923 |
|
|
1924 |
@Override |
|
1925 |
public DescribeResponse describe(Identifier pid) throws InvalidToken, |
|
1926 |
NotAuthorized, NotImplemented, ServiceFailure, NotFound { |
|
1927 |
|
|
1928 |
return describe(null, pid); |
|
1929 |
} |
|
1930 |
|
|
1931 |
@Override |
|
1932 |
public InputStream get(Identifier pid) throws InvalidToken, ServiceFailure, |
|
1933 |
NotAuthorized, NotFound, NotImplemented { |
|
1934 |
|
|
1935 |
return get(null, pid); |
|
1936 |
} |
|
1937 |
|
|
1938 |
@Override |
|
1939 |
public Checksum getChecksum(Identifier pid) throws InvalidToken, |
|
1940 |
ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
|
1941 |
|
|
1942 |
return getChecksum(null, pid); |
|
1943 |
} |
|
1944 |
|
|
1945 |
@Override |
|
1946 |
public SystemMetadata getSystemMetadata(Identifier pid) throws InvalidToken, |
|
1947 |
ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
|
1948 |
|
|
1949 |
return getSystemMetadata(null, pid); |
|
1950 |
} |
|
1951 |
|
|
1952 |
@Override |
|
1953 |
public ObjectList listObjects(Date startTime, Date endTime, |
|
1954 |
ObjectFormatIdentifier formatid, Boolean replicaStatus, Integer start, Integer count) |
|
1955 |
throws InvalidRequest, InvalidToken, NotAuthorized, NotImplemented, |
|
1956 |
ServiceFailure { |
|
1957 |
|
|
1958 |
return listObjects(null, startTime, endTime, formatid, replicaStatus, start, count); |
|
1959 |
} |
|
1960 |
|
|
1961 |
@Override |
|
1962 |
public ObjectLocationList resolve(Identifier pid) throws InvalidToken, |
|
1963 |
ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
|
1964 |
|
|
1965 |
return resolve(null, pid); |
|
1966 |
} |
|
1967 |
|
|
1968 |
@Override |
|
1969 |
public ObjectList search(String queryType, String query) throws InvalidToken, |
|
1970 |
ServiceFailure, NotAuthorized, InvalidRequest, NotImplemented { |
|
1971 |
|
|
1972 |
return search(null, queryType, query); |
|
1973 |
} |
|
1974 |
|
|
1975 |
@Override |
|
1976 |
public boolean deleteReplicationMetadata(Identifier pid, NodeReference nodeId, |
|
1977 |
long serialVersion) throws InvalidToken, InvalidRequest, ServiceFailure, |
|
1978 |
NotAuthorized, NotFound, NotImplemented, VersionMismatch { |
|
1979 |
|
|
1980 |
return deleteReplicationMetadata(null, pid, nodeId, serialVersion); |
|
1981 |
} |
|
1982 |
|
|
1983 |
@Override |
|
1984 |
public boolean isNodeAuthorized(Subject targetNodeSubject, Identifier pid) |
|
1985 |
throws NotImplemented, NotAuthorized, InvalidToken, ServiceFailure, |
|
1986 |
NotFound, InvalidRequest { |
|
1987 |
|
|
1988 |
return isNodeAuthorized(null, targetNodeSubject, pid); |
|
1989 |
} |
|
1990 |
|
|
1991 |
@Override |
|
1992 |
public boolean setReplicationPolicy(Identifier pid, ReplicationPolicy policy, |
|
1993 |
long serialVersion) throws NotImplemented, NotFound, NotAuthorized, |
|
1994 |
ServiceFailure, InvalidRequest, InvalidToken, VersionMismatch { |
|
1995 |
|
|
1996 |
return setReplicationPolicy(null, pid, policy, serialVersion); |
|
1997 |
} |
|
1998 |
|
|
1999 |
@Override |
|
2000 |
public boolean setReplicationStatus(Identifier pid, NodeReference targetNode, |
|
2001 |
ReplicationStatus status, BaseException failure) throws ServiceFailure, |
|
2002 |
NotImplemented, InvalidToken, NotAuthorized, InvalidRequest, NotFound { |
|
2003 |
|
|
2004 |
return setReplicationStatus(null, pid, targetNode, status, failure); |
|
2005 |
} |
|
2006 |
|
|
2007 |
@Override |
|
2008 |
public boolean updateReplicationMetadata(Identifier pid, Replica replica, |
|
2009 |
long serialVersion) throws NotImplemented, NotAuthorized, ServiceFailure, |
|
2010 |
NotFound, InvalidRequest, InvalidToken, VersionMismatch { |
|
2011 |
|
|
2012 |
return updateReplicationMetadata(null, pid, replica, serialVersion); |
|
2013 |
} |
|
2014 |
|
|
2015 |
@Override |
|
2016 |
public QueryEngineDescription getQueryEngineDescription(String arg0) |
|
2017 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented, |
|
2018 |
NotFound { |
|
2019 |
throw new NotImplemented("4410", "getQueryEngineDescription not implemented"); |
|
2020 |
|
|
2021 |
} |
|
2022 |
|
|
2023 |
@Override |
|
2024 |
public QueryEngineList listQueryEngines() throws InvalidToken, ServiceFailure, |
|
2025 |
NotAuthorized, NotImplemented { |
|
2026 |
throw new NotImplemented("4420", "listQueryEngines not implemented"); |
|
2027 |
|
|
2028 |
} |
|
2029 |
|
|
2030 |
@Override |
|
2031 |
public InputStream query(String arg0, String arg1) throws InvalidToken, |
|
2032 |
ServiceFailure, NotAuthorized, InvalidRequest, NotImplemented, NotFound { |
|
2033 |
throw new NotImplemented("4324", "query not implemented"); |
|
2034 |
|
|
2035 |
} |
|
2036 | 1966 |
} |
Also available in: Unified diff
add support for v2 DataONE API.