Skip to content

Commit c32010c

Browse files
Merge pull request #649 from jean-philippe-martin/gcs-nio
Migrate GCS NIO from App Engine to gcloud-storage
2 parents 2e2b450 + b01d842 commit c32010c

31 files changed

Lines changed: 918 additions & 472 deletions

gcloud-java-contrib/README.md

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,10 @@ Google Cloud Java Contributions
33

44
Packages that provide higher-level abstraction/functionality for common gcloud-java use cases.
55

6-
Quickstart
7-
----------
8-
If you are using Maven, add this to your pom.xml file
9-
```xml
10-
<dependency>
11-
<groupId>com.google.gcloud</groupId>
12-
<artifactId>gcloud-java-contrib</artifactId>
13-
<version>0.1.3</version>
14-
</dependency>
15-
```
16-
If you are using Gradle, add this to your dependencies
17-
```Groovy
18-
compile 'com.google.gcloud:gcloud-java-contrib:0.1.3'
19-
```
20-
If you are using SBT, add this to your dependencies
21-
```Scala
22-
libraryDependencies += "com.google.gcloud" % "gcloud-java-contrib" % "0.1.3"
23-
```
24-
25-
Java Versions
26-
-------------
27-
28-
Java 7 or above is required for using this client.
29-
30-
Versioning
31-
----------
32-
33-
This library follows [Semantic Versioning] (http://semver.org/).
34-
35-
It is currently in major version zero (``0.y.z``), which means that anything
36-
may change at any time and the public API should not be considered
37-
stable.
6+
Contents
7+
--------
8+
9+
* [gcloud-java-nio](./gcloud-java-nio/): NIO Filesystem Provider for Google Cloud Storage.
3810

3911
Contributing
4012
------------

gcloud-java-contrib/gcloud-java-nio/pom.xml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@
4949
<version>1.1</version>
5050
<scope>provided</scope> <!-- to leave out of the all-deps jar -->
5151
</dependency>
52-
<dependency>
53-
<groupId>com.google.appengine.tools</groupId>
54-
<artifactId>appengine-gcs-client</artifactId>
55-
<version>0.5</version>
56-
</dependency>
5752
<dependency>
5853
<groupId>junit</groupId>
5954
<artifactId>junit</artifactId>
@@ -77,24 +72,6 @@
7772
<artifactId>mockito-core</artifactId>
7873
<version>1.9.5</version>
7974
</dependency>
80-
<dependency>
81-
<groupId>com.google.appengine</groupId>
82-
<artifactId>appengine-testing</artifactId>
83-
<version>1.9.30</version>
84-
<scope>test</scope>
85-
</dependency>
86-
<dependency>
87-
<groupId>com.google.appengine</groupId>
88-
<artifactId>appengine-api-stubs</artifactId>
89-
<version>1.9.30</version>
90-
<scope>test</scope>
91-
</dependency>
92-
<dependency>
93-
<groupId>com.google.appengine</groupId>
94-
<artifactId>appengine-local-endpoints</artifactId>
95-
<version>1.9.30</version>
96-
<scope>test</scope>
97-
</dependency>
9875
</dependencies>
9976
<build>
10077
<plugins>

gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageConfiguration.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
import java.util.Map;
88

9-
/** Configuration class for {@link CloudStorageFileSystem#forBucket} */
9+
/** CloudStorageConfiguration is the configuration class for
10+
* {@link CloudStorageFileSystem#forBucket}. */
1011
@AutoValue
1112
public abstract class CloudStorageConfiguration {
1213

13-
/** Returns the path of the current working directory. Defaults to the root directory. */
14+
/** Returns the path of the current working directory. Defaults to the root directory.
15+
*/
1416
public abstract String workingDirectory();
1517

1618
/**
@@ -46,7 +48,8 @@ public static Builder builder() {
4648
return new Builder();
4749
}
4850

49-
/** Builder for {@link CloudStorageConfiguration}. */
51+
/** Builder for {@link CloudStorageConfiguration}.
52+
*/
5053
public static final class Builder {
5154

5255
private String workingDirectory = UnixPath.ROOT;
@@ -87,7 +90,8 @@ public Builder stripPrefixSlash(boolean value) {
8790
return this;
8891
}
8992

90-
/** Configures if paths with a trailing slash should be treated as fake directories. */
93+
/** Configures if paths with a trailing slash should be treated as fake directories.
94+
*/
9195
public Builder usePseudoDirectories(boolean value) {
9296
usePseudoDirectories = value;
9397
return this;
@@ -103,7 +107,9 @@ public Builder blockSize(int value) {
103107
return this;
104108
}
105109

106-
/** Creates a new instance, but does not destroy the builder. */
110+
111+
/** Creates a new instance, but does not destroy the builder.
112+
*/
107113
public CloudStorageConfiguration build() {
108114
return new AutoValue_CloudStorageConfiguration(
109115
workingDirectory,

gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileAttributeView.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import static com.google.common.base.Verify.verifyNotNull;
44

5-
import com.google.appengine.tools.cloudstorage.GcsFileMetadata;
65
import com.google.common.base.MoreObjects;
6+
import com.google.gcloud.storage.BlobInfo;
7+
import com.google.gcloud.storage.Storage;
78

89
import java.io.IOException;
910
import java.nio.file.NoSuchFileException;
@@ -14,19 +15,22 @@
1415
import javax.annotation.Nullable;
1516
import javax.annotation.concurrent.Immutable;
1617

17-
/** Metadata view for a Google Cloud Storage object. */
18+
/** Metadata view for a Google Cloud Storage object.
19+
*/
1820
@Immutable
1921
public final class CloudStorageFileAttributeView implements BasicFileAttributeView {
2022

21-
private final CloudStorageFileSystemProvider provider;
23+
//private final CloudStorageFileSystemProvider provider;
24+
private final Storage storage;
2225
private final CloudStoragePath path;
2326

24-
CloudStorageFileAttributeView(CloudStorageFileSystemProvider provider, CloudStoragePath path) {
25-
this.provider = verifyNotNull(provider);
27+
CloudStorageFileAttributeView(Storage storage, CloudStoragePath path) {
28+
this.storage = verifyNotNull(storage);
2629
this.path = verifyNotNull(path);
2730
}
2831

29-
/** Returns {@value CloudStorageFileSystem#GCS_VIEW} */
32+
/** Returns {@value CloudStorageFileSystem#GCS_VIEW}.
33+
*/
3034
@Override
3135
public String name() {
3236
return CloudStorageFileSystem.GCS_VIEW;
@@ -36,19 +40,18 @@ public String name() {
3640
public CloudStorageFileAttributes readAttributes() throws IOException {
3741
if (path.seemsLikeADirectory()
3842
&& path.getFileSystem().config().usePseudoDirectories()) {
39-
return CloudStoragePseudoDirectoryAttributes.SINGLETON_INSTANCE;
43+
return new CloudStoragePseudoDirectoryAttributes(path);
4044
}
41-
GcsFileMetadata metadata = provider.getGcsService().getMetadata(path.getGcsFilename());
42-
if (metadata == null) {
45+
BlobInfo blobInfo = storage.get(path.getBlobId());
46+
if (blobInfo == null) {
4347
throw new NoSuchFileException(path.toUri().toString());
4448
}
45-
return new CloudStorageObjectAttributes(metadata);
49+
50+
return new CloudStorageObjectAttributes(blobInfo);
4651
}
4752

4853
/**
4954
* This feature is not supported, since Cloud Storage objects are immutable.
50-
*
51-
* @throws UnsupportedOperationException
5255
*/
5356
@Override
5457
public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime) {
@@ -59,19 +62,19 @@ public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTim
5962
public boolean equals(@Nullable Object other) {
6063
return this == other
6164
|| other instanceof CloudStorageFileAttributeView
62-
&& Objects.equals(provider, ((CloudStorageFileAttributeView) other).provider)
65+
&& Objects.equals(storage, ((CloudStorageFileAttributeView) other).storage)
6366
&& Objects.equals(path, ((CloudStorageFileAttributeView) other).path);
6467
}
6568

6669
@Override
6770
public int hashCode() {
68-
return Objects.hash(provider, path);
71+
return Objects.hash(storage, path);
6972
}
7073

7174
@Override
7275
public String toString() {
7376
return MoreObjects.toStringHelper(this)
74-
.add("provider", provider)
77+
.add("storage", storage)
7578
.add("path", path)
7679
.toString();
7780
}

gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileAttributes.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import com.google.common.base.Optional;
44
import com.google.common.collect.ImmutableMap;
5+
import com.google.gcloud.storage.Acl;
56

67
import java.nio.file.attribute.BasicFileAttributes;
8+
import java.util.List;
79

810
/** Interface for attributes on a cloud storage file or pseudo-directory. */
911
public interface CloudStorageFileAttributes extends BasicFileAttributes {
@@ -27,7 +29,7 @@ public interface CloudStorageFileAttributes extends BasicFileAttributes {
2729
*
2830
* @see "https://developers.google.com/storage/docs/reference-headers#acl"
2931
*/
30-
Optional<String> acl();
32+
Optional<List<Acl>> acl();
3133

3234
/**
3335
* Returns the {@code Cache-Control} HTTP header value, if set on this object.

gcloud-java-contrib/gcloud-java-nio/src/main/java/com/google/gcloud/storage/contrib/nio/CloudStorageFileSystem.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,41 +89,48 @@ public CloudStorageFileSystemProvider provider() {
8989
return provider;
9090
}
9191

92-
/** Returns the Cloud Storage bucket name being served by this file system. */
92+
/** Returns the Cloud Storage bucket name being served by this file system.
93+
*/
9394
public String bucket() {
9495
return bucket;
9596
}
9697

97-
/** Returns the configuration object for this filesystem instance. */
98+
/** Returns the configuration object for this filesystem instance.
99+
*/
98100
public CloudStorageConfiguration config() {
99101
return config;
100102
}
101103

102-
/** Converts a cloud storage object name to a {@link Path} object. */
104+
/** Converts a cloud storage object name to a {@link Path} object.
105+
*/
103106
@Override
104107
public CloudStoragePath getPath(String first, String... more) {
105108
checkArgument(!first.startsWith(URI_SCHEME + ":"),
106109
"GCS FileSystem.getPath() must not have schema and bucket name: %s", first);
107110
return CloudStoragePath.getPath(this, first, more);
108111
}
109112

110-
/** Does nothing. */
113+
/** Does nothing.
114+
*/
111115
@Override
112116
public void close() {}
113117

114-
/** Returns {@code true} */
118+
/** Returns {@code true}.
119+
*/
115120
@Override
116121
public boolean isOpen() {
117122
return true;
118123
}
119124

120-
/** Returns {@code false} */
125+
/** Returns {@code false}.
126+
*/
121127
@Override
122128
public boolean isReadOnly() {
123129
return false;
124130
}
125131

126-
/** Returns {@value UnixPath#SEPARATOR} */
132+
/** Returns {@value UnixPath#SEPARATOR}.
133+
*/
127134
@Override
128135
public String getSeparator() {
129136
return "" + UnixPath.SEPARATOR;
@@ -144,24 +151,26 @@ public Set<String> supportedFileAttributeViews() {
144151
return SUPPORTED_VIEWS;
145152
}
146153

147-
/** @throws UnsupportedOperationException */
154+
/** Always throws {@link UnsupportedOperationException}. */
148155
@Override
149156
public PathMatcher getPathMatcher(String syntaxAndPattern) {
150-
// TODO(b/18997520): Implement me.
157+
// TODO: Implement me.
151158
throw new UnsupportedOperationException();
152159
}
153160

154-
/** @throws UnsupportedOperationException */
161+
/** Always throws {@link UnsupportedOperationException}.
162+
*/
155163
@Override
156164
public UserPrincipalLookupService getUserPrincipalLookupService() {
157-
// TODO(b/18997520): Implement me.
165+
// TODO: Implement me.
158166
throw new UnsupportedOperationException();
159167
}
160168

161-
/** @throws UnsupportedOperationException */
169+
/** Always throws {@link UnsupportedOperationException}.
170+
*/
162171
@Override
163172
public WatchService newWatchService() throws IOException {
164-
// TODO(b/18997520): Implement me.
173+
// TODO: Implement me.
165174
throw new UnsupportedOperationException();
166175
}
167176

0 commit comments

Comments
 (0)