Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding storage api #43

Merged
merged 49 commits into from
May 7, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
0613f53
storage work in progress
aozarov Mar 2, 2015
125d6e9
wip
aozarov Mar 3, 2015
40e9739
wip
aozarov Mar 4, 2015
79215c4
wip
aozarov Mar 18, 2015
d15a682
work in progress
aozarov Mar 20, 2015
1188ac6
work in progress
aozarov Apr 1, 2015
c9611f2
work in progress
aozarov Apr 1, 2015
43d0761
work in progress
aozarov Apr 2, 2015
7dcee4b
wip
aozarov Apr 3, 2015
59f0d85
work in progress
aozarov Apr 9, 2015
a7b661a
Merge remote-tracking branch 'upstream/master'
aozarov Apr 9, 2015
126b043
work in progress
aozarov Apr 9, 2015
4f65b2d
work in progress
aozarov Apr 10, 2015
a3cf907
work in progress
aozarov Apr 10, 2015
2cdc4e3
work in progress
aozarov Apr 11, 2015
24f8a0b
work in progress
aozarov Apr 14, 2015
4836863
work in progress
aozarov Apr 14, 2015
fcb3dcd
work in progress
aozarov Apr 14, 2015
d3f0356
work in progress
aozarov Apr 14, 2015
3171d8c
work in progress
aozarov Apr 16, 2015
f88107c
work in progress
aozarov Apr 18, 2015
8ef30c8
work in progress
aozarov Apr 21, 2015
89a5024
work in progress
aozarov Apr 21, 2015
2841929
work in progress
aozarov Apr 22, 2015
803527d
work in progress
aozarov Apr 22, 2015
f327dad
work in progress
aozarov Apr 23, 2015
c92f2ea
make AuthCredentials serializable
aozarov Apr 24, 2015
d504256
work in progress
aozarov Apr 24, 2015
c148817
work in progress
aozarov Apr 24, 2015
09a890f
work in progress
aozarov Apr 24, 2015
a4076b7
work in progress
aozarov Apr 25, 2015
9cb77fa
work in progress
aozarov Apr 29, 2015
acff3c1
add default content type to compose
aozarov Apr 29, 2015
ad396b7
work in progress
aozarov Apr 30, 2015
6df1164
adding batch
aozarov May 1, 2015
a4ee293
work in progress
aozarov May 2, 2015
2ed5ce1
work in progress
aozarov May 2, 2015
4c2f40e
complete batch
aozarov May 4, 2015
59410ab
add multi info to example
aozarov May 4, 2015
f0920d0
work in progress
aozarov May 4, 2015
64da673
find project-id from env
aozarov May 4, 2015
e3222e5
update ini hanlding
aozarov May 4, 2015
9b751ae
implement Serializable reader
aozarov May 4, 2015
2d279f4
work in progress
aozarov May 5, 2015
4260e8e
work in progress
aozarov May 5, 2015
e830ad3
work in progress
aozarov May 6, 2015
a964351
work in progress
aozarov May 6, 2015
6d4ac35
work in progress
aozarov May 6, 2015
d2c6344
complete output writer
aozarov May 7, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
work in progress
  • Loading branch information
aozarov committed Apr 14, 2015
commit 24f8a0b9187bd9c6f345c0e03a66d00c00125e7b
16 changes: 7 additions & 9 deletions src/main/java/com/google/gcloud/examples/StorageExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

package com.google.gcloud.examples;

import com.google.api.services.storage.Storage;
import com.google.gcloud.storage.BucketInfo;
import com.google.gcloud.storage.Bucket;
import com.google.gcloud.storage.StorageService;
import com.google.gcloud.storage.StorageServiceFactory;
import com.google.gcloud.storage.StorageServiceOptions;
Expand Down Expand Up @@ -47,7 +46,7 @@ public class StorageExample {

private static abstract class StorageAction {

abstract void run(StorageService storage, BucketInfo bucket, String folder, String... args);
abstract void run(StorageService storage, Bucket bucket, String folder, String... args);

protected String getRequiredParams() {
return "";
Expand All @@ -65,7 +64,7 @@ protected String fullPath(String folder, String file) {

private static class DeleteAction extends StorageAction {
@Override
public void run(StorageService storage, BucketInfo bucket, String folder, String... args) {
public void run(StorageService storage, Bucket bucket, String folder, String... args) {
for (String file : args) {
storage.delete(bucket.name(), fullPath(folder, file));
}
Expand All @@ -84,18 +83,18 @@ public String getRequiredParams() {
public static void main(String... args) {
StorageAction action = null;
StorageService storage = null;
BucketInfo bucketInfo = null;
Bucket bucket = null;
String folder = DEFAULT_FOLDER;
if (args.length > 0) {
String bucket = args[0];
String bucketName = args[0];
String actionName = DEFAULT_ACTION;
if (args.length > 1) {
folder = args[1];
if (args.length > 2) {
actionName = args[2].toLowerCase();
}
storage = StorageServiceFactory.getDefault(StorageServiceOptions.builder().build());
bucketInfo = storage.get(bucket);
bucket = storage.get(bucketName);
}
action = ACTIONS.get(actionName);
}
Expand All @@ -117,7 +116,6 @@ public static void main(String... args) {
}

args = args.length > 2 ? Arrays.copyOfRange(args, 2, args.length): new String []{};
action.run(bucketInfo, folder, args);
}
action.run(storage, bucket, folder, args);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.gcloud.spi;import com.google.api.client.http.HttpRequestInitializer;import com.google.api.client.http.HttpTransport;import com.google.api.client.json.jackson.JacksonFactory;import com.google.api.services.storage.Storage;import com.google.api.services.storage.model.Bucket;import com.google.api.services.storage.model.Buckets;import com.google.gcloud.storage.StorageServiceOptions;import java.io.IOException;import java.util.List;public class DefaultStorageRpc implements StorageRpc { private final StorageServiceOptions options; private final Storage storage; public DefaultStorageRpc(StorageServiceOptions options) { HttpTransport transport = options.httpTransport(); HttpRequestInitializer initializer = transport.createRequestFactory() .getInitializer(); this.options = options; storage = new Storage.Builder(transport, new JacksonFactory(), initializer).build(); } @Override public List<Bucket> buckets() throws IOException { Buckets buckets = storage.buckets().list(options.project()).execute(); return buckets.getItems(); } @Override public Bucket bucket(String bucket) throws IOException { return storage.buckets().get(bucket).execute(); }}
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.gcloud.spi;import com.google.api.client.http.HttpRequestInitializer;import com.google.api.client.http.HttpTransport;import com.google.api.client.json.jackson.JacksonFactory;import com.google.api.services.storage.Storage;import com.google.api.services.storage.model.Bucket;import com.google.api.services.storage.model.Buckets;import com.google.api.services.storage.model.StorageObject;import com.google.gcloud.storage.StorageServiceOptions;import java.io.IOException;import java.util.List;public class DefaultStorageRpc implements StorageRpc { private final StorageServiceOptions options; private final Storage storage; public DefaultStorageRpc(StorageServiceOptions options) { HttpTransport transport = options.httpTransport(); HttpRequestInitializer initializer = transport.createRequestFactory() .getInitializer(); this.options = options; storage = new Storage.Builder(transport, new JacksonFactory(), initializer).build(); } @Override public List<Bucket> buckets() throws IOException { Buckets buckets = storage.buckets().list(options.project()).execute(); return buckets.getItems(); } @Override public List<StorageObject> objects(String bucket, String prefix, String delimiter) throws IOException { return null; } @Override public Bucket get(String bucket) throws IOException { return storage.buckets().get(bucket).execute(); } @Override public StorageObject get(String bucket, String object) throws IOException { return storage.objects().get(bucket, object).execute(); } @Override public Bucket patch(Bucket bucket) throws IOException { return storage.buckets().patch(bucket.getName(), bucket).execute(); } @Override public StorageObject patch(StorageObject storageObject) throws IOException { return storage.objects() .patch(storageObject.getBucket(), storageObject.getName(), storageObject).execute(); } @Override public void delete(String bucket, String object) throws IOException { storage.objects().delete(bucket, object).execute(); }}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/google/gcloud/spi/StorageRpc.java
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.gcloud.spi;import com.google.api.services.storage.model.Bucket;import com.google.api.services.storage.model.StorageObject;import java.io.IOException;import java.util.List;public interface StorageRpc { List<Bucket> buckets() throws IOException; Bucket bucket(String name) throws IOException; void patch(Bucket bucket) throws IOException; void patch(StorageObject storageObject) throws IOException;}
/* * Copyright 2015 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.gcloud.spi;import com.google.api.services.storage.model.Bucket;import com.google.api.services.storage.model.StorageObject;import java.io.IOException;import java.util.List;public interface StorageRpc { List<Bucket> buckets() throws IOException; List<StorageObject> objects(String bucket, String prefix, String delimiter) throws IOException; Bucket get(String bucket) throws IOException; StorageObject get(String bucket, String object) throws IOException; Bucket patch(Bucket bucket) throws IOException; StorageObject patch(StorageObject storageObject) throws IOException; //void delete(String bucket) throws IOException; void delete(String bucket, String object) throws IOException;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.api.client.util.DateTime;
import com.google.api.services.storage.model.ObjectAccessControl;
import com.google.api.services.storage.model.StorageObject;
import com.google.api.services.storage.model.StorageObject.Owner;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand All @@ -29,7 +30,7 @@
import java.util.List;
import java.util.Map;

public class ObjectInfo implements Serializable {
public class Blob implements Serializable {

private static final long serialVersionUID = 2228487739943277159L;

Expand Down Expand Up @@ -194,12 +195,12 @@ public Builder updateTime(long updateTime) {
return this;
}

public ObjectInfo build() {
return new ObjectInfo(this);
public Blob build() {
return new Blob(this);
}
}

private ObjectInfo(Builder builder) {
private Blob(Builder builder) {
bucket = builder.bucket;
id = builder.id;
name = builder.name;
Expand Down Expand Up @@ -346,8 +347,7 @@ StorageObject toPb() {
StorageObject storageObject = new StorageObject();
storageObject.setAcl(Lists.transform(acl,
new Function<Acl, ObjectAccessControl>() {
@Override
public ObjectAccessControl apply(Acl acl) {
@Override public ObjectAccessControl apply(Acl acl) {
return acl.toObjectPb();
}
}));
Expand All @@ -363,7 +363,7 @@ public ObjectAccessControl apply(Acl acl) {
storageObject.setMetadata(metadata);
storageObject.setMetageneration(metageneration);
storageObject.setName(name);
storageObject.setOwner(new StorageObject.Owner().setEntity(owner.toPb()));
storageObject.setOwner(new Owner().setEntity(owner.toPb()));
storageObject.setUpdated(new DateTime(updateTime));
storageObject.setSize(BigInteger.valueOf(size));
storageObject.setContentDisposition(contentDisposition);
Expand All @@ -375,7 +375,7 @@ public ObjectAccessControl apply(Acl acl) {
return storageObject;
}

static ObjectInfo fromPb(StorageObject storageObject) {
static Blob fromPb(StorageObject storageObject) {
return builder()
.acl(Lists.transform(storageObject.getAcl(),
new Function<ObjectAccessControl, Acl>() {
Expand Down
Loading