mirror of https://github.com/apache/jclouds.git
Updated BackendServiceOptions to AutoValue + Builder
This commit is contained in:
parent
7ac7197e83
commit
a9eecfad81
|
@ -21,154 +21,135 @@ import java.util.List;
|
||||||
|
|
||||||
import org.jclouds.googlecomputeengine.domain.BackendService.Backend;
|
import org.jclouds.googlecomputeengine.domain.BackendService.Backend;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
import org.jclouds.json.SerializedNames;
|
||||||
|
|
||||||
public class BackendServiceOptions {
|
import com.google.auto.value.AutoValue;
|
||||||
|
|
||||||
private String name;
|
@AutoValue
|
||||||
@Nullable private String description;
|
public abstract class BackendServiceOptions {
|
||||||
private List<URI> healthChecks;
|
|
||||||
private List<Backend> backends;
|
|
||||||
private Integer timeoutSec;
|
|
||||||
private Integer port;
|
|
||||||
private String protocol;
|
|
||||||
private String fingerprint;
|
|
||||||
private String portName;
|
|
||||||
|
|
||||||
/**
|
@Nullable public abstract String name();
|
||||||
* Name of the BackendService resource.
|
@Nullable public abstract String description();
|
||||||
* @return name, provided by the client.
|
@Nullable public abstract List<URI> healthChecks();
|
||||||
*/
|
@Nullable public abstract List<Backend> backends();
|
||||||
public String getName(){
|
@Nullable public abstract Integer timeoutSec();
|
||||||
return name;
|
@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(){
|
||||||
* @see BackendServiceOptions#getName()
|
|
||||||
*/
|
|
||||||
public BackendServiceOptions name(String name) {
|
|
||||||
this.name = name;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static class Builder {
|
||||||
* An optional textual description of the BackendService.
|
|
||||||
* @return description, provided by the client.
|
|
||||||
*/
|
|
||||||
public String getDescription(){
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
private String name;
|
||||||
* @see BackendServiceOptions#getDescription()
|
private String description;
|
||||||
*/
|
private List<URI> healthChecks;
|
||||||
public BackendServiceOptions description(String description) {
|
private List<Backend> backends;
|
||||||
this.description = description;
|
private Integer timeoutSec;
|
||||||
return this;
|
private Integer port;
|
||||||
}
|
private String protocol;
|
||||||
|
private String fingerprint;
|
||||||
|
private String portName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of {@link HttpHealthCheck#selfLink Links} to the HttpHealthCheck resource for health checking this BackendService.
|
* @param name, provided by the client.
|
||||||
* Currently at most one health check can be specified, and a health check is required.
|
* @param healthChecks The list of {@link HttpHealthCheck#selfLink Links} to the HttpHealthCheck
|
||||||
*/
|
* resource for health checking this BackendService.
|
||||||
public List<URI> getHealthChecks() {
|
* Currently at most one health check can be specified, and a health check is required.
|
||||||
return healthChecks;
|
*/
|
||||||
}
|
public Builder(String name, List<URI> healthChecks){
|
||||||
|
this.name = name;
|
||||||
|
this.healthChecks = healthChecks;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see BackendServiceOptions#getHealthChecks()
|
* Empty builder for use when patching or updating and existing BackendService
|
||||||
*/
|
* Otherwise use the other {@link #Builder(String, List) builder}
|
||||||
public BackendServiceOptions healthChecks(List<URI> healthChecks) {
|
*/
|
||||||
this.healthChecks = healthChecks;
|
public Builder(){
|
||||||
return this;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of backends that serve this BackendService.
|
* An optional textual description of the BackendService.
|
||||||
*/
|
*/
|
||||||
public List<Backend> getBackends() {
|
public Builder description(String description){
|
||||||
return backends;
|
this.description = description;
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see BackendServiceOptions#getBackends()
|
* HealthChecks - The list of {@link HttpHealthCheck#selfLink Links} to the HttpHealthCheck
|
||||||
*/
|
* resource for health checking this BackendService.
|
||||||
public BackendServiceOptions backends(List<Backend> backends){
|
* Currently at most one health check can be specified, and a health check is required.
|
||||||
this.backends = backends;
|
*/
|
||||||
return this;
|
public Builder healthChecks(List<URI> healthChecks){
|
||||||
}
|
this.healthChecks = healthChecks;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many seconds to wait for the backend before considering it a failed request.
|
* The list of backends that serve this BackendService.
|
||||||
* Default is 30 seconds.
|
*/
|
||||||
*/
|
public Builder backends(List<Backend> backends){
|
||||||
public Integer getTimeoutSec() {
|
this.backends = backends;
|
||||||
return timeoutSec;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see BackendServiceOptions#getTimeoutSec()
|
* How many seconds to wait for the backend before considering it a failed request.
|
||||||
*/
|
* Default is 30 seconds.
|
||||||
public BackendServiceOptions timeoutSec(Integer timeoutSec) {
|
*/
|
||||||
this.timeoutSec = timeoutSec;
|
public Builder timeoutSec(Integer timeoutSec) {
|
||||||
return this;
|
this.timeoutSec = timeoutSec;
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The TCP port to connect on the backend.
|
* The TCP port to connect on the backend.
|
||||||
* The default value is 80.
|
* The default value is 80.
|
||||||
*/
|
*/
|
||||||
public Integer getPort() {
|
public Builder port(Integer port) {
|
||||||
return port;
|
this.port = port;
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see BackendServiceOptions#getPort()
|
* The protocol for incoming requests.
|
||||||
*/
|
*/
|
||||||
public BackendServiceOptions port(Integer port) {
|
public Builder protocol(String protocol) {
|
||||||
this.port = port;
|
this.protocol = protocol;
|
||||||
return this;
|
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) {
|
||||||
* The protocol for incoming requests.
|
this.portName = portName;
|
||||||
*/
|
return this;
|
||||||
public String getProtocol() {
|
}
|
||||||
return protocol;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public BackendServiceOptions build(){
|
||||||
* @see BackendServiceOptions#getProtocol()
|
return create(name, description, healthChecks,
|
||||||
*/
|
backends, timeoutSec, port, protocol, fingerprint, portName);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,8 @@ public class BackendServiceApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
|
||||||
assertOperationDoneSuccessfully(api.httpHeathChecks().insert(BACKEND_SERVICE_HEALTH_CHECK_NAME));
|
assertOperationDoneSuccessfully(api.httpHeathChecks().insert(BACKEND_SERVICE_HEALTH_CHECK_NAME));
|
||||||
|
|
||||||
List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(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));
|
assertOperationDoneSuccessfully(api().create(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,11 +62,10 @@ public class BackendServiceApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
|
||||||
@Test(groups = "live", dependsOnMethods = "testGetBackendService")
|
@Test(groups = "live", dependsOnMethods = "testGetBackendService")
|
||||||
public void testPatchBackendService() {
|
public void testPatchBackendService() {
|
||||||
String fingerprint = api().get(BACKEND_SERVICE_NAME).fingerprint();
|
String fingerprint = api().get(BACKEND_SERVICE_NAME).fingerprint();
|
||||||
BackendServiceOptions backendService = new BackendServiceOptions()
|
BackendServiceOptions backendService = new BackendServiceOptions.Builder(BACKEND_SERVICE_NAME, ImmutableList.of(getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME)))
|
||||||
.name(BACKEND_SERVICE_NAME)
|
|
||||||
.healthChecks(ImmutableList.of(getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME)))
|
|
||||||
.timeoutSec(10)
|
.timeoutSec(10)
|
||||||
.fingerprint(fingerprint);
|
.fingerprint(fingerprint)
|
||||||
|
.build();
|
||||||
|
|
||||||
assertOperationDoneSuccessfully(api().update(BACKEND_SERVICE_NAME, backendService));
|
assertOperationDoneSuccessfully(api().update(BACKEND_SERVICE_NAME, backendService));
|
||||||
assertBackendServiceEquals(api().get(BACKEND_SERVICE_NAME), backendService);
|
assertBackendServiceEquals(api().get(BACKEND_SERVICE_NAME), backendService);
|
||||||
|
@ -75,12 +75,11 @@ public class BackendServiceApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
|
||||||
public void testUpdateBackendService() {
|
public void testUpdateBackendService() {
|
||||||
String fingerprint = api().get(BACKEND_SERVICE_NAME).fingerprint();
|
String fingerprint = api().get(BACKEND_SERVICE_NAME).fingerprint();
|
||||||
|
|
||||||
BackendServiceOptions backendService = new BackendServiceOptions()
|
BackendServiceOptions backendService = new BackendServiceOptions.Builder(BACKEND_SERVICE_NAME, ImmutableList.of(getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME)))
|
||||||
.name(BACKEND_SERVICE_NAME)
|
|
||||||
.healthChecks(ImmutableList.of(getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME)))
|
|
||||||
.timeoutSec(45)
|
.timeoutSec(45)
|
||||||
.port(8080)
|
.port(8080)
|
||||||
.fingerprint(fingerprint);
|
.fingerprint(fingerprint)
|
||||||
|
.build();
|
||||||
|
|
||||||
assertOperationDoneSuccessfully(api().update(BACKEND_SERVICE_NAME, backendService));
|
assertOperationDoneSuccessfully(api().update(BACKEND_SERVICE_NAME, backendService));
|
||||||
assertBackendServiceEquals(api().get(BACKEND_SERVICE_NAME),
|
assertBackendServiceEquals(api().get(BACKEND_SERVICE_NAME),
|
||||||
|
@ -119,13 +118,13 @@ public class BackendServiceApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertBackendServiceEquals(BackendService result, BackendServiceOptions expected) {
|
private void assertBackendServiceEquals(BackendService result, BackendServiceOptions expected) {
|
||||||
assertEquals(result.name(), expected.getName());
|
assertEquals(result.name(), expected.name());
|
||||||
assertEquals(result.healthChecks(), expected.getHealthChecks());
|
assertEquals(result.healthChecks(), expected.healthChecks());
|
||||||
if (expected.getTimeoutSec() != null) {
|
if (expected.timeoutSec() != null) {
|
||||||
org.testng.Assert.assertEquals(result.timeoutSec(), expected.getTimeoutSec().intValue());
|
org.testng.Assert.assertEquals(result.timeoutSec(), expected.timeoutSec().intValue());
|
||||||
}
|
}
|
||||||
if (expected.getPort() != null) {
|
if (expected.port() != null) {
|
||||||
org.testng.Assert.assertEquals(result.port(), expected.getPort().intValue());
|
org.testng.Assert.assertEquals(result.port(), expected.port().intValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,11 +57,11 @@ public class BackendServiceApiMockTest extends BaseGoogleComputeEngineApiMockTes
|
||||||
List<URI> healthChecks = ImmutableList.of(URI.create(url("/projects/"
|
List<URI> healthChecks = ImmutableList.of(URI.create(url("/projects/"
|
||||||
+ "myproject/global/httpHealthChecks/jclouds-test")));
|
+ "myproject/global/httpHealthChecks/jclouds-test")));
|
||||||
|
|
||||||
assertEquals(backendServiceApi().create( new BackendServiceOptions().name("jclouds-test")
|
assertEquals(backendServiceApi().create( new BackendServiceOptions.Builder("jclouds-test", healthChecks)
|
||||||
.protocol("HTTP")
|
.protocol("HTTP")
|
||||||
.port(80)
|
.port(80)
|
||||||
.timeoutSec(30)
|
.timeoutSec(30)
|
||||||
.healthChecks(healthChecks)),
|
.build()),
|
||||||
new ParseOperationTest().expected(url("/projects")));
|
new ParseOperationTest().expected(url("/projects")));
|
||||||
|
|
||||||
assertSent(server, "POST", "/projects/party/global/backendServices",
|
assertSent(server, "POST", "/projects/party/global/backendServices",
|
||||||
|
@ -75,11 +75,11 @@ public class BackendServiceApiMockTest extends BaseGoogleComputeEngineApiMockTes
|
||||||
+ "myproject/global/httpHealthChecks/jclouds-test")));
|
+ "myproject/global/httpHealthChecks/jclouds-test")));
|
||||||
|
|
||||||
assertEquals(backendServiceApi().update("jclouds-test",
|
assertEquals(backendServiceApi().update("jclouds-test",
|
||||||
new BackendServiceOptions().name("jclouds-test")
|
new BackendServiceOptions.Builder("jclouds-test", healthChecks)
|
||||||
.protocol("HTTP")
|
.protocol("HTTP")
|
||||||
.port(80)
|
.port(80)
|
||||||
.timeoutSec(30)
|
.timeoutSec(30)
|
||||||
.healthChecks(healthChecks)),
|
.build()),
|
||||||
new ParseOperationTest().expected(url("/projects")));
|
new ParseOperationTest().expected(url("/projects")));
|
||||||
assertSent(server, "PUT", "/projects/party/global/backendServices/jclouds-test",
|
assertSent(server, "PUT", "/projects/party/global/backendServices/jclouds-test",
|
||||||
stringFromResource("/backend_service_insert.json"));
|
stringFromResource("/backend_service_insert.json"));
|
||||||
|
@ -92,11 +92,11 @@ public class BackendServiceApiMockTest extends BaseGoogleComputeEngineApiMockTes
|
||||||
+ "myproject/global/httpHealthChecks/jclouds-test")));
|
+ "myproject/global/httpHealthChecks/jclouds-test")));
|
||||||
|
|
||||||
assertEquals(backendServiceApi().patch("jclouds-test",
|
assertEquals(backendServiceApi().patch("jclouds-test",
|
||||||
new BackendServiceOptions().name("jclouds-test")
|
new BackendServiceOptions.Builder("jclouds-test", healthChecks)
|
||||||
.protocol("HTTP")
|
.protocol("HTTP")
|
||||||
.port(80)
|
.port(80)
|
||||||
.timeoutSec(30)
|
.timeoutSec(30)
|
||||||
.healthChecks(healthChecks)),
|
.build()),
|
||||||
new ParseOperationTest().expected(url("/projects")));
|
new ParseOperationTest().expected(url("/projects")));
|
||||||
assertSent(server, "PATCH", "/projects/party/global/backendServices/jclouds-test",
|
assertSent(server, "PATCH", "/projects/party/global/backendServices/jclouds-test",
|
||||||
stringFromResource("/backend_service_insert.json"));
|
stringFromResource("/backend_service_insert.json"));
|
||||||
|
|
|
@ -61,8 +61,7 @@ public class GlobalForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiL
|
||||||
|
|
||||||
|
|
||||||
List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(GLOBAL_FORWARDING_RULE_HEALTH_CHECK_NAME));
|
List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(GLOBAL_FORWARDING_RULE_HEALTH_CHECK_NAME));
|
||||||
BackendServiceOptions b = new BackendServiceOptions().name(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME)
|
BackendServiceOptions b = new BackendServiceOptions.Builder(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME, healthChecks).build();
|
||||||
.healthChecks(healthChecks);
|
|
||||||
assertOperationDoneSuccessfully(api.backendServices()
|
assertOperationDoneSuccessfully(api.backendServices()
|
||||||
.create(b));
|
.create(b));
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,8 @@ public class TargetHttpProxyApiLiveTest extends BaseGoogleComputeEngineApiLiveTe
|
||||||
assertOperationDoneSuccessfully(api.httpHeathChecks().insert(HEALTH_CHECK_NAME));
|
assertOperationDoneSuccessfully(api.httpHeathChecks().insert(HEALTH_CHECK_NAME));
|
||||||
|
|
||||||
List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(HEALTH_CHECK_NAME));
|
List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(HEALTH_CHECK_NAME));
|
||||||
BackendServiceOptions b = new BackendServiceOptions().name(URL_MAP_DEFAULT_SERVICE_NAME)
|
BackendServiceOptions b = new BackendServiceOptions.Builder(URL_MAP_DEFAULT_SERVICE_NAME, healthChecks)
|
||||||
.healthChecks(healthChecks);
|
.build();
|
||||||
|
|
||||||
assertOperationDoneSuccessfully(api.backendServices().create(b));
|
assertOperationDoneSuccessfully(api.backendServices().create(b));
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,7 @@ public class UrlMapApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
|
||||||
assertOperationDoneSuccessfully(api.httpHeathChecks().insert(HEALTH_CHECK_NAME));
|
assertOperationDoneSuccessfully(api.httpHeathChecks().insert(HEALTH_CHECK_NAME));
|
||||||
|
|
||||||
List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(HEALTH_CHECK_NAME));
|
List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(HEALTH_CHECK_NAME));
|
||||||
BackendServiceOptions b = new BackendServiceOptions().name(URL_MAP_BACKEND_SERVICE_NAME)
|
BackendServiceOptions b = new BackendServiceOptions.Builder(URL_MAP_BACKEND_SERVICE_NAME, healthChecks).build();
|
||||||
.healthChecks(healthChecks);
|
|
||||||
assertOperationDoneSuccessfully(api.backendServices().create(b));
|
assertOperationDoneSuccessfully(api.backendServices().create(b));
|
||||||
|
|
||||||
UrlMapOptions map = new UrlMapOptions.Builder().name(URL_MAP_NAME).description("simple url map")
|
UrlMapOptions map = new UrlMapOptions.Builder().name(URL_MAP_NAME).description("simple url map")
|
||||||
|
|
Loading…
Reference in New Issue