Skip to content

Commit ad23488

Browse files
committed
Remove some deprecation warnings
(But really this needs serious attention, and deletion of some of the “legacy” pieces - so not going through everything).
1 parent d4a02c7 commit ad23488

File tree

41 files changed

+174
-262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+174
-262
lines changed

cloudstack/src/main/java/brooklyn/networking/cloudstack/HttpUtil.java

Lines changed: 21 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,12 @@
2020
import java.security.cert.X509Certificate;
2121
import java.util.Map;
2222

23-
import org.apache.http.HttpEntity;
24-
import org.apache.http.HttpResponse;
25-
import org.apache.http.auth.AuthScope;
23+
import org.apache.brooklyn.util.exceptions.Exceptions;
24+
import org.apache.brooklyn.util.http.HttpTool;
25+
import org.apache.brooklyn.util.http.HttpToolResponse;
2626
import org.apache.http.auth.Credentials;
2727
import org.apache.http.client.HttpClient;
28-
import org.apache.http.client.methods.HttpGet;
29-
import org.apache.http.client.methods.HttpPost;
30-
import org.apache.http.conn.scheme.Scheme;
31-
import org.apache.http.conn.ssl.SSLSocketFactory;
3228
import org.apache.http.conn.ssl.TrustStrategy;
33-
import org.apache.http.entity.ByteArrayEntity;
34-
import org.apache.http.impl.client.DefaultHttpClient;
35-
import org.apache.http.util.EntityUtils;
3629
import org.bouncycastle.util.io.Streams;
3730
import org.slf4j.Logger;
3831
import org.slf4j.LoggerFactory;
@@ -41,53 +34,36 @@
4134
import com.google.common.collect.Multimap;
4235
import com.google.common.collect.Multimaps;
4336

44-
import org.apache.brooklyn.util.http.HttpToolResponse;
45-
import org.apache.brooklyn.util.exceptions.Exceptions;
46-
4737
/**
4838
* HTTP convenience static methods.
4939
* <p>
5040
* Uses the Apache {@link HttpClient} for connections.
41+
*
42+
* @deprecated since 0.10.0; instead use {@link HttpTool}.
5143
*/
44+
@Deprecated
5245
public class HttpUtil {
5346

5447
public static final Logger LOG = LoggerFactory.getLogger(HttpUtil.class);
5548

5649
public static HttpClient createHttpClient(URI uri, Optional<Credentials> credentials) {
57-
final DefaultHttpClient httpClient = new DefaultHttpClient();
58-
59-
// TODO if supplier returns null, we may wish to defer initialization until url available?
60-
if (uri != null && "https".equalsIgnoreCase(uri.getScheme())) {
61-
try {
62-
int port = (uri.getPort() >= 0) ? uri.getPort() : 443;
63-
SSLSocketFactory socketFactory = new SSLSocketFactory(
64-
new TrustAllStrategy(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
65-
Scheme sch = new Scheme("https", port, socketFactory);
66-
httpClient.getConnectionManager().getSchemeRegistry().register(sch);
67-
} catch (Exception e) {
68-
LOG.warn("Error in HTTP Feed of {}, setting trust for uri {}", uri);
69-
throw Exceptions.propagate(e);
70-
}
71-
}
72-
73-
// Set credentials
74-
if (uri != null && credentials.isPresent()) {
75-
String hostname = uri.getHost();
76-
int port = uri.getPort();
77-
httpClient.getCredentialsProvider().setCredentials(new AuthScope(hostname, port), credentials.get());
78-
}
79-
80-
return httpClient;
50+
return HttpTool.httpClientBuilder()
51+
.uri(uri)
52+
.credential(credentials)
53+
.build();
8154
}
8255

8356
public static HttpToolResponse invoke(org.jclouds.http.HttpRequest request) {
84-
HttpClient client = HttpUtil.createHttpClient(request.getEndpoint(), Optional.<Credentials>absent());
57+
HttpClient client = HttpTool.httpClientBuilder()
58+
.uri(request.getEndpoint())
59+
.build();
8560
String method = request.getMethod();
8661
try {
8762
if ("GET".equalsIgnoreCase(method)) {
88-
return HttpUtil.httpGet(client, request.getEndpoint(), request.getHeaders());
63+
return HttpTool.httpGet(client, request.getEndpoint(), request.getHeaders());
8964
} else if ("POST".equalsIgnoreCase(method)) {
90-
return HttpUtil.httpPost(client, request.getEndpoint(), request.getHeaders(), Streams.readAll(request.getPayload().openStream()));
65+
return HttpTool.httpPost(client, request.getEndpoint(), request.getHeaders(), Streams.readAll(request.getPayload().openStream()));
66+
// return HttpUtil.httpPost(client, request.getEndpoint(), request.getHeaders(), Streams.readAll(request.getPayload().openStream()));
9167
} else {
9268
// TODO being lazy!
9369
throw new UnsupportedOperationException("Unsupported method: "+method+" for "+request);
@@ -99,58 +75,23 @@ public static HttpToolResponse invoke(org.jclouds.http.HttpRequest request) {
9975

10076
public static HttpToolResponse httpGet(URI uri, Multimap<String,String> headers) {
10177
HttpClient client = HttpUtil.createHttpClient(uri, Optional.<Credentials>absent());
102-
return HttpUtil.httpGet(client, uri, headers);
78+
return HttpTool.httpGet(client, uri, headers);
10379
}
10480

10581
public static HttpToolResponse httpGet(HttpClient httpClient, URI uri, Map<String,String> headers) {
106-
return httpGet(httpClient, uri, Multimaps.forMap(headers));
82+
return HttpTool.httpGet(httpClient, uri, Multimaps.forMap(headers));
10783
}
10884

10985
public static HttpToolResponse httpGet(HttpClient httpClient, URI uri, Multimap<String,String> headers) {
110-
HttpGet httpGet = new HttpGet(uri);
111-
for (Map.Entry<String,String> entry : headers.entries()) {
112-
httpGet.addHeader(entry.getKey(), entry.getValue());
113-
}
114-
115-
long startTime = System.currentTimeMillis();
116-
try {
117-
HttpResponse httpResponse = httpClient.execute(httpGet);
118-
try {
119-
return new HttpToolResponse(httpResponse, startTime);
120-
} finally {
121-
EntityUtils.consume(httpResponse.getEntity());
122-
}
123-
} catch (Exception e) {
124-
throw Exceptions.propagate(e);
125-
}
86+
return HttpTool.httpGet(httpClient, uri, headers);
12687
}
12788

12889
public static HttpToolResponse httpPost(HttpClient httpClient, URI uri, Map<String,String> headers, byte[] body) {
129-
return httpPost(httpClient, uri, Multimaps.forMap(headers), body);
90+
return HttpTool.httpPost(httpClient, uri, Multimaps.forMap(headers), body);
13091
}
13192

13293
public static HttpToolResponse httpPost(HttpClient httpClient, URI uri, Multimap<String,String> headers, byte[] body) {
133-
HttpPost httpPost = new HttpPost(uri);
134-
for (Map.Entry<String,String> entry : headers.entries()) {
135-
httpPost.addHeader(entry.getKey(), entry.getValue());
136-
}
137-
if (body != null) {
138-
HttpEntity httpEntity = new ByteArrayEntity(body);
139-
httpPost.setEntity(httpEntity);
140-
}
141-
142-
long startTime = System.currentTimeMillis();
143-
try {
144-
HttpResponse httpResponse = httpClient.execute(httpPost);
145-
146-
try {
147-
return new HttpToolResponse(httpResponse, startTime);
148-
} finally {
149-
EntityUtils.consume(httpResponse.getEntity());
150-
}
151-
} catch (Exception e) {
152-
throw Exceptions.propagate(e);
153-
}
94+
return HttpTool.httpPost(httpClient, uri, headers, body);
15495
}
15596

15697
public static class TrustAllStrategy implements TrustStrategy {

cloudstack/src/main/java/brooklyn/networking/cloudstack/legacy/LegacyAbstractSubnetApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected void applyDefaultConfig() {
7979
setIfNotAlreadySet(USE_SUBNET, true);
8080
// FIXME not safe for persistence
8181
if (config().getRaw(LegacyJcloudsCloudstackSubnetLocation.PORT_FORWARDING_MANAGER).isAbsent()) {
82-
PortForwardManager pfm = (PortForwardManager) getManagementContext().getLocationRegistry().resolve("portForwardManager(scope=global)");
82+
PortForwardManager pfm = (PortForwardManager) getManagementContext().getLocationRegistry().getLocationManaged("portForwardManager(scope=global)");
8383
config().set(LegacyJcloudsCloudstackSubnetLocation.PORT_FORWARDING_MANAGER, pfm);
8484
}
8585

cloudstack/src/main/java/brooklyn/networking/cloudstack/legacy/LegacyJcloudsCloudstackSubnetLocation.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import org.apache.brooklyn.util.text.Strings;
5656
import org.apache.brooklyn.util.time.Duration;
5757
import org.apache.brooklyn.util.time.Time;
58-
import org.apache.commons.lang3.tuple.Pair;
5958
import org.jclouds.cloudstack.CloudStackApi;
6059
import org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions;
6160
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
@@ -92,7 +91,6 @@
9291
*/
9392
public class LegacyJcloudsCloudstackSubnetLocation extends JcloudsLocation {
9493

95-
private static final long serialVersionUID = -6097237757668759966L;
9694
private static final Logger LOG = LoggerFactory.getLogger(LegacyJcloudsCloudstackSubnetLocation.class);
9795

9896
/* Config on the subnet jclouds location */

cloudstack/src/main/java/brooklyn/networking/cloudstack/legacy/LegacySubnetTier.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
import java.util.Map;
1919

20-
import org.jclouds.cloudstack.domain.FirewallRule;
21-
2220
import org.apache.brooklyn.api.entity.Entity;
2321
import org.apache.brooklyn.api.entity.ImplementedBy;
2422
import org.apache.brooklyn.api.sensor.AttributeSensor;
@@ -29,7 +27,11 @@
2927
import org.apache.brooklyn.core.location.access.BrooklynAccessUtils;
3028
import org.apache.brooklyn.core.location.access.PortForwardManager;
3129
import org.apache.brooklyn.core.sensor.BasicAttributeSensor;
30+
import org.apache.brooklyn.core.sensor.Sensors;
3231
import org.apache.brooklyn.util.net.Cidr;
32+
import org.jclouds.cloudstack.domain.FirewallRule;
33+
34+
import com.google.common.reflect.TypeToken;
3335

3436
@ImplementedBy(LegacySubnetTierImpl.class)
3537
public interface LegacySubnetTier extends Entity, Startable {
@@ -64,7 +66,9 @@ public interface LegacySubnetTier extends Entity, Startable {
6466
public static final AttributeSensor<String> PRIVATE_HOSTNAME = new BasicAttributeSensor<String>(String.class, "hostname.private",
6567
"A private hostname or IP within the subnet (used so don't lose private address when transforming hostname etc on an entity)");
6668

67-
public static final AttributeSensor<Map<String,String>> PUBLIC_HOSTNAME_IP_IDS = new BasicAttributeSensor(Map.class, "subnet.publicips.mapping",
69+
@SuppressWarnings("serial")
70+
public static final AttributeSensor<Map<String,String>> PUBLIC_HOSTNAME_IP_IDS = Sensors.newSensor(
71+
new TypeToken<Map<String,String>>() {}, "subnet.publicips.mapping",
6872
"Provides a mapping from ip ID to actual public IP");
6973

7074
@SuppressWarnings({ "unchecked", "rawtypes" })

cloudstack/src/main/java/brooklyn/networking/cloudstack/legacy/LegacySubnetTierImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.jclouds.cloudstack.options.CreateNetworkOptions;
4242

4343
import org.apache.brooklyn.api.entity.Entity;
44-
import org.apache.brooklyn.api.entity.EntityLocal;
4544
import org.apache.brooklyn.api.location.Location;
4645
import org.apache.brooklyn.api.sensor.AttributeSensor;
4746
import org.apache.brooklyn.api.sensor.SensorEvent;
@@ -227,7 +226,7 @@ private synchronized PortForwardManager getPortForwardManager() {
227226
pfw = getConfig(PORT_FORWARDING_MANAGER);
228227
if (pfw==null) {
229228
// FIXME not safe for persistence
230-
pfw = (PortForwardManager) getManagementContext().getLocationRegistry().resolve("portForwardManager(scope=global)");
229+
pfw = (PortForwardManager) getManagementContext().getLocationRegistry().getLocationManaged("portForwardManager(scope=global)");
231230
setConfigEvenIfOwned(PORT_FORWARDING_MANAGER, pfw);
232231
}
233232
sensors().set(SUBNET_SERVICE_PORT_FORWARDS, pfw);
@@ -710,7 +709,7 @@ public void onEvent(SensorEvent<Object> event) {
710709
apply(event.getSource(), event.getValue());
711710
}
712711
public void apply(Entity source, Object valueIgnored) {
713-
Location targetVm = Iterables.getOnlyElement(((EntityLocal)serviceToForward).getLocations(), null);
712+
Location targetVm = Iterables.getOnlyElement(serviceToForward.getLocations(), null);
714713
if (targetVm==null) {
715714
log.warn("Skipping port forward rule for "+serviceToForward+" because it does not have a location");
716715
return;

cloudstack/src/main/java/brooklyn/networking/cloudstack/legacy/VirtualPrivateCloud.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.brooklyn.api.sensor.AttributeSensor;
2424
import org.apache.brooklyn.config.ConfigKey;
2525
import org.apache.brooklyn.core.config.BasicConfigKey;
26-
import org.apache.brooklyn.core.entity.AbstractEntity;
2726
import org.apache.brooklyn.core.sensor.BasicAttributeSensor;
2827
import org.apache.brooklyn.location.jclouds.JcloudsLocation;
2928
import org.apache.brooklyn.util.collections.MutableMap;

cloudstack/src/main/java/brooklyn/networking/cloudstack/loadbalancer/CloudStackLoadBalancer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ public interface CloudStackLoadBalancer extends AbstractNonProvisionedController
5656

5757
/** @deprecated in CloudStack; open firewall explicitly */
5858
@Deprecated
59+
@SuppressWarnings("serial")
5960
ConfigKey<Set<String>> ALLOWED_SOURCE_CIDRs = ConfigKeys.newConfigKey(
60-
new TypeToken<Set<String>>() { }, "cloudstack.loadbalancer.cidr", "List of allowed source CIDRs (Deprecated in CloudStack)");
61+
new TypeToken<Set<String>>() {}, "cloudstack.loadbalancer.cidr", "List of allowed source CIDRs (Deprecated in CloudStack)");
6162

6263
/** @deprecated in CloudStack; open firewall explicitly */
6364
@Deprecated

cloudstack/src/main/java/brooklyn/networking/cloudstack/loadbalancer/CloudStackLoadBalancerImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.apache.brooklyn.config.ConfigKey;
4545
import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
4646
import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
47-
import org.apache.brooklyn.core.feed.ConfigToAttributes;
4847
import org.apache.brooklyn.core.location.access.BrooklynAccessUtils;
4948
import org.apache.brooklyn.core.location.cloud.names.BasicCloudMachineNamer;
5049
import org.apache.brooklyn.entity.proxy.AbstractNonProvisionedControllerImpl;

cloudstack/src/main/java/brooklyn/networking/cloudstack/portforwarding/CloudstackPortForwarder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public CloudstackPortForwarder(PortForwardManager portForwardManager) {
8787
@Override
8888
public void setManagementContext(ManagementContext managementContext) {
8989
if (portForwardManager == null) {
90-
portForwardManager = (PortForwardManager) managementContext.getLocationRegistry().resolve("portForwardManager(scope=global)");
90+
portForwardManager = (PortForwardManager) managementContext.getLocationRegistry().getLocationManaged("portForwardManager(scope=global)");
9191
}
9292
}
9393

cloudstack/src/test/java/brooklyn/networking/cloudstack/Cleanup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static void main(String[] args) {
4848

4949
public Cleanup(String accountName) {
5050
managementContext = new LocalManagementContext();
51-
loc = (JcloudsLocation) managementContext.getLocationRegistry().resolve("citrix-cloudplatform");
51+
loc = (JcloudsLocation) managementContext.getLocationRegistry().getLocationManaged("citrix-cloudplatform");
5252
networking = new CloudstackNetworking(loc);
5353
client = CloudstackNew40FeaturesClient.newInstance(loc);
5454

0 commit comments

Comments
 (0)