Revision 55485
Added by Sandro La Bruzzo almost 5 years ago
modules/dnet-modular-objectstore-service/trunk/src/main/java/eu/dnetlib/data/objectstore/modular/CreateObjectStoreAction.java | ||
---|---|---|
39 | 39 |
protected void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) { |
40 | 40 |
try { |
41 | 41 |
final String interpretation = job.getParameters().get("interpretation"); |
42 |
final String basePath = job.getParameters().get("basePath"); |
|
43 |
if (StringUtils.isBlank(basePath)) { |
|
44 |
throw new ObjectStoreServiceException("missing basePath param"); |
|
45 |
} |
|
42 |
// final String basePath = job.getParameters().get("basePath");
|
|
43 |
// if (StringUtils.isBlank(basePath)) {
|
|
44 |
// throw new ObjectStoreServiceException("missing basePath param");
|
|
45 |
// }
|
|
46 | 46 |
|
47 | 47 |
final String objID = profileCreator.registerProfile(interpretation); |
48 | 48 |
try { |
49 |
getDao().createObjectStore(objID, interpretation, basePath);
|
|
49 |
getDao().createObjectStore(objID, interpretation, null);
|
|
50 | 50 |
} catch (Throwable e) { |
51 | 51 |
log.warn("cannot created objectStore, deleting profile"); |
52 | 52 |
profileCreator.deleteProfile(objID); |
modules/dnet-modular-objectstore-service/trunk/pom.xml | ||
---|---|---|
9 | 9 |
<groupId>eu.dnetlib</groupId> |
10 | 10 |
<artifactId>dnet-modular-objectstore-service</artifactId> |
11 | 11 |
<packaging>jar</packaging> |
12 |
<version>4.2.2-SNAPSHOT</version>
|
|
12 |
<version>5.0.0-SNAPSHOT</version>
|
|
13 | 13 |
<scm> |
14 | 14 |
<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-modular-objectstore-service/trunk</developerConnection> |
15 | 15 |
</scm> |
modules/dnet-s3-objectStore/trunk/src/test/java/eu/dnetlib/data/objectStore/S3/S3ObjectStoreTest.java | ||
---|---|---|
51 | 51 |
// System.out.println(objectMetadata.getContentMD5()); |
52 | 52 |
|
53 | 53 |
|
54 |
|
|
55 |
|
|
54 | 56 |
} |
55 | 57 |
} |
modules/dnet-s3-objectStore/trunk/src/main/java/eu/dnetlib/data/objectstore/s3/ModularObjectStoreRESTService.java | ||
---|---|---|
1 |
package eu.dnetlib.data.objectstore.s3; |
|
2 |
|
|
3 |
import java.io.*; |
|
4 |
import java.net.URLEncoder; |
|
5 |
import java.nio.file.Files; |
|
6 |
import java.nio.file.Path; |
|
7 |
import javax.servlet.http.HttpServletResponse; |
|
8 |
|
|
9 |
import com.amazonaws.ClientConfiguration; |
|
10 |
import com.amazonaws.Protocol; |
|
11 |
import com.amazonaws.auth.AWSCredentials; |
|
12 |
import com.amazonaws.auth.AWSStaticCredentialsProvider; |
|
13 |
import com.amazonaws.auth.BasicAWSCredentials; |
|
14 |
import com.amazonaws.client.builder.AwsClientBuilder; |
|
15 |
import com.amazonaws.services.s3.AmazonS3; |
|
16 |
import com.amazonaws.services.s3.AmazonS3ClientBuilder; |
|
17 |
import com.amazonaws.services.s3.model.S3Object; |
|
18 |
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException; |
|
19 |
import eu.dnetlib.miscutils.datetime.HumanTime; |
|
20 |
import org.apache.commons.io.IOUtils; |
|
21 |
import org.apache.commons.logging.Log; |
|
22 |
import org.apache.commons.logging.LogFactory; |
|
23 |
import org.springframework.beans.factory.annotation.Value; |
|
24 |
import org.springframework.stereotype.Controller; |
|
25 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
26 |
import org.springframework.web.bind.annotation.RequestParam; |
|
27 |
|
|
28 |
/** |
|
29 |
* The Class ModularObjectStoreRESTService implement the controller REST of the object Store. |
|
30 |
*/ |
|
31 |
@Controller |
|
32 |
public class ModularObjectStoreRESTService { |
|
33 |
|
|
34 |
private static final Log log = LogFactory.getLog(ModularObjectStoreRESTService.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
@Value("${dnet.objectStore.s3.accessKey}") |
|
39 |
private String accessKey; |
|
40 |
|
|
41 |
|
|
42 |
@Value("${dnet.objectStore.s3.secretKey}") |
|
43 |
private String secretKey; |
|
44 |
|
|
45 |
@Value("${dnet.objectStore.s3.endPoint}") |
|
46 |
private String s3EndPoint; |
|
47 |
|
|
48 |
@Value("${dnet.objectStore.s3.objectStoreBucket}") |
|
49 |
private String objectStoreBucket; |
|
50 |
|
|
51 |
private AmazonS3 client; |
|
52 |
|
|
53 |
private static final String S3_REGION = "eu-west-3"; |
|
54 |
|
|
55 |
|
|
56 |
private AmazonS3 initializeClient() throws ObjectStoreServiceException { |
|
57 |
try { |
|
58 |
final AWSCredentials credentials = new BasicAWSCredentials(this.accessKey, this.secretKey); |
|
59 |
final ClientConfiguration cfg = new ClientConfiguration().withProtocol(Protocol.HTTPS); |
|
60 |
final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)) |
|
61 |
.withClientConfiguration(cfg) |
|
62 |
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(this.s3EndPoint, S3_REGION)) |
|
63 |
.build(); |
|
64 |
if (s3 == null) |
|
65 |
throw new ObjectStoreServiceException("Cannot initialize s3 client because is NULL"); |
|
66 |
return s3; |
|
67 |
} catch (Throwable e) { |
|
68 |
log.error("An Error happen on initialize client ", e); |
|
69 |
throw new ObjectStoreServiceException("Cannot initialize s3 client", e); |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
|
|
74 |
public static String retrieveURL(final String baseURI, final String basePath, final String objectStoreId, final String objectId) |
|
75 |
throws UnsupportedEncodingException { |
|
76 |
final StringBuilder sb = new StringBuilder(baseURI) |
|
77 |
.append("?objectStore=" + encode(objectStoreId)) |
|
78 |
.append("&objectId=" + encode(objectId)) |
|
79 |
.append("&basePath=" + encode(basePath)); |
|
80 |
return sb.toString(); |
|
81 |
} |
|
82 |
|
|
83 |
private static String encode(final String s) throws UnsupportedEncodingException { |
|
84 |
return URLEncoder.encode(s, "UTF-8"); |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* |
|
89 |
* @param res |
|
90 |
* @param objectStoreId |
|
91 |
* @param objectId |
|
92 |
* @throws IOException |
|
93 |
* @throws ObjectStoreServiceException |
|
94 |
*/ |
|
95 |
@RequestMapping(value = "/**/objectStore/retrieve.do") |
|
96 |
public void retrieve(final HttpServletResponse res, |
|
97 |
@RequestParam(value = "objectStore", required = true) final String objectStoreId, |
|
98 |
@RequestParam(value = "objectId", required = true) final String objectId) throws IOException, ObjectStoreServiceException { |
|
99 |
|
|
100 |
final long start = System.currentTimeMillis(); |
|
101 |
if (client == null) |
|
102 |
client = initializeClient(); |
|
103 |
final S3Object object = this.client.getObject(objectStoreBucket, objectStoreId + "/" + objectId); |
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
if (object == null) { |
|
108 |
final String msg = String.format("Object with identifier: %s not found the in %s", objectId, objectStoreId); |
|
109 |
res.sendError(HttpServletResponse.SC_NOT_FOUND, msg); |
|
110 |
log.warn(msg); |
|
111 |
} else { |
|
112 |
try ( final InputStream is = object.getObjectContent()) { |
|
113 |
|
|
114 |
res.setHeader("Content-Length", String.valueOf(object.getObjectMetadata().getContentLength())); |
|
115 |
IOUtils.copyLarge(is, res.getOutputStream()); |
|
116 |
if (log.isDebugEnabled()) { |
|
117 |
log.debug(String.format("retrive.do completed in %s, objId: %s", HumanTime.exactly(System.currentTimeMillis() - start), objectId)); |
|
118 |
} |
|
119 |
} catch (IOException e) { |
|
120 |
final String msg = "unable to close input Stream"; |
|
121 |
res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg); |
|
122 |
log.error(msg, e); |
|
123 |
} |
|
124 |
} |
|
125 |
} |
|
126 |
} |
modules/dnet-s3-objectStore/trunk/src/main/java/eu/dnetlib/data/objectstore/s3/S3ObjectStore.java | ||
---|---|---|
145 | 145 |
if (objectStoreRecord!= null && objectStoreRecord.getInputStream()!= null ) { |
146 | 146 |
log.debug("Saving object with ID: " + objectStoreRecord.getFileMetadata().getObjectID() + " on s3 "); |
147 | 147 |
this.client.putObject(objectStoreBucket, id + "/" + objectStoreRecord.getFileMetadata().getObjectID(), objectStoreRecord.getInputStream(), null); |
148 |
final S3Object s3Object = this.client.getObject(id, "/" + objectStoreRecord.getFileMetadata().getObjectID());
|
|
148 |
final S3Object s3Object = this.client.getObject(objectStoreBucket ,id+ "/" + objectStoreRecord.getFileMetadata().getObjectID());
|
|
149 | 149 |
log.debug("Total time to put into the ObjectStore " + (System.currentTimeMillis() - start)); |
150 | 150 |
log.debug("Saved object on s3 "); |
151 | 151 |
double timestamp = System.currentTimeMillis(); |
... | ... | |
160 | 160 |
log.debug("saving metadata object to the collection: " + metadata.toString()); |
161 | 161 |
start = System.currentTimeMillis(); |
162 | 162 |
mongoCollection.insertOne(metadata); |
163 |
log.debug("Total time to sav in Mongo " + (System.currentTimeMillis() - start)); |
|
163 |
log.debug("Total time to save in Mongo " + (System.currentTimeMillis() - start));
|
|
164 | 164 |
|
165 | 165 |
} |
166 | 166 |
} catch (Throwable e) { |
modules/dnet-s3-objectStore/trunk/pom.xml | ||
---|---|---|
3 | 3 |
<parent> |
4 | 4 |
<groupId>eu.dnetlib</groupId> |
5 | 5 |
<artifactId>dnet45-parent</artifactId> |
6 |
<version>1.0.0</version> |
|
6 |
<version>1.0.0-SNAPSHOT</version>
|
|
7 | 7 |
</parent> |
8 | 8 |
<groupId>eu.dnetlib</groupId> |
9 | 9 |
<artifactId>dnet-s3-objectStore</artifactId> |
... | ... | |
21 | 21 |
<dependency> |
22 | 22 |
<groupId>eu.dnetlib</groupId> |
23 | 23 |
<artifactId>dnet-modular-objectstore-service</artifactId> |
24 |
<version>[4.2.0,5.0.0)</version>
|
|
24 |
<version>5.0.0-SNAPSHOT</version>
|
|
25 | 25 |
</dependency> |
26 | 26 |
<dependency> |
27 | 27 |
<groupId>eu.dnetlib</groupId> |
modules/dnet-objectStore-ui/trunk/src/main/resources/eu/dnetlib/web/resources/html/objectStore/inspect.html | ||
---|---|---|
177 | 177 |
<div class="col-lg-8 text-left"><a href="{{item.downloadedURL}}">{{item.downloadedURL}}</a> |
178 | 178 |
</div> |
179 | 179 |
<div class="col-lg-3 text-right"><b>Object Store URL:</b></div> |
180 |
<div class="col-lg-8 text-left">{{item.uri}}</div>
|
|
180 |
<div class="col-lg-8 text-left"><a href="../objectStore/retrieve.do?objectStore={{objectStoreInfo.objectStoreId}}&objectId={{item.objectID}}">{{item.uri}}</a></div>
|
|
181 | 181 |
</div> |
182 | 182 |
|
183 | 183 |
|
Also available in: Unified diff
implemented ObjectStores3 to avoid to saving tmp file before putting on s3 and added rest controller to download object from s3, used only by UI