Skip to content
Permalink
Browse files
- added subnet api
    - added new binders
    - added new methods to the load balancer api
    - renamed availabilityZoneResultHandler to more generic MemberResultHandler
    - updated jclouds version to 2.1.0
    - added BaseELBApiMockTest
    - added subnet mock test
    - added com.squareup.okhttp dependency for mock tests
    - removed checkNotNull on policyType description because this field is not always present
    - made some of the tests signle threaded
    - updated BindSubnetIdsToIndexedFormParams for readability
    - added subnet live test
  • Loading branch information
justinThompson authored and andreaturli committed Jan 27, 2017
1 parent 3eb2646 commit e248c37dce384c285fc80425b24256f502d8c8ac
Showing 28 changed files with 1,112 additions and 46 deletions.
@@ -117,6 +117,18 @@
<artifactId>auto-service</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
<exclusions>
<!-- Already provided by jclouds-sshj -->
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<profiles>
@@ -21,9 +21,11 @@

import org.jclouds.aws.filters.FormSigner;
import org.jclouds.elb.features.AvailabilityZoneApi;
import org.jclouds.elb.features.HealthCheckApi;
import org.jclouds.elb.features.InstanceApi;
import org.jclouds.elb.features.LoadBalancerApi;
import org.jclouds.elb.features.PolicyApi;
import org.jclouds.elb.features.SubnetApi;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Region;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
@@ -91,4 +93,20 @@ InstanceApi getInstanceApiForRegion(
AvailabilityZoneApi getAvailabilityZoneApiForRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);

/**
* Provides access to HealthCheck features.
*/
@Delegate
HealthCheckApi getHealthCheckApi();

@Delegate
HealthCheckApi getHealthCheckApiForRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);

/**
* Provides access to Subnet features.
*/
@Delegate
SubnetApi getSubnetApi();

}
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.elb.binders;

import static com.google.common.base.Preconditions.checkNotNull;

import org.jclouds.elb.domain.HealthCheck;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;

import com.google.common.collect.ImmutableMultimap;

public class BindHealthCheckToFormParams implements Binder {

/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
HealthCheck healthCheck = checkNotNull(input, "healthCheck must be set!") instanceof HealthCheck ?
HealthCheck.class.cast(input) : (HealthCheck) input;

ImmutableMultimap.Builder<String, String> formParameters = ImmutableMultimap.builder();
formParameters.put("HealthCheck.HealthyThreshold", healthCheck.getHealthyThreshold() + "");
formParameters.put("HealthCheck.UnhealthyThreshold", healthCheck.getUnhealthyThreshold() + "");
formParameters.put("HealthCheck.Target", healthCheck.getTarget());
formParameters.put("HealthCheck.Interval", healthCheck.getInterval() + "");
formParameters.put("HealthCheck.Timeout", healthCheck.getTimeout() + "");
return (R) request.toBuilder().replaceFormParams(formParameters.build()).build();

}
}
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.elb.binders;

import static org.jclouds.aws.util.AWSUtils.indexIterableToFormValuesWithPrefix;

import javax.inject.Singleton;

import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;

/**
* Binds the Iterable<String> to form parameters named with prefix LoadBalancerPorts.member
*/
@Singleton
public class BindListenerPortsToIndexedFormParams implements Binder {

@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
return indexIterableToFormValuesWithPrefix(request, "LoadBalancerPorts.member", input);

}

}
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.elb.binders;

import static com.google.common.base.Preconditions.checkNotNull;

import javax.inject.Singleton;

import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;

import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableMultimap.Builder;

/**
* Binds the Iterable<String> to form parameters named with Subnets.member.index
*/
@Singleton
public class BindSubnetIdsToIndexedFormParams implements Binder {

@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
Iterable<?> values = Iterable.class.cast(checkNotNull(input, "subnetIds"));
Builder<String, String> builder = ImmutableMultimap.builder();
int i = 1;
for (Object o : values) {
builder.put("Subnets.member." + (i++), o.toString());
}
ImmutableMultimap<String, String> forms = builder.build();
return (R) (forms.size() == 0 ? request : request.toBuilder().replaceFormParams(forms).build());
}

}
@@ -29,7 +29,7 @@
*
*
* @see <a
* href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/DeveloperGuide/ConfigureHealthCheck.html"
* href="http://docs.aws.amazon.com/elasticloadbalancing/2012-06-01/APIReference/API_ConfigureHealthCheck.html"
* >doc</a>
*/
public class HealthCheck {
@@ -95,7 +95,7 @@ public Builder fromPolicyType(PolicyType in) {

protected PolicyType(String name, String description, Iterable<AttributeMetadata<?>> attributeMetadata) {
this.name = checkNotNull(name, "name");
this.description = checkNotNull(description, "description");
this.description = description;
this.attributeMetadata = ImmutableSet.copyOf(checkNotNull(attributeMetadata, "attributeMetadata"));
}

@@ -27,7 +27,7 @@

import org.jclouds.aws.filters.FormSigner;
import org.jclouds.elb.binders.BindAvailabilityZonesToIndexedFormParams;
import org.jclouds.elb.xml.AvailabilityZonesResultHandler;
import org.jclouds.elb.xml.MemberResultHandler;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters;
@@ -70,7 +70,7 @@ public interface AvailabilityZoneApi {
@Named("EnableAvailabilityZonesForLoadBalancer")
@POST
@Path("/")
@XMLResponseParser(AvailabilityZonesResultHandler.class)
@XMLResponseParser(MemberResultHandler.class)
@FormParams(keys = ACTION, values = "EnableAvailabilityZonesForLoadBalancer")
Set<String> addAvailabilityZonesToLoadBalancer(
@BinderParam(BindAvailabilityZonesToIndexedFormParams.class) Iterable<String> zones,
@@ -83,7 +83,7 @@ Set<String> addAvailabilityZonesToLoadBalancer(
@Named("EnableAvailabilityZonesForLoadBalancer")
@POST
@Path("/")
@XMLResponseParser(AvailabilityZonesResultHandler.class)
@XMLResponseParser(MemberResultHandler.class)
@FormParams(keys = ACTION, values = "EnableAvailabilityZonesForLoadBalancer")
Set<String> addAvailabilityZoneToLoadBalancer(
@FormParam("AvailabilityZones.member.1") String zone,
@@ -128,7 +128,7 @@ Set<String> addAvailabilityZoneToLoadBalancer(
@Named("DisableAvailabilityZonesForLoadBalancer")
@POST
@Path("/")
@XMLResponseParser(AvailabilityZonesResultHandler.class)
@XMLResponseParser(MemberResultHandler.class)
@FormParams(keys = ACTION, values = "DisableAvailabilityZonesForLoadBalancer")
Set<String> removeAvailabilityZonesFromLoadBalancer(
@BinderParam(BindAvailabilityZonesToIndexedFormParams.class) Iterable<String> zones,
@@ -140,7 +140,7 @@ Set<String> removeAvailabilityZonesFromLoadBalancer(
@Named("DisableAvailabilityZonesForLoadBalancer")
@POST
@Path("/")
@XMLResponseParser(AvailabilityZonesResultHandler.class)
@XMLResponseParser(MemberResultHandler.class)
@FormParams(keys = ACTION, values = "DisableAvailabilityZonesForLoadBalancer")
Set<String> removeAvailabilityZoneFromLoadBalancer(
@FormParam("AvailabilityZones.member.1") String zone,
@@ -0,0 +1,65 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.elb.features;

import static org.jclouds.aws.reference.FormParameters.ACTION;

import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;

import org.jclouds.Fallbacks;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.elb.binders.BindHealthCheckToFormParams;
import org.jclouds.elb.domain.HealthCheck;
import org.jclouds.elb.xml.HealthCheckHandler;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;

/**
* Provides access to Amazon ELB Health Check functionality via the Query API
* <p/>
*/
@RequestFilters(FormSigner.class)
@Consumes(MediaType.APPLICATION_XML)
@VirtualHost
public interface HealthCheckApi {

/**
* @see <a href="http://docs.aws.amazon.com/elasticloadbalancing/2012-06-01/APIReference/API_ConfigureHealthCheck.html">doc</a>
*
* @param loadBalancerName
* @param healthCheck
* @return
*/
@Named("ConfigureHealthCheck")
@POST
@Path("/")
@XMLResponseParser(HealthCheckHandler.class)
@FormParams(keys = ACTION, values = "ConfigureHealthCheck")
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
HealthCheck configureHealthCheck(@FormParam("LoadBalancerName") String loadBalancerName,
@BinderParam(BindHealthCheckToFormParams.class) HealthCheck healthCheck);

}

0 comments on commit e248c37

Please sign in to comment.