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.javax.annotation.Nullable;
|
||||
import org.jclouds.json.SerializedNames;
|
||||
|
||||
public class BackendServiceOptions {
|
||||
import com.google.auto.value.AutoValue;
|
||||
|
||||
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;
|
||||
@AutoValue
|
||||
public abstract class BackendServiceOptions {
|
||||
|
||||
/**
|
||||
* Name of the BackendService resource.
|
||||
* @return name, provided by the client.
|
||||
*/
|
||||
public String getName(){
|
||||
return name;
|
||||
@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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BackendServiceOptions#getName()
|
||||
*/
|
||||
public BackendServiceOptions name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
BackendServiceOptions(){
|
||||
}
|
||||
|
||||
/**
|
||||
* An optional textual description of the BackendService.
|
||||
* @return description, provided by the client.
|
||||
*/
|
||||
public String getDescription(){
|
||||
return description;
|
||||
}
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see BackendServiceOptions#getDescription()
|
||||
*/
|
||||
public BackendServiceOptions description(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BackendServiceOptions#getHealthChecks()
|
||||
*/
|
||||
public BackendServiceOptions healthChecks(List<URI> healthChecks) {
|
||||
this.healthChecks = healthChecks;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Empty builder for use when patching or updating and existing BackendService
|
||||
* Otherwise use the other {@link #Builder(String, List) builder}
|
||||
*/
|
||||
public Builder(){
|
||||
}
|
||||
|
||||
/**
|
||||
* The list of backends that serve this BackendService.
|
||||
*/
|
||||
public List<Backend> getBackends() {
|
||||
return backends;
|
||||
}
|
||||
/**
|
||||
* An optional textual description of the BackendService.
|
||||
*/
|
||||
public Builder description(String description){
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BackendServiceOptions#getBackends()
|
||||
*/
|
||||
public BackendServiceOptions backends(List<Backend> backends){
|
||||
this.backends = backends;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many seconds to wait for the backend before considering it a failed request.
|
||||
* Default is 30 seconds.
|
||||
*/
|
||||
public Integer getTimeoutSec() {
|
||||
return timeoutSec;
|
||||
}
|
||||
/**
|
||||
* The list of backends that serve this BackendService.
|
||||
*/
|
||||
public Builder backends(List<Backend> backends){
|
||||
this.backends = backends;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BackendServiceOptions#getTimeoutSec()
|
||||
*/
|
||||
public BackendServiceOptions timeoutSec(Integer timeoutSec) {
|
||||
this.timeoutSec = timeoutSec;
|
||||
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 Integer getPort() {
|
||||
return port;
|
||||
}
|
||||
/**
|
||||
* The TCP port to connect on the backend.
|
||||
* The default value is 80.
|
||||
*/
|
||||
public Builder port(Integer port) {
|
||||
this.port = port;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BackendServiceOptions#getPort()
|
||||
*/
|
||||
public BackendServiceOptions 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* The protocol for incoming requests.
|
||||
*/
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
public Builder portName(String portName) {
|
||||
this.portName = portName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
public BackendServiceOptions build(){
|
||||
return create(name, description, healthChecks,
|
||||
backends, timeoutSec, port, protocol, fingerprint, portName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue