diff options
14 files changed, 153 insertions, 145 deletions
diff --git a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/FloatingIpDnsExtension.java b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/FloatingIpDnsExtension.java index f2a6bd6..8442e3d 100644 --- a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/FloatingIpDnsExtension.java +++ b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/FloatingIpDnsExtension.java @@ -25,33 +25,33 @@ import com.woorea.openstack.nova.model.FloatingIpDomain; import com.woorea.openstack.nova.model.FloatingIpDomains; public class FloatingIpDnsExtension { - + private final OpenStackClient CLIENT; - + public FloatingIpDnsExtension(OpenStackClient client) { CLIENT = client; } - + public ListDomains listFloatingIpDomains() { return new ListDomains(); } - + public CreateDomain create(FloatingIpDomain floatingIpDomain) { return new CreateDomain(floatingIpDomain); } - + public ShowDomain show(String id) { return new ShowDomain(id); } - + public UpdateDomain update(FloatingIpDomain floatingIpDomain) { return new UpdateDomain(floatingIpDomain); } - + public DeleteDomain delete(String id) { return new DeleteDomain(id); } - + public class ListDomains extends OpenStackRequest<FloatingIpDomains> { public ListDomains() { @@ -62,44 +62,44 @@ public class FloatingIpDnsExtension { public class CreateDomain extends OpenStackRequest<FloatingIpDomain> { - private FloatingIpDomain floatingIpDomain; - + + public CreateDomain(FloatingIpDomain floatingIpDomain) { super(CLIENT, HttpMethod.POST, "/os-floating-ip-dns", Entity.json(floatingIpDomain), FloatingIpDomain.class); - this.floatingIpDomain = floatingIpDomain; + } - + } - + public class ShowDomain extends OpenStackRequest<FloatingIpDomain> { - + public ShowDomain(String id) { super(CLIENT, HttpMethod.GET, new StringBuffer("/os-floating-ip-dns/").append(id).toString(), null, FloatingIpDomain.class); } - + } - + public static class UpdateDomain extends OpenStackRequest<FloatingIpDomain> { - private FloatingIpDomain floatingIpDomain; - + + public UpdateDomain(FloatingIpDomain floatingIpDomain) { - //super(CLIENT, HttpMethod.PUT, new StringBuffer("/os-floating-ip-dns/").append(id).toString(), Entity.json(floatingIpDomain), FloatingIpDomain.class); - this.floatingIpDomain = floatingIpDomain; + + } - + } - + public class DeleteDomain extends OpenStackRequest<Void> { - + public DeleteDomain(String id) { super(CLIENT, HttpMethod.DELETE, new StringBuffer("/os-floating-ip-dns/").append(id).toString(), null, Void.class); } - + } - - - -} + + + +}
\ No newline at end of file diff --git a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/FloatingIpPoolsExtension.java b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/FloatingIpPoolsExtension.java index d574ef6..c6325d4 100644 --- a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/FloatingIpPoolsExtension.java +++ b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/FloatingIpPoolsExtension.java @@ -23,13 +23,13 @@ import com.woorea.openstack.base.client.OpenStackRequest; import com.woorea.openstack.nova.model.FloatingIpPools; public class FloatingIpPoolsExtension { - + private final OpenStackClient CLIENT; - + public FloatingIpPoolsExtension(OpenStackClient client) { CLIENT = client; } - + public List list() { return new List(); } @@ -42,6 +42,6 @@ public class FloatingIpPoolsExtension { } - -} + +}
\ No newline at end of file diff --git a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/FloatingIpsExtension.java b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/FloatingIpsExtension.java index 4b39b2e..d1ae7f4 100644 --- a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/FloatingIpsExtension.java +++ b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/FloatingIpsExtension.java @@ -28,13 +28,13 @@ import com.woorea.openstack.nova.model.FloatingIp; import com.woorea.openstack.nova.model.FloatingIps; public class FloatingIpsExtension { - + private final OpenStackClient CLIENT; - + public FloatingIpsExtension(OpenStackClient client) { CLIENT = client; } - + public class List extends OpenStackRequest<FloatingIps> { public List() { @@ -44,40 +44,39 @@ public class FloatingIpsExtension { } public class Allocate extends OpenStackRequest<FloatingIp> { - + public Allocate(Entity<?> entity) { super(CLIENT, HttpMethod.POST, "/os-floating-ips", entity, FloatingIp.class); } } - + public class Deallocate extends OpenStackRequest<Void> { - + public Deallocate(String id) { super(CLIENT, HttpMethod.DELETE, new StringBuffer("/os-floating-ips/").append(id).toString(), null, Void.class); } - + } public List list() { return new List(); } - + public Allocate allocate(String pool) { Entity<?> entity=null; if(pool!=null) { - Map<String, String> body = new HashMap<String, String>(); + Map<String, String> body = new HashMap<>(); body.put("pool", pool); entity=Entity.json(body); } return new Allocate(entity); } - + public Deallocate deallocate(String id) { return new Deallocate(id); } - - - -} + + +} diff --git a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/HostsExtension.java b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/HostsExtension.java index f5a0693..b9c6db4 100644 --- a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/HostsExtension.java +++ b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/HostsExtension.java @@ -24,17 +24,17 @@ import com.woorea.openstack.nova.model.Host; import com.woorea.openstack.nova.model.Hosts; public class HostsExtension { - + private final OpenStackClient CLIENT; - + public HostsExtension(OpenStackClient client) { CLIENT = client; } - + public List list() { return new List(); } - + public Show show(String id) { return new Show(id); } @@ -48,13 +48,13 @@ public class HostsExtension { } public class Show extends OpenStackRequest<Host> { - + public Show(String id) { super(CLIENT, HttpMethod.GET, new StringBuffer("/os-hosts/").append(id).toString(), null, Host.class); } - + } - - -} + + +}
\ No newline at end of file diff --git a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/HypervisorsExtension.java b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/HypervisorsExtension.java index 9561601..8331f1f 100644 --- a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/HypervisorsExtension.java +++ b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/HypervisorsExtension.java @@ -16,6 +16,6 @@ package com.woorea.openstack.nova.api.extensions; -public class HypervisorsExtension { +public interface HypervisorsExtension { -} +}
\ No newline at end of file diff --git a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/KeyPairsExtension.java b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/KeyPairsExtension.java index a8a39b6..4ebbe21 100644 --- a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/KeyPairsExtension.java +++ b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/KeyPairsExtension.java @@ -25,13 +25,13 @@ import com.woorea.openstack.nova.model.KeyPair; import com.woorea.openstack.nova.model.KeyPairs; public class KeyPairsExtension { - + private final OpenStackClient CLIENT; - + public KeyPairsExtension(OpenStackClient client) { CLIENT = client; } - + public List list() { return new List(); } @@ -62,7 +62,7 @@ public class KeyPairsExtension { public class Delete extends OpenStackRequest<Void> { - private String name; + public Delete(String name) { super(CLIENT, HttpMethod.DELETE, new StringBuilder("/os-keypairs/").append(name).toString(), null, Void.class); @@ -77,5 +77,5 @@ public class KeyPairsExtension { } } - -} + +}
\ No newline at end of file diff --git a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/NetworksExtension.java b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/NetworksExtension.java index 7570254..d920a06 100644 --- a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/NetworksExtension.java +++ b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/NetworksExtension.java @@ -25,13 +25,13 @@ import com.woorea.openstack.nova.model.Network; import com.woorea.openstack.nova.model.Networks; public class NetworksExtension { - + private final OpenStackClient CLIENT; - + public NetworksExtension(OpenStackClient client) { CLIENT = client; } - + public List list() { return new List(); } @@ -93,6 +93,6 @@ public class NetworksExtension { } - -} + +}
\ No newline at end of file diff --git a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/SecurityGroupsExtension.java b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/SecurityGroupsExtension.java index bcfc96c..fb9bdc4 100644 --- a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/SecurityGroupsExtension.java +++ b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/SecurityGroupsExtension.java @@ -27,9 +27,9 @@ import com.woorea.openstack.nova.model.SecurityGroupRuleForCreate; import com.woorea.openstack.nova.model.SecurityGroups; public class SecurityGroupsExtension { - + private final OpenStackClient CLIENT; - + public SecurityGroupsExtension(OpenStackClient client) { CLIENT = client; } @@ -72,7 +72,7 @@ public class SecurityGroupsExtension { public class Delete extends OpenStackRequest<Void> { /** - * + * * @param id * @deprecated */ @@ -99,7 +99,7 @@ public class SecurityGroupsExtension { public class DeleteRule extends OpenStackRequest<Void> { /** - * + * * @param id * @deprecated */ @@ -107,7 +107,7 @@ public class SecurityGroupsExtension { public DeleteRule(Integer id) { super(CLIENT, HttpMethod.DELETE, new StringBuilder("/os-security-group-rules/").append(String.valueOf(id)).toString(), null, Void.class); } - + public DeleteRule(String id) { super(CLIENT, HttpMethod.DELETE, new StringBuilder("/os-security-group-rules/").append(String.valueOf(id)).toString(), null, Void.class); } @@ -118,7 +118,7 @@ public class SecurityGroupsExtension { } public Create createSecurityGroup(String name, - String description) { + String description) { return new Create(new SecurityGroupForCreate(name, description)); } @@ -129,20 +129,20 @@ public class SecurityGroupsExtension { public Show showSecurityGroup(Integer id) { return new Show(String.valueOf(id)); } - + public Show showSecurityGroup(String id) { return new Show(id); } public Delete deleteSecurityGroup(Integer id) { return new Delete(String.valueOf(id)); } - + public Delete deleteSecurityGroup(String id) { return new Delete(id); } /** - * + * * @param parentSecurityGroupId * @param ipProtocol * @param fromPort @@ -160,7 +160,7 @@ public class SecurityGroupsExtension { return new CreateRule(securityGroupRuleForCreate); } /** - * + * * @param parentSecurityGroupId * @param ipProtocol * @param fromPort @@ -178,7 +178,7 @@ public class SecurityGroupsExtension { sourceGroupId); return new CreateRule(securityGroupRuleForCreate); } - + public CreateRule createSecurityGroupRule( String parentSecurityGroupId, String ipProtocol, Integer fromPort, Integer toPort, String cidr) { @@ -192,7 +192,7 @@ public class SecurityGroupsExtension { Integer toPort) { SecurityGroupRuleForCreate securityGroupRuleForCreate = new SecurityGroupRuleForCreate( parentSecurityGroupId, sourceGroupId,ipProtocol, fromPort, toPort - ); + ); return new CreateRule(securityGroupRuleForCreate); } public DeleteRule deleteSecurityGroupRule(String id) { @@ -202,4 +202,4 @@ public class SecurityGroupsExtension { return new DeleteRule(String.valueOf(id)); } -} +}
\ No newline at end of file diff --git a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/SnapshotsExtension.java b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/SnapshotsExtension.java index 1afba7e..252e55b 100644 --- a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/SnapshotsExtension.java +++ b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/SnapshotsExtension.java @@ -27,76 +27,75 @@ import com.woorea.openstack.nova.model.SnapshotForCreate; import com.woorea.openstack.nova.model.Snapshots; public class SnapshotsExtension { - + private final OpenStackClient CLIENT; - + public SnapshotsExtension(OpenStackClient client) { CLIENT = client; } - + public List list(boolean detail) { return new List(detail); } - + public Create create(SnapshotForCreate snapshotForCreate) { return new Create(snapshotForCreate); } - + public Show show(String id) { return new Show(id); } - + public ShowMetadata showMetadata(String id) { return new ShowMetadata(id); } - + public Delete delete(String id) { return new Delete(id); } public class List extends OpenStackRequest<Snapshots> { - + public List(boolean detail) { super(CLIENT, HttpMethod.GET, detail ? "/os-snapshots/detail" : "/os-snapshots", null, Snapshots.class); } } - + public class Create extends OpenStackRequest<SnapshotForCreate> { private SnapshotForCreate snapshotForCreate; - + public Create(SnapshotForCreate snapshotForCreate) { super(CLIENT, HttpMethod.POST, "/os-snapshots", Entity.json(snapshotForCreate), SnapshotForCreate.class); this.snapshotForCreate = snapshotForCreate; } - + } - + public class Show extends OpenStackRequest<Snapshot> { - + public Show(String id) { super(CLIENT, HttpMethod.GET, new StringBuilder("/os-snapshots/").append(id).toString(), null, Snapshot.class); } } - + public class ShowMetadata extends OpenStackRequest<Metadata> { - + public ShowMetadata(String id) { super(CLIENT, HttpMethod.GET, new StringBuilder("/os-snapshots/").append(id).append("/metadata").toString(), null, Metadata.class); } } - + public class Delete extends OpenStackRequest<Void> { - + public Delete(String id) { super(CLIENT, HttpMethod.DELETE, new StringBuilder("/os-snapshots/").append(id).toString(), null, Void.class); } - + } - -} +} diff --git a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/VolumesExtension.java b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/VolumesExtension.java index b46983f..f154b5f 100644 --- a/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/VolumesExtension.java +++ b/nova-client/src/main/java/com/woorea/openstack/nova/api/extensions/VolumesExtension.java @@ -69,12 +69,12 @@ public class VolumesExtension { public class Create extends OpenStackRequest<Volume> { - // private Volume volume; + public Create(VolumeForCreate volume) { super(CLIENT, HttpMethod.POST, "/os-volumes", Entity.json(volume), Volume.class); - // this.volume = volume; + } } @@ -85,7 +85,7 @@ public class VolumesExtension { public UploadToImage(VolumeForImageCreate volumeForImageCreate) { super(CLIENT, HttpMethod.POST, new StringBuilder("/volumes/") - .append(volumeForImageCreate.getVolumeId() + "/action"), + .append(volumeForImageCreate.getVolumeId() + "/action"), Entity.json(volumeForImageCreate), Void.class); } @@ -104,7 +104,7 @@ public class VolumesExtension { public ShowMetadata(String id) { super(CLIENT, HttpMethod.GET, new StringBuilder("/os-volumes/") - .append(id).append("/metadata").toString(), null, + .append(id).append("/metadata").toString(), null, Metadata.class); } @@ -119,4 +119,4 @@ public class VolumesExtension { } -} +}
\ No newline at end of file diff --git a/openstack-client-connectors/http-connector/src/main/java/com/woorea/openstack/connector/HttpClientConnector.java b/openstack-client-connectors/http-connector/src/main/java/com/woorea/openstack/connector/HttpClientConnector.java index 9b2f2e2..c266f20 100644 --- a/openstack-client-connectors/http-connector/src/main/java/com/woorea/openstack/connector/HttpClientConnector.java +++ b/openstack-client-connectors/http-connector/src/main/java/com/woorea/openstack/connector/HttpClientConnector.java @@ -102,11 +102,7 @@ public class HttpClientConnector implements OpenStackClientConnector { try { URIBuilder uriBuilder = new URIBuilder(request.endpoint() + request.path()); - for(Map.Entry<String, List<Object> > entry : request.queryParams().entrySet()) { - for (Object o : entry.getValue()) { - uriBuilder.setParameter(entry.getKey(), String.valueOf(o)); - } - } + setUriBuilderParams(request, uriBuilder); uri = uriBuilder.build(); } catch (URISyntaxException e) { @@ -136,30 +132,7 @@ public class HttpClientConnector implements OpenStackClientConnector { // Determine the HttpRequest class based on the method HttpUriRequest httpRequest; - switch (request.method()) { - case POST: - HttpPost post = new HttpPost(uri); - post.setEntity (entity); - httpRequest = post; - break; - - case GET: - httpRequest = new HttpGet(uri); - break; - - case PUT: - HttpPut put = new HttpPut(uri); - put.setEntity (entity); - httpRequest = put; - break; - - case DELETE: - httpRequest = new HttpDelete(uri); - break; - - default: - throw new HttpClientException ("Unrecognized HTTP Method: " + request.method()); - } + httpRequest = getHttpUriRequest(request, uri, entity); for (Entry<String, List<Object>> h : request.headers().entrySet()) { StringBuilder sb = new StringBuilder(); @@ -226,4 +199,41 @@ public class HttpClientConnector implements OpenStackClientConnector { httpClientResponse); } + private <T> HttpUriRequest getHttpUriRequest(OpenStackRequest<T> request, URI uri, HttpEntity entity) { + HttpUriRequest httpRequest; + switch (request.method()) { + case POST: + HttpPost post = new HttpPost(uri); + post.setEntity (entity); + httpRequest = post; + break; + + case GET: + httpRequest = new HttpGet(uri); + break; + + case PUT: + HttpPut put = new HttpPut(uri); + put.setEntity (entity); + httpRequest = put; + break; + + case DELETE: + httpRequest = new HttpDelete(uri); + break; + + default: + throw new HttpClientException("Unrecognized HTTP Method: " + request.method()); + } + return httpRequest; + } + + private <T> void setUriBuilderParams(OpenStackRequest<T> request, URIBuilder uriBuilder) { + for(Entry<String, List<Object>> entry : request.queryParams().entrySet()) { + for (Object o : entry.getValue()) { + uriBuilder.setParameter(entry.getKey(), String.valueOf(o)); + } + } + } + }
\ No newline at end of file diff --git a/openstack-client-connectors/http-connector/src/main/java/com/woorea/openstack/connector/HttpClientResponse.java b/openstack-client-connectors/http-connector/src/main/java/com/woorea/openstack/connector/HttpClientResponse.java index 468e859..99421b8 100644 --- a/openstack-client-connectors/http-connector/src/main/java/com/woorea/openstack/connector/HttpClientResponse.java +++ b/openstack-client-connectors/http-connector/src/main/java/com/woorea/openstack/connector/HttpClientResponse.java @@ -92,7 +92,7 @@ public class HttpClientResponse implements OpenStackResponse { @Override public Map<String, String> headers() { - Map<String, String> headers = new HashMap<String, String>(); + Map<String, String> headers = new HashMap<>(); Header responseHeaders[] = response.getAllHeaders(); for (Header h : responseHeaders) { diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/Entity.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/Entity.java index 25bb014..c68a308 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/Entity.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/Entity.java @@ -19,17 +19,17 @@ package com.woorea.openstack.base.client; public class Entity<T> { - + private T entity; - + private String contentType; - + public static <T> Entity<T> json(T entity) { - return new Entity<T>(entity, "application/json"); + return new Entity<>(entity, "application/json"); } - + public static <T> Entity<T> stream(T entity) { - return new Entity<T>(entity, "application/octet-stream"); + return new Entity<>(entity, "application/octet-stream"); } public Entity(T entity, String contentType) { @@ -65,5 +65,5 @@ public class Entity<T> { public void setContentType(String contentType) { this.contentType = contentType; } - + } diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseException.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseException.java index 1fcd7a5..e8b1e87 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseException.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseException.java @@ -29,7 +29,7 @@ public class OpenStackResponseException extends OpenStackBaseException { protected final int status; // Make the response available for exception handling (includes body) - protected final OpenStackResponse response; + protected final transient OpenStackResponse response; public OpenStackResponseException(String message, int status) { this.message = message; |