You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2015/02/18 11:03:15 UTC
[2/5] jclouds-labs-google git commit: Updated BackendServiceOptions
to AutoValue + Builder
Updated BackendServiceOptions to AutoValue + Builder
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/2555ff69
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/2555ff69
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/2555ff69
Branch: refs/heads/master
Commit: 2555ff69423681a53914159b05005580c28ed35f
Parents: e05dadc
Author: Daniel Broudy <br...@google.com>
Authored: Tue Jan 27 16:47:16 2015 -0800
Committer: Ignasi Barrera <na...@apache.org>
Committed: Wed Feb 18 10:58:36 2015 +0100
----------------------------------------------------------------------
.../options/BackendServiceOptions.java | 279 +++++++++----------
.../features/BackendServiceApiLiveTest.java | 29 +-
.../features/BackendServiceApiMockTest.java | 12 +-
.../GlobalForwardingRuleApiLiveTest.java | 3 +-
.../features/TargetHttpProxyApiLiveTest.java | 4 +-
.../features/UrlMapApiLiveTest.java | 3 +-
6 files changed, 154 insertions(+), 176 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/2555ff69/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/BackendServiceOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/BackendServiceOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/BackendServiceOptions.java
index 60f1e4f..0257882 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/BackendServiceOptions.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/BackendServiceOptions.java
@@ -21,154 +21,135 @@ import java.util.List;
import org.jclouds.googlecomputeengine.domain.BackendService.Backend;
import org.jclouds.javax.annotation.Nullable;
-
-public class BackendServiceOptions {
-
- private String name;
- @Nullable private String description;
- private List<URI> healthChecks;
- private List<Backend> backends;
- private Integer timeoutSec;
- private Integer port;
- private String protocol;
- private String fingerprint;
- private String portName;
-
- /**
- * Name of the BackendService resource.
- * @return name, provided by the client.
- */
- public String getName(){
- return name;
- }
-
- /**
- * @see BackendServiceOptions#getName()
- */
- public BackendServiceOptions name(String name) {
- this.name = name;
- return this;
- }
-
- /**
- * An optional textual description of the BackendService.
- * @return description, provided by the client.
- */
- public String getDescription(){
- return description;
- }
-
- /**
- * @see BackendServiceOptions#getDescription()
- */
- public BackendServiceOptions description(String description) {
- this.description = description;
- return this;
- }
-
- /**
- * The list of {@link HttpHealthCheck#selfLink Links} to the HttpHealthCheck resource for health checking this BackendService.
- * Currently at most one health check can be specified, and a health check is required.
- */
- public List<URI> getHealthChecks() {
- return healthChecks;
- }
-
- /**
- * @see BackendServiceOptions#getHealthChecks()
- */
- public BackendServiceOptions healthChecks(List<URI> healthChecks) {
- this.healthChecks = healthChecks;
- return this;
- }
-
- /**
- * The list of backends that serve this BackendService.
- */
- public List<Backend> getBackends() {
- return backends;
- }
-
- /**
- * @see BackendServiceOptions#getBackends()
- */
- public BackendServiceOptions backends(List<Backend> backends){
- this.backends = backends;
- return this;
- }
-
- /**
- * How many seconds to wait for the backend before considering it a failed request.
- * Default is 30 seconds.
- */
- public Integer getTimeoutSec() {
- return timeoutSec;
- }
-
- /**
- * @see BackendServiceOptions#getTimeoutSec()
- */
- public BackendServiceOptions timeoutSec(Integer timeoutSec) {
- this.timeoutSec = timeoutSec;
- return this;
- }
-
- /**
- * The TCP port to connect on the backend.
- * The default value is 80.
- */
- public Integer getPort() {
- return port;
- }
-
- /**
- * @see BackendServiceOptions#getPort()
- */
- public BackendServiceOptions port(Integer port) {
- this.port = port;
- return this;
- }
-
-
- /**
- * The protocol for incoming requests.
- */
- public String getProtocol() {
- return protocol;
- }
-
- /**
- * @see BackendServiceOptions#getProtocol()
- */
- public BackendServiceOptions protocol(String protocol) {
- this.protocol = protocol;
- return this;
- }
-
- /**
- * Fingerprint of this resource. A hash of the contents stored in this object.
- * This field is used in optimistic locking. This field will be ignored when
- * inserting a BackendService. An up-to-date fingerprint must be provided in
- * order to update the BackendService.
- */
- public String getFingerprint() {
- return fingerprint;
- }
-
- /**
- * @see BackendServiceOptions#getFingerprint()
- */
- public BackendServiceOptions fingerprint(String fingerprint) {
- this.fingerprint = fingerprint;
- return this;
- }
-
- public String getPortName() {
- return portName;
- }
-
- public BackendServiceOptions portName(String portName) {
- this.portName = portName;
- return this;
+import org.jclouds.json.SerializedNames;
+
+import com.google.auto.value.AutoValue;
+
+@AutoValue
+public abstract class BackendServiceOptions {
+
+ @Nullable public abstract String name();
+ @Nullable public abstract String description();
+ @Nullable public abstract List<URI> healthChecks();
+ @Nullable public abstract List<Backend> backends();
+ @Nullable public abstract Integer timeoutSec();
+ @Nullable public abstract Integer port();
+ @Nullable public abstract String protocol();
+ @Nullable public abstract String fingerprint();
+ @Nullable public abstract String portName();
+
+ @SerializedNames({"name", "description", "healthChecks", "backends", "timeoutSec",
+ "port", "protocol", "fingerprint", "portName"})
+ static BackendServiceOptions create(String name, String description, List<URI> healthChecks,
+ List<Backend> backends, Integer timeoutSec, Integer port, String protocol, String fingerprint, String portName){
+ return new AutoValue_BackendServiceOptions(name, description, healthChecks,
+ backends, timeoutSec, port, protocol, fingerprint, portName);
+ }
+
+ BackendServiceOptions(){
+ }
+
+ public static class Builder {
+
+ private String name;
+ private String description;
+ private List<URI> healthChecks;
+ private List<Backend> backends;
+ private Integer timeoutSec;
+ private Integer port;
+ private String protocol;
+ private String fingerprint;
+ private String portName;
+
+ /**
+ * @param name, provided by the client.
+ * @param healthChecks The list of {@link HttpHealthCheck#selfLink Links} to the HttpHealthCheck
+ * resource for health checking this BackendService.
+ * Currently at most one health check can be specified, and a health check is required.
+ */
+ public Builder(String name, List<URI> healthChecks){
+ this.name = name;
+ this.healthChecks = healthChecks;
+ }
+
+ /**
+ * Empty builder for use when patching or updating and existing BackendService
+ * Otherwise use the other {@link #Builder(String, List) builder}
+ */
+ public Builder(){
+ }
+
+ /**
+ * An optional textual description of the BackendService.
+ */
+ public Builder description(String description){
+ this.description = description;
+ return this;
+ }
+
+ /**
+ * HealthChecks - The list of {@link HttpHealthCheck#selfLink Links} to the HttpHealthCheck
+ * resource for health checking this BackendService.
+ * Currently at most one health check can be specified, and a health check is required.
+ */
+ public Builder healthChecks(List<URI> healthChecks){
+ this.healthChecks = healthChecks;
+ return this;
+ }
+
+ /**
+ * The list of backends that serve this BackendService.
+ */
+ public Builder backends(List<Backend> backends){
+ this.backends = backends;
+ return this;
+ }
+
+ /**
+ * How many seconds to wait for the backend before considering it a failed request.
+ * Default is 30 seconds.
+ */
+ public Builder timeoutSec(Integer timeoutSec) {
+ this.timeoutSec = timeoutSec;
+ return this;
+ }
+
+ /**
+ * The TCP port to connect on the backend.
+ * The default value is 80.
+ */
+ public Builder port(Integer port) {
+ this.port = port;
+ return this;
+ }
+
+ /**
+ * The protocol for incoming requests.
+ */
+ public Builder protocol(String protocol) {
+ this.protocol = protocol;
+ return this;
+ }
+
+ /**
+ * Fingerprint of this resource. A hash of the contents stored in this object.
+ * This field is used in optimistic locking. This field will be ignored when
+ * inserting a BackendService. An up-to-date fingerprint must be provided in
+ * order to update the BackendService.
+ */
+ public Builder fingerprint(String fingerprint) {
+ this.fingerprint = fingerprint;
+ return this;
+ }
+
+ public Builder portName(String portName) {
+ this.portName = portName;
+ return this;
+ }
+
+ public BackendServiceOptions build(){
+ return create(name, description, healthChecks,
+ backends, timeoutSec, port, protocol, fingerprint, portName);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/2555ff69/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiLiveTest.java
index c5eeee6..9ed6ceb 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiLiveTest.java
@@ -47,7 +47,8 @@ public class BackendServiceApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
assertOperationDoneSuccessfully(api.httpHeathChecks().insert(BACKEND_SERVICE_HEALTH_CHECK_NAME));
List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME));
- BackendServiceOptions b = new BackendServiceOptions().name(BACKEND_SERVICE_NAME).healthChecks(healthChecks);
+
+ BackendServiceOptions b = new BackendServiceOptions.Builder(BACKEND_SERVICE_NAME, healthChecks).build();
assertOperationDoneSuccessfully(api().create(b));
}
@@ -61,11 +62,10 @@ public class BackendServiceApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
@Test(groups = "live", dependsOnMethods = "testGetBackendService")
public void testPatchBackendService() {
String fingerprint = api().get(BACKEND_SERVICE_NAME).fingerprint();
- BackendServiceOptions backendService = new BackendServiceOptions()
- .name(BACKEND_SERVICE_NAME)
- .healthChecks(ImmutableList.of(getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME)))
+ BackendServiceOptions backendService = new BackendServiceOptions.Builder(BACKEND_SERVICE_NAME, ImmutableList.of(getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME)))
.timeoutSec(10)
- .fingerprint(fingerprint);
+ .fingerprint(fingerprint)
+ .build();
assertOperationDoneSuccessfully(api().update(BACKEND_SERVICE_NAME, backendService));
assertBackendServiceEquals(api().get(BACKEND_SERVICE_NAME), backendService);
@@ -75,12 +75,11 @@ public class BackendServiceApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
public void testUpdateBackendService() {
String fingerprint = api().get(BACKEND_SERVICE_NAME).fingerprint();
- BackendServiceOptions backendService = new BackendServiceOptions()
- .name(BACKEND_SERVICE_NAME)
- .healthChecks(ImmutableList.of(getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME)))
+ BackendServiceOptions backendService = new BackendServiceOptions.Builder(BACKEND_SERVICE_NAME, ImmutableList.of(getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME)))
.timeoutSec(45)
.port(8080)
- .fingerprint(fingerprint);
+ .fingerprint(fingerprint)
+ .build();
assertOperationDoneSuccessfully(api().update(BACKEND_SERVICE_NAME, backendService));
assertBackendServiceEquals(api().get(BACKEND_SERVICE_NAME),
@@ -119,13 +118,13 @@ public class BackendServiceApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
}
private void assertBackendServiceEquals(BackendService result, BackendServiceOptions expected) {
- assertEquals(result.name(), expected.getName());
- assertEquals(result.healthChecks(), expected.getHealthChecks());
- if (expected.getTimeoutSec() != null) {
- org.testng.Assert.assertEquals(result.timeoutSec(), expected.getTimeoutSec().intValue());
+ assertEquals(result.name(), expected.name());
+ assertEquals(result.healthChecks(), expected.healthChecks());
+ if (expected.timeoutSec() != null) {
+ org.testng.Assert.assertEquals(result.timeoutSec(), expected.timeoutSec().intValue());
}
- if (expected.getPort() != null) {
- org.testng.Assert.assertEquals(result.port(), expected.getPort().intValue());
+ if (expected.port() != null) {
+ org.testng.Assert.assertEquals(result.port(), expected.port().intValue());
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/2555ff69/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiMockTest.java
index 1cc8400..fd9a639 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiMockTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiMockTest.java
@@ -57,11 +57,11 @@ public class BackendServiceApiMockTest extends BaseGoogleComputeEngineApiMockTes
List<URI> healthChecks = ImmutableList.of(URI.create(url("/projects/"
+ "myproject/global/httpHealthChecks/jclouds-test")));
- assertEquals(backendServiceApi().create( new BackendServiceOptions().name("jclouds-test")
+ assertEquals(backendServiceApi().create( new BackendServiceOptions.Builder("jclouds-test", healthChecks)
.protocol("HTTP")
.port(80)
.timeoutSec(30)
- .healthChecks(healthChecks)),
+ .build()),
new ParseOperationTest().expected(url("/projects")));
assertSent(server, "POST", "/projects/party/global/backendServices",
@@ -75,11 +75,11 @@ public class BackendServiceApiMockTest extends BaseGoogleComputeEngineApiMockTes
+ "myproject/global/httpHealthChecks/jclouds-test")));
assertEquals(backendServiceApi().update("jclouds-test",
- new BackendServiceOptions().name("jclouds-test")
+ new BackendServiceOptions.Builder("jclouds-test", healthChecks)
.protocol("HTTP")
.port(80)
.timeoutSec(30)
- .healthChecks(healthChecks)),
+ .build()),
new ParseOperationTest().expected(url("/projects")));
assertSent(server, "PUT", "/projects/party/global/backendServices/jclouds-test",
stringFromResource("/backend_service_insert.json"));
@@ -92,11 +92,11 @@ public class BackendServiceApiMockTest extends BaseGoogleComputeEngineApiMockTes
+ "myproject/global/httpHealthChecks/jclouds-test")));
assertEquals(backendServiceApi().patch("jclouds-test",
- new BackendServiceOptions().name("jclouds-test")
+ new BackendServiceOptions.Builder("jclouds-test", healthChecks)
.protocol("HTTP")
.port(80)
.timeoutSec(30)
- .healthChecks(healthChecks)),
+ .build()),
new ParseOperationTest().expected(url("/projects")));
assertSent(server, "PATCH", "/projects/party/global/backendServices/jclouds-test",
stringFromResource("/backend_service_insert.json"));
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/2555ff69/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java
index a3656a0..3aa012b 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java
@@ -61,8 +61,7 @@ public class GlobalForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiL
List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(GLOBAL_FORWARDING_RULE_HEALTH_CHECK_NAME));
- BackendServiceOptions b = new BackendServiceOptions().name(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME)
- .healthChecks(healthChecks);
+ BackendServiceOptions b = new BackendServiceOptions.Builder(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME, healthChecks).build();
assertOperationDoneSuccessfully(api.backendServices()
.create(b));
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/2555ff69/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java
index ef3abae..be51627 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java
@@ -52,8 +52,8 @@ public class TargetHttpProxyApiLiveTest extends BaseGoogleComputeEngineApiLiveTe
assertOperationDoneSuccessfully(api.httpHeathChecks().insert(HEALTH_CHECK_NAME));
List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(HEALTH_CHECK_NAME));
- BackendServiceOptions b = new BackendServiceOptions().name(URL_MAP_DEFAULT_SERVICE_NAME)
- .healthChecks(healthChecks);
+ BackendServiceOptions b = new BackendServiceOptions.Builder(URL_MAP_DEFAULT_SERVICE_NAME, healthChecks)
+ .build();
assertOperationDoneSuccessfully(api.backendServices().create(b));
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/2555ff69/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java
index f48e44a..c5df2ff 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java
@@ -54,8 +54,7 @@ public class UrlMapApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
assertOperationDoneSuccessfully(api.httpHeathChecks().insert(HEALTH_CHECK_NAME));
List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(HEALTH_CHECK_NAME));
- BackendServiceOptions b = new BackendServiceOptions().name(URL_MAP_BACKEND_SERVICE_NAME)
- .healthChecks(healthChecks);
+ BackendServiceOptions b = new BackendServiceOptions.Builder(URL_MAP_BACKEND_SERVICE_NAME, healthChecks).build();
assertOperationDoneSuccessfully(api.backendServices().create(b));
UrlMapOptions map = new UrlMapOptions.Builder().name(URL_MAP_NAME).description("simple url map")