Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<dependency>
<groupId>org.dasein</groupId>
<artifactId>dasein-cloud-core</artifactId>
<version>2016.02.1-SNAPSHOT</version>
<version>0.9.0</version>
<scope>compile</scope>
<optional>false</optional>
</dependency>
Expand Down Expand Up @@ -107,7 +107,36 @@
<version>1.2.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.5.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.5.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>3.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>3.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>3.4</version>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down Expand Up @@ -246,9 +275,9 @@
<value>${test.machineImage}</value>
</property>
</systemProperties>
<excludes>
<exclude>**/TestSuite.java</exclude>
</excludes>
<includes>
<include>**/TestSuite.java</include>
</includes>
</configuration>
<executions>
<execution>
Expand Down
200 changes: 77 additions & 123 deletions src/main/java/org/dasein/cloud/openstack/nova/os/AbstractMethod.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,10 @@ public class NovaLocationServices extends AbstractDataCenterServices<NovaOpenSta
public DataCenter getDataCenter(String providerDataCenterId) throws InternalException, CloudException {
APITrace.begin(getProvider(), "DC.getDataCenter");
try {
ProviderContext ctx = getProvider().getContext();

if( ctx == null ) {
throw new CloudException("No context exists for this request");
}
String regionId = ctx.getRegionId();
String regionId = getContext().getRegionId();

if( regionId == null ) {
throw new CloudException("No region is known for zones request");
throw new InternalException("No region is known for zones request");
}
for( DataCenter dc : listDataCenters(regionId) ) {
if( dc.getProviderDataCenterId().equals(providerDataCenterId) ) {
Expand Down Expand Up @@ -107,7 +102,7 @@ public Collection<DataCenter> 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();

Expand Down
78 changes: 41 additions & 37 deletions src/main/java/org/dasein/cloud/openstack/nova/os/NovaMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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+"/";
Expand All @@ -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 ) {
Expand All @@ -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) {
Expand All @@ -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 ) {
Expand All @@ -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) {
Expand All @@ -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 ) {
Expand All @@ -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) {
Expand All @@ -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 ) {
Expand All @@ -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());
Expand All @@ -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 ) {
Expand All @@ -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());
Expand All @@ -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) {
Expand All @@ -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 ) {
Expand All @@ -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("/"))) {
Expand All @@ -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) {
Expand All @@ -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 ) {
Expand All @@ -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("/"))) {
Expand All @@ -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) {
Expand All @@ -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));
Expand All @@ -385,11 +389,11 @@ else if( suffix ) {

public void putHPCDN(final String container) throws CloudException, InternalException {
Map<String,String> headers = new HashMap<String, String>();
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");
Expand All @@ -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) {
Expand All @@ -416,11 +420,11 @@ public void putHPCDN(final String container) throws CloudException, InternalExce
}

public void postHPCDN(@Nonnull final String container, @Nonnull final Map<String,String> 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");
Expand All @@ -441,11 +445,11 @@ public void postHPCDN(@Nonnull final String container, @Nonnull final Map<String
}

public void deleteHPCDN(@Nonnull final String container) 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 {
delete(context.getAuthToken(), endpoint, "/" + container);
Expand Down
Loading