mirror of https://github.com/apache/jclouds.git
Merge pull request #1229 from rackspace/rax-clb-less-parsers
These Parsers are unnecessary when the domain objects have ConstructorProperties.
This commit is contained in:
commit
60d83cdd89
|
@ -20,6 +20,8 @@ package org.jclouds.rackspace.cloudloadbalancers.domain;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
|
@ -37,7 +39,10 @@ public class ConnectionThrottle {
|
|||
private final int maxConnectionRate;
|
||||
private final int rateInterval;
|
||||
|
||||
protected ConnectionThrottle(int maxConnections, int minConnections, int maxConnectionRate, int rateInterval) {
|
||||
@ConstructorProperties({
|
||||
"maxConnections", "minConnections", "maxConnectionRate", "rateInterval"
|
||||
})
|
||||
protected ConnectionThrottle(Integer maxConnections, Integer minConnections, Integer maxConnectionRate, Integer rateInterval) {
|
||||
this.maxConnections = maxConnections;
|
||||
this.minConnections = minConnections;
|
||||
this.maxConnectionRate = maxConnectionRate;
|
||||
|
|
|
@ -33,12 +33,12 @@ import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
|||
import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
|
||||
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
|
||||
import org.jclouds.rackspace.cloudloadbalancers.domain.ConnectionThrottle;
|
||||
import org.jclouds.rackspace.cloudloadbalancers.functions.ParseConnectionThrottle;
|
||||
import org.jclouds.rackspace.cloudloadbalancers.functions.ParseNestedBoolean;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
import org.jclouds.rest.annotations.Payload;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.annotations.WrapWith;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
@ -70,7 +70,7 @@ public interface ConnectionAsyncApi {
|
|||
@Named("connectionthrottle:get")
|
||||
@GET
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseConnectionThrottle.class)
|
||||
@SelectJson("connectionThrottle")
|
||||
@Fallback(NullOnNotFoundOr404.class)
|
||||
@Path("/connectionthrottle")
|
||||
ListenableFuture<ConnectionThrottle> getConnectionThrottle();
|
||||
|
|
|
@ -31,10 +31,9 @@ import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
|||
import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
|
||||
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
|
||||
import org.jclouds.rackspace.cloudloadbalancers.domain.HealthMonitor;
|
||||
import org.jclouds.rackspace.cloudloadbalancers.functions.ParseHealthMonitor;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.annotations.WrapWith;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
@ -65,7 +64,7 @@ public interface HealthMonitorAsyncApi {
|
|||
@Named("healthmonitor:get")
|
||||
@GET
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseHealthMonitor.class)
|
||||
@SelectJson("healthMonitor")
|
||||
@Fallback(NullOnNotFoundOr404.class)
|
||||
@Path("/healthmonitor")
|
||||
ListenableFuture<HealthMonitor> get();
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.rackspace.cloudloadbalancers.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.rackspace.cloudloadbalancers.domain.ConnectionThrottle;
|
||||
import org.jclouds.rest.InvocationContext;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* @author Everett Toews
|
||||
*/
|
||||
public class ParseConnectionThrottle implements
|
||||
Function<HttpResponse, ConnectionThrottle>, InvocationContext<ParseConnectionThrottle> {
|
||||
|
||||
private final ParseJson<Map<String, ConnectionThrottle>> json;
|
||||
|
||||
@Inject
|
||||
ParseConnectionThrottle(ParseJson<Map<String, ConnectionThrottle>> json) {
|
||||
this.json = checkNotNull(json, "json");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionThrottle apply(HttpResponse response) {
|
||||
Map<String, ConnectionThrottle> map = json.apply(response);
|
||||
|
||||
if (map == null || map.size() == 0)
|
||||
throw new HttpResponseException("Unexpected connection throttle format returned.", null, response);
|
||||
|
||||
ConnectionThrottle connectionThrottle = Iterables.get(map.values(), 0);
|
||||
|
||||
return connectionThrottle.isValid() ? connectionThrottle : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParseConnectionThrottle setContext(HttpRequest request) {
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.rackspace.cloudloadbalancers.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.rackspace.cloudloadbalancers.domain.HealthMonitor;
|
||||
import org.jclouds.rest.InvocationContext;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* @author Everett Toews
|
||||
*/
|
||||
public class ParseHealthMonitor implements
|
||||
Function<HttpResponse, HealthMonitor>, InvocationContext<ParseHealthMonitor> {
|
||||
|
||||
private final ParseJson<Map<String, HealthMonitor>> json;
|
||||
|
||||
@Inject
|
||||
ParseHealthMonitor(ParseJson<Map<String, HealthMonitor>> json) {
|
||||
this.json = checkNotNull(json, "json");
|
||||
}
|
||||
|
||||
@Override
|
||||
public HealthMonitor apply(HttpResponse response) {
|
||||
Map<String, HealthMonitor> map = json.apply(response);
|
||||
|
||||
if (map == null || map.size() == 0)
|
||||
return null;
|
||||
|
||||
HealthMonitor healthMonitor = Iterables.get(map.values(), 0);
|
||||
|
||||
return healthMonitor.isValid() ? healthMonitor : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParseHealthMonitor setContext(HttpRequest request) {
|
||||
return this;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue