summaryrefslogtreecommitdiffstats
path: root/openstack-client/src
diff options
context:
space:
mode:
authorSmokowski, Steve (ss835w) <ss835w@us.att.com>2019-05-02 09:42:55 -0400
committerSmokowski, Steve (ss835w) <ss835w@us.att.com>2019-05-07 10:02:17 -0400
commit3f9a0c3183480d150089c0d5a6e507c877f7d121 (patch)
treeb3db04cbe2cef23f81503177a50edc5360ffa486 /openstack-client/src
parente153f0adfbed711ce1e215748594a4d04fd1edaf (diff)
Enhance Openstack Client
Update Openstack Client to support additional fields Updat all formatting issues Issue-ID: SO-1844 Change-Id: I1369e0c18cc25274db8df7e12855a020b8da38da Signed-off-by: Smokowski, Steve (ss835w) <ss835w@us.att.com>
Diffstat (limited to 'openstack-client/src')
-rw-r--r--openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackBaseException.java79
-rw-r--r--openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClient.java15
-rw-r--r--openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackConnectException.java7
-rw-r--r--openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackRequest.java254
-rw-r--r--openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponse.java4
-rw-r--r--openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseException.java2
-rw-r--r--openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponseStatus.java4
-rw-r--r--openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackSimpleTokenProvider.java3
-rw-r--r--openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSession.java2
-rw-r--r--openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSessionHolder.java2
-rw-r--r--openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientMockUtils.java6
-rw-r--r--openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientTest.java8
12 files changed, 191 insertions, 195 deletions
diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackBaseException.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackBaseException.java
index 53d2595..bcb7d51 100644
--- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackBaseException.java
+++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackBaseException.java
@@ -1,40 +1,39 @@
-/*-
- * ============LICENSE_START=======================================================
- * 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=========================================================
- */
-
-
-package com.woorea.openstack.base.client;
-
-/**
- * A common abstract parent of all Openstack Exception types, allowing
- * calling classes the choice to catch all error exceptions together.
- */
-public abstract class OpenStackBaseException extends RuntimeException
-{
- private static final long serialVersionUID = 1L;
-
- /*
- * Implement only the basic constructors
- */
- public OpenStackBaseException () {}
-
- public OpenStackBaseException(String message) {
- super(message);
- }
-
- public OpenStackBaseException(String message, Throwable cause) {
- super(message, cause);
- }
-} \ No newline at end of file
+/*-
+ * ============LICENSE_START=======================================================
+ * 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=========================================================
+ */
+
+
+package com.woorea.openstack.base.client;
+
+/**
+ * A common abstract parent of all Openstack Exception types, allowing calling classes the choice to catch all error
+ * exceptions together.
+ */
+public abstract class OpenStackBaseException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ /*
+ * Implement only the basic constructors
+ */
+ public OpenStackBaseException() {}
+
+ public OpenStackBaseException(String message) {
+ super(message);
+ }
+
+ public OpenStackBaseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
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 a111975..8c61b30 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
@@ -70,23 +70,24 @@ public class OpenStackClient {
try {
return connector.request(request);
} catch (OpenStackResponseException e) {
- if (e.getStatus() != OpenStackResponseStatus.NOT_AUTHORIZED
- || tokenProvider == null) {
+ if (e.getStatus() != OpenStackResponseStatus.NOT_AUTHORIZED || tokenProvider == null) {
throw e;
}
authException = e;
tokenProvider.expireToken();
}
}
- if(null == authException){
- authException = new OpenStackResponseException("Unknown issue",500);
+ if (null == authException) {
+ authException = new OpenStackResponseException("Unknown issue", 500);
}
throw authException;
}
public <T> T execute(OpenStackRequest<T> request) {
- OpenStackResponse response = request(request);
- return (request.returnType() != null && request.returnType() != Void.class) ? response.getEntity(request.returnType()) : null;
+ OpenStackResponse response = request(request);
+ return (request.returnType() != null && request.returnType() != Void.class)
+ ? response.getEntity(request.returnType())
+ : null;
}
public void property(String property, String value) {
@@ -105,4 +106,4 @@ public class OpenStackClient {
return new OpenStackRequest<>(this, HttpMethod.GET, path, null, returnType);
}
-} \ No newline at end of file
+}
diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackConnectException.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackConnectException.java
index 0e29335..30d6722 100644
--- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackConnectException.java
+++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackConnectException.java
@@ -18,9 +18,8 @@
package com.woorea.openstack.base.client;
/**
- * Custom RuntimeException to report connection errors to Openstack endpoints.
- * Must be a RuntimeException to conform with OpenstackClient interface, which
- * does not declare specific Exceptions.
+ * Custom RuntimeException to report connection errors to Openstack endpoints. Must be a RuntimeException to conform
+ * with OpenstackClient interface, which does not declare specific Exceptions.
*/
public class OpenStackConnectException extends OpenStackBaseException {
@@ -33,4 +32,4 @@ public class OpenStackConnectException extends OpenStackBaseException {
public OpenStackConnectException(String message, Throwable cause) {
super(message, cause);
}
-} \ No newline at end of file
+}
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 07b6f70..d896837 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
@@ -25,137 +25,137 @@ import java.util.Map;
public class OpenStackRequest<R> {
- private OpenStackClient client;
+ private OpenStackClient client;
- private String endpoint;
-
- private HttpMethod method;
+ private String endpoint;
+
+ private HttpMethod method;
- private StringBuilder path = new StringBuilder();
+ private StringBuilder path = new StringBuilder();
- private Map<String, List<Object>> headers = new HashMap<>();
+ private Map<String, List<Object>> headers = new HashMap<>();
- private Entity<?> entity;
+ private Entity<?> entity;
- private Class<R> returnType;
+ private Class<R> returnType;
- public OpenStackRequest() {
-
- }
-
- public OpenStackRequest(OpenStackClient client, HttpMethod method, CharSequence path, Entity<?> entity,
- Class<R> returnType) {
- this.client = client;
- this.method = method;
- this.path = new StringBuilder(path);
- this.entity = entity;
- this.returnType = returnType;
- header("Accept", "application/json");
- }
-
- public OpenStackRequest<R> endpoint(String endpoint) {
- this.endpoint = endpoint;
- return this;
- }
-
- public String endpoint() {
- return endpoint;
- }
-
- public OpenStackRequest<R> method(HttpMethod method) {
- this.method = method;
- return this;
- }
-
- public HttpMethod method() {
- return method;
- }
-
- public OpenStackRequest<R> path(String path) {
- this.path.append(path);
- return this;
- }
-
- public String path() {
- return path.toString();
- }
-
- public OpenStackRequest<R> header(String name, Object value) {
- if (value != null) {
- headers.put(name, Arrays.asList(value));
- }
- return this;
- }
-
- public Map<String, List<Object>> headers() {
- return headers;
- }
-
- public <T> Entity<T> entity(T entity, String contentType) {
- return new Entity<>(entity, contentType);
- }
-
- public Entity<?> entity() {
- return entity;
- }
-
- public <T> Entity<T> json(T entity) {
- return entity(entity, "application/json");
- }
-
- public void returnType(Class<R> returnType) {
- this.returnType = returnType;
- }
-
- public Class<R> returnType() {
- return returnType;
- }
-
- public R execute() {
- return client.execute(this);
- }
-
- public OpenStackResponse request() {
- return client.request(this);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "OpenStackRequest [endpoint=" + endpoint + ", method=" + method + ", path=" + path + ", headers="
- + headers + ", entity=" + entity + ", returnType=" + returnType + "]";
- }
-
- private Map<String, List<Object>> queryParams = new LinkedHashMap<>();
-
- public Map<String, List<Object>> queryParams() {
- return queryParams;
- }
-
- public OpenStackRequest<R> queryParam(String key, Object value) {
- if (value != null) {
- if (queryParams.containsKey(key)) {
- List<Object> values = queryParams.get(key);
- values.add(value);
- } else {
- List<Object> values = new ArrayList<>();
- values.add(value);
- queryParams.put(key, values);
- }
- }
- return this;
- }
-
- protected static String buildPath(String... elements) {
- StringBuilder stringBuilder = new StringBuilder();
- for (String element : elements) {
- stringBuilder.append(element);
- }
-
- return stringBuilder.toString();
- }
+ public OpenStackRequest() {
+
+ }
+
+ public OpenStackRequest(OpenStackClient client, HttpMethod method, CharSequence path, Entity<?> entity,
+ Class<R> returnType) {
+ this.client = client;
+ this.method = method;
+ this.path = new StringBuilder(path);
+ this.entity = entity;
+ this.returnType = returnType;
+ header("Accept", "application/json");
+ }
+
+ public OpenStackRequest<R> endpoint(String endpoint) {
+ this.endpoint = endpoint;
+ return this;
+ }
+
+ public String endpoint() {
+ return endpoint;
+ }
+
+ public OpenStackRequest<R> method(HttpMethod method) {
+ this.method = method;
+ return this;
+ }
+
+ public HttpMethod method() {
+ return method;
+ }
+
+ public OpenStackRequest<R> path(String path) {
+ this.path.append(path);
+ return this;
+ }
+
+ public String path() {
+ return path.toString();
+ }
+
+ public OpenStackRequest<R> header(String name, Object value) {
+ if (value != null) {
+ headers.put(name, Arrays.asList(value));
+ }
+ return this;
+ }
+
+ public Map<String, List<Object>> headers() {
+ return headers;
+ }
+
+ public <T> Entity<T> entity(T entity, String contentType) {
+ return new Entity<>(entity, contentType);
+ }
+
+ public Entity<?> entity() {
+ return entity;
+ }
+
+ public <T> Entity<T> json(T entity) {
+ return entity(entity, "application/json");
+ }
+
+ public void returnType(Class<R> returnType) {
+ this.returnType = returnType;
+ }
+
+ public Class<R> returnType() {
+ return returnType;
+ }
+
+ public R execute() {
+ return client.execute(this);
+ }
+
+ public OpenStackResponse request() {
+ return client.request(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "OpenStackRequest [endpoint=" + endpoint + ", method=" + method + ", path=" + path + ", headers="
+ + headers + ", entity=" + entity + ", returnType=" + returnType + "]";
+ }
+
+ private Map<String, List<Object>> queryParams = new LinkedHashMap<>();
+
+ public Map<String, List<Object>> queryParams() {
+ return queryParams;
+ }
+
+ public OpenStackRequest<R> queryParam(String key, Object value) {
+ if (value != null) {
+ if (queryParams.containsKey(key)) {
+ List<Object> values = queryParams.get(key);
+ values.add(value);
+ } else {
+ List<Object> values = new ArrayList<>();
+ values.add(value);
+ queryParams.put(key, values);
+ }
+ }
+ return this;
+ }
+
+ protected static String buildPath(String... elements) {
+ StringBuilder stringBuilder = new StringBuilder();
+ for (String element : elements) {
+ stringBuilder.append(element);
+ }
+
+ return stringBuilder.toString();
+ }
}
diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponse.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponse.java
index 0add524..dfc1d13 100644
--- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponse.java
+++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackResponse.java
@@ -32,7 +32,7 @@ public interface OpenStackResponse {
public InputStream getInputStream();
public String header(String name);
-
+
public Map<String, String> headers();
-
+
}
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 e8b1e87..1d7f29b 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
@@ -56,4 +56,4 @@ public class OpenStackResponseException extends OpenStackBaseException {
return response;
}
-} \ No newline at end of file
+}
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 73204e9..aa552ad 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,7 +18,7 @@ package com.woorea.openstack.base.client;
public class OpenStackResponseStatus {
- private OpenStackResponseStatus(){
+ private OpenStackResponseStatus() {
}
@@ -28,4 +28,4 @@ public class OpenStackResponseStatus {
public static final int CONFLICT = 409;
-} \ No newline at end of file
+}
diff --git a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackSimpleTokenProvider.java b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackSimpleTokenProvider.java
index a7dd2e5..74b92a1 100644
--- a/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackSimpleTokenProvider.java
+++ b/openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackSimpleTokenProvider.java
@@ -30,7 +30,6 @@ public class OpenStackSimpleTokenProvider implements OpenStackTokenProvider {
}
@Override
- public void expireToken() {
- }
+ public void expireToken() {}
}
diff --git a/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSession.java b/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSession.java
index 618adb5..edef0a9 100644
--- a/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSession.java
+++ b/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSession.java
@@ -14,4 +14,4 @@
* ============LICENSE_END=========================================================
*/
-package com.woorea.openstack.common.session; \ No newline at end of file
+package com.woorea.openstack.common.session;
diff --git a/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSessionHolder.java b/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSessionHolder.java
index 618adb5..edef0a9 100644
--- a/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSessionHolder.java
+++ b/openstack-client/src/main/java/com/woorea/openstack/common/session/OpenStackSessionHolder.java
@@ -14,4 +14,4 @@
* ============LICENSE_END=========================================================
*/
-package com.woorea.openstack.common.session; \ No newline at end of file
+package com.woorea.openstack.common.session;
diff --git a/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientMockUtils.java b/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientMockUtils.java
index 8ff2634..29580ba 100644
--- a/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientMockUtils.java
+++ b/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientMockUtils.java
@@ -63,9 +63,9 @@ public class OpenStackClientMockUtils {
return this;
}
- public <T extends OpenStackRequest> OpenStackClientMockUtils mockRequestThrow(T request, String message, int status) {
- Mockito.when(connector.request(Mockito.eq(request)))
- .thenThrow(new OpenStackResponseException(message, status));
+ public <T extends OpenStackRequest> OpenStackClientMockUtils mockRequestThrow(T request, String message,
+ int status) {
+ Mockito.when(connector.request(Mockito.eq(request))).thenThrow(new OpenStackResponseException(message, status));
return this;
}
diff --git a/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientTest.java b/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientTest.java
index 9a83903..e4a4098 100644
--- a/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientTest.java
+++ b/openstack-client/src/test/java/com/woorea/openstack/base/client/OpenStackClientTest.java
@@ -43,11 +43,9 @@ public class OpenStackClientTest {
}
private OpenStackClientConnector mockClientConnector() {
- return OpenStackClientMockUtils.getInstance()
- .mockRequestResponse(Entity.class, Entity.json(SUCCESS))
+ return OpenStackClientMockUtils.getInstance().mockRequestResponse(Entity.class, Entity.json(SUCCESS))
.mockRequestThrow(notAuthorizedRequest, "Not Authorized", OpenStackResponseStatus.NOT_AUTHORIZED)
- .mockRequestThrow(conflictRequest, "Conflict", OpenStackResponseStatus.CONFLICT)
- .getConnector();
+ .mockRequestThrow(conflictRequest, "Conflict", OpenStackResponseStatus.CONFLICT).getConnector();
}
@@ -69,4 +67,4 @@ public class OpenStackClientTest {
public void executeConflict() {
client.execute(conflictRequest);
}
-} \ No newline at end of file
+}