JCLOUDS-1336: GCS object-level storage class

This commit is contained in:
Andrew Gaul 2017-09-01 11:55:58 -07:00
parent 2817b27725
commit 1937e200e3
3 changed files with 22 additions and 0 deletions

View File

@ -421,6 +421,7 @@ public final class GoogleCloudStorageBlobStore extends BaseBlobStore {
public MultipartPart uploadMultipartPart(MultipartUpload mpu, int partNumber, Payload payload) {
String partName = getMPUPartName(mpu, partNumber);
long partSize = payload.getContentMetadata().getContentLength();
// TODO: JCLOUDS-1337: use multipartUpload to set storage class
InsertObjectOptions insertOptions = new InsertObjectOptions().name(partName);
GoogleCloudStorageObject object = api.getObjectApi().simpleUpload(mpu.containerName(),
mpu.blobMetadata().getContentMetadata().getContentType(), partSize, payload, insertOptions);

View File

@ -17,9 +17,12 @@
package org.jclouds.googlecloudstorage.domain.templates;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import java.util.Map;
import org.jclouds.googlecloudstorage.domain.DomainResourceReferences.StorageClass;
import org.jclouds.googlecloudstorage.domain.ObjectAccessControls;
import com.google.common.base.MoreObjects;
@ -38,6 +41,7 @@ public class ObjectTemplate {
private String contentType;
private String crc32c;
private String md5Hash;
private StorageClass storageClass;
private Map<String, String> metadata;
private List<ObjectAccessControls> acl;
@ -107,6 +111,11 @@ public class ObjectTemplate {
return this;
}
public ObjectTemplate storageClass(StorageClass storageClass) {
this.storageClass = checkNotNull(storageClass);
return this;
}
public ObjectTemplate addAcl(ObjectAccessControls acl) {
if (this.acl == null) {
this.acl = Lists.newArrayList();
@ -155,6 +164,10 @@ public class ObjectTemplate {
return md5Hash;
}
public StorageClass storageClass() {
return storageClass;
}
public String name() {
return name;
}
@ -179,6 +192,7 @@ public class ObjectTemplate {
.add("contentType", contentType)
.add("crc32c", crc32c)
.add("md5Hash", md5Hash)
.add("storageClass", storageClass)
.add("metadata", metadata)
.add("acl", acl)
.toString();

View File

@ -34,6 +34,7 @@ import org.jclouds.googlecloudstorage.domain.Bucket;
import org.jclouds.googlecloudstorage.domain.DomainResourceReferences.DestinationPredefinedAcl;
import org.jclouds.googlecloudstorage.domain.DomainResourceReferences.ObjectRole;
import org.jclouds.googlecloudstorage.domain.DomainResourceReferences.Projection;
import org.jclouds.googlecloudstorage.domain.DomainResourceReferences.StorageClass;
import org.jclouds.googlecloudstorage.domain.GoogleCloudStorageObject;
import org.jclouds.googlecloudstorage.domain.ListPageWithPrefixes;
import org.jclouds.googlecloudstorage.domain.ObjectAccessControls;
@ -424,6 +425,7 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {
template.contentType("image/jpeg").addAcl(oacl).size(contentLength).name(MULTIPART_UPLOAD_OBJECT)
.contentLanguage("en").contentDisposition("attachment").md5Hash(md5Hash)
.storageClass(StorageClass.NEARLINE)
.customMetadata("custommetakey1", "custommetavalue1").crc32c(crc32c)
.customMetadata(ImmutableMap.of("Adrian", "powderpuff"));
@ -436,6 +438,11 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {
assertThat(gcsObject.metadata()).contains(entry("custommetakey1", "custommetavalue1"),
entry("Adrian", "powderpuff")).doesNotContainKey("adrian");
gcsObject = api().getObject(BUCKET_NAME, MULTIPART_UPLOAD_OBJECT, null);
assertThat(gcsObject).isNotNull();
assertThat(gcsObject.storageClass()).isEqualTo(StorageClass.NEARLINE);
PayloadEnclosing impl = api().download(BUCKET_NAME, MULTIPART_UPLOAD_OBJECT);
assertThat(ByteStreams2.toByteArrayAndClose(impl.getPayload().openStream())).isEqualTo(