You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by dh...@apache.org on 2016/06/06 21:45:40 UTC
[1/2] incubator-beam git commit: Closes #421
Repository: incubator-beam
Updated Branches:
refs/heads/master 523e820b0 -> fe1889316
Closes #421
Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/fe188931
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/fe188931
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/fe188931
Branch: refs/heads/master
Commit: fe1889316a8260205055c2519868492fed782f0c
Parents: 523e820 135aabd
Author: Dan Halperin <dh...@google.com>
Authored: Mon Jun 6 14:45:32 2016 -0700
Committer: Dan Halperin <dh...@google.com>
Committed: Mon Jun 6 14:45:32 2016 -0700
----------------------------------------------------------------------
.../org/apache/beam/sdk/util/PubsubClient.java | 54 ++++++++++++--------
1 file changed, 32 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
[2/2] incubator-beam git commit: Fix validation in PubsubIO
Posted by dh...@apache.org.
Fix validation in PubsubIO
Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/135aabd6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/135aabd6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/135aabd6
Branch: refs/heads/master
Commit: 135aabd60e7d7045d17c9e2c7b7679a361669c83
Parents: 523e820
Author: Kenneth Knowles <kl...@google.com>
Authored: Mon Jun 6 13:07:35 2016 -0700
Committer: Dan Halperin <dh...@google.com>
Committed: Mon Jun 6 14:45:32 2016 -0700
----------------------------------------------------------------------
.../org/apache/beam/sdk/util/PubsubClient.java | 54 ++++++++++++--------
1 file changed, 32 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/135aabd6/sdks/java/core/src/main/java/org/apache/beam/sdk/util/PubsubClient.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/PubsubClient.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/PubsubClient.java
index 76bf03f..36c4a9f 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/PubsubClient.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/PubsubClient.java
@@ -123,20 +123,27 @@ public abstract class PubsubClient implements Closeable {
* Path representing a cloud project id.
*/
public static class ProjectPath implements Serializable {
- private final String path;
+ private final String projectId;
+ /**
+ * Creates a {@link ProjectPath} from a {@link String} representation, which
+ * must be of the form {@code "projects/" + projectId}.
+ */
ProjectPath(String path) {
- this.path = path;
+ String[] splits = path.split("/");
+ checkArgument(
+ splits.length == 2 && splits[0].equals("projects"),
+ "Malformed project path \"%s\": must be of the form \"projects/\" + <project id>",
+ path);
+ this.projectId = splits[1];
}
public String getPath() {
- return path;
+ return String.format("projects/%s", projectId);
}
public String getId() {
- String[] splits = path.split("/");
- checkState(splits.length == 1, "Malformed project path %s", path);
- return splits[1];
+ return projectId;
}
@Override
@@ -150,18 +157,17 @@ public abstract class PubsubClient implements Closeable {
ProjectPath that = (ProjectPath) o;
- return path.equals(that.path);
-
+ return projectId.equals(that.projectId);
}
@Override
public int hashCode() {
- return path.hashCode();
+ return projectId.hashCode();
}
@Override
public String toString() {
- return path;
+ return getPath();
}
}
@@ -177,26 +183,29 @@ public abstract class PubsubClient implements Closeable {
* Path representing a Pubsub subscription.
*/
public static class SubscriptionPath implements Serializable {
- private final String path;
+ private final String projectId;
+ private final String subscriptionName;
SubscriptionPath(String path) {
- this.path = path;
+ String[] splits = path.split("/");
+ checkState(
+ splits.length == 4 && splits[0].equals("projects") && splits[2].equals("subscriptions"),
+ "Malformed subscription path %s: "
+ + "must be of the form \"projects/\" + <project id> + \"subscriptions\"", path);
+ this.projectId = splits[1];
+ this.subscriptionName = splits[3];
}
public String getPath() {
- return path;
+ return String.format("projects/%s/subscriptions/%s", projectId, subscriptionName);
}
public String getName() {
- String[] splits = path.split("/");
- checkState(splits.length == 4, "Malformed subscription path %s", path);
- return splits[3];
+ return subscriptionName;
}
public String getV1Beta1Path() {
- String[] splits = path.split("/");
- checkState(splits.length == 4, "Malformed subscription path %s", path);
- return String.format("/subscriptions/%s/%s", splits[1], splits[3]);
+ return String.format("/subscriptions/%s/%s", projectId, subscriptionName);
}
@Override
@@ -208,17 +217,18 @@ public abstract class PubsubClient implements Closeable {
return false;
}
SubscriptionPath that = (SubscriptionPath) o;
- return path.equals(that.path);
+ return this.subscriptionName.equals(that.subscriptionName)
+ && this.projectId.equals(that.projectId);
}
@Override
public int hashCode() {
- return path.hashCode();
+ return Objects.hashCode(projectId, subscriptionName);
}
@Override
public String toString() {
- return path;
+ return getPath();
}
}