diff options
18 files changed, 128 insertions, 139 deletions
diff --git a/ceilometer-client/src/main/java/com/woorea/openstack/ceilometer/Ceilometer.java b/ceilometer-client/src/main/java/com/woorea/openstack/ceilometer/Ceilometer.java index aa089df..6c18858 100644 --- a/ceilometer-client/src/main/java/com/woorea/openstack/ceilometer/Ceilometer.java +++ b/ceilometer-client/src/main/java/com/woorea/openstack/ceilometer/Ceilometer.java @@ -24,14 +24,14 @@ import com.woorea.openstack.ceilometer.v2.api.ResourcesResource; public class Ceilometer extends OpenStackClient { - private final MetersResource METERS; + private final MetersResource meters; - private final ResourcesResource RESOURCES; + private final ResourcesResource resources; public Ceilometer(String endpoint, OpenStackClientConnector connector) { super(endpoint, connector); - METERS = new MetersResource(this); - RESOURCES = new ResourcesResource(this); + meters = new MetersResource(this); + resources = new ResourcesResource(this); } public Ceilometer(String endpoint) { @@ -40,11 +40,11 @@ public class Ceilometer extends OpenStackClient { } public ResourcesResource resources() { - return RESOURCES; + return resources; } public MetersResource meters() { - return METERS; + return meters; } } diff --git a/ceilometer-client/src/main/java/com/woorea/openstack/ceilometer/v2/api/MetersResource.java b/ceilometer-client/src/main/java/com/woorea/openstack/ceilometer/v2/api/MetersResource.java index df17c82..ae8f085 100644 --- a/ceilometer-client/src/main/java/com/woorea/openstack/ceilometer/v2/api/MetersResource.java +++ b/ceilometer-client/src/main/java/com/woorea/openstack/ceilometer/v2/api/MetersResource.java @@ -18,16 +18,15 @@ package com.woorea.openstack.ceilometer.v2.api; import com.woorea.openstack.base.client.OpenStackClient; -import com.woorea.openstack.base.client.OpenStackRequest; import com.woorea.openstack.ceilometer.QueriableCeilometerCommand; import com.woorea.openstack.ceilometer.v2.model.Sample; public class MetersResource { - private final OpenStackClient CLIENT; + private final OpenStackClient client; public MetersResource(OpenStackClient client) { - CLIENT = client; + this.client = client; } public List list() { @@ -52,30 +51,30 @@ public class MetersResource { private String name; + public Show() { + + } + public Show name(String name) { this.name = name; return this; } - public Show() { - - } - } public class Statistics extends QueriableCeilometerCommand<Statistics, java.util.List<Statistics>> { private String name; + public Statistics() { + + } + public Statistics name(String name) { this.name = name; return this; } - public Statistics() { - - } - } }
\ No newline at end of file diff --git a/ceilometer-client/src/main/java/com/woorea/openstack/ceilometer/v2/api/ResourcesResource.java b/ceilometer-client/src/main/java/com/woorea/openstack/ceilometer/v2/api/ResourcesResource.java index 9d392f7..3fac7b8 100644 --- a/ceilometer-client/src/main/java/com/woorea/openstack/ceilometer/v2/api/ResourcesResource.java +++ b/ceilometer-client/src/main/java/com/woorea/openstack/ceilometer/v2/api/ResourcesResource.java @@ -25,10 +25,10 @@ import com.woorea.openstack.ceilometer.v2.model.Resource; public class ResourcesResource { - private final OpenStackClient CLIENT; + private final OpenStackClient client; public ResourcesResource(OpenStackClient client) { - CLIENT = client; + this.client = client; } public class ResourceList extends QueriableCeilometerCommand<ResourceList, List<Resource>> { @@ -44,15 +44,15 @@ public class ResourcesResource { private String id; + public ResourceShow(OpenStackClient client) { + + } + public ResourceShow id(String id) { this.id = id; return this; } - public ResourceShow(OpenStackClient client) { - - } - } }
\ 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..d43e6c9 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 @@ -29,7 +29,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.UnknownHostException; import java.util.List; -import java.util.Map; import java.util.Map.Entry; import org.apache.http.HttpEntity; @@ -66,7 +65,7 @@ public class HttpClientConnector implements OpenStackClientConnector { public static final ObjectMapper DEFAULT_MAPPER; public static final ObjectMapper WRAPPED_MAPPER; - private static Logger LOGGER = LoggerFactory.getLogger(HttpClientConnector.class); + private static Logger logger = LoggerFactory.getLogger(HttpClientConnector.class); static { DEFAULT_MAPPER = new ObjectMapper(); @@ -102,11 +101,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) { @@ -124,7 +119,7 @@ public class HttpClientConnector implements OpenStackClientConnector { String entityJson = mapper.writeValueAsString (request.entity().getEntity()); entity = new StringEntity(entityJson, ContentType.create(request.entity().getContentType())); - LOGGER.debug ("Request JSON Body: " + entityJson.replaceAll("\"password\":\"[^\"]*\"", "\"password\":\"***\"")); + logger.debug ("Request JSON Body: " + entityJson.replaceAll("\"password\":\"[^\"]*\"", "\"password\":\"***\"")); } catch (JsonProcessingException e) { throw new HttpClientException ("Json processing error on request entity", e); @@ -136,30 +131,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(); @@ -169,7 +141,7 @@ public class HttpClientConnector implements OpenStackClientConnector { httpRequest.addHeader(h.getKey(), sb.toString()); } - LOGGER.debug ("Sending HTTP request: " + httpRequest.toString()); + logger.debug ("Sending HTTP request: " + httpRequest.toString()); // Get the Response. But don't get the body entity yet, as this response // will be wrapped in an HttpClientResponse. The HttpClientResponse @@ -182,7 +154,7 @@ public class HttpClientConnector implements OpenStackClientConnector { try { httpResponse = httpClient.execute(httpRequest); - LOGGER.debug ("Response status: " + httpResponse.getStatusLine().getStatusCode()); + logger.debug ("Response status: " + httpResponse.getStatusLine().getStatusCode()); httpClientResponse = new HttpClientResponse (httpResponse); @@ -207,7 +179,7 @@ public class HttpClientConnector implements OpenStackClientConnector { } catch (Exception e) { // Catchall for anything else, must throw as a RuntimeException - LOGGER.error ("Unexpected client exception: " +e.getMessage()); + logger.error ("Unexpected client exception: " +e.getMessage()); throw new RuntimeException("Unexpected client exception", e); } finally { @@ -216,7 +188,7 @@ public class HttpClientConnector implements OpenStackClientConnector { try { httpResponse.close(); } catch (IOException e) { - LOGGER.warn("Unable to close HTTP Response: " + e); + logger.warn("Unable to close HTTP Response: " + e); } } @@ -226,4 +198,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..f1c8c78 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 @@ -34,7 +34,7 @@ import java.util.Map; public class HttpClientResponse implements OpenStackResponse { - private static Logger LOGGER = LoggerFactory.getLogger(HttpClientConnector.class); + private static Logger logger = LoggerFactory.getLogger(HttpClientConnector.class); private HttpResponse response = null; private String entityBody = null; @@ -46,7 +46,7 @@ public class HttpClientResponse implements OpenStackResponse { // Read the body so InputStream can be closed if (response.getEntity() == null) { // No body - LOGGER.debug ("No Response Body"); + logger.debug ("No Response Body"); return; } @@ -57,7 +57,7 @@ public class HttpClientResponse implements OpenStackResponse { throw new HttpClientException ("Error Reading Response Body", e); } entityBody = responseBody.toString(); - LOGGER.debug (entityBody); + logger.debug (entityBody); } @@ -92,9 +92,9 @@ 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(); + Header[] responseHeaders = response.getAllHeaders(); for (Header h : responseHeaders) { headers.put(h.getName(), h.getValue()); } 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..1e2dfcc 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,18 +19,10 @@ 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"); - } - - public static <T> Entity<T> stream(T entity) { - return new Entity<T>(entity, "application/octet-stream"); - } public Entity(T entity, String contentType) { super(); @@ -38,6 +30,14 @@ public class Entity<T> { this.contentType = contentType; } + public static <T> Entity<T> json(T entity) { + return new Entity<>(entity, "application/json"); + } + + public static <T> Entity<T> stream(T entity) { + return new Entity<>(entity, "application/octet-stream"); + } + /** * @return the entity */ @@ -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/OpenStackClient.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClient.java index 23ee8dc..a111975 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClient.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClient.java @@ -29,38 +29,38 @@ public class OpenStackClient { protected OpenStackTokenProvider tokenProvider; - protected static int AUTHENTICATION_RETRIES = 1; + protected static int authenticationRetries = 1; protected OpenStackClientConnector connector; protected Properties properties = new Properties(); - protected static OpenStackClientConnector DEFAULT_CONNECTOR; + protected static OpenStackClientConnector defaultConnector; static { ServiceLoader<OpenStackClientConnector> connectorLoader; connectorLoader = ServiceLoader.load(OpenStackClientConnector.class); for (OpenStackClientConnector clientConnector : connectorLoader) { - DEFAULT_CONNECTOR = clientConnector; + defaultConnector = clientConnector; break; } } public OpenStackClient(String endpoint) { this.endpoint = endpoint; - this.connector = DEFAULT_CONNECTOR; + this.connector = defaultConnector; } public OpenStackClient(String endpoint, OpenStackClientConnector connector) { this.endpoint = endpoint; - this.connector = (connector == null) ? DEFAULT_CONNECTOR : connector; + this.connector = (connector == null) ? defaultConnector : connector; } public <T> OpenStackResponse request(OpenStackRequest<T> request) { OpenStackResponseException authException = null; - for (int i = 0; i <= AUTHENTICATION_RETRIES; i++) { + for (int i = 0; i <= authenticationRetries; i++) { request.endpoint(endpoint); if (tokenProvider != null) { diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackRequest.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackRequest.java index 3a082a2..3374a10 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackRequest.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackRequest.java @@ -26,6 +26,18 @@ import java.util.Map; public class OpenStackRequest<R> { private OpenStackClient client; + + private String endpoint; + + private HttpMethod method; + + private StringBuilder path = new StringBuilder(); + + private Map<String, List<Object>> headers = new HashMap<>(); + + private Entity<?> entity; + + private Class<R> returnType; public OpenStackRequest() { @@ -39,18 +51,7 @@ public class OpenStackRequest<R> { this.returnType = returnType; header("Accept", "application/json"); } - - private String endpoint; - - private HttpMethod method; - - private StringBuilder path = new StringBuilder(); - - private Map<String, List<Object>> headers = new HashMap<>(); - - private Entity<?> entity; - - private Class<R> returnType; + public OpenStackRequest<R> endpoint(String endpoint) { this.endpoint = endpoint; 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; diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseStatus.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseStatus.java index b69e0e1..73204e9 100644 --- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseStatus.java +++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseStatus.java @@ -18,10 +18,14 @@ package com.woorea.openstack.base.client; public class OpenStackResponseStatus { + private OpenStackResponseStatus(){ + + } + public static final int OK = 200; public static final int NOT_AUTHORIZED = 401; public static final int CONFLICT = 409; -} +}
\ No newline at end of file diff --git a/quantum-model/src/main/java/com/woorea/openstack/quantum/model/GatewayInfo.java b/quantum-model/src/main/java/com/woorea/openstack/quantum/model/GatewayInfo.java index 9ef68ff..88fb6a4 100644 --- a/quantum-model/src/main/java/com/woorea/openstack/quantum/model/GatewayInfo.java +++ b/quantum-model/src/main/java/com/woorea/openstack/quantum/model/GatewayInfo.java @@ -16,8 +16,6 @@ package com.woorea.openstack.quantum.model; -import java.util.List; - import com.fasterxml.jackson.annotation.JsonProperty; import java.io.Serializable; diff --git a/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Port.java b/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Port.java index 5efe995..1951a60 100644 --- a/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Port.java +++ b/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Port.java @@ -190,7 +190,7 @@ public class Port implements Serializable { private List<String> securityGroups; @JsonUnwrapped - private Binding binding; + private Binding binding; /** * @return the adminStateUp @@ -386,4 +386,4 @@ public class Port implements Serializable { + ", securityGroups=" + securityGroups + ", binding=" + binding + "]"; } -} +}
\ No newline at end of file diff --git a/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Router.java b/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Router.java index 722bb0d..d180a12 100644 --- a/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Router.java +++ b/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Router.java @@ -36,7 +36,7 @@ public class Router implements Serializable { private String name; @JsonProperty("admin_state_up") - private String admin_state_up; + private String adminStateUp; @JsonProperty("tenant_id") private String tenantId; @@ -59,11 +59,11 @@ public class Router implements Serializable { public void setRoutes(List<HostRoute> routes) { this.routes = routes; } - public String getAdmin_state_up() { - return admin_state_up; + public String getAdminStateUp() { + return adminStateUp; } - public void setAdmin_state_up(String admin_state_up) { - this.admin_state_up = admin_state_up; + public void setAdminStateUp(String adminStateUp) { + this.adminStateUp = adminStateUp; } public String getStatus() { return status; diff --git a/quantum-model/src/main/java/com/woorea/openstack/quantum/model/RouterForCreate.java b/quantum-model/src/main/java/com/woorea/openstack/quantum/model/RouterForCreate.java index c524ef5..6f5ddae 100644 --- a/quantum-model/src/main/java/com/woorea/openstack/quantum/model/RouterForCreate.java +++ b/quantum-model/src/main/java/com/woorea/openstack/quantum/model/RouterForCreate.java @@ -32,7 +32,7 @@ public class RouterForCreate implements Serializable { private List<HostRoute> routes; @JsonProperty("admin_state_up") - private String admin_state_up; + private String adminStateUp; @JsonProperty("status") private String status; @@ -58,11 +58,12 @@ public class RouterForCreate implements Serializable { public void setRoutes(List<HostRoute> routes) { this.routes = routes; } - public String getAdmin_state_up() { - return admin_state_up; + public String getAdminStateUp() { + return adminStateUp; } - public void setAdmin_state_up(String admin_state_up) { - this.admin_state_up = admin_state_up; + + public void setAdminStateUp(String adminStateUp) { + this.adminStateUp = adminStateUp; } public String getStatus() { return status; diff --git a/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Segment.java b/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Segment.java index b5279cd..25e27c3 100644 --- a/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Segment.java +++ b/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Segment.java @@ -14,29 +14,6 @@ * ============LICENSE_END========================================================= */ -/* - * ============LICENSE_START========================================== - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * Licensed 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. - * ============LICENSE_END============================================ - * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. - * - */ - package com.woorea.openstack.quantum.model; import java.io.Serializable; @@ -92,4 +69,4 @@ public class Segment implements Serializable { ", provider:network_type=" + providerNetworkType + ", provider:segmentation_id=" + providerSegmentationId + "]"; } -} +}
\ No newline at end of file diff --git a/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Subnet.java b/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Subnet.java index 90ee325..a2319d4 100644 --- a/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Subnet.java +++ b/quantum-model/src/main/java/com/woorea/openstack/quantum/model/Subnet.java @@ -61,7 +61,7 @@ public class Subnet implements Serializable { private String id; - public static enum IpVersion implements Serializable { + public enum IpVersion implements Serializable { IPV4(4), IPV6(6); private int code; @@ -277,4 +277,4 @@ public class Subnet implements Serializable { + dnsNames + ", host_routes=" + hostRoutes + "]"; } -} +}
\ No newline at end of file diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterForCreateTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterForCreateTest.java index b84e639..31a0373 100644 --- a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterForCreateTest.java +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterForCreateTest.java @@ -84,9 +84,9 @@ public class RouterForCreateTest { Assert.assertEquals(2, routes.size()); routerforcreate.setRoutes(routes); - String admin_state_up = routerforcreate.getAdmin_state_up(); + String admin_state_up = routerforcreate.getAdminStateUp(); Assert.assertNotNull(admin_state_up); - routerforcreate.setAdmin_state_up(admin_state_up); + routerforcreate.setAdminStateUp(admin_state_up); String name = routerforcreate.getName(); Assert.assertNotNull(name); diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterTest.java index b75cac8..81573df 100644 --- a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterTest.java +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterTest.java @@ -84,9 +84,9 @@ public class RouterTest { Assert.assertEquals(2, routes.size()); router.setRoutes(routes); - String admin_state_up = router.getAdmin_state_up(); + String admin_state_up = router.getAdminStateUp(); Assert.assertNotNull(admin_state_up); - router.setAdmin_state_up(admin_state_up); + router.setAdminStateUp(admin_state_up); String name = router.getName(); Assert.assertNotNull(name); |