Revision 5805
Added by berkley almost 14 years ago
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* '$RCSfile$' |
3 |
* Copyright: 2000 Regents of the University of California and the
|
|
3 |
* Copyright: 2011 Regents of the University of California and the
|
|
4 | 4 |
* National Center for Ecological Analysis and Synthesis |
5 | 5 |
* |
6 | 6 |
* '$Author: Serhan AKIN $' |
... | ... | |
23 | 23 |
package edu.ucsb.nceas.metacat.restservice; |
24 | 24 |
|
25 | 25 |
import java.io.*; |
26 |
import java.net.URL; |
|
26 | 27 |
import java.util.*; |
27 | 28 |
|
28 | 29 |
import javax.mail.BodyPart; |
... | ... | |
41 | 42 |
import org.apache.commons.io.IOUtils; |
42 | 43 |
import org.apache.log4j.Logger; |
43 | 44 |
import org.apache.maven.artifact.ant.shaded.IOUtil; |
45 |
import org.dataone.service.NodeListParser; |
|
44 | 46 |
import org.dataone.service.exceptions.BaseException; |
45 | 47 |
import org.dataone.service.exceptions.IdentifierNotUnique; |
46 | 48 |
import org.dataone.service.exceptions.InsufficientResources; |
... | ... | |
589 | 591 |
String pathInfo = request.getPathInfo(); |
590 | 592 |
pathInfo = pathInfo.substring(1); |
591 | 593 |
System.out.println("pathInfo: " + pathInfo); |
592 |
String nodeId = pathInfo.substring(0, pathInfo.indexOf("/")); |
|
593 | 594 |
String guid = pathInfo.substring(pathInfo.indexOf("/") + 1, pathInfo.length()); |
594 |
System.out.println("replicating (pulling) " + guid + " from node " + nodeId); |
|
595 | 595 |
|
596 |
//get the system metadata from the request |
|
597 |
Hashtable<String, File> mmpFiles = writeMMPPartsToFiles(request.getInputStream()); |
|
598 |
SystemMetadata sm = (SystemMetadata) |
|
599 |
deserializeServiceType(SystemMetadata.class, |
|
600 |
new FileInputStream(mmpFiles.get("systemmetadata"))); |
|
601 |
String nodeId = sm.getAuthoritativeMemberNode().getValue(); |
|
602 |
//lookup nodeId from the registry |
|
603 |
URL url = new URL("http://cn.dataone.org/cn/node"); |
|
604 |
InputStream is = url.openStream(); |
|
605 |
Map<String,String> m = NodeListParser.parseNodeListFile(is); |
|
606 |
String nodeUrl = m.get(nodeId); |
|
607 |
if(nodeUrl == null) |
|
608 |
{ |
|
609 |
response.setStatus(500); |
|
610 |
response.getOutputStream().write(("Member Node id " + |
|
611 |
nodeId + " not found in node registry.").getBytes()); |
|
612 |
response.getOutputStream().close(); |
|
613 |
} |
|
614 |
|
|
615 |
//we at least have enough information to continue so |
|
616 |
//tell the cn we're ok |
|
596 | 617 |
//respond to cn with 200/OK |
597 |
//lookup nodeId from the registry |
|
618 |
response.setStatus(200); |
|
619 |
response.getOutputStream().write("OK".getBytes()); |
|
620 |
response.getOutputStream().close(); |
|
621 |
|
|
598 | 622 |
//get the document |
599 | 623 |
//verify checksum |
600 | 624 |
//insert the document in local db |
Also available in: Unified diff
implementing replicate