diff --git a/pom.xml b/pom.xml
index d5277f6..a4f8db4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,7 +36,7 @@
org.dasein
dasein-cloud-core
- 2016.02.1-SNAPSHOT
+ 0.9.0
compile
false
@@ -107,7 +107,36 @@
1.2.3
test
-
+
+ org.powermock
+ powermock-module-junit4
+ 1.5.5
+ test
+
+
+ org.powermock
+ powermock-api-mockito
+ 1.5.5
+ test
+
+
+ com.hazelcast
+ hazelcast
+ 3.4
+ test
+
+
+ com.hazelcast
+ hazelcast
+ 3.4
+ test
+
+
+ com.hazelcast
+ hazelcast
+ 3.4
+ test
+
@@ -246,9 +275,9 @@
${test.machineImage}
-
- **/TestSuite.java
-
+
+ **/TestSuite.java
+
diff --git a/src/main/java/org/dasein/cloud/openstack/nova/os/AbstractMethod.java b/src/main/java/org/dasein/cloud/openstack/nova/os/AbstractMethod.java
index 05d419c..1d8d5d8 100644
--- a/src/main/java/org/dasein/cloud/openstack/nova/os/AbstractMethod.java
+++ b/src/main/java/org/dasein/cloud/openstack/nova/os/AbstractMethod.java
@@ -63,11 +63,7 @@
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
-import org.dasein.cloud.CloudErrorType;
-import org.dasein.cloud.CloudException;
-import org.dasein.cloud.ContextRequirements;
-import org.dasein.cloud.InternalException;
-import org.dasein.cloud.ProviderContext;
+import org.dasein.cloud.*;
import org.dasein.cloud.openstack.nova.os.ext.hp.db.HPRDBMS;
import org.dasein.cloud.util.APITrace;
import org.dasein.cloud.util.Cache;
@@ -94,12 +90,12 @@ public abstract class AbstractMethod {
ProviderContext ctx = provider.getContext();
if( ctx == null ) {
- throw new CloudException("Unable to authenticate due to lack of context");
+ throw new InternalException("Unable to authenticate due to lack of context");
}
- String endpoint = ctx.getEndpoint();
+ String endpoint = ctx.getCloud().getEndpoint();
if( endpoint == null ) {
- throw new CloudException("No authentication endpoint");
+ throw new InternalException("No authentication endpoint");
}
AuthenticationContext auth;
@@ -170,8 +166,7 @@ else if( endpoint.startsWith("st:") ) {
}
catch( UnsupportedEncodingException e ) {
std.error("authenticateKeystone(): Unable to read access credentials: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
+ throw new InternalException("Unable to read access credentials", e);
}
if( std.isInfoEnabled() ) {
@@ -247,7 +242,7 @@ else if( provider.getCloudProvider().equals(OpenStackProvider.RACKSPACE) ) {
post.setEntity(new StringEntity(payload == null ? "" : payload, "application/json", "UTF-8"));
}
catch( UnsupportedEncodingException e ) {
- throw new InternalException(e);
+ throw new InternalException("Unable to encode", e);
}
/*try { wire.debug(EntityUtils.toString(post.getEntity())); }
catch( IOException ignore ) { }*/
@@ -269,8 +264,7 @@ else if( provider.getCloudProvider().equals(OpenStackProvider.RACKSPACE) ) {
}
catch( IOException e ) {
std.error("I/O error from server communications: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
+ throw new CommunicationException("I/O error from server communications: " + e.getMessage(), e);
}
int code = response.getStatusLine().getStatusCode();
@@ -297,8 +291,7 @@ else if( provider.getCloudProvider().equals(OpenStackProvider.RACKSPACE) ) {
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Unable to read the response", e);
}
NovaException.ExceptionItems items = NovaException.parseException(code, data);
@@ -328,8 +321,7 @@ else if( provider.getCloudProvider().equals(OpenStackProvider.RACKSPACE) ) {
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException(e.getMessage(), e);
}
if( data != null && !data.trim().equals("") ) {
if( std.isInfoEnabled() ) {
@@ -357,15 +349,14 @@ else if( provider.getCloudProvider().equals(OpenStackProvider.RACKSPACE) ) {
}
catch( JSONException e ) {
std.error("authenticateKeystone(): Invalid response from server: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException(e.getMessage(), e);
}
if( tenantId == null ) {
tenantId = account;
}
if( id != null ) {
- HashMap> services = new HashMap>();
- HashMap> bestVersion = new HashMap>();
+ Map> services = new HashMap>();
+ Map> bestVersion = new HashMap>();
String myRegionId = provider.getContext().getRegionId();
if( std.isDebugEnabled() ) {
@@ -470,8 +461,7 @@ else if( regionId == null && (type.equals("compute") || type.equals("object-stor
}
catch( JSONException e ) {
std.error("authenticateKeystone(): Failed to read JSON from server: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException(e.getMessage(), e);
}
}
if( std.isDebugEnabled() ) {
@@ -488,7 +478,7 @@ else if( regionId == null && (type.equals("compute") || type.equals("object-stor
}
}
}
- throw new CloudException("No authentication tokens were provided");
+ throw new InternalException("No authentication tokens were provided");
}
finally {
if (client != null) {
@@ -527,8 +517,7 @@ else if( regionId == null && (type.equals("compute") || type.equals("object-stor
}
catch( UnsupportedEncodingException e ) {
std.error("authenticateKeystone(): Unable to read access credentials: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
+ throw new InternalException("Unable to read access credentials", e);
}
String[] endpoints;
@@ -581,8 +570,7 @@ else if( regionId == null && (type.equals("compute") || type.equals("object-stor
}
catch( IOException e ) {
std.error("I/O error from server communications: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
+ throw new CommunicationException("I/O error from server communications: " + e.getMessage(), e);
}
int code = response.getStatusLine().getStatusCode();
@@ -607,8 +595,7 @@ else if( regionId == null && (type.equals("compute") || type.equals("object-stor
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
if( code == HttpStatus.SC_INTERNAL_SERVER_ERROR && data.contains("") ) {
return null;
@@ -696,7 +683,7 @@ else if( h.getName().equalsIgnoreCase("x-cdn-management-url") ) {
}
if( authToken == null ) {
std.warn("authenticateStandard(): No authentication token in response");
- throw new CloudException("No authentication token in cloud response");
+ throw new AuthenticationException("No authentication token in cloud response");
}
return new AuthenticationContext(myRegion, authToken, tenantId, services, null);
}
@@ -730,8 +717,7 @@ else if( h.getName().equalsIgnoreCase("x-cdn-management-url") ) {
}
catch( UnsupportedEncodingException e ) {
std.error("authenticateKeystone(): Unable to read access credentials: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
+ throw new InternalException("Unable to read access credentials", e);
}
String tenantId = accountNum;
String authToken = null, storageToken = null;
@@ -788,8 +774,7 @@ else if( h.getName().equalsIgnoreCase("x-cdn-management-url") ) {
}
catch( IOException e ) {
std.error("I/O error from server communications: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
+ throw new CommunicationException("I/O error from server communications: " + e.getMessage(), e);
}
int code = response.getStatusLine().getStatusCode();
@@ -814,8 +799,7 @@ else if( h.getName().equalsIgnoreCase("x-cdn-management-url") ) {
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
NovaException.ExceptionItems items = NovaException.parseException(code, data);
@@ -865,7 +849,7 @@ else if( h.getName().equalsIgnoreCase("x-storage-token") ) {
}
if( authToken == null ) {
std.warn("authenticate(): No authentication token in response");
- throw new CloudException("No authentication token in cloud response");
+ throw new CommunicationException("No authentication token in cloud response");
}
return new AuthenticationContext(thisRegion, authToken, tenantId, services, storageToken);
}
@@ -889,7 +873,7 @@ public void deleteResource(@Nonnull final String service, @Nonnull final String
String endpoint = context.getServiceUrl(service);
if( endpoint == null ) {
- throw new CloudException("No " + service + " endpoint exists");
+ throw new InternalException("No " + service + " endpoint exists");
}
String resourceUri = resource + "/" + resourceId;
if( suffix != null ) {
@@ -950,8 +934,7 @@ protected void delete(@Nonnull final String authToken, @Nonnull final String end
}
catch( IOException e ) {
std.error("I/O error from server communications: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
+ throw new CommunicationException("I/O error from server communications: " + e.getMessage(), e);
}
int code = response.getStatusLine().getStatusCode();
@@ -973,8 +956,7 @@ protected void delete(@Nonnull final String authToken, @Nonnull final String end
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
NovaException.ExceptionItems items = NovaException.parseException(code, data);
@@ -1011,7 +993,7 @@ protected void delete(@Nonnull final String authToken, @Nonnull final String end
String endpoint = context.getServiceUrl(service);
if( endpoint == null ) {
- throw new CloudException("No " + service + " URL has been established in " + context.getMyRegion());
+ throw new InternalException("No " + service + " URL has been established in " + context.getMyRegion());
}
String resourceUri = resource;
if( suffix ) {
@@ -1053,7 +1035,7 @@ protected void delete(@Nonnull final String authToken, @Nonnull final String end
String endpoint = context.getServiceUrl(service);
if( endpoint == null ) {
- throw new CloudException("No " + service + " URL has been established in " + context.getMyRegion());
+ throw new InternalException("No " + service + " URL has been established in " + context.getMyRegion());
}
String resourceUri = resource;
if( resourceId != null ) {
@@ -1077,7 +1059,7 @@ else if( suffix ) {
return new JSONObject(response);
}
catch( JSONException e ) {
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", response);
+ throw new CommunicationException("Invalid response from server", e);
}
}
catch (NovaException ex) {
@@ -1133,8 +1115,7 @@ else if( suffix ) {
}
catch( IOException e ) {
std.error("I/O error from server communications: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
+ throw new CommunicationException("I/O error from server communications: " + e.getMessage(), e);
}
int code = response.getStatusLine().getStatusCode();
@@ -1160,8 +1141,7 @@ else if( suffix ) {
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
try {
JSONObject err = (new JSONObject(data)).getJSONObject("badRequest");
@@ -1202,8 +1182,7 @@ else if( suffix ) {
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
NovaException.ExceptionItems items = NovaException.parseException(code, data);
@@ -1236,8 +1215,7 @@ else if( suffix ) {
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
return data;
}
@@ -1296,8 +1274,7 @@ else if( suffix ) {
}
catch( IOException e ) {
std.error("I/O error from server communications: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
+ throw new CommunicationException("I/O error from server communications: " + e.getMessage(), e);
}
int code = response.getStatusLine().getStatusCode();
@@ -1322,8 +1299,7 @@ else if( suffix ) {
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
NovaException.ExceptionItems items = NovaException.parseException(code, data);
@@ -1350,9 +1326,9 @@ else if( suffix ) {
catch( IOException e ) {
std.error("getStream(): Failed to read response error due to a cloud I/O error: " + e.getMessage());
if( std.isTraceEnabled() ) {
- e.printStackTrace();
+ std.trace("IO error", e);
}
- throw new CloudException(e);
+ throw new CommunicationException("getStream(): Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
if( wire.isDebugEnabled() ) {
wire.debug("---> Binary Data <---");
@@ -1430,7 +1406,7 @@ public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws Ce
String endpoint = context.getServiceUrl(service);
if( endpoint == null ) {
- throw new CloudException("No " + service + " URL has been established in " + context.getMyRegion());
+ throw new InternalException("No " + service + " URL has been established in " + context.getMyRegion());
}
String resourceUri = resource;
if( resource == null && resourceId == null ) {
@@ -1496,8 +1472,7 @@ else if( resourceId != null ) {
}
catch( IOException e ) {
std.error("I/O error from server communications: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
+ throw new CommunicationException("I/O error from server communications: " + e.getMessage(), e);
}
int code = response.getStatusLine().getStatusCode();
@@ -1522,8 +1497,7 @@ else if( resourceId != null ) {
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
NovaException.ExceptionItems items = NovaException.parseException(code, data);
@@ -1559,7 +1533,7 @@ public void postResourceHeaders(final String service, final String resource, fin
String endpoint = context.getServiceUrl(service);
if( endpoint == null ) {
- throw new CloudException("No " + service + " has been established in " + context.getMyRegion());
+ throw new InternalException("No " + service + " has been established in " + context.getMyRegion());
}
if( resourceId == null ) {
throw new InternalException("No container was specified");
@@ -1628,8 +1602,7 @@ public void postResourceHeaders(final String service, final String resource, fin
}
catch( IOException e ) {
std.error("I/O error from server communications: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
+ throw new CommunicationException("I/O error from server communications: " + e.getMessage(), e);
}
int code = response.getStatusLine().getStatusCode();
@@ -1651,8 +1624,7 @@ public void postResourceHeaders(final String service, final String resource, fin
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
try {
if( data != null ) {
@@ -1664,7 +1636,7 @@ public void postResourceHeaders(final String service, final String resource, fin
int min = ob.getInt("retryAfter");
if( min < 1 ) {
- throw new CloudException(CloudErrorType.CAPACITY, 413, "Over Limit", ob.has("message") ? ob.getString("message") : "Over Limit");
+ throw new GeneralCloudException(CloudErrorType.CAPACITY, 413, "Over Limit", ob.has("message") ? ob.getString("message") : "Over Limit");
}
try { Thread.sleep(CalendarWrapper.MINUTE * min); }
catch( InterruptedException ignore ) { }
@@ -1674,7 +1646,7 @@ public void postResourceHeaders(final String service, final String resource, fin
}
}
catch( JSONException e ) {
- throw new CloudException(e);
+ throw new CommunicationException("Invalid response", e);
}
}
@@ -1695,8 +1667,7 @@ public void postResourceHeaders(final String service, final String resource, fin
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
NovaException.ExceptionItems items = NovaException.parseException(code, data);
@@ -1727,8 +1698,7 @@ public void postResourceHeaders(final String service, final String resource, fin
}
catch( IOException e ) {
std.error("Failed to read response due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response due to a cloud I/O error: " + e.getMessage(), e);
}
if( data != null && !data.trim().equals("") ) {
return data;
@@ -1756,7 +1726,7 @@ public void postResourceHeaders(final String service, final String resource, fin
String endpoint = context.getServiceUrl(service);
if( endpoint == null ) {
- throw new CloudException("No " + service + " endpoint exists");
+ throw new InternalException("No " + service + " endpoint exists");
}
try {
String response = postString(context.getAuthToken(), endpoint, resource + "/" + resourceId + "/" + extra, body.toString());
@@ -1768,7 +1738,7 @@ public void postResourceHeaders(final String service, final String resource, fin
return new JSONObject(response);
}
catch( JSONException e ) {
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", response);
+ throw new CommunicationException("Invalid response", e);
}
}
catch (NovaException ex) {
@@ -1793,7 +1763,7 @@ public void postResourceHeaders(final String service, final String resource, fin
String endpoint = context.getServiceUrl(service);
if( endpoint == null ) {
- throw new CloudException("No " + service + " endpoint exists");
+ throw new InternalException("No " + service + " endpoint exists");
}
try {
String response = postString(context.getAuthToken(), endpoint, resourceUri, body.toString());
@@ -1804,7 +1774,7 @@ public void postResourceHeaders(final String service, final String resource, fin
return new JSONObject(response);
}
catch( JSONException e ) {
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", response);
+ throw new CommunicationException("Invalid response", e);
}
}
catch (NovaException ex) {
@@ -1850,7 +1820,7 @@ public void postResourceHeaders(final String service, final String resource, fin
post.setEntity(new StringEntity(payload == null ? "" : payload, "application/json", "UTF-8"));
}
catch( UnsupportedEncodingException e ) {
- throw new InternalException(e);
+ throw new InternalException("Unable to encode", e);
}
try { wire.debug(EntityUtils.toString(post.getEntity())); }
catch( IOException ignore ) { }
@@ -1872,8 +1842,7 @@ public void postResourceHeaders(final String service, final String resource, fin
}
catch( IOException e ) {
std.error("I/O error from server communications: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException("Communication error while reading from cloud endpoint", e);
+ throw new CommunicationException("Communication error while reading from cloud endpoint", e);
}
int code = response.getStatusLine().getStatusCode();
@@ -1894,8 +1863,7 @@ public void postResourceHeaders(final String service, final String resource, fin
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
try {
if( data != null ) {
@@ -1905,7 +1873,7 @@ public void postResourceHeaders(final String service, final String resource, fin
int min = ob.optInt("retryAfter", 0);
if( min < 1 ) {
- throw new CloudException(CloudErrorType.CAPACITY, 413, "Over Limit", ob.has("message") ? ob.getString("message") : "Over Limit");
+ throw new GeneralCloudException(CloudErrorType.CAPACITY, 413, "Over Limit", ob.has("message") ? ob.getString("message") : "Over Limit");
}
try { Thread.sleep(CalendarWrapper.MINUTE * min); }
catch( InterruptedException ignore ) { }
@@ -1914,7 +1882,7 @@ public void postResourceHeaders(final String service, final String resource, fin
}
}
catch( JSONException e ) {
- throw new CloudException(e);
+ throw new CommunicationException("Invalid response", e);
}
}
if( code != HttpStatus.SC_OK && code != HttpStatus.SC_ACCEPTED && code != HttpStatus.SC_NO_CONTENT && code != HttpStatus.SC_CREATED ) {
@@ -1934,8 +1902,7 @@ public void postResourceHeaders(final String service, final String resource, fin
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
NovaException.ExceptionItems items = NovaException.parseException(code, data);
@@ -1966,8 +1933,7 @@ public void postResourceHeaders(final String service, final String resource, fin
}
catch( IOException e ) {
std.error("Failed to read response due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response due to a cloud I/O error: " + e.getMessage(), e);
}
if( data != null && !data.trim().equals("") ) {
return data;
@@ -2045,8 +2011,7 @@ else if( code == HttpStatus.SC_ACCEPTED ) {
}
catch( IOException e ) {
std.error("I/O error from server communications: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
+ throw new CommunicationException("I/O error from server communications: " + e.getMessage());
}
int code = response.getStatusLine().getStatusCode();
@@ -2060,7 +2025,7 @@ else if( code == HttpStatus.SC_ACCEPTED ) {
}
}
if( responseHash != null && md5Hash != null && !responseHash.equals(md5Hash) ) {
- throw new CloudException("MD5 hash values do not match, probably data corruption");
+ throw new CommunicationException("MD5 hash values do not match, probably data corruption");
}
if( code != HttpStatus.SC_ACCEPTED && code != HttpStatus.SC_NO_CONTENT ) {
std.error("postStream(): Expected ACCEPTED or NO CONTENT for POST request, got " + code);
@@ -2079,8 +2044,7 @@ else if( code == HttpStatus.SC_ACCEPTED ) {
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage());
}
NovaException.ExceptionItems items = NovaException.parseException(code, data);
@@ -2112,8 +2076,7 @@ else if( code == HttpStatus.SC_ACCEPTED ) {
}
catch( IOException e ) {
std.error("Failed to read response due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response due to a cloud I/O error: " + e.getMessage(), e);
}
if( data != null && !data.trim().equals("") ) {
return data;
@@ -2141,7 +2104,7 @@ public void putResourceHeaders(@Nonnull final String service, @Nullable final St
String endpoint = context.getServiceUrl(service);
if( endpoint == null ) {
- throw new CloudException("No " + service + " has been established in " + context.getMyRegion());
+ throw new InternalException("No " + service + " has been established in " + context.getMyRegion());
}
String resourceUri = resource;
if( resource == null && resourceId == null ) {
@@ -2217,8 +2180,7 @@ else if( resourceId != null ) {
}
catch( IOException e ) {
std.error("I/O error from server communications: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
+ throw new CommunicationException("I/O error from server communications: " + e.getMessage(), e);
}
int code = response.getStatusLine().getStatusCode();
@@ -2241,8 +2203,7 @@ else if( resourceId != null ) {
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
NovaException.ExceptionItems items = NovaException.parseException(code, data);
@@ -2273,8 +2234,7 @@ else if( resourceId != null ) {
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
if( data != null && !data.trim().equals("") ) {
return data;
@@ -2305,7 +2265,7 @@ else if( resourceId != null ) {
}
String endpoint = context.getServiceUrl(service);
if( endpoint == null ) {
- throw new CloudException("No " + service + " endpoint exists");
+ throw new InternalException("No " + service + " endpoint exists");
}
try {
String response = putString(context.getAuthToken(), endpoint, resourceUri, body.toString());
@@ -2316,7 +2276,7 @@ else if( resourceId != null ) {
return new JSONObject(response);
}
catch( JSONException e ) {
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", response);
+ throw new CommunicationException("Invalid response", e);
}
}
catch (NovaException ex) {
@@ -2363,7 +2323,7 @@ else if( resourceId != null ) {
put.setEntity(new StringEntity(payload == null ? "" : payload, "application/json", "UTF-8"));
}
catch( UnsupportedEncodingException e ) {
- throw new InternalException(e);
+ throw new InternalException("Unable to encode", e);
}
try { wire.debug(EntityUtils.toString(put.getEntity())); }
catch( IOException ignore ) { }
@@ -2385,8 +2345,7 @@ else if( resourceId != null ) {
}
catch( IOException e ) {
std.error("I/O error from server communications: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
+ throw new CommunicationException("I/O error from server communications: " + e.getMessage(), e);
}
int code = response.getStatusLine().getStatusCode();
@@ -2409,8 +2368,7 @@ else if( resourceId != null ) {
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
NovaException.ExceptionItems items = NovaException.parseException(code, data);
@@ -2441,8 +2399,7 @@ else if( resourceId != null ) {
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
if( data != null && !data.trim().equals("") ) {
return data;
@@ -2513,8 +2470,7 @@ else if( resourceId != null ) {
}
catch( IOException e ) {
std.error("I/O error from server communications: " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
+ throw new CommunicationException("I/O error from server communications: " + e.getMessage(), e);
}
int code = response.getStatusLine().getStatusCode();
@@ -2528,7 +2484,7 @@ else if( resourceId != null ) {
}
}
if( responseHash != null && md5Hash != null && !responseHash.equals(md5Hash) ) {
- throw new CloudException("MD5 hash values do not match, probably data corruption");
+ throw new CommunicationException("MD5 hash values do not match, probably data corruption");
}
if( code != HttpStatus.SC_CREATED && code != HttpStatus.SC_ACCEPTED && code != HttpStatus.SC_NO_CONTENT ) {
std.error("putStream(): Expected CREATED, ACCEPTED, or NO CONTENT for PUT request, got " + code);
@@ -2547,8 +2503,7 @@ else if( resourceId != null ) {
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
NovaException.ExceptionItems items = NovaException.parseException(code, data);
@@ -2579,8 +2534,7 @@ else if( resourceId != null ) {
}
catch( IOException e ) {
std.error("Failed to read response error due to a cloud I/O error: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Failed to read response error due to a cloud I/O error: " + e.getMessage(), e);
}
if( data != null && !data.trim().equals("") ) {
return data;
@@ -2677,9 +2631,9 @@ else if( ver2 == null ) {
result = major1 - major2;
if (result==0)
result = minor1 - minor2;
- } catch (Exception e) {
+ } catch (NumberFormatException e) {
// Something really stupid showed up in the version string...
- throw new InternalException(e);
+ throw new InternalException("Unable to parse the version", e);
}
finally {
if( logger.isTraceEnabled() ) {
diff --git a/src/main/java/org/dasein/cloud/openstack/nova/os/NovaLocationServices.java b/src/main/java/org/dasein/cloud/openstack/nova/os/NovaLocationServices.java
index f92ee7f..6f2d010 100644
--- a/src/main/java/org/dasein/cloud/openstack/nova/os/NovaLocationServices.java
+++ b/src/main/java/org/dasein/cloud/openstack/nova/os/NovaLocationServices.java
@@ -62,15 +62,10 @@ public class NovaLocationServices extends AbstractDataCenterServices listDataCenters(String providerRegionId) throws In
Region region = getRegion(providerRegionId);
if( region == null ) {
- throw new CloudException("No such region: " + providerRegionId);
+ throw new InternalException("No such region: " + providerRegionId);
}
DataCenter dc = new DataCenter();
diff --git a/src/main/java/org/dasein/cloud/openstack/nova/os/NovaMethod.java b/src/main/java/org/dasein/cloud/openstack/nova/os/NovaMethod.java
index 534a6a7..f26d771 100644
--- a/src/main/java/org/dasein/cloud/openstack/nova/os/NovaMethod.java
+++ b/src/main/java/org/dasein/cloud/openstack/nova/os/NovaMethod.java
@@ -20,9 +20,7 @@
package org.dasein.cloud.openstack.nova.os;
import org.apache.http.HttpStatus;
-import org.dasein.cloud.CloudErrorType;
-import org.dasein.cloud.CloudException;
-import org.dasein.cloud.InternalException;
+import org.dasein.cloud.*;
import org.dasein.cloud.openstack.nova.os.ext.hp.cdn.HPCDN;
import org.dasein.cloud.util.Cache;
import org.dasein.cloud.util.CacheLevel;
@@ -36,15 +34,17 @@
import java.util.HashMap;
import java.util.Map;
+import org.dasein.cloud.openstack.nova.os.*;
+
public class NovaMethod extends AbstractMethod {
public NovaMethod(NovaOpenStack provider) { super(provider); }
public void deleteServers(@Nonnull final String resource, @Nonnull final String resourceId) throws CloudException, InternalException {
- AuthenticationContext context = provider.getAuthenticationContext();
+ AuthenticationContext context = getAuthenticationContext();
String endpoint = context.getComputeUrl();
if( endpoint == null ) {
- throw new CloudException("No compute endpoint exists");
+ throw new InternalException("No compute endpoint exists");
}
try {
delete(context.getAuthToken(), endpoint, resource + "/" + resourceId);
@@ -62,11 +62,11 @@ public void deleteServers(@Nonnull final String resource, @Nonnull final String
}
public void deleteNetworks(@Nonnull final String resource, @Nonnull final String resourceId) throws CloudException, InternalException {
- AuthenticationContext context = provider.getAuthenticationContext();
+ AuthenticationContext context = getAuthenticationContext();
String endpoint = context.getNetworkUrl();
if( endpoint == null ) {
- throw new CloudException("No network endpoint exists");
+ throw new InternalException("No network endpoint exists");
}
if (resource != null && (!endpoint.endsWith("/") && !resource.startsWith("/"))) {
endpoint = endpoint+"/";
@@ -87,11 +87,11 @@ public void deleteNetworks(@Nonnull final String resource, @Nonnull final String
}
public @Nullable JSONObject getPorts(@Nonnull final String resource, @Nonnull final String resourceId) throws CloudException, InternalException {
- AuthenticationContext context = provider.getAuthenticationContext();
+ AuthenticationContext context = getAuthenticationContext();
String endpoint = context.getComputeUrl();
if( endpoint == null ) {
- throw new CloudException("No compute URL has been established in " + context.getMyRegion());
+ throw new InternalException("No compute URL has been established in " + context.getMyRegion());
}
String resourceUri = resource;
if( resourceId != null ) {
@@ -108,7 +108,7 @@ public void deleteNetworks(@Nonnull final String resource, @Nonnull final String
return new JSONObject(response);
}
catch( JSONException e ) {
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", response);
+ throw new CommunicationException("Unable to understand getPorts response: " + e.getMessage(), e);
}
}
catch (NovaException ex) {
@@ -122,13 +122,17 @@ public void deleteNetworks(@Nonnull final String resource, @Nonnull final String
}
}
}
-
+
+ public AuthenticationContext getAuthenticationContext() throws CloudException, InternalException {
+ return provider.getAuthenticationContext();
+ }
+
public @Nullable JSONObject getServers(@Nonnull final String resource, @Nullable final String resourceId, final boolean suffix) throws CloudException, InternalException {
- AuthenticationContext context = provider.getAuthenticationContext();
+ AuthenticationContext context = getAuthenticationContext();
String endpoint = context.getComputeUrl();
if( endpoint == null ) {
- throw new CloudException("No compute URL has been established in " + context.getMyRegion());
+ throw new InternalException("No compute URL has been established in " + context.getMyRegion());
}
String resourceUri = resource; // make a copy in case we need to retry with the original resource
if( resourceId != null ) {
@@ -147,7 +151,7 @@ else if( suffix ) {
return new JSONObject(response);
}
catch( JSONException e ) {
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", response);
+ throw new CommunicationException("Unable to understand getServers response: " + e.getMessage(), e);
}
}
catch (NovaException ex) {
@@ -167,11 +171,11 @@ else if( suffix ) {
}
public @Nullable JSONObject getNetworks(@Nonnull final String resource, @Nullable final String resourceId, final boolean suffix, final String query) throws CloudException, InternalException {
- AuthenticationContext context = provider.getAuthenticationContext();
+ AuthenticationContext context = getAuthenticationContext();
String endpoint = context.getNetworkUrl();
if( endpoint == null ) {
- throw new CloudException("No network URL has been established in " + context.getMyRegion());
+ throw new InternalException("No network URL has been established in " + context.getMyRegion());
}
String resourceUri = resource; // make a copy in case we need to retry with the original resource
if( resourceId != null ) {
@@ -196,7 +200,7 @@ else if( suffix ) {
return new JSONObject(response);
}
catch( JSONException e ) {
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", response);
+ throw new CommunicationException("Unable to understand getNetworks response: " + e.getMessage(), e);
}
}
catch (NovaException ex) {
@@ -212,7 +216,7 @@ else if( suffix ) {
}
public @Nullable String postServersForString(@Nonnull final String resource, @Nullable final String resourceId, @Nonnull final JSONObject body, final boolean suffix) throws CloudException, InternalException {
- AuthenticationContext context = provider.getAuthenticationContext();
+ AuthenticationContext context = getAuthenticationContext();
String resourceUri = resource;
if( resourceId != null ) {
@@ -221,7 +225,7 @@ else if( suffix ) {
String computeEndpoint = context.getComputeUrl();
if( computeEndpoint == null ) {
- throw new CloudException("No compute endpoint exists");
+ throw new InternalException("No compute endpoint exists");
}
try {
return postString(context.getAuthToken(), computeEndpoint, resourceUri, body.toString());
@@ -239,7 +243,7 @@ else if( suffix ) {
}
public @Nullable JSONObject postServers(@Nonnull final String resource, @Nullable final String resourceId, @Nonnull final JSONObject body, final boolean suffix) throws CloudException, InternalException {
- AuthenticationContext context = provider.getAuthenticationContext();
+ AuthenticationContext context = getAuthenticationContext();
String resourceUri = resource;
if( resourceId != null ) {
@@ -248,7 +252,7 @@ else if( suffix ) {
String computeEndpoint = context.getComputeUrl();
if( computeEndpoint == null ) {
- throw new CloudException("No compute endpoint exists");
+ throw new InternalException("No compute endpoint exists");
}
try {
String response = postString(context.getAuthToken(), computeEndpoint, resourceUri, body.toString());
@@ -260,7 +264,7 @@ else if( suffix ) {
return new JSONObject(response);
}
catch( JSONException e ) {
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", response);
+ throw new CommunicationException("Unable to understand postServers response: " + e.getMessage(), e);
}
}
catch (NovaException ex) {
@@ -276,7 +280,7 @@ else if( suffix ) {
}
public @Nullable JSONObject postNetworks(@Nonnull final String resource, @Nullable final String resourceId, @Nonnull final JSONObject body, @Nullable final String action) throws CloudException, InternalException {
- AuthenticationContext context = provider.getAuthenticationContext();
+ AuthenticationContext context = getAuthenticationContext();
String resourceUri = resource;
if( resourceId != null ) {
@@ -285,7 +289,7 @@ else if( suffix ) {
String endpoint = context.getNetworkUrl();
if( endpoint == null ) {
- throw new CloudException("No network endpoint exists");
+ throw new InternalException("No network endpoint exists");
}
if (resourceUri != null && (!endpoint.endsWith("/") && !resourceUri.startsWith("/"))) {
@@ -301,7 +305,7 @@ else if( suffix ) {
return new JSONObject(response);
}
catch( JSONException e ) {
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", response);
+ throw new CommunicationException("Unable to understand postNetworks response: " + e.getMessage(), e);
}
}
catch (NovaException ex) {
@@ -317,7 +321,7 @@ else if( suffix ) {
}
public @Nullable JSONObject putNetworks(@Nonnull final String resource, @Nullable final String resourceId, @Nonnull final JSONObject body, final String action) throws CloudException, InternalException {
- AuthenticationContext context = provider.getAuthenticationContext();
+ AuthenticationContext context = getAuthenticationContext();
String resourceUri = resource;
if( resourceId != null ) {
@@ -326,7 +330,7 @@ else if( suffix ) {
String endpoint = context.getNetworkUrl();
if( endpoint == null ) {
- throw new CloudException("No network endpoint exists");
+ throw new InternalException("No network endpoint exists");
}
if (resourceUri != null && (!endpoint.endsWith("/") && !resourceUri.startsWith("/"))) {
@@ -342,7 +346,7 @@ else if( suffix ) {
return new JSONObject(response);
}
catch( JSONException e ) {
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", response);
+ throw new CommunicationException("Unable to understand putNetworks response: " + e.getMessage(), e);
}
}
catch (NovaException ex) {
@@ -362,11 +366,11 @@ else if( suffix ) {
}
public @Nullable String getHPCDN(@Nullable final String resourceId) throws CloudException, InternalException {
- AuthenticationContext context = provider.getAuthenticationContext();
+ AuthenticationContext context = getAuthenticationContext();
String endpoint = context.getServiceUrl(HPCDN.SERVICE);
if( endpoint == null ) {
- throw new CloudException("No CDN URL has been established in " + context.getMyRegion());
+ throw new InternalException("No CDN URL has been established in " + context.getMyRegion());
}
try {
return getString(context.getAuthToken(), endpoint, resourceId == null ? "" : ("/" + resourceId));
@@ -385,11 +389,11 @@ else if( suffix ) {
public void putHPCDN(final String container) throws CloudException, InternalException {
Map headers = new HashMap();
- AuthenticationContext context = provider.getAuthenticationContext();
+ AuthenticationContext context = getAuthenticationContext();
String endpoint = context.getServiceUrl(HPCDN.SERVICE);
if( endpoint == null ) {
- throw new CloudException("No CDN URL has been established in " + context.getMyRegion());
+ throw new InternalException("No CDN URL has been established in " + context.getMyRegion());
}
if( container == null ) {
throw new InternalException("No container was specified");
@@ -400,7 +404,7 @@ public void putHPCDN(final String container) throws CloudException, InternalExce
headers = headResource(HPCDN.SERVICE, HPCDN.RESOURCE, container);
if( headers == null ) {
- throw new CloudException("No container enabled");
+ throw new InternalException("No container enabled");
}
}
catch (NovaException ex) {
@@ -416,11 +420,11 @@ public void putHPCDN(final String container) throws CloudException, InternalExce
}
public void postHPCDN(@Nonnull final String container, @Nonnull final Map headers) throws CloudException, InternalException {
- AuthenticationContext context = provider.getAuthenticationContext();
+ AuthenticationContext context = getAuthenticationContext();
String endpoint = context.getServiceUrl(HPCDN.SERVICE);
if( endpoint == null ) {
- throw new CloudException("No CDN URL has been established in " + context.getMyRegion());
+ throw new InternalException("No CDN URL has been established in " + context.getMyRegion());
}
if( container == null ) {
throw new InternalException("No container was specified");
@@ -441,11 +445,11 @@ public void postHPCDN(@Nonnull final String container, @Nonnull final Map current = cache.get(ctx);
AuthenticationContext authenticationContext = null;
@@ -201,11 +195,9 @@ else if( getCloudProvider().equals(OpenStackProvider.RACKSPACE) ) {
}
}
catch( CloudException e ) {
- e.printStackTrace();
return null;
}
catch( InternalException e ) {
- e.printStackTrace();
return null;
}
return new SwiftStorageServices(this);
@@ -349,7 +341,7 @@ public boolean isPostCactus() throws CloudException, InternalException {
return (getMajorVersion() > 1 || getMinorVersion() > 0);
}
- static public long parseTimestamp(String time) throws CloudException {
+ static public long parseTimestamp(String time) throws InternalException {
if( time == null ) {
return 0L;
}
@@ -381,7 +373,7 @@ static public long parseTimestamp(String time) throws CloudException {
return fmt.parse(time).getTime();
}
catch( ParseException because ) {
- throw new CloudException("Could not parse date: " + time);
+ throw new InternalException("Could not parse date: " + time);
}
}
}
diff --git a/src/main/java/org/dasein/cloud/openstack/nova/os/SwiftMethod.java b/src/main/java/org/dasein/cloud/openstack/nova/os/SwiftMethod.java
index 0642336..c681f33 100644
--- a/src/main/java/org/dasein/cloud/openstack/nova/os/SwiftMethod.java
+++ b/src/main/java/org/dasein/cloud/openstack/nova/os/SwiftMethod.java
@@ -47,7 +47,7 @@ public void delete(@Nonnull String bucket) throws CloudException, InternalExcept
String endpoint = context.getStorageUrl();
if( endpoint == null ) {
- throw new CloudException("No storage endpoint exists for " + context.getMyRegion());
+ throw new InternalException("No storage endpoint exists for " + context.getMyRegion());
}
try {
delete(context.getAuthToken(), endpoint, "/" + bucket);
@@ -70,7 +70,7 @@ public void delete(@Nonnull String bucket, @Nonnull String object) throws CloudE
String endpoint = context.getStorageUrl();
if( endpoint == null ) {
- throw new CloudException("No storage endpoint exists for " + context.getMyRegion());
+ throw new InternalException("No storage endpoint exists for " + context.getMyRegion());
}
try {
delete(context.getAuthToken(), endpoint, "/" + bucket + "/" + object);
@@ -92,7 +92,7 @@ public void delete(@Nonnull String bucket, @Nonnull String object) throws CloudE
String endpoint = context.getStorageUrl();
if( endpoint == null ) {
- throw new CloudException("No storage endpoint exists for " + context.getMyRegion());
+ throw new InternalException("No storage endpoint exists for " + context.getMyRegion());
}
try {
String response = getString(context.getAuthToken(), endpoint, bucket == null ? "/" : "/" + bucket);
@@ -134,7 +134,7 @@ public void delete(@Nonnull String bucket, @Nonnull String object) throws CloudE
String endpoint = context.getStorageUrl();
if( endpoint == null ) {
- throw new CloudException("No storage endpoint exists for " + context.getMyRegion());
+ throw new InternalException("No storage endpoint exists for " + context.getMyRegion());
}
try {
return getStream(context.getAuthToken(), endpoint, "/" + bucket + "/" + object);
@@ -157,7 +157,7 @@ public void delete(@Nonnull String bucket, @Nonnull String object) throws CloudE
String endpoint = context.getStorageUrl();
if( endpoint == null ) {
- throw new CloudException("No storage endpoint exists for " + context.getMyRegion());
+ throw new InternalException("No storage endpoint exists for " + context.getMyRegion());
}
try {
return head(context.getAuthToken(), endpoint, "/" + bucket);
@@ -179,7 +179,7 @@ public void delete(@Nonnull String bucket, @Nonnull String object) throws CloudE
String endpoint = context.getStorageUrl();
if( endpoint == null ) {
- throw new CloudException("No storage endpoint exists for " + context.getMyRegion());
+ throw new InternalException("No storage endpoint exists for " + context.getMyRegion());
}
try {
return head(context.getAuthToken(), endpoint, "/" + bucket + "/" + object);
@@ -201,7 +201,7 @@ public void put(@Nonnull String bucket) throws CloudException, InternalException
String endpoint = context.getStorageUrl();
if( endpoint == null ) {
- throw new CloudException("No storage endpoint exists for " + context.getMyRegion());
+ throw new InternalException("No storage endpoint exists for " + context.getMyRegion());
}
try {
putString(context.getAuthToken(), endpoint, "/" + bucket, null);
@@ -223,7 +223,7 @@ public void put(@Nonnull String bucket, @Nonnull String object, @Nullable String
String endpoint = context.getStorageUrl();
if( endpoint == null ) {
- throw new CloudException("No storage endpoint exists for " + context.getMyRegion());
+ throw new InternalException("No storage endpoint exists for " + context.getMyRegion());
}
try {
putStream(context.getAuthToken(), endpoint, "/" + bucket + "/" + object, md5Hash, payload);
@@ -244,7 +244,7 @@ public void put(@Nonnull String bucket, @Nonnull String prefix, @Nonnull Tag ...
AuthenticationContext context = provider.getAuthenticationContext();
String endpoint = context.getStorageUrl();
if( endpoint == null ) {
- throw new CloudException("No storage endpoint exists for " + context.getMyRegion());
+ throw new InternalException("No storage endpoint exists for " + context.getMyRegion());
}
try {
HashMap customHeaders = new HashMap();
diff --git a/src/main/java/org/dasein/cloud/openstack/nova/os/compute/CinderSnapshot.java b/src/main/java/org/dasein/cloud/openstack/nova/os/compute/CinderSnapshot.java
index c6e0cf6..0659d91 100644
--- a/src/main/java/org/dasein/cloud/openstack/nova/os/compute/CinderSnapshot.java
+++ b/src/main/java/org/dasein/cloud/openstack/nova/os/compute/CinderSnapshot.java
@@ -20,12 +20,7 @@
package org.dasein.cloud.openstack.nova.os.compute;
import org.apache.log4j.Logger;
-import org.dasein.cloud.CloudErrorType;
-import org.dasein.cloud.CloudException;
-import org.dasein.cloud.InternalException;
-import org.dasein.cloud.OperationNotSupportedException;
-import org.dasein.cloud.ResourceStatus;
-import org.dasein.cloud.Tag;
+import org.dasein.cloud.*;
import org.dasein.cloud.compute.AbstractSnapshotSupport;
import org.dasein.cloud.compute.Snapshot;
import org.dasein.cloud.compute.SnapshotCapabilities;
@@ -43,9 +38,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Locale;
+import java.util.*;
/**
* Implements support for snapshots from the OpenStack Cinder API.
@@ -66,12 +59,12 @@ public CinderSnapshot(NovaOpenStack provider) {
}
private @Nonnull String getTenantId() throws CloudException, InternalException {
- return ((NovaOpenStack)getProvider()).getContext().getAccountNumber();
+ return getContext().getAccountNumber();
}
private @Nonnull String getResource() {
// hp seems to be used the regular grizzly resource
- // return (((NovaOpenStack)getProvider()).isHP() ? "/os-snapshots" : "/snapshots");
+ // return ((getProvider()).isHP() ? "/os-snapshots" : "/snapshots");
return "/snapshots";
}
@@ -85,9 +78,9 @@ public CinderSnapshot(NovaOpenStack provider) {
throw new OperationNotSupportedException("Snapshot copying is not supported in " + getProvider().getCloudName());
}
- HashMap wrapper = new HashMap();
- HashMap json = new HashMap();
- NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
+ Map wrapper = new HashMap<>();
+ Map json = new HashMap<>();
+ NovaMethod method = new NovaMethod(getProvider());
json.put("volume_id", volumeId);
json.put("display_name", options.getName());
@@ -106,14 +99,12 @@ public CinderSnapshot(NovaOpenStack provider) {
}
catch( JSONException e ) {
logger.error("create(): Unable to understand create response: " + e.getMessage());
- if( logger.isTraceEnabled() ) {
- e.printStackTrace();
- }
- throw new CloudException(e);
+ throw new CommunicationException("Unable to understand create response: " + e.getMessage(), e);
+
}
}
logger.error("snapshot(): No snapshot was created by the create attempt, and no error was returned");
- throw new CloudException("No snapshot was created");
+ throw new GeneralCloudException("No snapshot was created", CloudErrorType.GENERAL);
}
finally {
@@ -122,11 +113,12 @@ public CinderSnapshot(NovaOpenStack provider) {
}
private transient volatile CinderSnapshotCapabilities capabilities;
+
@Nonnull
@Override
public SnapshotCapabilities getCapabilities() throws CloudException, InternalException {
if( capabilities == null ) {
- capabilities = new CinderSnapshotCapabilities((NovaOpenStack)getProvider());
+ capabilities = new CinderSnapshotCapabilities(getProvider());
}
return capabilities;
}
@@ -135,7 +127,7 @@ public SnapshotCapabilities getCapabilities() throws CloudException, InternalExc
public @Nullable Snapshot getSnapshot(@Nonnull String snapshotId) throws InternalException, CloudException {
APITrace.begin(getProvider(), "Snapshot.getSnapshot");
try {
- NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
+ NovaMethod method = new NovaMethod(getProvider());
JSONObject ob = method.getResource(SERVICE, getResource(), snapshotId, true);
if( ob == null ) {
@@ -148,7 +140,7 @@ public SnapshotCapabilities getCapabilities() throws CloudException, InternalExc
}
catch( JSONException e ) {
logger.error("getSnapshot(): Unable to identify expected values in JSON: " + e.getMessage());
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for snapshot");
+ throw new CommunicationException("Unable to identify expected values in JSON: " + e.getMessage(), e);
}
return null;
}
@@ -161,8 +153,8 @@ public SnapshotCapabilities getCapabilities() throws CloudException, InternalExc
public @Nonnull Iterable listSnapshotStatus() throws InternalException, CloudException {
APITrace.begin(getProvider(), "Snapshot.listSnapshotStatus");
try {
- NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
- ArrayList snapshots = new ArrayList();
+ NovaMethod method = new NovaMethod(getProvider());
+ List snapshots = new ArrayList<>();
JSONObject json = method.getResource(SERVICE, getResource(), null, false);
@@ -179,7 +171,7 @@ public SnapshotCapabilities getCapabilities() throws CloudException, InternalExc
}
}
catch( JSONException e ) {
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for snapshots in " + json.toString());
+ throw new CommunicationException("Unable to parse response: " + e.getMessage(), e);
}
}
return snapshots;
@@ -198,7 +190,7 @@ public boolean isPublic(@Nonnull String snapshotId) throws InternalException, Cl
public boolean isSubscribed() throws InternalException, CloudException {
APITrace.begin(getProvider(), "Snapshot.isSubscribed");
try {
- return (((NovaOpenStack)getProvider()).getAuthenticationContext().getServiceUrl(SERVICE) != null);
+ return (getProvider().getAuthenticationContext().getServiceUrl(SERVICE) != null);
}
finally {
APITrace.end();
@@ -209,8 +201,8 @@ public boolean isSubscribed() throws InternalException, CloudException {
public @Nonnull Iterable listSnapshots() throws InternalException, CloudException {
APITrace.begin(getProvider(), "Snapshot.listSnapshots");
try {
- NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
- ArrayList snapshots = new ArrayList();
+ NovaMethod method = new NovaMethod(getProvider());
+ List snapshots = new ArrayList<>();
JSONObject json = method.getResource(SERVICE, getResource(), null, false);
@@ -228,8 +220,7 @@ public boolean isSubscribed() throws InternalException, CloudException {
}
catch( JSONException e ) {
logger.error("listSnapshots(): Unable to identify expected values in JSON: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for snapshots in " + json.toString());
+ throw new CommunicationException("Unable to parse response " + e.getMessage(), e);
}
}
return snapshots;
@@ -262,7 +253,7 @@ public void remove(@Nonnull String snapshotId) throws InternalException, CloudEx
try { Thread.sleep(15000L); }
catch( InterruptedException ignore ) { }
}
- NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
+ NovaMethod method = new NovaMethod(getProvider());
method.deleteResource(SERVICE, getResource(), snapshotId, null);
timeout = System.currentTimeMillis() + (CalendarWrapper.MINUTE * 5L);
@@ -290,8 +281,8 @@ public void remove(@Nonnull String snapshotId) throws InternalException, CloudEx
public @Nonnull Iterable searchSnapshots(@Nonnull SnapshotFilterOptions options) throws InternalException, CloudException {
APITrace.begin(getProvider(), "Snapshot.searchSnapshots");
try {
- NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
- ArrayList snapshots = new ArrayList();
+ NovaMethod method = new NovaMethod(getProvider());
+ List snapshots = new ArrayList<>();
JSONObject json = method.getResource(SERVICE, getResource(), null, false);
@@ -309,8 +300,7 @@ public void remove(@Nonnull String snapshotId) throws InternalException, CloudEx
}
catch( JSONException e ) {
logger.error("searchSnapshots(): Unable to identify expected values in JSON: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for snapshots in " + json.toString());
+ throw new CommunicationException("Unable to identify expected values in JSON: " + e.getMessage(), e);
}
}
return snapshots;
@@ -325,7 +315,7 @@ public void remove(@Nonnull String snapshotId) throws InternalException, CloudEx
return new String[0];
}
- private @Nullable Snapshot toSnapshot(@Nullable JSONObject json) throws CloudException, InternalException {
+ @Nullable Snapshot toSnapshot( @Nullable JSONObject json ) throws CloudException, InternalException {
if( json == null ) {
return null;
}
@@ -379,10 +369,10 @@ else if( status.equalsIgnoreCase("creating") ) {
logger.warn("DEBUG: Unknown OpenStack snapshot state: " + status);
}
}
- long created = (json.has("createdAt") ? ((NovaOpenStack)getProvider()).parseTimestamp(json.getString("createdAt")) : -1L);
+ long created = (json.has("createdAt") ? getProvider().parseTimestamp(json.getString("createdAt")) : -1L);
if( created < 1L ) {
- created = (json.has("created_at") ? ((NovaOpenStack)getProvider()).parseTimestamp(json.getString("created_at")) : -1L);
+ created = (json.has("created_at") ? getProvider().parseTimestamp(json.getString("created_at")) : -1L);
}
int size = (json.has("size") ? json.getInt("size") : 0);
@@ -400,11 +390,11 @@ else if( status.equalsIgnoreCase("creating") ) {
return snapshot;
}
catch( JSONException e ) {
- throw new CloudException(e);
+ throw new CommunicationException("Unable to parse response: " + e.getMessage(), e);
}
}
- private @Nullable ResourceStatus toStatus(@Nullable JSONObject json) throws CloudException, InternalException {
+ protected @Nullable ResourceStatus toStatus(@Nullable JSONObject json) throws CloudException, InternalException {
if( json == null ) {
return null;
}
@@ -436,7 +426,7 @@ else if( status.equalsIgnoreCase("creating") ) {
return new ResourceStatus(snapshotId, state);
}
catch( JSONException e ) {
- throw new CloudException(e);
+ throw new CommunicationException("Unable to parse response: " + e.getMessage(), e);
}
}
@@ -444,7 +434,7 @@ else if( status.equalsIgnoreCase("creating") ) {
public void setTags(@Nonnull String snapshotId, @Nonnull Tag... tags) throws CloudException, InternalException {
APITrace.begin(getProvider(), "Snapshot.setTags");
try {
- ((NovaOpenStack) getProvider()).createTags( SERVICE, "/snapshots", snapshotId, tags);
+ getProvider().createTags( SERVICE, "/snapshots", snapshotId, tags);
}
finally {
APITrace.end();
@@ -462,7 +452,7 @@ public void setTags(@Nonnull String[] snapshotIds, @Nonnull Tag... tags) throws
public void updateTags(@Nonnull String snapshotId, @Nonnull Tag... tags) throws CloudException, InternalException {
APITrace.begin(getProvider(), "Snapshot.updateTags");
try {
- ((NovaOpenStack) getProvider()).updateTags( SERVICE, "/snapshots", snapshotId, tags);
+ getProvider().updateTags( SERVICE, "/snapshots", snapshotId, tags);
}
finally {
APITrace.end();
@@ -480,7 +470,7 @@ public void updateTags(@Nonnull String[] snapshotIds, @Nonnull Tag... tags) thro
public void removeTags(@Nonnull String snapshotId, @Nonnull Tag... tags) throws CloudException, InternalException {
APITrace.begin(getProvider(), "Snapshot.removeTags");
try {
- ((NovaOpenStack) getProvider()).removeTags( SERVICE, "/snapshots", snapshotId, tags);
+ getProvider().removeTags( SERVICE, "/snapshots", snapshotId, tags);
}
finally {
APITrace.end();
diff --git a/src/main/java/org/dasein/cloud/openstack/nova/os/compute/CinderVolume.java b/src/main/java/org/dasein/cloud/openstack/nova/os/compute/CinderVolume.java
index f27724c..a6bef9e 100644
--- a/src/main/java/org/dasein/cloud/openstack/nova/os/compute/CinderVolume.java
+++ b/src/main/java/org/dasein/cloud/openstack/nova/os/compute/CinderVolume.java
@@ -20,13 +20,7 @@
package org.dasein.cloud.openstack.nova.os.compute;
import org.apache.log4j.Logger;
-import org.dasein.cloud.CloudErrorType;
-import org.dasein.cloud.CloudException;
-import org.dasein.cloud.InternalException;
-import org.dasein.cloud.OperationNotSupportedException;
-import org.dasein.cloud.Requirement;
-import org.dasein.cloud.ResourceStatus;
-import org.dasein.cloud.Tag;
+import org.dasein.cloud.*;
import org.dasein.cloud.compute.AbstractVolumeSupport;
import org.dasein.cloud.compute.Platform;
import org.dasein.cloud.compute.Volume;
@@ -50,11 +44,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
+import java.util.*;
/**
* Support for the Cinder volumes API in Dasein Cloud.
@@ -63,7 +53,7 @@
* @version 2012.09.1 copied over from volume extension for HP
* @since 2012.09.1
*/
-public class CinderVolume extends AbstractVolumeSupport {
+public class CinderVolume extends AbstractVolumeSupport {
static private final Logger logger = NovaOpenStack.getLogger(CinderVolume.class, "std");
static public final String SERVICE = "volume";
@@ -72,17 +62,17 @@ public CinderVolume(@Nonnull NovaOpenStack provider) {
super(provider);
}
- private @Nonnull String getAttachmentsResource() {
+ @Nonnull String getAttachmentsResource() {
return "os-volume_attachments";
}
private @Nonnull String getResource() {
// 20130930 dmayne: seems like hp may have upgraded and uses the same resource
return "/volumes";
- // return (((NovaOpenStack)getProvider()).isHP() ? "/os-volumes" : "/volumes");
+ // return ((getProvider()).isHP() ? "/os-volumes" : "/volumes");
}
- private @Nonnull String getTypesResource() {
+ @Nonnull String getTypesResource() {
return "/types";
}
@@ -90,16 +80,16 @@ public CinderVolume(@Nonnull NovaOpenStack provider) {
public void attach(@Nonnull String volumeId, @Nonnull String toServer, @Nonnull String device) throws InternalException, CloudException {
APITrace.begin(getProvider(), "Volume.attach");
try {
- HashMap attachment = new HashMap();
- HashMap wrapper = new HashMap();
- NovaMethod method = new NovaMethod(((NovaOpenStack)getProvider()));
+ Map attachment = new HashMap<>();
+ Map wrapper = new HashMap<>();
+ NovaMethod method = new NovaMethod(getProvider());
attachment.put("volumeId", volumeId);
attachment.put("device", device);
wrapper.put("volumeAttachment", attachment);
if( method.postString(NovaServer.SERVICE, "/servers", toServer, getAttachmentsResource(), new JSONObject(wrapper)) == null ) {
- throw new CloudException("No response from the cloud");
+ throw new CommunicationException("No response from the cloud");
}
}
finally {
@@ -114,9 +104,9 @@ public void attach(@Nonnull String volumeId, @Nonnull String toServer, @Nonnull
}
APITrace.begin(getProvider(), "Volume.createVolume");
try {
- HashMap wrapper = new HashMap();
- HashMap json = new HashMap();
- NovaMethod method = new NovaMethod(((NovaOpenStack)getProvider()));
+ Map wrapper = new HashMap<>();
+ Map json = new HashMap<>();
+ NovaMethod method = new NovaMethod(getProvider());
json.put("display_name", options.getName());
json.put("display_description", options.getDescription());
@@ -127,11 +117,11 @@ public void attach(@Nonnull String volumeId, @Nonnull String toServer, @Nonnull
Storage size = options.getVolumeSize();
- if( size == null || (size.intValue() < getMinimumVolumeSize().intValue()) ) {
- size = getMinimumVolumeSize();
+ if( size == null || (size.intValue() < getCapabilities().getMinimumVolumeSize().intValue()) ) {
+ size = getCapabilities().getMinimumVolumeSize();
}
- else if( getMaximumVolumeSize() != null && size.intValue() > getMaximumVolumeSize().intValue() ) {
- size = getMaximumVolumeSize();
+ else if( getCapabilities().getMaximumVolumeSize() != null && size.intValue() > getCapabilities().getMaximumVolumeSize().intValue() ) {
+ size = getCapabilities().getMaximumVolumeSize();
}
json.put("size", size.intValue());
if( options.getSnapshotId() != null ) {
@@ -144,8 +134,7 @@ else if( getMaximumVolumeSize() != null && size.intValue() > getMaximumVolumeSiz
}
if( options.getVolumeProductId() != null ) {
// TODO: cinder was broken and expected the name prior Grizzly
- json.put("volume_type", options.getVolumeProductId());
-
+ json.put("volume_type", options.getVolumeProductId());
}
wrapper.put("volume", json);
JSONObject result = method.postString(SERVICE, getResource(), null, new JSONObject(wrapper), true);
@@ -160,14 +149,11 @@ else if( getMaximumVolumeSize() != null && size.intValue() > getMaximumVolumeSiz
}
catch( JSONException e ) {
logger.error("create(): Unable to understand create response: " + e.getMessage());
- if( logger.isTraceEnabled() ) {
- e.printStackTrace();
- }
- throw new CloudException(e);
+ throw new CommunicationException("Unable to understand createVolume response: " + e.getMessage(), e);
}
}
logger.error("create(): No volume was created by the create attempt, and no error was returned");
- throw new CloudException("No volume was created");
+ throw new ResourceNotFoundException("volume", options.getVolumeProductId());
}
finally {
@@ -182,12 +168,12 @@ public void detach(@Nonnull String volumeId, boolean force) throws InternalExcep
Volume volume = getVolume(volumeId);
if( volume == null ) {
- throw new CloudException("No such volume: " + volumeId);
+ throw new ResourceNotFoundException("volume", volumeId);
}
if( volume.getProviderVirtualMachineId() == null ) {
- throw new CloudException("Volume " + volumeId + " is not attached");
+ throw new ResourceNotFoundException("Volume ", volumeId + " is not attached");
}
- NovaMethod method = new NovaMethod(((NovaOpenStack)getProvider()));
+ NovaMethod method = new NovaMethod(getProvider());
method.deleteResource(NovaServer.SERVICE, "/servers", volume.getProviderVirtualMachineId(), getAttachmentsResource() + "/" + volumeId);
}
@@ -197,42 +183,20 @@ public void detach(@Nonnull String volumeId, boolean force) throws InternalExcep
}
private transient volatile CinderVolumeCapabilities capabilities;
+
@Override
public VolumeCapabilities getCapabilities() throws CloudException, InternalException {
if( capabilities == null ) {
- capabilities = new CinderVolumeCapabilities((NovaOpenStack)getProvider());
+ capabilities = new CinderVolumeCapabilities(getProvider());
}
return capabilities;
}
- @Override
- public int getMaximumVolumeCount() throws InternalException, CloudException {
- return -2;
- }
-
- @Override
- public Storage getMaximumVolumeSize() throws InternalException, CloudException {
- return new Storage(1024, Storage.GIGABYTE);
- }
-
- @Override
- public @Nonnull Storage getMinimumVolumeSize() throws InternalException, CloudException {
- if( ((NovaOpenStack)getProvider()).isRackspace() ) {
- return new Storage(100, Storage.GIGABYTE);
- }
- return new Storage(1, Storage.GIGABYTE);
- }
-
- @Override
- public @Nonnull String getProviderTermForVolume(@Nonnull Locale locale) {
- return "volume";
- }
-
@Override
public @Nullable Volume getVolume(@Nonnull String volumeId) throws InternalException, CloudException {
APITrace.begin(getProvider(), "Volume.getVolume");
try {
- NovaMethod method = new NovaMethod(((NovaOpenStack)getProvider()));
+ NovaMethod method = new NovaMethod(getProvider());
JSONObject ob = method.getResource(SERVICE, getResource(), volumeId, true);
if( ob == null ) {
@@ -245,7 +209,7 @@ public Storage getMaximumVolumeSize() throws InternalException, CloudE
}
catch( JSONException e ) {
logger.error("getVolume(): Unable to identify expected values in JSON: " + e.getMessage());
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for volume");
+ throw new CommunicationException("Unable to understand getVolume response: " + e.getMessage(), e);
}
return null;
}
@@ -254,63 +218,26 @@ public Storage getMaximumVolumeSize() throws InternalException, CloudE
}
}
- @Override
- public @Nonnull Requirement getVolumeProductRequirement() throws InternalException, CloudException {
- return (((NovaOpenStack)getProvider()).isHP() ? Requirement.NONE : Requirement.OPTIONAL);
+ private Iterable getCachedProducts() throws InternalException {
+ Cache cache = Cache.getInstance(getProvider(), "volumeProducts", VolumeProduct.class, CacheLevel.REGION_ACCOUNT);
+ return cache.get(getContext());
}
- @Override
- public boolean isVolumeSizeDeterminedByProduct() throws InternalException, CloudException {
- return false;
- }
-
- @Override
- public @Nonnull Iterable listPossibleDeviceIds(@Nonnull Platform platform) throws InternalException, CloudException {
- ArrayList list = new ArrayList();
-
- if( platform.isWindows() ) {
- if (((NovaOpenStack)getProvider()).isHP()) {
- list.add("/dev/vdf");
- list.add("/dev/vdg");
- list.add("/dev/vdh");
- list.add("/dev/vdi");
- list.add("/dev/vdj");
- }
- else {
- list.add("/dev/xvdf");
- list.add("/dev/xvdg");
- list.add("/dev/xvdh");
- list.add("/dev/xvdi");
- list.add("/dev/xvdj");
- }
- }
- else {
- list.add("/dev/vdf");
- list.add("/dev/vdg");
- list.add("/dev/vdh");
- list.add("/dev/vdi");
- list.add("/dev/vdj");
- }
- return list;
- }
-
- @Override
- public @Nonnull Iterable listSupportedFormats() throws InternalException, CloudException {
- return Collections.singletonList(VolumeFormat.BLOCK);
+ private void saveProductsToCache(Iterable products) throws InternalException {
+ Cache cache = Cache.getInstance(getProvider(), "volumeProducts", VolumeProduct.class, CacheLevel.REGION_ACCOUNT);
+ cache.put(getContext(), products);
}
@Override
public @Nonnull Iterable listVolumeProducts() throws InternalException, CloudException {
APITrace.begin(getProvider(), "Volume.listVolumeProducts");
try {
- Cache cache = Cache.getInstance(getProvider(), "volumeProducts", VolumeProduct.class, CacheLevel.REGION_ACCOUNT);
- Iterable current = cache.get(getContext());
-
- if( current != null ) {
- return current;
+ Iterable cached = getCachedProducts();
+ if( cached != null ) {
+ return cached;
}
- NovaMethod method = new NovaMethod(((NovaOpenStack)getProvider()));
- ArrayList products = new ArrayList();
+ NovaMethod method = new NovaMethod(getProvider());
+ List products = new ArrayList<>();
JSONObject json = method.getResource(SERVICE, getTypesResource(), null, false);
@@ -351,11 +278,10 @@ public boolean isVolumeSizeDeterminedByProduct() throws InternalException, Cloud
}
catch( JSONException e ) {
logger.error("listVolumes(): Unable to identify expected values in JSON: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for volumes in " + json.toString());
+ throw new CommunicationException("Unable to understand listVolumes response: " + e.getMessage(), e);
}
}
- cache.put(getContext(), Collections.unmodifiableList(products));
+ saveProductsToCache(products);
return products;
}
finally {
@@ -367,8 +293,8 @@ public boolean isVolumeSizeDeterminedByProduct() throws InternalException, Cloud
public @Nonnull Iterable listVolumeStatus() throws InternalException, CloudException {
APITrace.begin(getProvider(), "Volume.listVolumeStatus");
try {
- NovaMethod method = new NovaMethod(((NovaOpenStack)getProvider()));
- ArrayList volumes = new ArrayList();
+ NovaMethod method = new NovaMethod(getProvider());
+ List volumes = new ArrayList<>();
JSONObject json = method.getResource(SERVICE, getResource(), null, false);
@@ -386,8 +312,7 @@ public boolean isVolumeSizeDeterminedByProduct() throws InternalException, Cloud
}
catch( JSONException e ) {
logger.error("listVolumes(): Unable to identify expected values in JSON: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for volumes in " + json.toString());
+ throw new CommunicationException("Unable to understand listVolumeStatus response: " + e.getMessage(), e);
}
}
return volumes;
@@ -402,8 +327,8 @@ public boolean isVolumeSizeDeterminedByProduct() throws InternalException, Cloud
APITrace.begin(getProvider(), "Volume.listVolumes");
try {
Iterable products = listVolumeProducts();
- NovaMethod method = new NovaMethod(((NovaOpenStack)getProvider()));
- ArrayList volumes = new ArrayList();
+ NovaMethod method = new NovaMethod(getProvider());
+ List volumes = new ArrayList<>();
JSONObject json = method.getResource(SERVICE, getResource(), null, false);
@@ -422,8 +347,7 @@ public boolean isVolumeSizeDeterminedByProduct() throws InternalException, Cloud
}
catch( JSONException e ) {
logger.error("listVolumes(): Unable to identify expected values in JSON: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for volumes in " + json.toString());
+ throw new CommunicationException("Unable to understand listVolumes response: " + e.getMessage(), e);
}
}
return volumes;
@@ -437,7 +361,7 @@ public boolean isVolumeSizeDeterminedByProduct() throws InternalException, Cloud
public boolean isSubscribed() throws CloudException, InternalException {
APITrace.begin(getProvider(), "Volume.isSubscribed");
try {
- return (((NovaOpenStack)getProvider()).getAuthenticationContext().getServiceUrl(SERVICE) != null);
+ return getProvider().getAuthenticationContext().getServiceUrl(SERVICE) != null;
}
finally {
APITrace.end();
@@ -467,7 +391,7 @@ public void remove(@Nonnull String volumeId) throws InternalException, CloudExce
// ignore
}
}
- NovaMethod method = new NovaMethod(((NovaOpenStack)getProvider()));
+ NovaMethod method = new NovaMethod(getProvider());
method.deleteResource(SERVICE, getResource(), volumeId, null);
@@ -493,7 +417,7 @@ public void remove(@Nonnull String volumeId) throws InternalException, CloudExce
}
}
- private @Nullable ResourceStatus toStatus(@Nullable JSONObject json) throws CloudException, InternalException {
+ protected @Nullable ResourceStatus toStatus(@Nullable JSONObject json) throws CloudException, InternalException {
if( json == null ) {
return null;
}
@@ -534,11 +458,11 @@ else if( status.equals("attaching") ) {
return new ResourceStatus(volumeId, state);
}
catch( JSONException e ) {
- throw new CloudException(e);
+ throw new CommunicationException("Unable to understand toStatus response: " + e.getMessage(), e);
}
}
- private @Nullable Volume toVolume(@Nullable JSONObject json, @Nonnull Iterable types) throws CloudException, InternalException {
+ protected @Nullable Volume toVolume(@Nullable JSONObject json, @Nonnull Iterable types) throws CloudException, InternalException {
if( json == null ) {
return null;
}
@@ -579,10 +503,10 @@ else if( status.equals("attaching") ) {
}
}
- long created = (json.has("createdAt") ? ((NovaOpenStack)getProvider()).parseTimestamp(json.getString("createdAt")) : -1L);
+ long created = (json.has("createdAt") ? (getProvider()).parseTimestamp(json.getString("createdAt")) : -1L);
if( created < 1L ) {
- created = (json.has("created_at") ? ((NovaOpenStack)getProvider()).parseTimestamp(json.getString("created_at")) : -1L);
+ created = (json.has("created_at") ? (getProvider()).parseTimestamp(json.getString("created_at")) : -1L);
}
int size = 0;
@@ -662,7 +586,7 @@ else if( status.equals("attaching") ) {
volume.setProviderSnapshotId(snapshotId);
volume.setProviderVirtualMachineId(vmId);
volume.setProviderVolumeId(volumeId);
- volume.setSize(new Storage(size, Storage.GIGABYTE));
+ volume.setSize(new Storage<>(size, Storage.GIGABYTE));
if( productId != null ) {
VolumeProduct match = null;
@@ -694,7 +618,7 @@ else if( status.equals("attaching") ) {
return volume;
}
catch( JSONException e ) {
- throw new CloudException(e);
+ throw new CommunicationException("Unable to understand toVolume response: " + e.getMessage(), e);
}
}
@@ -702,7 +626,7 @@ else if( status.equals("attaching") ) {
public void setTags(@Nonnull String volumeId, @Nonnull Tag... tags) throws CloudException, InternalException {
APITrace.begin(getProvider(), "Volume.setTags");
try {
- ((NovaOpenStack) getProvider()).createTags( SERVICE, "/volumes", volumeId, tags);
+ getProvider().createTags( SERVICE, "/volumes", volumeId, tags);
}
finally {
APITrace.end();
@@ -720,7 +644,7 @@ public void setTags(@Nonnull String[] volumeIds, @Nonnull Tag... tags) throws Cl
public void updateTags(@Nonnull String volumeId, @Nonnull Tag... tags) throws CloudException, InternalException {
APITrace.begin(getProvider(), "Volume.updateTags");
try {
- ((NovaOpenStack) getProvider()).updateTags( SERVICE, "/volumes", volumeId, tags);
+ getProvider().updateTags( SERVICE, "/volumes", volumeId, tags);
}
finally {
APITrace.end();
@@ -738,7 +662,7 @@ public void updateTags(@Nonnull String[] volumeIds, @Nonnull Tag... tags) throws
public void removeTags(@Nonnull String volumeId, @Nonnull Tag... tags) throws CloudException, InternalException {
APITrace.begin(getProvider(), "Volume.removeTags");
try {
- ((NovaOpenStack) getProvider()).removeTags( SERVICE, "/volumes", volumeId, tags);
+ getProvider().removeTags( SERVICE, "/volumes", volumeId, tags);
}
finally {
APITrace.end();
diff --git a/src/main/java/org/dasein/cloud/openstack/nova/os/compute/NovaImage.java b/src/main/java/org/dasein/cloud/openstack/nova/os/compute/NovaImage.java
index cb1f448..79800a1 100644
--- a/src/main/java/org/dasein/cloud/openstack/nova/os/compute/NovaImage.java
+++ b/src/main/java/org/dasein/cloud/openstack/nova/os/compute/NovaImage.java
@@ -19,23 +19,14 @@
package org.dasein.cloud.openstack.nova.os.compute;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Locale;
+import java.util.*;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.http.HttpStatus;
import org.apache.log4j.Logger;
-import org.dasein.cloud.AsynchronousTask;
-import org.dasein.cloud.CloudErrorType;
-import org.dasein.cloud.CloudException;
-import org.dasein.cloud.InternalException;
-import org.dasein.cloud.Requirement;
-import org.dasein.cloud.ResourceStatus;
-import org.dasein.cloud.Tag;
+import org.dasein.cloud.*;
import org.dasein.cloud.compute.AbstractImageSupport;
import org.dasein.cloud.compute.Architecture;
import org.dasein.cloud.compute.ComputeServices;
@@ -61,20 +52,24 @@
public class NovaImage extends AbstractImageSupport {
static private final Logger logger = NovaOpenStack.getLogger(NovaImage.class, "std");
- private static final String SERVICE = "compute";
+ protected static final String SERVICE = "compute";
NovaImage(NovaOpenStack provider) {
super(provider);
}
- private @Nonnull String getTenantId() throws CloudException, InternalException {
- return ((NovaOpenStack)getProvider()).getContext().getAccountNumber();
+ protected NovaMethod getMethod() {
+ return new NovaMethod(getProvider());
+ }
+
+ protected @Nonnull String getTenantId() throws CloudException, InternalException {
+ return getContext().getAccountNumber();
}
public @Nullable String getImageRef(@Nonnull String machineImageId) throws CloudException, InternalException {
APITrace.begin(getProvider(), "Image.getImageRef");
try {
- NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
+ NovaMethod method = getMethod();
JSONObject ob = method.getServers("/images", machineImageId, true);
if( ob == null ) {
@@ -102,7 +97,7 @@ else if( def == null ) {
}
catch( JSONException e ) {
logger.error("getImageRef(): Unable to identify expected values in JSON: " + e.getMessage());
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for images: " + e.getMessage());
+ throw new CommunicationException("Missing JSON element for images: " + e.getMessage(), e);
}
}
finally {
@@ -114,8 +109,8 @@ else if( def == null ) {
protected MachineImage capture(@Nonnull ImageCreateOptions options, @Nullable AsynchronousTask task) throws CloudException, InternalException {
APITrace.begin(getProvider(), "Image.capture");
try {
- NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
- HashMap action = new HashMap();
+ NovaMethod method = getMethod();
+ Map action = new HashMap<>();
action.put("name", options.getName());
if( task != null ) {
@@ -129,7 +124,7 @@ protected MachineImage capture(@Nonnull ImageCreateOptions options, @Nullable As
while( timeout > System.currentTimeMillis() ) {
try {
- ComputeServices services = getProvider().getComputeServices();
+ ComputeServices services = getComputeServices();
VirtualMachine vm = null;
if( services != null ) {
@@ -140,7 +135,7 @@ protected MachineImage capture(@Nonnull ImageCreateOptions options, @Nullable As
}
}
if( vm == null ) {
- throw new CloudException("No such virtual machine: " + vmId);
+ throw new ResourceNotFoundException("vm", vmId);
}
platform = vm.getPlatform();
if( !VmState.PENDING.equals(vm.getCurrentState()) ) {
@@ -160,9 +155,9 @@ protected MachineImage capture(@Nonnull ImageCreateOptions options, @Nullable As
}
JSONObject result;
- if( ((NovaOpenStack)getProvider()).isPostCactus() ) {
- HashMap json = new HashMap();
- HashMap metaData = new HashMap();
+ if( getProvider().isPostCactus() ) {
+ Map json = new HashMap();
+ Map metaData = new HashMap();
metaData.put("org.dasein.description", options.getDescription());
if( platform != null ) {
@@ -174,7 +169,7 @@ protected MachineImage capture(@Nonnull ImageCreateOptions options, @Nullable As
result = method.postServers("/servers", vmId, new JSONObject(json), true);
}
else {
- HashMap json = new HashMap();
+ Map json = new HashMap();
action.put("serverId", String.valueOf(vmId));
json.put("image", action);
@@ -193,7 +188,7 @@ protected MachineImage capture(@Nonnull ImageCreateOptions options, @Nullable As
}
}
catch( JSONException e ) {
- throw new CloudException(e);
+ throw new CommunicationException("Invalid response", e);
}
}
else if( result != null && result.has("location") ) {
@@ -220,22 +215,26 @@ else if( result != null && result.has("location") ) {
}
}
catch( JSONException e ) {
- throw new CloudException(e);
+ throw new CommunicationException("Invalid response", e);
}
}
logger.error("No image was created by the imaging attempt, and no error was returned");
- throw new CloudException("No image was created");
+ throw new GeneralCloudException("No image was created", CloudErrorType.GENERAL);
}
finally {
APITrace.end();
}
}
+ protected ComputeServices getComputeServices() {
+ return getProvider().getComputeServices();
+ }
+
private transient volatile NovaImageCapabilities capabilities;
@Override
public ImageCapabilities getCapabilities() throws CloudException, InternalException {
if( capabilities == null ) {
- capabilities = new NovaImageCapabilities((NovaOpenStack)getProvider());
+ capabilities = new NovaImageCapabilities(getProvider());
}
return capabilities;
}
@@ -244,7 +243,7 @@ public ImageCapabilities getCapabilities() throws CloudException, InternalExcept
public MachineImage getImage(@Nonnull String providerImageId) throws CloudException, InternalException {
APITrace.begin(getProvider(), "Image.getImage");
try {
- NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
+ NovaMethod method = getMethod();
JSONObject ob = method.getServers("/images", providerImageId, true);
if( ob == null ) {
@@ -262,7 +261,7 @@ public MachineImage getImage(@Nonnull String providerImageId) throws CloudExcept
}
catch( JSONException e ) {
logger.error("getMachineImage(): Unable to identify expected values in JSON: " + e.getMessage());
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for images: " + e.getMessage());
+ throw new CommunicationException("Missing JSON element for images: " + e.getMessage(), e);
}
return null;
}
@@ -271,21 +270,6 @@ public MachineImage getImage(@Nonnull String providerImageId) throws CloudExcept
}
}
- @Override
- public @Nonnull String getProviderTermForImage(@Nonnull Locale locale, @Nonnull ImageClass cls) {
- switch( cls ) {
- case MACHINE: return "machine image";
- case KERNEL: return "kernel image";
- case RAMDISK: return "ramdisk image";
- }
- return "image";
- }
-
- @Override
- public boolean hasPublicLibrary() {
- return true;
- }
-
@Override
public boolean isImageSharedWithPublic(@Nonnull String machineImageId) throws CloudException, InternalException {
APITrace.begin(getProvider(), "Image.isImageSharedWithPublic");
@@ -318,9 +302,9 @@ public boolean isSubscribed() throws CloudException, InternalException {
if( !cls.equals(ImageClass.MACHINE) ) {
return Collections.emptyList();
}
- NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
+ NovaMethod method = new NovaMethod(getProvider());
JSONObject ob = method.getServers("/images", null, true);
- ArrayList images = new ArrayList();
+ List images = new ArrayList<>();
try {
if( ob != null && ob.has("images") ) {
@@ -338,7 +322,7 @@ public boolean isSubscribed() throws CloudException, InternalException {
}
}
catch( JSONException e ) {
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for images: " + e.getMessage());
+ throw new CommunicationException("Missing JSON element for images: " + e.getMessage(), e);
}
return images;
}
@@ -363,7 +347,7 @@ public boolean isSubscribed() throws CloudException, InternalException {
}
NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
JSONObject ob = method.getServers("/images", null, true);
- ArrayList images = new ArrayList();
+ List images = new ArrayList();
try {
if( ob != null && ob.has("images") ) {
@@ -380,7 +364,7 @@ public boolean isSubscribed() throws CloudException, InternalException {
}
}
catch( JSONException e ) {
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for images: " + e.getMessage());
+ throw new CommunicationException("Missing JSON element for images: " + e.getMessage(), e);
}
return images;
}
@@ -393,7 +377,7 @@ public boolean isSubscribed() throws CloudException, InternalException {
public void remove(@Nonnull String providerImageId, boolean checkState) throws CloudException, InternalException {
APITrace.begin(getProvider(), "Image.remove");
try {
- NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
+ NovaMethod method = new NovaMethod(getProvider());
long timeout = System.currentTimeMillis() + CalendarWrapper.HOUR;
do {
@@ -418,9 +402,9 @@ public void remove(@Nonnull String providerImageId, boolean checkState) throws C
public @Nonnull Iterable searchPublicImages(@Nonnull ImageFilterOptions options) throws InternalException, CloudException {
APITrace.begin(getProvider(), "Image.searchPublicImages");
try {
- NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
+ NovaMethod method = new NovaMethod(getProvider());
JSONObject ob = method.getServers("/images", null, true);
- ArrayList images = new ArrayList();
+ List images = new ArrayList<>();
String me = getTenantId();
try {
@@ -438,7 +422,7 @@ public void remove(@Nonnull String providerImageId, boolean checkState) throws C
}
}
catch( JSONException e ) {
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for images: " + e.getMessage());
+ throw new CommunicationException("Missing JSON element for images: " + e.getMessage(), e);
}
return images;
}
@@ -447,14 +431,7 @@ public void remove(@Nonnull String providerImageId, boolean checkState) throws C
}
}
- @Override
- public boolean supportsCustomImages() {
- return true;
- }
-
- public @Nullable MachineImage toImage(@Nullable JSONObject json) throws CloudException, InternalException {
- Logger logger = NovaOpenStack.getLogger(NovaImage.class, "std");
-
+ protected @Nullable MachineImage toImage(@Nullable JSONObject json) throws CloudException, InternalException {
if( logger.isTraceEnabled() ) {
logger.trace("enter - " + NovaImage.class.getName() + ".toImage(" + json + ")");
}
@@ -470,7 +447,7 @@ public boolean supportsCustomImages() {
JSONObject md = (json.has("metadata") ? json.getJSONObject("metadata") : null);
Architecture architecture = Architecture.I64;
Platform platform = Platform.UNKNOWN;
- String owner = ((NovaOpenStack)getProvider()).getCloudProvider().getDefaultImageOwner(getTenantId());
+ String owner = getProvider().getCloudProvider().getDefaultImageOwner(getTenantId());
if( md != null ) {
if( description == null && md.has("org.dasein.description") ) {
@@ -529,7 +506,7 @@ else if( md.has("image_type") && !md.isNull("image_type") && md.getString("image
owner = getTenantId();
}
}
- long created = (json.has("created") ? ((NovaOpenStack)getProvider()).parseTimestamp(json.getString("created")) : -1L);
+ long created = (json.has("created") ? getProvider().parseTimestamp(json.getString("created")) : -1L);
MachineImageState currentState = MachineImageState.PENDING;
@@ -589,17 +566,17 @@ else if( platform.equals(Platform.UNIX) ) {
}
}
}
- boolean bMinSize = false;
- if(json.has("minDisk")){
- bMinSize = true;
- image.setTag("minDisk", json.getString("minDisk"));
+ if( json.has("minDisk") ){
+ image.setMinimumDiskSizeGb(json.getLong("minDisk"));
+ }
+ else if( json.has("OS-EXT-IMG-SIZE:size") ) {
+ image.setMinimumDiskSizeGb(json.getLong("OS-EXT-IMG-SIZE:size"));
}
- if(!bMinSize)if(json.has("OS-EXT-IMG-SIZE:size"))image.setTag("minSize", json.getString("OS-EXT-IMG-SIZE:size"));
return image;
}
catch( JSONException e ) {
- throw new CloudException(e);
+ throw new CommunicationException("Invalid response", e);
}
}
finally {
@@ -609,12 +586,12 @@ else if( platform.equals(Platform.UNIX) ) {
}
}
- public @Nullable ResourceStatus toStatus(@Nullable JSONObject json) throws CloudException, InternalException {
+ protected @Nullable ResourceStatus toStatus(@Nullable JSONObject json) throws CloudException, InternalException {
if( json == null ) {
return null;
}
- String owner = ((NovaOpenStack)getProvider()).getCloudProvider().getDefaultImageOwner(getTenantId());
+ String owner = getProvider().getCloudProvider().getDefaultImageOwner(getTenantId());
MachineImageState state = MachineImageState.PENDING;
String id = null;
@@ -657,7 +634,7 @@ else if( s.equals("failed") ) {
}
}
catch( JSONException e ) {
- throw new InternalException(e);
+ throw new CommunicationException("Unable to parse", e);
}
if( !owner.equals(getTenantId()) ) {
return null;
diff --git a/src/main/java/org/dasein/cloud/openstack/nova/os/compute/NovaServer.java b/src/main/java/org/dasein/cloud/openstack/nova/os/compute/NovaServer.java
index 86fe610..4df10c7 100644
--- a/src/main/java/org/dasein/cloud/openstack/nova/os/compute/NovaServer.java
+++ b/src/main/java/org/dasein/cloud/openstack/nova/os/compute/NovaServer.java
@@ -81,7 +81,7 @@ public class NovaServer extends AbstractVMSupport {
}
@Nonnull protected String getTenantId() throws CloudException, InternalException {
- return getProvider().getContext().getAccountNumber();
+ return getContext().getAccountNumber();
}
private transient volatile NovaServerCapabilities capabilities;
@@ -159,9 +159,9 @@ protected Platform getPlatform(String vmName, String vmDescription, String image
VirtualMachine vm = getVirtualMachine(vmId);
if( vm == null ) {
- throw new CloudException("No such virtual machine: " + vmId);
+ throw new ResourceNotFoundException("vm", vmId);
}
- Map json = new HashMap();
+ Map json = new HashMap<>();
json.put("os-getConsoleOutput", new HashMap());
@@ -247,7 +247,7 @@ protected OpenStackProvider getCloudProvider() {
}
catch( JSONException e ) {
logger.error("getVirtualMachine(): Unable to identify expected values in JSON: " + e.getMessage());
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for servers");
+ throw new CommunicationException("Missing JSON element for servers", e);
}
return null;
}
@@ -263,7 +263,7 @@ protected OpenStackProvider getCloudProvider() {
return ob.getJSONObject("server").getString("status");
}
catch( JSONException e ) {
- throw new CloudException(e);
+ throw new CommunicationException("Unable to parse the server status response", e);
}
finally {
APITrace.end();
@@ -274,8 +274,8 @@ protected OpenStackProvider getCloudProvider() {
public @Nonnull VirtualMachine alterVirtualMachineProduct(@Nonnull String virtualMachineId, @Nonnull String productId) throws InternalException, CloudException {
APITrace.begin(getProvider(), "VM.resize");
try {
- Map json = new HashMap();
- Map action = new HashMap();
+ Map json = new HashMap<>();
+ Map action = new HashMap<>();
action.put("flavorRef", productId);
json.put("resize", action);
@@ -296,7 +296,8 @@ protected OpenStackProvider getCloudProvider() {
}
VirtualMachine vm = getVirtualMachine(virtualMachineId);
if( status.equals("ACTIVE") && !( vm.getProductId().equals(productId) ) ) {
- throw new CloudException("Failed to resize VM from " + getProduct(vm.getProductId()).getName() + " to " + getProduct(productId).getName());
+ throw new GeneralCloudException("Failed to resize VM from " + getProduct(vm.getProductId()).getName() + " to " + getProduct(productId).getName(),
+ CloudErrorType.GENERAL);
}
return vm;
}
@@ -363,7 +364,7 @@ protected void prepareVlanForLaunch(VMLaunchOptions options, Map
}
catch (CloudException e) {
if (e.getHttpCode() != 403) {
- throw new CloudException(e.getMessage());
+ throw e;
}
logger.warn("Unable to create port - trying to launch into general network");
@@ -385,7 +386,7 @@ protected void prepareVlanForLaunch(VMLaunchOptions options, Map
try {
MachineImage targetImage = getImage(options.getMachineImageId());
if( targetImage == null ) {
- throw new CloudException("No such machine image: " + options.getMachineImageId());
+ throw new ResourceNotFoundException("machine image: ", options.getMachineImageId());
}
//Additional LPAR Call
boolean isBareMetal = isBareMetal(options.getMachineImageId());
@@ -480,21 +481,18 @@ protected void prepareVlanForLaunch(VMLaunchOptions options, Map
vm = getVirtualMachine(vmId);
}
if( vm == null || vm.getCurrentState() == null ) {
- throw new CloudException("VM failed to launch with a meaningful status");
+ throw new GeneralCloudException("VM failed to launch with a meaningful status", CloudErrorType.GENERAL);
}
return vm;
}
}
catch( JSONException e ) {
logger.error("launch(): Unable to understand launch response: " + e.getMessage());
- if( logger.isTraceEnabled() ) {
- e.printStackTrace();
- }
- throw new CloudException(e);
+ throw new CommunicationException("Invalid response", e);
}
}
logger.error("launch(): No server was created by the launch attempt, and no error was returned");
- throw new CloudException("No virtual machine was launched");
+ throw new GeneralCloudException("No virtual machine was launched", CloudErrorType.GENERAL);
}
finally {
@@ -554,7 +552,7 @@ public static int roundUpToGB(Long size) {
firewalls = Collections.emptyList();
}
JSONArray groups = server.getJSONArray("security_groups");
- List results = new ArrayList();
+ List results = new ArrayList<>();
for( int i=0; i results = new ArrayList();
+ List results = new ArrayList<>();
JSONObject ob = getMethod().getServers("/os-security-groups/servers", vmId + "/os-security-groups", true);
@@ -599,8 +597,8 @@ else if( name.equals(fw.getName()) ) {
}
}
catch( JSONException e ) {
- throw new CloudException(e);
- }
+ logger.error("Unable to understand listFirewalls response: " + e.getMessage());
+ throw new CommunicationException("Unable to understand listFirewalls response: " + e.getMessage(), e); }
}
@Override
@@ -618,11 +616,11 @@ else if( name.equals(fw.getName()) ) {
return listFirewalls(vmId, server);
}
- throw new CloudException("No such server: " + vmId);
+ throw new ResourceNotFoundException("server", vmId);
}
catch( JSONException e ) {
logger.error("listFirewalls(): Unable to identify expected values in JSON: " + e.getMessage());
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for servers");
+ throw new CommunicationException("Unable to understand listFirewalls response: " + e.getMessage(), e);
}
}
finally {
@@ -659,7 +657,7 @@ protected void cacheFlavors(Iterable refs) throws InternalException {
}
JSONObject ob = getMethod().getServers("/flavors", null, true);
- List flavors = new ArrayList();
+ List flavors = new ArrayList<>();
try {
if( ob != null && ob.has("flavors") ) {
@@ -703,7 +701,7 @@ protected void cacheFlavors(Iterable refs) throws InternalException {
}
catch( JSONException e ) {
logger.error("listProducts(): Unable to identify expected values in JSON: " + e.getMessage());
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for flavors: " + e.getMessage());
+ throw new CommunicationException("Unable to understand listProducts response: " + e.getMessage(), e);
}
cacheFlavors(flavors);
return flavors;
@@ -742,7 +740,7 @@ else if( def == null && link[1] != null ) {
APITrace.begin(getProvider(), "VM.listProducts");
try {
- List products = new ArrayList();
+ List products = new ArrayList<>();
for( FlavorRef flavor : listFlavors() ) {
if (options != null) {
@@ -766,7 +764,7 @@ else if( def == null && link[1] != null ) {
APITrace.begin(getProvider(), "VM.listVirtualMachineStatus");
try {
JSONObject ob = getMethod().getServers("/servers", null, true);
- List servers = new ArrayList();
+ List servers = new ArrayList<>();
try {
if( ob != null && ob.has("servers") ) {
@@ -779,13 +777,12 @@ else if( def == null && link[1] != null ) {
if( vm != null ) {
servers.add(vm);
}
-
}
}
}
catch( JSONException e ) {
- logger.error("listVirtualMachines(): Unable to identify expected values in JSON: " + e.getMessage()); e.printStackTrace();
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for servers in " + ob.toString());
+ logger.error("listVirtualMachines(): Unable to identify expected values in JSON: " + e.getMessage());
+ throw new CommunicationException("Unable to understand listVirtualMachines response: " + e.getMessage(), e);
}
return servers;
}
@@ -799,7 +796,7 @@ else if( def == null && link[1] != null ) {
APITrace.begin(getProvider(), "VM.listVirtualMachines");
try {
JSONObject ob = getMethod().getServers("/servers", null, true);
- List servers = new ArrayList();
+ List servers = new ArrayList<>();
Iterable ipv4 = Collections.emptyList(), ipv6 = Collections.emptyList();
Iterable nets = Collections.emptyList();
@@ -831,8 +828,8 @@ else if( def == null && link[1] != null ) {
}
}
catch( JSONException e ) {
- logger.error("listVirtualMachines(): Unable to identify expected values in JSON: " + e.getMessage()); e.printStackTrace();
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for servers in " + ob.toString());
+ logger.error("listVirtualMachines(): Unable to identify expected values in JSON: " + e.getMessage());
+ throw new CommunicationException("Unable to understand listVirtualMachines response: " + e.getMessage(), e);
}
return servers;
}
@@ -848,12 +845,12 @@ public void pause(@Nonnull String vmId) throws InternalException, CloudException
VirtualMachine vm = getVirtualMachine(vmId);
if( vm == null ) {
- throw new CloudException("No such virtual machine: " + vmId);
+ throw new ResourceNotFoundException("vm", vmId);
}
if( !getCapabilities().supportsPause() ) {
throw new OperationNotSupportedException("Pause/unpause is not supported in " + getProvider().getCloudName());
}
- Map json = new HashMap();
+ Map json = new HashMap<>();
json.put("pause", null);
@@ -871,12 +868,12 @@ public void resume(@Nonnull String vmId) throws InternalException, CloudExceptio
VirtualMachine vm = getVirtualMachine(vmId);
if( vm == null ) {
- throw new CloudException("No such virtual machine: " + vmId);
+ throw new ResourceNotFoundException("vm", vmId);
}
if( !getCapabilities().supportsResume() ) {
throw new OperationNotSupportedException("Suspend/resume is not supported in " + getProvider().getCloudName());
}
- Map json = new HashMap();
+ Map json = new HashMap<>();
json.put("resume", null);
@@ -894,12 +891,12 @@ public void start(@Nonnull String vmId) throws InternalException, CloudException
VirtualMachine vm = getVirtualMachine(vmId);
if( vm == null ) {
- throw new CloudException("No such virtual machine: " + vmId);
+ throw new ResourceNotFoundException("vm", vmId);
}
if( !getCapabilities().supportsStart() ) {
throw new OperationNotSupportedException("Start/stop is not supported in " + getProvider().getCloudName());
}
- Map json = new HashMap();
+ Map json = new HashMap<>();
json.put("os-start", null);
@@ -917,12 +914,12 @@ public void stop(@Nonnull String vmId, boolean force) throws InternalException,
VirtualMachine vm = getVirtualMachine(vmId);
if( vm == null ) {
- throw new CloudException("No such virtual machine: " + vmId);
+ throw new ResourceNotFoundException("vm", vmId);
}
if( !getCapabilities().supportsStop() ) {
throw new OperationNotSupportedException("Start/stop is not supported in " + getProvider().getCloudName());
}
- Map json = new HashMap();
+ Map json = new HashMap<>();
json.put("os-stop", null);
@@ -940,12 +937,12 @@ public void suspend(@Nonnull String vmId) throws InternalException, CloudExcepti
VirtualMachine vm = getVirtualMachine(vmId);
if( vm == null ) {
- throw new CloudException("No such virtual machine: " + vmId);
+ throw new ResourceNotFoundException("vm", vmId);
}
if( !getCapabilities().supportsSuspend() ) {
throw new OperationNotSupportedException("Suspend/resume is not supported in " + getProvider().getCloudName());
}
- Map json = new HashMap();
+ Map json = new HashMap<>();
json.put("suspend", null);
@@ -963,12 +960,12 @@ public void unpause(@Nonnull String vmId) throws InternalException, CloudExcepti
VirtualMachine vm = getVirtualMachine(vmId);
if( vm == null ) {
- throw new CloudException("No such virtual machine: " + vmId);
+ throw new ResourceNotFoundException("vm", vmId);
}
if( !getCapabilities().supportsUnPause() ) {
throw new OperationNotSupportedException("Pause/unpause is not supported in " + getProvider().getCloudName());
}
- Map json = new HashMap();
+ Map json = new HashMap<>();
json.put("unpause", null);
@@ -983,8 +980,8 @@ public void unpause(@Nonnull String vmId) throws InternalException, CloudExcepti
public void reboot(@Nonnull String vmId) throws CloudException, InternalException {
APITrace.begin(getProvider(), "VM.reboot");
try {
- Map json = new HashMap();
- Map action = new HashMap();
+ Map json = new HashMap<>();
+ Map action = new HashMap<>();
action.put("type", "HARD");
json.put("reboot", action);
@@ -1056,10 +1053,10 @@ public void terminate(@Nonnull String vmId, @Nullable String explanation) throws
product.setDescription(json.getString("description"));
}
if( json.has("ram") ) {
- product.setRamSize(new Storage(json.getInt("ram"), Storage.MEGABYTE));
+ product.setRamSize(new Storage<>(json.getInt("ram"), Storage.MEGABYTE));
}
if( json.has("disk") ) {
- product.setRootVolumeSize(new Storage(json.getInt("disk"), Storage.GIGABYTE));
+ product.setRootVolumeSize(new Storage<>(json.getInt("disk"), Storage.GIGABYTE));
}
product.setCpuCount(1);
@@ -1177,12 +1174,12 @@ else if( s.equals("reboot") || s.equals("hard_reboot") ) {
}
JSONObject md = (server.has("metadata") && !server.isNull("metadata")) ? server.getJSONObject("metadata") : null;
- Map map = new HashMap();
+ Map map = new HashMap<>();
boolean imaging = false;
if( md != null ) {
if( md.has("org.dasein.description") && vm.getDescription() == null ) {
- description = md.getString("org.dasein.description");
+ description = md.getString("org.dasein.description");
}
else if( md.has("Server Label") ) {
description = md.getString("Server Label");
@@ -1311,8 +1308,8 @@ else if( s.equals("reboot") || s.equals("hard_reboot") ) {
String[] names = JSONObject.getNames(addrs);
if( names != null && names.length > 0 ) {
- List pub = new ArrayList();
- List priv = new ArrayList();
+ List pub = new ArrayList<>();
+ List priv = new ArrayList<>();
for( String name : names ) {
JSONArray arr = addrs.getJSONArray(name);
diff --git a/src/main/java/org/dasein/cloud/openstack/nova/os/ext/hp/cdn/HPCDN.java b/src/main/java/org/dasein/cloud/openstack/nova/os/ext/hp/cdn/HPCDN.java
index 65b0ddd..7c748c3 100644
--- a/src/main/java/org/dasein/cloud/openstack/nova/os/ext/hp/cdn/HPCDN.java
+++ b/src/main/java/org/dasein/cloud/openstack/nova/os/ext/hp/cdn/HPCDN.java
@@ -20,11 +20,7 @@
package org.dasein.cloud.openstack.nova.os.ext.hp.cdn;
import org.apache.log4j.Logger;
-import org.dasein.cloud.CloudErrorType;
-import org.dasein.cloud.CloudException;
-import org.dasein.cloud.InternalException;
-import org.dasein.cloud.ProviderContext;
-import org.dasein.cloud.ResourceStatus;
+import org.dasein.cloud.*;
import org.dasein.cloud.identity.ServiceAction;
import org.dasein.cloud.openstack.nova.os.NovaMethod;
import org.dasein.cloud.openstack.nova.os.NovaOpenStack;
@@ -181,8 +177,7 @@ public boolean isSubscribed() throws InternalException, CloudException {
}
catch( IOException e ) {
logger.error("list(): I/O error parsing response: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidResponse", "I/O error parsing " + response);
+ throw new CommunicationException("I/O error parsing " + response);
}
return distributions;
}
@@ -214,8 +209,7 @@ public boolean isSubscribed() throws InternalException, CloudException {
}
}
catch( IOException e ) {
- e.printStackTrace();
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidResponse", "I/O error parsing " + response);
+ throw new CommunicationException("I/O error parsing " + response);
}
return distributions;
}
@@ -289,7 +283,7 @@ else if( key.equalsIgnoreCase("X-CDN-URI") ) {
}
}
catch( URISyntaxException e ) {
- throw new CloudException(e);
+ throw new GeneralCloudException("Unable to parse the service URL from " + uriString, CloudErrorType.GENERAL);
}
Distribution distribution = new Distribution();
diff --git a/src/main/java/org/dasein/cloud/openstack/nova/os/ext/hp/db/HPRDBMS.java b/src/main/java/org/dasein/cloud/openstack/nova/os/ext/hp/db/HPRDBMS.java
index c354f7c..eb7c098 100644
--- a/src/main/java/org/dasein/cloud/openstack/nova/os/ext/hp/db/HPRDBMS.java
+++ b/src/main/java/org/dasein/cloud/openstack/nova/os/ext/hp/db/HPRDBMS.java
@@ -20,11 +20,7 @@
package org.dasein.cloud.openstack.nova.os.ext.hp.db;
import org.apache.log4j.Logger;
-import org.dasein.cloud.CloudErrorType;
-import org.dasein.cloud.CloudException;
-import org.dasein.cloud.InternalException;
-import org.dasein.cloud.ProviderContext;
-import org.dasein.cloud.ResourceStatus;
+import org.dasein.cloud.*;
import org.dasein.cloud.identity.ServiceAction;
import org.dasein.cloud.openstack.nova.os.NovaMethod;
import org.dasein.cloud.openstack.nova.os.NovaOpenStack;
@@ -57,22 +53,15 @@ public class HPRDBMS extends AbstractRelationalDatabaseSupport {
public HPRDBMS(NovaOpenStack provider) { super(provider); }
private @Nonnull String getTenantId() throws CloudException, InternalException {
- return getProvider().getContext().getAccountNumber();
+ return getContext().getAccountNumber();
}
@Override
public @Nonnull String createFromScratch(@Nonnull String dataSourceName, @Nonnull DatabaseProduct product, @Nonnull String databaseVersion, @Nonnull String withAdminUser, @Nonnull String withAdminPassword, int hostPort) throws CloudException, InternalException {
APITrace.begin(getProvider(), "RDBMS.createFromScratch");
try {
- ProviderContext ctx = getProvider().getContext();
-
- if( ctx == null ) {
- logger.error("No context exists for this request");
- throw new InternalException("No context exists for this request");
- }
-
- Map wrapper = new HashMap();
- Map json = new HashMap();
+ Map wrapper = new HashMap<>();
+ Map json = new HashMap<>();
NovaMethod method = new NovaMethod(getProvider());
json.put("flavorRef", getFlavorRef(product.getProductSize()));
@@ -80,7 +69,7 @@ public class HPRDBMS extends AbstractRelationalDatabaseSupport {
json.put("name", dataSourceName);
json.put("port", hostPort > 0 ? hostPort : 3306);
if( product.getEngine().equals(DatabaseEngine.MYSQL) ) {
- Map type = new HashMap();
+ Map type = new HashMap<>();
type.put("name", "mysql");
if( databaseVersion != null ) {
@@ -99,14 +88,14 @@ else if( product.getEngine().equals(DatabaseEngine.MYSQL50) ) {
json.put("dbtype", type);
}
else {
- throw new CloudException("Unsupported database product: " + product);
+ throw new InternalException("Unsupported database product: " + product);
}
wrapper.put("instance", json);
JSONObject result = method.postString(SERVICE, RESOURCE, null, new JSONObject(wrapper), true);
if( result != null && result.has("instance") ) {
try {
- Database db = toDatabase(ctx, result.getJSONObject("instance"));
+ Database db = toDatabase(result.getJSONObject("instance"));
if( db != null ) {
return db.getProviderDatabaseId();
@@ -114,12 +103,11 @@ else if( product.getEngine().equals(DatabaseEngine.MYSQL50) ) {
}
catch( JSONException e ) {
logger.error("createFromScratch(): Unable to understand create response: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Unable to understand create response: " + e.getMessage(), e);
}
}
logger.error("createFromScratch(): No database was created by the create attempt, and no error was returned");
- throw new CloudException("No database was created");
+ throw new GeneralCloudException("No database was created", CloudErrorType.GENERAL);
}
finally {
@@ -139,7 +127,7 @@ public String createFromLatest(String dataSourceName, String providerDatabaseId,
}
}
if( snapshot == null ) {
- throw new CloudException("No snapshots exist from which to create a new database instance");
+ throw new InternalException("No snapshots exist from which to create a new database instance");
}
return createFromSnapshot(dataSourceName, providerDatabaseId, snapshot.getProviderSnapshotId(), productSize, providerDataCenterId, hostPort);
}
@@ -152,15 +140,8 @@ public String createFromLatest(String dataSourceName, String providerDatabaseId,
public String createFromSnapshot(String dataSourceName, String providerDatabaseId, String providerDbSnapshotId, String productSize, String providerDataCenterId, int hostPort) throws CloudException, InternalException {
APITrace.begin(getProvider(), "RDBMS.createFromSnapshot");
try {
- ProviderContext ctx = getProvider().getContext();
-
- if( ctx == null ) {
- logger.error("No context exists for this request");
- throw new InternalException("No context exists for this request");
- }
-
- Map wrapper = new HashMap();
- Map json = new HashMap();
+ Map wrapper = new HashMap<>();
+ Map json = new HashMap<>();
NovaMethod method = new NovaMethod(getProvider());
json.put("flavorRef", getFlavorRef(productSize));
@@ -174,7 +155,7 @@ public String createFromSnapshot(String dataSourceName, String providerDatabaseI
if( result != null && result.has("instance") ) {
try {
- Database db = toDatabase(ctx, result.getJSONObject("instance"));
+ Database db = toDatabase(result.getJSONObject("instance"));
if( db != null ) {
return db.getProviderDatabaseId();
@@ -182,12 +163,11 @@ public String createFromSnapshot(String dataSourceName, String providerDatabaseI
}
catch( JSONException e ) {
logger.error("createFromSnapshot(): Unable to understand create response: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Unable to understand create response: " + e.getMessage(), e);
}
}
logger.error("createFromSnapshot(): No database was created by the create attempt, and no error was returned");
- throw new CloudException("No database was created");
+ throw new GeneralCloudException("No database was created", CloudErrorType.GENERAL);
}
finally {
@@ -207,7 +187,7 @@ public String createFromTimestamp(String dataSourceName, String providerDatabase
}
}
if( snapshot == null ) {
- throw new CloudException("No snapshots exist from which to create a new database instance");
+ throw new InternalException("No snapshots exist from which to create a new database instance");
}
return createFromSnapshot(dataSourceName, providerDatabaseId, snapshot.getProviderSnapshotId(), productSize, providerDataCenterId, hostPort);
}
@@ -235,12 +215,6 @@ public RelationalDatabaseCapabilities getCapabilities() throws InternalException
public @Nullable Database getDatabase(@Nonnull String providerDatabaseId) throws CloudException, InternalException {
APITrace.begin(getProvider(), "RDBMS.getDatabase");
try {
- ProviderContext ctx = getProvider().getContext();
-
- if( ctx == null ) {
- logger.error("No context exists for this request");
- throw new InternalException("No context exists for this request");
- }
NovaMethod method = new NovaMethod(getProvider());
JSONObject ob = method.getResource(SERVICE, RESOURCE, providerDatabaseId, false);
@@ -249,12 +223,12 @@ public RelationalDatabaseCapabilities getCapabilities() throws InternalException
}
try {
if( ob.has("instance") ) {
- return toDatabase(ctx, ob.getJSONObject("instance"));
+ return toDatabase(ob.getJSONObject("instance"));
}
}
catch( JSONException e ) {
logger.error("getDatabase(): Unable to identify expected values in JSON: " + e.getMessage());
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for instance");
+ throw new CommunicationException("Unable to understand create response: " + e.getMessage(), e);
}
return null;
}
@@ -308,17 +282,11 @@ public Iterable getDatabaseProducts(DatabaseEngine forEngine) t
std.trace("ENTER: " + HPRDBMS.class.getName() + ".getDatabaseProducts()");
}
try {
- ProviderContext ctx = getProvider().getContext();
-
- if( ctx == null ) {
- std.error("No context exists for this request");
- throw new InternalException("No context exists for this request");
- }
NovaMethod method = new NovaMethod(getProvider());
JSONObject json = method.getResource(SERVICE, "/flavors", null, false);
- List products = new ArrayList();
+ List products = new ArrayList<>();
if( json != null && json.has("flavors") ) {
try {
@@ -329,7 +297,7 @@ public Iterable getDatabaseProducts(DatabaseEngine forEngine) t
if( flavor != null ) {
for( int size : new int[] { 2, 5, 10, 20, 25, 30, 40, 50, 60, 70, 80, 90, 100, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900, 1000 } ) {
- DatabaseProduct product = toProduct(ctx, size, flavor);
+ DatabaseProduct product = toProduct(size, flavor);
if( product != null ) {
products.add(product);
@@ -340,8 +308,7 @@ public Iterable getDatabaseProducts(DatabaseEngine forEngine) t
}
catch( JSONException e ) {
std.error("getDatabaseProducts(): Unable to identify expected values in JSON: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for flavors in " + json.toString());
+ throw new CommunicationException("Unable to identify expected values in JSON: " + e.getMessage(), e);
}
}
return products;
@@ -360,23 +327,15 @@ public Iterable getDatabaseProducts(DatabaseEngine forEngine) t
@Override
public Iterable listDatabaseProducts(DatabaseEngine databaseEngine) throws CloudException, InternalException {
if( DatabaseEngine.MYSQL.equals(databaseEngine) ) {
- Logger std = NovaOpenStack.getLogger(HPRDBMS.class, "std");
-
- if( std.isTraceEnabled() ) {
- std.trace("ENTER: " + HPRDBMS.class.getName() + ".getDatabaseProducts()");
+ if( logger.isTraceEnabled() ) {
+ logger.trace("ENTER: " + HPRDBMS.class.getName() + ".getDatabaseProducts()");
}
try {
- ProviderContext ctx = getProvider().getContext();
-
- if( ctx == null ) {
- std.error("No context exists for this request");
- throw new InternalException("No context exists for this request");
- }
NovaMethod method = new NovaMethod(getProvider());
JSONObject json = method.getResource(SERVICE, "/flavors", null, false);
- List products = new ArrayList();
+ List products = new ArrayList<>();
if( json != null && json.has("flavors") ) {
try {
@@ -387,7 +346,7 @@ public Iterable listDatabaseProducts(DatabaseEngine databaseEng
if( flavor != null ) {
for( int size : new int[] { 2, 5, 10, 20, 25, 30, 40, 50, 60, 70, 80, 90, 100, 150, 200, 250, 300, 400, 500, 600, 700, 800, 900, 1000 } ) {
- DatabaseProduct product = toProduct(ctx, size, flavor);
+ DatabaseProduct product = toProduct(size, flavor);
if( product != null ) {
products.add(product);
@@ -397,16 +356,15 @@ public Iterable listDatabaseProducts(DatabaseEngine databaseEng
}
}
catch( JSONException e ) {
- std.error("getDatabaseProducts(): Unable to identify expected values in JSON: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for flavors in " + json.toString());
+ logger.error("getDatabaseProducts(): Unable to identify expected values in JSON: " + e.getMessage());
+ throw new CommunicationException("Unable to identify expected values in JSON: " + e.getMessage(), e);
}
}
return products;
}
finally {
- if( std.isTraceEnabled() ) {
- std.trace("exit - " + HPRDBMS.class.getName() + ".getDatabaseProducts()");
+ if( logger.isTraceEnabled() ) {
+ logger.trace("exit - " + HPRDBMS.class.getName() + ".getDatabaseProducts()");
}
}
}
@@ -416,18 +374,10 @@ public Iterable listDatabaseProducts(DatabaseEngine databaseEng
}
private @Nullable String getFlavorRef(@Nonnull String productId) throws CloudException, InternalException {
- Logger std = NovaOpenStack.getLogger(HPRDBMS.class, "std");
-
- if( std.isTraceEnabled() ) {
- std.trace("ENTER: " + HPRDBMS.class.getName() + ".getFlavorRef(" + productId + ")");
+ if( logger.isTraceEnabled() ) {
+ logger.trace("ENTER: " + HPRDBMS.class.getName() + ".getFlavorRef(" + productId + ")");
}
try {
- ProviderContext ctx = getProvider().getContext();
-
- if( ctx == null ) {
- std.error("No context exists for this request");
- throw new InternalException("No context exists for this request");
- }
int idx = productId.indexOf(":");
if( idx > -1 ) {
@@ -460,16 +410,15 @@ public Iterable listDatabaseProducts(DatabaseEngine databaseEng
}
}
catch( JSONException e ) {
- std.error("getFlavorRef(): Unable to identify expected values in JSON: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for flavors in " + json.toString());
+ logger.error("getFlavorRef(): Unable to identify expected values in JSON: " + e.getMessage());
+ throw new CommunicationException("Unable to identify expected values in JSON: " + e.getMessage(), e);
}
}
return null;
}
finally {
- if( std.isTraceEnabled() ) {
- std.trace("exit - " + HPRDBMS.class.getName() + ".getFlavorRef()");
+ if( logger.isTraceEnabled() ) {
+ logger.trace("exit - " + HPRDBMS.class.getName() + ".getFlavorRef()");
}
}
}
@@ -478,12 +427,6 @@ public Iterable listDatabaseProducts(DatabaseEngine databaseEng
public DatabaseSnapshot getSnapshot(String providerDbSnapshotId) throws CloudException, InternalException {
APITrace.begin(getProvider(), "RDBMS.getSnapshot");
try {
- ProviderContext ctx = getProvider().getContext();
-
- if( ctx == null ) {
- logger.error("No context exists for this request");
- throw new InternalException("No context exists for this request");
- }
NovaMethod method = new NovaMethod(getProvider());
JSONObject ob = method.getResource(SERVICE, SNAPSHOTS, providerDbSnapshotId, false);
@@ -492,12 +435,12 @@ public DatabaseSnapshot getSnapshot(String providerDbSnapshotId) throws CloudExc
}
try {
if( ob.has("snapshot") ) {
- return toSnapshot(ctx, ob.getJSONObject("snapshot"));
+ return toSnapshot(ob.getJSONObject("snapshot"));
}
}
catch( JSONException e ) {
logger.error("getSnapshot(): Unable to identify expected values in JSON: " + e.getMessage());
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for snapshots");
+ throw new CommunicationException("Unable to identify expected values in JSON: " + e.getMessage(), e);
}
return null;
}
@@ -532,7 +475,7 @@ public Iterable listConfigurations() throws CloudExceptio
APITrace.begin(getProvider(), "RDBMS.listDatabaseStatus");
try {
NovaMethod method = new NovaMethod(getProvider());
- List databases = new ArrayList();
+ List databases = new ArrayList<>();
JSONObject json = method.getResource(SERVICE, RESOURCE, null, false);
@@ -549,8 +492,7 @@ public Iterable listConfigurations() throws CloudExceptio
}
}
catch( JSONException e ) {
- e.printStackTrace();
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for instances in " + json.toString());
+ throw new CommunicationException("Unable to identify expected values in JSON: " + e.getMessage(), e);
}
}
return databases;
@@ -564,14 +506,8 @@ public Iterable listConfigurations() throws CloudExceptio
public Iterable listDatabases() throws CloudException, InternalException {
APITrace.begin(getProvider(), "RDBMS.listDatabases");
try {
- ProviderContext ctx = getProvider().getContext();
-
- if( ctx == null ) {
- logger.error("No context exists for this request");
- throw new InternalException("No context exists for this request");
- }
NovaMethod method = new NovaMethod(getProvider());
- List databases = new ArrayList();
+ List databases = new ArrayList<>();
JSONObject json = method.getResource(SERVICE, RESOURCE, null, false);
@@ -580,7 +516,7 @@ public Iterable listDatabases() throws CloudException, InternalExcepti
JSONArray list = json.getJSONArray("instances");
for( int i=0; i listDatabases() throws CloudException, InternalExcepti
}
catch( JSONException e ) {
logger.error("listDatabases(): Unable to identify expected values in JSON: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for instances in " + json.toString());
+ throw new CommunicationException("Unable to identify expected values in JSON: " + e.getMessage(), e);
}
}
return databases;
@@ -609,12 +544,6 @@ public Collection listParameters(String forProviderConfi
public Iterable listSnapshots(String forOptionalProviderDatabaseId) throws CloudException, InternalException {
APITrace.begin(getProvider(), "RDBMS.listSnapshots");
try {
- ProviderContext ctx = getProvider().getContext();
-
- if( ctx == null ) {
- logger.error("No context exists for this request");
- throw new InternalException("No context exists for this request");
- }
NovaMethod method = new NovaMethod(getProvider());
List snapshots = new ArrayList();
@@ -625,7 +554,7 @@ public Iterable listSnapshots(String forOptionalProviderDataba
JSONArray list = json.getJSONArray("snapshots");
for( int i=0; i listSnapshots(String forOptionalProviderDataba
}
catch( JSONException e ) {
logger.error("listSnapshots(): Unable to identify expected values in JSON: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(CloudErrorType.COMMUNICATION, 200, "invalidJson", "Missing JSON element for snapshots in " + json.toString());
+ throw new CommunicationException("Unable to identify expected values in JSON: " + e.getMessage(), e);
}
}
return snapshots;
@@ -649,12 +577,6 @@ public Iterable listSnapshots(String forOptionalProviderDataba
public void removeDatabase(String providerDatabaseId) throws CloudException, InternalException {
APITrace.begin(getProvider(), "RDBMS.removeDatabase");
try {
- ProviderContext ctx = getProvider().getContext();
-
- if( ctx == null ) {
- logger.error("No context exists for this request");
- throw new InternalException("No context exists for this request");
- }
NovaMethod method = new NovaMethod(getProvider());
method.deleteResource(SERVICE, RESOURCE, providerDatabaseId, null);
@@ -668,14 +590,7 @@ public void removeDatabase(String providerDatabaseId) throws CloudException, Int
public void removeSnapshot(String providerSnapshotId) throws CloudException, InternalException {
APITrace.begin(getProvider(), "RDBMS.removeSnapshot");
try {
- ProviderContext ctx = getProvider().getContext();
-
- if( ctx == null ) {
- logger.error("No context exists for this request");
- throw new InternalException("No context exists for this request");
- }
NovaMethod method = new NovaMethod(getProvider());
-
method.deleteResource(SERVICE, SNAPSHOTS, providerSnapshotId, null);
}
finally {
@@ -692,15 +607,7 @@ public void resetConfiguration(String providerConfigurationId, String... paramet
public void restart(String providerDatabaseId, boolean blockUntilDone) throws CloudException, InternalException {
APITrace.begin(getProvider(), "RDBMS.restart");
try {
- ProviderContext ctx = getProvider().getContext();
-
- if( ctx == null ) {
- logger.error("No context exists for this request");
- throw new InternalException("No context exists for this request");
- }
-
NovaMethod method = new NovaMethod(getProvider());
-
method.postResourceHeaders(SERVICE, RESOURCE, providerDatabaseId + "/restart", new HashMap());
}
@@ -713,15 +620,8 @@ public void restart(String providerDatabaseId, boolean blockUntilDone) throws Cl
public DatabaseSnapshot snapshot(String providerDatabaseId, String name) throws CloudException, InternalException {
APITrace.begin(getProvider(), "RDBMS.snapshot");
try {
- ProviderContext ctx = getProvider().getContext();
-
- if( ctx == null ) {
- logger.error("No context exists for this request");
- throw new InternalException("No context exists for this request");
- }
-
- Map wrapper = new HashMap();
- Map json = new HashMap();
+ Map wrapper = new HashMap<>();
+ Map json = new HashMap<>();
NovaMethod method = new NovaMethod(getProvider());
json.put("name", name);
@@ -732,7 +632,7 @@ public DatabaseSnapshot snapshot(String providerDatabaseId, String name) throws
if( result != null && result.has("snapshot") ) {
try {
- DatabaseSnapshot snapshot = toSnapshot(ctx, result.getJSONObject("snapshot"));
+ DatabaseSnapshot snapshot = toSnapshot(result.getJSONObject("snapshot"));
if( snapshot != null ) {
return snapshot;
@@ -740,12 +640,11 @@ public DatabaseSnapshot snapshot(String providerDatabaseId, String name) throws
}
catch( JSONException e ) {
logger.error("snapshot(): Unable to understand create response: " + e.getMessage());
- e.printStackTrace();
- throw new CloudException(e);
+ throw new CommunicationException("Unable to understand create response: " + e.getMessage(), e);
}
}
logger.error("snapshot(): No snapshot was created by the create attempt, and no error was returned");
- throw new CloudException("No snapshot was created");
+ throw new GeneralCloudException("No snapshot was created", CloudErrorType.GENERAL);
}
finally {
@@ -758,12 +657,12 @@ public DatabaseSnapshot snapshot(String providerDatabaseId, String name) throws
return new String[0];
}
- private @Nullable Database toDatabase(@Nonnull ProviderContext ctx, @Nullable JSONObject json) throws CloudException, InternalException {
+ private @Nullable Database toDatabase(@Nullable JSONObject json) throws CloudException, InternalException {
if( json == null ) {
return null;
}
- String regionId = ctx.getRegionId();
+ String regionId = getContext().getRegionId();
try {
String dbId = (json.has("id") ? json.getString("id") : null);
@@ -792,7 +691,7 @@ else if( status.equalsIgnoreCase("running") ) {
currentState = DatabaseState.AVAILABLE;
}
else {
- System.out.println("DEBUG OS DB STATE: " + status);
+ logger.debug("DEBUG OS DB STATE: " + status);
}
}
long created = (json.has("created") ? getProvider().parseTimestamp(json.getString("created")) : -1L);
@@ -847,13 +746,13 @@ else if( version.startsWith("5.0") ) {
}
else {
*/
- System.out.println("DEBUG OS UNKNOWN MYSQL VERSION " + version);
+ logger.debug("DEBUG OS UNKNOWN MYSQL VERSION " + version);
engine = DatabaseEngine.MYSQL;
// }
}
}
else {
- System.out.println("DEBUG OS UNKNOWN DB: " + db + " " + version);
+ logger.debug("DEBUG OS UNKNOWN DB: " + db + " " + version);
}
}
DatabaseProduct product = (flavor == null ? null : getDatabaseProduct(flavor));
@@ -871,24 +770,24 @@ else if( version.startsWith("5.0") ) {
database.setName(name);
database.setProductSize(flavor);
database.setProviderDatabaseId(dbId);
- database.setProviderRegionId(ctx.getRegionId());
+ database.setProviderRegionId(getContext().getRegionId());
database.setProviderDataCenterId(regionId + "-a");
database.setProviderOwnerId(getTenantId());
database.setProviderRegionId(regionId);
return database;
}
catch( JSONException e ) {
- throw new CloudException(e);
+ throw new CommunicationException("Unable to understand response: " + e.getMessage(), e);
}
}
- private @Nullable DatabaseSnapshot toSnapshot(@Nonnull ProviderContext ctx, @Nullable JSONObject json) throws CloudException, InternalException {
+ private @Nullable DatabaseSnapshot toSnapshot(@Nullable JSONObject json) throws CloudException, InternalException {
if( json == null ) {
return null;
}
try {
- String regionId = ctx.getRegionId();
+ String regionId = getContext().getRegionId();
String snapshotId = (json.has("id") ? json.getString("id") : null);
@@ -911,7 +810,7 @@ else if( status.equalsIgnoreCase("deleted") ) {
currentState = DatabaseSnapshotState.DELETED;
}
else {
- System.out.println("DEBUG OS DBSNAP STATE: " + status);
+ logger.debug("DEBUG OS DBSNAP STATE: " + status);
}
}
long created = (json.has("created") ? getProvider().parseTimestamp(json.getString("created")) : -1L);
@@ -929,11 +828,11 @@ else if( status.equalsIgnoreCase("deleted") ) {
return snapshot;
}
catch( JSONException e ) {
- throw new CloudException(e);
+ throw new CommunicationException("Unable to understand response: " + e.getMessage(), e);
}
}
- private @Nullable DatabaseProduct toProduct(@Nonnull ProviderContext ctx, @Nonnegative int size, @Nullable JSONObject json) throws CloudException, InternalException {
+ private @Nullable DatabaseProduct toProduct(@Nonnegative int size, @Nullable JSONObject json) throws CloudException, InternalException {
if( json == null ) {
return null;
}
@@ -954,7 +853,7 @@ else if( status.equalsIgnoreCase("deleted") ) {
}
id = id + ":" + size;
- String regionId = ctx.getRegionId();
+ String regionId = getContext().getRegionId();
if( regionId == null ) {
throw new InternalException("No region is associated with this request");
@@ -978,7 +877,7 @@ else if( status.equalsIgnoreCase("deleted") ) {
return product;
}
catch( JSONException e ) {
- throw new CloudException(e);
+ throw new CommunicationException("Unable to understand response: " + e.getMessage(), e);
}
}
@@ -1008,13 +907,13 @@ else if( status.equalsIgnoreCase("running") ) {
currentState = DatabaseState.AVAILABLE;
}
else {
- System.out.println("DEBUG OS DB STATE: " + status);
+ logger.debug("DEBUG OS DB STATE: " + status);
}
}
return new ResourceStatus(dbId, currentState);
}
catch( JSONException e ) {
- throw new CloudException(e);
+ throw new CommunicationException("Unable to understand response: " + e.getMessage(), e);
}
}
}
diff --git a/src/main/java/org/dasein/cloud/openstack/nova/os/ext/rackspace/cdn/RackspaceCDN.java b/src/main/java/org/dasein/cloud/openstack/nova/os/ext/rackspace/cdn/RackspaceCDN.java
index 39681a9..3149d37 100644
--- a/src/main/java/org/dasein/cloud/openstack/nova/os/ext/rackspace/cdn/RackspaceCDN.java
+++ b/src/main/java/org/dasein/cloud/openstack/nova/os/ext/rackspace/cdn/RackspaceCDN.java
@@ -313,7 +313,7 @@ else if( key.equalsIgnoreCase("X-CDN-SSL-URI") ) {
}
}
catch( URISyntaxException e ) {
- throw new CloudException(e);
+ throw new InternalException(e);
}
Distribution distribution = new Distribution();
diff --git a/src/main/java/org/dasein/cloud/openstack/nova/os/ext/rackspace/db/RackspaceRDBMS.java b/src/main/java/org/dasein/cloud/openstack/nova/os/ext/rackspace/db/RackspaceRDBMS.java
index b3d22bf..4f66951 100644
--- a/src/main/java/org/dasein/cloud/openstack/nova/os/ext/rackspace/db/RackspaceRDBMS.java
+++ b/src/main/java/org/dasein/cloud/openstack/nova/os/ext/rackspace/db/RackspaceRDBMS.java
@@ -20,11 +20,7 @@
package org.dasein.cloud.openstack.nova.os.ext.rackspace.db;
import org.apache.log4j.Logger;
-import org.dasein.cloud.CloudErrorType;
-import org.dasein.cloud.CloudException;
-import org.dasein.cloud.InternalException;
-import org.dasein.cloud.ProviderContext;
-import org.dasein.cloud.ResourceStatus;
+import org.dasein.cloud.*;
import org.dasein.cloud.identity.ServiceAction;
import org.dasein.cloud.openstack.nova.os.NovaMethod;
import org.dasein.cloud.openstack.nova.os.NovaOpenStack;
@@ -59,29 +55,22 @@ public RackspaceRDBMS(NovaOpenStack provider) {
}
private @Nonnull String getTenantId() throws CloudException, InternalException {
- return getProvider().getContext().getAccountNumber();
+ return getContext().getAccountNumber();
}
@Override
public @Nonnull String createFromScratch(@Nonnull String dataSourceName, @Nonnull DatabaseProduct product, @Nonnull String databaseVersion, @Nonnull String withAdminUser, @Nonnull String withAdminPassword, int hostPort) throws CloudException, InternalException {
APITrace.begin(getProvider(), "RDBMS.createFromScratch");
try {
- ProviderContext ctx = getProvider().getContext();
-
- if( ctx == null ) {
- logger.error("No context exists for this request");
- throw new InternalException("No context exists for this request");
- }
-
- Map wrapper = new HashMap();
- Map json = new HashMap();
+ Map wrapper = new HashMap<>();
+ Map json = new HashMap<>();
NovaMethod method = new NovaMethod(getProvider());
- Map database = new HashMap();
+ Map database = new HashMap<>();
database.put("name", dataSourceName);
- List