Revision 8810
Added by ben leinfelder almost 10 years ago
MNodeService.java | ||
---|---|---|
55 | 55 |
|
56 | 56 |
import org.apache.commons.io.IOUtils; |
57 | 57 |
import org.apache.log4j.Logger; |
58 |
import org.dataone.client.CNode; |
|
59 |
import org.dataone.client.D1Client; |
|
60 |
import org.dataone.client.MNode; |
|
61 |
import org.dataone.client.ObjectFormatCache; |
|
58 |
import org.dataone.client.v2.CNode;
|
|
59 |
import org.dataone.client.v2.itk.D1Client;
|
|
60 |
import org.dataone.client.v2.MNode;
|
|
61 |
import org.dataone.client.v2.formats.ObjectFormatCache;
|
|
62 | 62 |
import org.dataone.client.auth.CertificateManager; |
63 |
import org.dataone.client.formats.ObjectFormatInfo; |
|
63 |
import org.dataone.client.v2.formats.ObjectFormatInfo;
|
|
64 | 64 |
import org.dataone.configuration.Settings; |
65 | 65 |
import org.dataone.ore.ResourceMapFactory; |
66 | 66 |
import org.dataone.service.exceptions.BaseException; |
... | ... | |
75 | 75 |
import org.dataone.service.exceptions.ServiceFailure; |
76 | 76 |
import org.dataone.service.exceptions.SynchronizationFailed; |
77 | 77 |
import org.dataone.service.exceptions.UnsupportedType; |
78 |
import org.dataone.service.mn.tier1.v1.MNCore; |
|
79 |
import org.dataone.service.mn.tier1.v1.MNRead; |
|
80 |
import org.dataone.service.mn.tier2.v1.MNAuthorization; |
|
81 |
import org.dataone.service.mn.tier3.v1.MNStorage; |
|
82 |
import org.dataone.service.mn.tier4.v1.MNReplication; |
|
83 |
import org.dataone.service.mn.v1.MNQuery; |
|
78 |
import org.dataone.service.mn.tier1.v2.MNCore; |
|
79 |
import org.dataone.service.mn.tier1.v2.MNRead; |
|
80 |
import org.dataone.service.mn.tier2.v2.MNAuthorization; |
|
81 |
import org.dataone.service.mn.tier3.v2.MNStorage; |
|
82 |
import org.dataone.service.mn.tier4.v2.MNReplication; |
|
83 |
import org.dataone.service.mn.v2.MNPackage; |
|
84 |
import org.dataone.service.mn.v2.MNQuery; |
|
85 |
import org.dataone.service.mn.v2.MNView; |
|
84 | 86 |
import org.dataone.service.types.v1.AccessRule; |
85 | 87 |
import org.dataone.service.types.v1.Checksum; |
86 | 88 |
import org.dataone.service.types.v1.DescribeResponse; |
87 | 89 |
import org.dataone.service.types.v1.Event; |
88 | 90 |
import org.dataone.service.types.v1.Identifier; |
89 |
import org.dataone.service.types.v1.Log; |
|
90 |
import org.dataone.service.types.v1.LogEntry; |
|
91 |
import org.dataone.service.types.v2.Log; |
|
92 |
import org.dataone.service.types.v2.LogEntry; |
|
93 |
import org.dataone.service.types.v2.OptionList; |
|
91 | 94 |
import org.dataone.service.types.v1.MonitorInfo; |
92 | 95 |
import org.dataone.service.types.v1.MonitorList; |
93 |
import org.dataone.service.types.v1.Node;
|
|
94 |
import org.dataone.service.types.v1.NodeList;
|
|
96 |
import org.dataone.service.types.v2.Node;
|
|
97 |
import org.dataone.service.types.v2.NodeList;
|
|
95 | 98 |
import org.dataone.service.types.v1.NodeReference; |
96 | 99 |
import org.dataone.service.types.v1.NodeState; |
97 | 100 |
import org.dataone.service.types.v1.NodeType; |
98 |
import org.dataone.service.types.v1.ObjectFormat;
|
|
101 |
import org.dataone.service.types.v2.ObjectFormat;
|
|
99 | 102 |
import org.dataone.service.types.v1.ObjectFormatIdentifier; |
100 | 103 |
import org.dataone.service.types.v1.ObjectList; |
101 | 104 |
import org.dataone.service.types.v1.Permission; |
... | ... | |
107 | 110 |
import org.dataone.service.types.v1.Session; |
108 | 111 |
import org.dataone.service.types.v1.Subject; |
109 | 112 |
import org.dataone.service.types.v1.Synchronization; |
110 |
import org.dataone.service.types.v1.SystemMetadata;
|
|
113 |
import org.dataone.service.types.v2.SystemMetadata;
|
|
111 | 114 |
import org.dataone.service.types.v1.util.AuthUtils; |
112 | 115 |
import org.dataone.service.types.v1.util.ChecksumUtil; |
113 | 116 |
import org.dataone.service.types.v1_1.QueryEngineDescription; |
... | ... | |
141 | 144 |
import edu.ucsb.nceas.metacat.shared.MetacatUtilException; |
142 | 145 |
import edu.ucsb.nceas.metacat.util.DeleteOnCloseFileInputStream; |
143 | 146 |
import edu.ucsb.nceas.metacat.util.DocumentUtil; |
147 |
import edu.ucsb.nceas.metacat.util.SkinUtil; |
|
144 | 148 |
import edu.ucsb.nceas.metacat.util.SystemUtil; |
145 | 149 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
146 | 150 |
import edu.ucsb.nceas.utilities.XMLUtilities; |
... | ... | |
177 | 181 |
* |
178 | 182 |
*/ |
179 | 183 |
public class MNodeService extends D1NodeService |
180 |
implements MNAuthorization, MNCore, MNRead, MNReplication, MNStorage, MNQuery { |
|
184 |
implements MNAuthorization, MNCore, MNRead, MNReplication, MNStorage, MNQuery, MNView, MNPackage {
|
|
181 | 185 |
|
182 | 186 |
//private static final String PATHQUERY = "pathquery"; |
183 | 187 |
public static final String UUID_SCHEME = "UUID"; |
... | ... | |
788 | 792 |
* @throws NotImplemented |
789 | 793 |
*/ |
790 | 794 |
@Override |
791 |
public ObjectList listObjects(Session session, Date startTime, Date endTime, ObjectFormatIdentifier objectFormatId, Boolean replicaStatus, Integer start, |
|
795 |
public ObjectList listObjects(Session session, Date startTime, Date endTime, ObjectFormatIdentifier objectFormatId, Identifier identifier, Boolean replicaStatus, Integer start,
|
|
792 | 796 |
Integer count) throws NotAuthorized, InvalidRequest, NotImplemented, ServiceFailure, InvalidToken { |
793 | 797 |
|
794 | 798 |
ObjectList objectList = null; |
... | ... | |
962 | 966 |
} |
963 | 967 |
} |
964 | 968 |
|
965 |
/** |
|
966 |
* Returns the number of operations that have been serviced by the node |
|
967 |
* over time periods of one and 24 hours. |
|
968 |
* |
|
969 |
* @param session - the Session object containing the credentials for the Subject |
|
970 |
* @param period - An ISO8601 compatible DateTime range specifying the time |
|
971 |
* range for which to return operation statistics. |
|
972 |
* @param requestor - Limit to operations performed by given requestor identity. |
|
973 |
* @param event - Enumerated value indicating the type of event being examined |
|
974 |
* @param format - Limit to events involving objects of the specified format |
|
975 |
* |
|
976 |
* @return the desired log records |
|
977 |
* |
|
978 |
* @throws InvalidToken |
|
979 |
* @throws ServiceFailure |
|
980 |
* @throws NotAuthorized |
|
981 |
* @throws InvalidRequest |
|
982 |
* @throws NotImplemented |
|
983 |
*/ |
|
984 |
public MonitorList getOperationStatistics(Session session, Date startTime, |
|
985 |
Date endTime, Subject requestor, Event event, ObjectFormatIdentifier formatId) |
|
986 |
throws NotImplemented, ServiceFailure, NotAuthorized, InsufficientResources, UnsupportedType { |
|
969 |
|
|
987 | 970 |
|
988 |
MonitorList monitorList = new MonitorList(); |
|
989 |
|
|
990 |
try { |
|
991 |
|
|
992 |
// get log records first |
|
993 |
Log logs = getLogRecords(session, startTime, endTime, event, null, 0, null); |
|
994 |
|
|
995 |
// TODO: aggregate by day or hour -- needs clarification |
|
996 |
int count = 1; |
|
997 |
for (LogEntry logEntry : logs.getLogEntryList()) { |
|
998 |
Identifier pid = logEntry.getIdentifier(); |
|
999 |
Date logDate = logEntry.getDateLogged(); |
|
1000 |
// if we are filtering by format |
|
1001 |
if (formatId != null) { |
|
1002 |
SystemMetadata sysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid); |
|
1003 |
if (!sysmeta.getFormatId().getValue().equals(formatId.getValue())) { |
|
1004 |
// does not match |
|
1005 |
continue; |
|
1006 |
} |
|
1007 |
} |
|
1008 |
MonitorInfo item = new MonitorInfo(); |
|
1009 |
item.setCount(count); |
|
1010 |
item.setDate(new java.sql.Date(logDate.getTime())); |
|
1011 |
monitorList.addMonitorInfo(item); |
|
1012 |
|
|
1013 |
} |
|
1014 |
} catch (Exception e) { |
|
1015 |
e.printStackTrace(); |
|
1016 |
throw new ServiceFailure("2081", "Could not retrieve statistics: " + e.getMessage()); |
|
1017 |
} |
|
1018 |
|
|
1019 |
return monitorList; |
|
1020 |
|
|
1021 |
} |
|
1022 |
|
|
1023 | 971 |
/** |
1024 | 972 |
* A callback method used by a CN to indicate to a MN that it cannot |
1025 | 973 |
* complete synchronization of the science metadata identified by pid. Log |
... | ... | |
1398 | 1346 |
return identifier; |
1399 | 1347 |
} |
1400 | 1348 |
|
1401 |
@Override |
|
1402 |
public boolean isAuthorized(Identifier pid, Permission permission) |
|
1403 |
throws ServiceFailure, InvalidRequest, InvalidToken, NotFound, |
|
1404 |
NotAuthorized, NotImplemented { |
|
1349 |
|
|
1405 | 1350 |
|
1406 |
return isAuthorized(null, pid, permission); |
|
1407 |
} |
|
1408 |
|
|
1409 | 1351 |
@Override |
1410 |
public boolean systemMetadataChanged(Identifier pid, long serialVersion, Date dateSysMetaLastModified)
|
|
1352 |
public QueryEngineDescription getQueryEngineDescription(Session session, String engine)
|
|
1411 | 1353 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented, |
1412 |
InvalidRequest { |
|
1413 |
|
|
1414 |
return systemMetadataChanged(null, pid, serialVersion, dateSysMetaLastModified); |
|
1415 |
} |
|
1416 |
|
|
1417 |
@Override |
|
1418 |
public Log getLogRecords(Date fromDate, Date toDate, Event event, String pidFilter, |
|
1419 |
Integer start, Integer count) throws InvalidRequest, InvalidToken, |
|
1420 |
NotAuthorized, NotImplemented, ServiceFailure { |
|
1421 |
|
|
1422 |
return getLogRecords(null, fromDate, toDate, event, pidFilter, start, count); |
|
1423 |
} |
|
1424 |
|
|
1425 |
@Override |
|
1426 |
public DescribeResponse describe(Identifier pid) throws InvalidToken, |
|
1427 |
NotAuthorized, NotImplemented, ServiceFailure, NotFound { |
|
1428 |
|
|
1429 |
return describe(null, pid); |
|
1430 |
} |
|
1431 |
|
|
1432 |
@Override |
|
1433 |
public InputStream get(Identifier pid) throws InvalidToken, NotAuthorized, |
|
1434 |
NotImplemented, ServiceFailure, NotFound, InsufficientResources { |
|
1435 |
|
|
1436 |
return get(null, pid); |
|
1437 |
} |
|
1438 |
|
|
1439 |
@Override |
|
1440 |
public Checksum getChecksum(Identifier pid, String algorithm) |
|
1441 |
throws InvalidRequest, InvalidToken, NotAuthorized, NotImplemented, |
|
1442 |
ServiceFailure, NotFound { |
|
1443 |
|
|
1444 |
return getChecksum(null, pid, algorithm); |
|
1445 |
} |
|
1446 |
|
|
1447 |
@Override |
|
1448 |
public SystemMetadata getSystemMetadata(Identifier pid) |
|
1449 |
throws InvalidToken, NotAuthorized, NotImplemented, ServiceFailure, |
|
1450 | 1354 |
NotFound { |
1451 |
|
|
1452 |
return getSystemMetadata(null, pid); |
|
1453 |
} |
|
1454 |
|
|
1455 |
@Override |
|
1456 |
public ObjectList listObjects(Date startTime, Date endTime, |
|
1457 |
ObjectFormatIdentifier objectFormatId, Boolean replicaStatus, Integer start, |
|
1458 |
Integer count) throws InvalidRequest, InvalidToken, NotAuthorized, |
|
1459 |
NotImplemented, ServiceFailure { |
|
1460 |
|
|
1461 |
return listObjects(null, startTime, endTime, objectFormatId, replicaStatus, start, count); |
|
1462 |
} |
|
1463 |
|
|
1464 |
@Override |
|
1465 |
public boolean synchronizationFailed(SynchronizationFailed syncFailed) |
|
1466 |
throws InvalidToken, NotAuthorized, NotImplemented, ServiceFailure { |
|
1467 |
|
|
1468 |
return synchronizationFailed(null, syncFailed); |
|
1469 |
} |
|
1470 |
|
|
1471 |
@Override |
|
1472 |
public InputStream getReplica(Identifier pid) throws InvalidToken, |
|
1473 |
NotAuthorized, NotImplemented, ServiceFailure, NotFound, |
|
1474 |
InsufficientResources { |
|
1475 |
|
|
1476 |
return getReplica(null, pid); |
|
1477 |
} |
|
1478 |
|
|
1479 |
@Override |
|
1480 |
public boolean replicate(SystemMetadata sysmeta, NodeReference sourceNode) |
|
1481 |
throws NotImplemented, ServiceFailure, NotAuthorized, |
|
1482 |
InvalidRequest, InvalidToken, InsufficientResources, |
|
1483 |
UnsupportedType { |
|
1484 |
|
|
1485 |
return replicate(null, sysmeta, sourceNode); |
|
1486 |
} |
|
1487 |
|
|
1488 |
@Override |
|
1489 |
public Identifier create(Identifier pid, InputStream object, |
|
1490 |
SystemMetadata sysmeta) throws IdentifierNotUnique, |
|
1491 |
InsufficientResources, InvalidRequest, InvalidSystemMetadata, |
|
1492 |
InvalidToken, NotAuthorized, NotImplemented, ServiceFailure, |
|
1493 |
UnsupportedType { |
|
1494 |
|
|
1495 |
return create(null, pid, object, sysmeta); |
|
1496 |
} |
|
1497 |
|
|
1498 |
@Override |
|
1499 |
public Identifier delete(Identifier pid) throws InvalidToken, |
|
1500 |
ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
|
1501 |
|
|
1502 |
return delete(null, pid); |
|
1503 |
} |
|
1504 |
|
|
1505 |
@Override |
|
1506 |
public Identifier generateIdentifier(String scheme, String fragment) |
|
1507 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented, |
|
1508 |
InvalidRequest { |
|
1509 |
|
|
1510 |
return generateIdentifier(null, scheme, fragment); |
|
1511 |
} |
|
1512 |
|
|
1513 |
@Override |
|
1514 |
public Identifier update(Identifier pid, InputStream object, |
|
1515 |
Identifier newPid, SystemMetadata sysmeta) throws IdentifierNotUnique, |
|
1516 |
InsufficientResources, InvalidRequest, InvalidSystemMetadata, |
|
1517 |
InvalidToken, NotAuthorized, NotImplemented, ServiceFailure, |
|
1518 |
UnsupportedType, NotFound { |
|
1519 |
|
|
1520 |
return update(null, pid, object, newPid, sysmeta); |
|
1521 |
} |
|
1522 |
|
|
1523 |
@Override |
|
1524 |
public QueryEngineDescription getQueryEngineDescription(String engine) |
|
1525 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented, |
|
1526 |
NotFound { |
|
1527 | 1355 |
if(engine != null && engine.equals(EnabledQueryEngines.PATHQUERYENGINE)) { |
1528 | 1356 |
if(!EnabledQueryEngines.getInstance().isEnabled(EnabledQueryEngines.PATHQUERYENGINE)) { |
1529 | 1357 |
throw new NotImplemented("0000", "MNodeService.query - the query engine "+engine +" hasn't been implemented or has been disabled."); |
... | ... | |
1569 | 1397 |
} |
1570 | 1398 |
|
1571 | 1399 |
@Override |
1572 |
public QueryEngineList listQueryEngines() throws InvalidToken, |
|
1400 |
public QueryEngineList listQueryEngines(Session session) throws InvalidToken,
|
|
1573 | 1401 |
ServiceFailure, NotAuthorized, NotImplemented { |
1574 | 1402 |
QueryEngineList qel = new QueryEngineList(); |
1575 | 1403 |
//qel.addQueryEngine(EnabledQueryEngines.PATHQUERYENGINE); |
... | ... | |
1582 | 1410 |
} |
1583 | 1411 |
|
1584 | 1412 |
@Override |
1585 |
public InputStream query(String engine, String query) throws InvalidToken, |
|
1413 |
public InputStream query(Session session, String engine, String query) throws InvalidToken,
|
|
1586 | 1414 |
ServiceFailure, NotAuthorized, InvalidRequest, NotImplemented, |
1587 | 1415 |
NotFound { |
1588 | 1416 |
String user = Constants.SUBJECT_PUBLIC; |
... | ... | |
1855 | 1683 |
query = "fl=id,resourceMap&wt=xml&q=resourceMap:[* TO *]+id:\"" + pid + "\""; |
1856 | 1684 |
} |
1857 | 1685 |
|
1858 |
InputStream results = this.query("solr", query); |
|
1686 |
InputStream results = this.query(null, "solr", query);
|
|
1859 | 1687 |
org.w3c.dom.Node rootNode = XMLUtilities.getXMLReaderAsDOMTreeRootNode(new InputStreamReader(results, "UTF-8")); |
1860 | 1688 |
//String resultString = XMLUtilities.getDOMTreeAsString(rootNode); |
1861 | 1689 |
org.w3c.dom.NodeList nodeList = XMLUtilities.getNodeListWithXPath(rootNode, "//arr[@name=\"resourceMap\"]/str"); |
... | ... | |
1875 | 1703 |
return retList; |
1876 | 1704 |
} |
1877 | 1705 |
|
1878 |
/** |
|
1879 |
* Packages the given package in a Bagit collection for download |
|
1880 |
* @param pid |
|
1881 |
* @throws NotImplemented |
|
1882 |
* @throws NotFound |
|
1883 |
* @throws NotAuthorized |
|
1884 |
* @throws ServiceFailure |
|
1885 |
* @throws InvalidToken |
|
1886 |
*/ |
|
1887 |
public InputStream getPackage(Session session, Identifier pid) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
|
1888 |
|
|
1706 |
|
|
1707 |
@Override |
|
1708 |
public InputStream getPackage(Session session, ObjectFormatIdentifier formatId, |
|
1709 |
Identifier pid) throws InvalidToken, ServiceFailure, |
|
1710 |
NotAuthorized, InvalidRequest, NotImplemented, NotFound { |
|
1889 | 1711 |
InputStream bagInputStream = null; |
1890 | 1712 |
BagFactory bagFactory = new BagFactory(); |
1891 | 1713 |
Bag bag = bagFactory.createBag(); |
... | ... | |
2145 | 1967 |
} |
2146 | 1968 |
|
2147 | 1969 |
return bagInputStream; |
1970 |
} |
|
2148 | 1971 |
|
1972 |
@Override |
|
1973 |
public OptionList listViews(Session arg0) throws InvalidToken, |
|
1974 |
ServiceFailure, NotAuthorized, InvalidRequest, NotImplemented { |
|
1975 |
OptionList views = new OptionList(); |
|
1976 |
Vector<String> skinNames = null; |
|
1977 |
try { |
|
1978 |
skinNames = SkinUtil.getSkinNames(); |
|
1979 |
} catch (PropertyNotFoundException e) { |
|
1980 |
throw new ServiceFailure("2841", e.getMessage()); |
|
1981 |
} |
|
1982 |
for (String skinName: skinNames) { |
|
1983 |
views.addOption(skinName); |
|
1984 |
} |
|
1985 |
return views; |
|
2149 | 1986 |
} |
2150 |
|
|
2151 |
/** |
|
2152 |
* Get a rendered view of the object identified by pid. |
|
2153 |
* Uses the registered format given by the format parameter. |
|
2154 |
* Typically, this is structured HTML that can be styled with CSS. |
|
2155 |
* @param session |
|
2156 |
* @param pid |
|
2157 |
* @param format |
|
2158 |
* @return |
|
2159 |
* @throws InvalidToken |
|
2160 |
* @throws ServiceFailure |
|
2161 |
* @throws NotAuthorized |
|
2162 |
* @throws NotFound |
|
2163 |
* @throws NotImplemented |
|
2164 |
*/ |
|
2165 |
public InputStream getView(Session session, Identifier pid, String format) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
|
1987 |
|
|
1988 |
@Override |
|
1989 |
public InputStream view(Session session, String format, Identifier pid) |
|
1990 |
throws InvalidToken, ServiceFailure, NotAuthorized, InvalidRequest, |
|
1991 |
NotImplemented, NotFound { |
|
2166 | 1992 |
InputStream resultInputStream = null; |
2167 | 1993 |
|
2168 | 1994 |
SystemMetadata sysMeta = this.getSystemMetadata(session, pid); |
... | ... | |
2231 | 2057 |
} |
2232 | 2058 |
|
2233 | 2059 |
return resultInputStream; |
2234 |
|
|
2235 | 2060 |
} |
2236 | 2061 |
|
2237 | 2062 |
} |
Also available in: Unified diff
add support for v2 DataONE API.