Skip to content

Commit

Permalink
Merge pull request #649 from jean-philippe-martin/gcs-nio
Browse files Browse the repository at this point in the history
Migrate GCS NIO from App Engine to gcloud-storage
  • Loading branch information
jean-philippe-martin committed Mar 2, 2016
2 parents 2e2b450 + b01d842 commit c32010c
Show file tree
Hide file tree
Showing 31 changed files with 918 additions and 472 deletions.
36 changes: 4 additions & 32 deletions gcloud-java-contrib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,10 @@ Google Cloud Java Contributions

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

Quickstart
----------
If you are using Maven, add this to your pom.xml file
```xml
<dependency>
<groupId>com.google.gcloud</groupId>
<artifactId>gcloud-java-contrib</artifactId>
<version>0.1.3</version>
</dependency>
```
If you are using Gradle, add this to your dependencies
```Groovy
compile 'com.google.gcloud:gcloud-java-contrib:0.1.3'
```
If you are using SBT, add this to your dependencies
```Scala
libraryDependencies += "com.google.gcloud" % "gcloud-java-contrib" % "0.1.3"
```

Java Versions
-------------

Java 7 or above is required for using this client.

Versioning
----------

This library follows [Semantic Versioning] (http://semver.org/).

It is currently in major version zero (``0.y.z``), which means that anything
may change at any time and the public API should not be considered
stable.
Contents
--------

* [gcloud-java-nio](./gcloud-java-nio/): NIO Filesystem Provider for Google Cloud Storage.

Contributing
------------
Expand Down
23 changes: 0 additions & 23 deletions gcloud-java-contrib/gcloud-java-nio/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@
<version>1.1</version>
<scope>provided</scope> <!-- to leave out of the all-deps jar -->
</dependency>
<dependency>
<groupId>com.google.appengine.tools</groupId>
<artifactId>appengine-gcs-client</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -77,24 +72,6 @@
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>1.9.30</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>1.9.30</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-local-endpoints</artifactId>
<version>1.9.30</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

import java.util.Map;

/** Configuration class for {@link CloudStorageFileSystem#forBucket} */
/** CloudStorageConfiguration is the configuration class for
* {@link CloudStorageFileSystem#forBucket}. */
@AutoValue
public abstract class CloudStorageConfiguration {

/** Returns the path of the current working directory. Defaults to the root directory. */
/** Returns the path of the current working directory. Defaults to the root directory.
*/
public abstract String workingDirectory();

/**
Expand Down Expand Up @@ -46,7 +48,8 @@ public static Builder builder() {
return new Builder();
}

/** Builder for {@link CloudStorageConfiguration}. */
/** Builder for {@link CloudStorageConfiguration}.
*/
public static final class Builder {

private String workingDirectory = UnixPath.ROOT;
Expand Down Expand Up @@ -87,7 +90,8 @@ public Builder stripPrefixSlash(boolean value) {
return this;
}

/** Configures if paths with a trailing slash should be treated as fake directories. */
/** Configures if paths with a trailing slash should be treated as fake directories.
*/
public Builder usePseudoDirectories(boolean value) {
usePseudoDirectories = value;
return this;
Expand All @@ -103,7 +107,9 @@ public Builder blockSize(int value) {
return this;
}

/** Creates a new instance, but does not destroy the builder. */

/** Creates a new instance, but does not destroy the builder.
*/
public CloudStorageConfiguration build() {
return new AutoValue_CloudStorageConfiguration(
workingDirectory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

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

import com.google.appengine.tools.cloudstorage.GcsFileMetadata;
import com.google.common.base.MoreObjects;
import com.google.gcloud.storage.BlobInfo;
import com.google.gcloud.storage.Storage;

import java.io.IOException;
import java.nio.file.NoSuchFileException;
Expand All @@ -14,19 +15,22 @@
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

/** Metadata view for a Google Cloud Storage object. */
/** Metadata view for a Google Cloud Storage object.
*/
@Immutable
public final class CloudStorageFileAttributeView implements BasicFileAttributeView {

private final CloudStorageFileSystemProvider provider;
//private final CloudStorageFileSystemProvider provider;
private final Storage storage;
private final CloudStoragePath path;

CloudStorageFileAttributeView(CloudStorageFileSystemProvider provider, CloudStoragePath path) {
this.provider = verifyNotNull(provider);
CloudStorageFileAttributeView(Storage storage, CloudStoragePath path) {
this.storage = verifyNotNull(storage);
this.path = verifyNotNull(path);
}

/** Returns {@value CloudStorageFileSystem#GCS_VIEW} */
/** Returns {@value CloudStorageFileSystem#GCS_VIEW}.
*/
@Override
public String name() {
return CloudStorageFileSystem.GCS_VIEW;
Expand All @@ -36,19 +40,18 @@ public String name() {
public CloudStorageFileAttributes readAttributes() throws IOException {
if (path.seemsLikeADirectory()
&& path.getFileSystem().config().usePseudoDirectories()) {
return CloudStoragePseudoDirectoryAttributes.SINGLETON_INSTANCE;
return new CloudStoragePseudoDirectoryAttributes(path);
}
GcsFileMetadata metadata = provider.getGcsService().getMetadata(path.getGcsFilename());
if (metadata == null) {
BlobInfo blobInfo = storage.get(path.getBlobId());
if (blobInfo == null) {
throw new NoSuchFileException(path.toUri().toString());
}
return new CloudStorageObjectAttributes(metadata);

return new CloudStorageObjectAttributes(blobInfo);
}

/**
* This feature is not supported, since Cloud Storage objects are immutable.
*
* @throws UnsupportedOperationException
*/
@Override
public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime) {
Expand All @@ -59,19 +62,19 @@ public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTim
public boolean equals(@Nullable Object other) {
return this == other
|| other instanceof CloudStorageFileAttributeView
&& Objects.equals(provider, ((CloudStorageFileAttributeView) other).provider)
&& Objects.equals(storage, ((CloudStorageFileAttributeView) other).storage)
&& Objects.equals(path, ((CloudStorageFileAttributeView) other).path);
}

@Override
public int hashCode() {
return Objects.hash(provider, path);
return Objects.hash(storage, path);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("provider", provider)
.add("storage", storage)
.add("path", path)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import com.google.gcloud.storage.Acl;

import java.nio.file.attribute.BasicFileAttributes;
import java.util.List;

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

/**
* Returns the {@code Cache-Control} HTTP header value, if set on this object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,41 +89,48 @@ public CloudStorageFileSystemProvider provider() {
return provider;
}

/** Returns the Cloud Storage bucket name being served by this file system. */
/** Returns the Cloud Storage bucket name being served by this file system.
*/
public String bucket() {
return bucket;
}

/** Returns the configuration object for this filesystem instance. */
/** Returns the configuration object for this filesystem instance.
*/
public CloudStorageConfiguration config() {
return config;
}

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

/** Does nothing. */
/** Does nothing.
*/
@Override
public void close() {}

/** Returns {@code true} */
/** Returns {@code true}.
*/
@Override
public boolean isOpen() {
return true;
}

/** Returns {@code false} */
/** Returns {@code false}.
*/
@Override
public boolean isReadOnly() {
return false;
}

/** Returns {@value UnixPath#SEPARATOR} */
/** Returns {@value UnixPath#SEPARATOR}.
*/
@Override
public String getSeparator() {
return "" + UnixPath.SEPARATOR;
Expand All @@ -144,24 +151,26 @@ public Set<String> supportedFileAttributeViews() {
return SUPPORTED_VIEWS;
}

/** @throws UnsupportedOperationException */
/** Always throws {@link UnsupportedOperationException}. */
@Override
public PathMatcher getPathMatcher(String syntaxAndPattern) {
// TODO(b/18997520): Implement me.
// TODO: Implement me.
throw new UnsupportedOperationException();
}

/** @throws UnsupportedOperationException */
/** Always throws {@link UnsupportedOperationException}.
*/
@Override
public UserPrincipalLookupService getUserPrincipalLookupService() {
// TODO(b/18997520): Implement me.
// TODO: Implement me.
throw new UnsupportedOperationException();
}

/** @throws UnsupportedOperationException */
/** Always throws {@link UnsupportedOperationException}.
*/
@Override
public WatchService newWatchService() throws IOException {
// TODO(b/18997520): Implement me.
// TODO: Implement me.
throw new UnsupportedOperationException();
}

Expand Down
Loading

0 comments on commit c32010c

Please sign in to comment.