fixed error handling on vcloud and renamed bluelock-vclouddirector to bluelock-vcdirector

This commit is contained in:
Adrian Cole 2010-09-19 10:22:09 -07:00
parent af094f6ffe
commit 9aced88ca1
22 changed files with 356 additions and 124 deletions

View File

@ -35,10 +35,10 @@
<properties> <properties>
<!-- when instances are hung, open a ticket and add their names here --> <!-- when instances are hung, open a ticket and add their names here -->
<jclouds.compute.blacklist.nodes></jclouds.compute.blacklist.nodes> <jclouds.compute.blacklist.nodes></jclouds.compute.blacklist.nodes>
<bluelock-vclouddirector.endpoint>https://vcenterprise.bluelock.com/api</bluelock-vclouddirector.endpoint> <bluelock-vcdirector.endpoint>https://vcenterprise.bluelock.com/api</bluelock-vcdirector.endpoint>
<bluelock-vclouddirector.apiversion>1.0</bluelock-vclouddirector.apiversion> <bluelock-vcdirector.apiversion>1.0</bluelock-vcdirector.apiversion>
<bluelock-vclouddirector.identity>FIXME</bluelock-vclouddirector.identity> <bluelock-vcdirector.identity>FIXME</bluelock-vcdirector.identity>
<bluelock-vclouddirector.credential>FIXME</bluelock-vclouddirector.credential> <bluelock-vcdirector.credential>FIXME</bluelock-vcdirector.credential>
</properties> </properties>
<scm> <scm>
@ -79,20 +79,20 @@
<configuration> <configuration>
<systemProperties> <systemProperties>
<property> <property>
<name>bluelock-vclouddirector.endpoint</name> <name>bluelock-vcdirector.endpoint</name>
<value>${bluelock-vclouddirector.endpoint}</value> <value>${bluelock-vcdirector.endpoint}</value>
</property> </property>
<property> <property>
<name>bluelock-vclouddirector.apiversion</name> <name>bluelock-vcdirector.apiversion</name>
<value>${bluelock-vclouddirector.apiversion}</value> <value>${bluelock-vcdirector.apiversion}</value>
</property> </property>
<property> <property>
<name>bluelock-vclouddirector.identity</name> <name>bluelock-vcdirector.identity</name>
<value>${bluelock-vclouddirector.identity}</value> <value>${bluelock-vcdirector.identity}</value>
</property> </property>
<property> <property>
<name>bluelock-vclouddirector.credential</name> <name>bluelock-vcdirector.credential</name>
<value>${bluelock-vclouddirector.credential}</value> <value>${bluelock-vcdirector.credential}</value>
</property> </property>
<property> <property>
<name>jclouds.compute.blacklist.nodes</name> <name>jclouds.compute.blacklist.nodes</name>

View File

@ -43,11 +43,11 @@ public class BlueLockVCloudDirectorClientLiveTest extends VCloudClientLiveTest {
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
@Override @Override
public void setupClient() { public void setupClient() {
identity = checkNotNull(System.getProperty("bluelock-vclouddirector.identity"), identity = checkNotNull(System.getProperty("bluelock-vcdirector.identity"),
"bluelock-vclouddirector.identity"); "bluelock-vcdirector.identity");
String credential = checkNotNull(System.getProperty("bluelock-vclouddirector.credential"), String credential = checkNotNull(System.getProperty("bluelock-vcdirector.credential"),
"bluelock-vclouddirector.credential"); "bluelock-vcdirector.credential");
context = new ComputeServiceContextFactory().createContext("bluelock-vclouddirector", identity, credential, ImmutableSet context = new ComputeServiceContextFactory().createContext("bluelock-vcdirector", identity, credential, ImmutableSet
.<Module> of(new Log4JLoggingModule()), new Properties()).getProviderSpecificContext(); .<Module> of(new Log4JLoggingModule()), new Properties()).getProviderSpecificContext();
connection = context.getApi(); connection = context.getApi();
} }

View File

@ -34,11 +34,11 @@ public class BlueLockVCloudDirectorGuestCustomizationLiveTest extends VCloudGues
@Override @Override
protected void setupCredentials() { protected void setupCredentials() {
provider = "bluelock-vclouddirector"; provider = "bluelock-vcdirector";
identity = checkNotNull(System.getProperty("bluelock-vclouddirector.identity"), identity = checkNotNull(System.getProperty("bluelock-vcdirector.identity"),
"bluelock-vclouddirector.identity"); "bluelock-vcdirector.identity");
credential = checkNotNull(System.getProperty("bluelock-vclouddirector.credential"), credential = checkNotNull(System.getProperty("bluelock-vcdirector.credential"),
"bluelock-vclouddirector.credential"); "bluelock-vcdirector.credential");
} }
} }

View File

@ -36,14 +36,14 @@ public class ProvidersInPropertiesTest {
@Test @Test
public void testSupportedProviders() { public void testSupportedProviders() {
Iterable<String> providers = Utils.getSupportedProviders(); Iterable<String> providers = Utils.getSupportedProviders();
assert Iterables.contains(providers, "bluelock-vclouddirector") : providers; assert Iterables.contains(providers, "bluelock-vcdirector") : providers;
} }
@Test @Test
public void testSupportedComputeServiceProviders() { public void testSupportedComputeServiceProviders() {
Iterable<String> providers = ComputeServiceUtils.getSupportedProviders(); Iterable<String> providers = ComputeServiceUtils.getSupportedProviders();
assert Iterables.contains(providers, "bluelock-vclouddirector") : providers; assert Iterables.contains(providers, "bluelock-vcdirector") : providers;
} }
} }

View File

@ -60,14 +60,14 @@ public class VCloudSessionRefreshLiveTest {
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() throws IOException { public void setupClient() throws IOException {
identity = checkNotNull(System.getProperty("bluelock-vclouddirector.identity"), "bluelock-vclouddirector.identity"); identity = checkNotNull(System.getProperty("bluelock-vcdirector.identity"), "bluelock-vcdirector.identity");
String credential = checkNotNull(System.getProperty("bluelock-vclouddirector.credential"), String credential = checkNotNull(System.getProperty("bluelock-vcdirector.credential"),
"bluelock-vclouddirector.credential"); "bluelock-vcdirector.credential");
Properties props = new Properties(); Properties props = new Properties();
props.setProperty(PROPERTY_SESSION_INTERVAL, 40 + ""); props.setProperty(PROPERTY_SESSION_INTERVAL, 40 + "");
context = new ComputeServiceContextFactory().createContext("bluelock-vclouddirector", identity, credential, context = new ComputeServiceContextFactory().createContext("bluelock-vcdirector", identity, credential,
ImmutableSet.<Module> of(new Log4JLoggingModule()), props); ImmutableSet.<Module> of(new Log4JLoggingModule()), props);
connection = VCloudClient.class.cast(context.getProviderSpecificContext().getApi()); connection = VCloudClient.class.cast(context.getProviderSpecificContext().getApi());

View File

@ -40,16 +40,16 @@ import org.testng.annotations.Test;
public class BlueLockVCloudDirectorComputeServiceLiveTest extends VCloudComputeServiceLiveTest { public class BlueLockVCloudDirectorComputeServiceLiveTest extends VCloudComputeServiceLiveTest {
@Override @Override
public void setServiceDefaults() { public void setServiceDefaults() {
provider = "bluelock-vclouddirector"; provider = "bluelock-vcdirector";
tag = "director"; tag = "director";
} }
@Override @Override
protected void setupCredentials() { protected void setupCredentials() {
identity = checkNotNull(System.getProperty("bluelock-vclouddirector.identity"), identity = checkNotNull(System.getProperty("bluelock-vcdirector.identity"),
"bluelock-vclouddirector.identity"); "bluelock-vcdirector.identity");
credential = checkNotNull(System.getProperty("bluelock-vclouddirector.credential"), credential = checkNotNull(System.getProperty("bluelock-vcdirector.credential"),
"bluelock-vclouddirector.credential"); "bluelock-vcdirector.credential");
} }
@Test @Test

View File

@ -31,9 +31,9 @@
<name>jclouds vcloud Components Core</name> <name>jclouds vcloud Components Core</name>
<description>jclouds Core components to access vcloud</description> <description>jclouds Core components to access vcloud</description>
<properties> <properties>
<jclouds.test.identity>${jclouds.vcloud.user}</jclouds.test.identity> <test.identity>${jclouds.vcloud.user}</test.identity>
<jclouds.test.credential>${jclouds.vcloud.password}</jclouds.test.credential> <test.credential>${jclouds.vcloud.password}</test.credential>
<jclouds.test.endpoint>${jclouds.vcloud.endpoint}</jclouds.test.endpoint> <test.endpoint>${jclouds.vcloud.endpoint}</test.endpoint>
</properties> </properties>
<scm> <scm>

View File

@ -27,6 +27,16 @@ import javax.ws.rs.core.MediaType;
* @see MediaType * @see MediaType
*/ */
public interface VCloudMediaType { public interface VCloudMediaType {
/**
* "application/vnd.vmware.vcloud.error+xml"
*/
public final static String ERROR_XML = "application/vnd.vmware.vcloud.error+xml";
/**
* "application/vnd.vmware.vcloud.error+xml"
*/
public final static MediaType ERROR_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.error+xml");
/** /**
* "application/vnd.vmware.vcloud.vcloud+xml" * "application/vnd.vmware.vcloud.vcloud+xml"
*/ */

View File

@ -0,0 +1,74 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.vcloud.domain.VCloudError;
/**
* Encapsulates an VCloud Error.
*
* @author Adrian Cole
*
*/
public class VCloudResponseException extends HttpResponseException {
private static final long serialVersionUID = 1L;
private org.jclouds.vcloud.domain.VCloudError error;
public VCloudResponseException(HttpCommand command, HttpResponse response, VCloudError error) {
super(String.format("request %s failed with code %s, error: %s", command.getRequest().getRequestLine(), response
.getStatusCode(), error.toString()), command, response);
this.setError(error);
}
public VCloudResponseException(HttpCommand command, HttpResponse response, VCloudError error, Throwable cause) {
super(String.format("request %1$s failed with error: %2$s", command.getRequest().getRequestLine(), error
.toString()), command, response, cause);
this.setError(error);
}
public VCloudResponseException(String message, HttpCommand command, HttpResponse response, VCloudError error) {
super(message, command, response);
this.setError(error);
}
public VCloudResponseException(String message, HttpCommand command, HttpResponse response, VCloudError error,
Throwable cause) {
super(message, command, response, cause);
this.setError(error);
}
public void setError(VCloudError error) {
this.error = error;
}
public VCloudError getError() {
return error;
}
}

View File

@ -71,6 +71,6 @@ public interface Task extends ReferenceType {
* error message or related information returned by the task * error message or related information returned by the task
*/ */
@Nullable @Nullable
Error getError(); VCloudError getError();
} }

View File

@ -19,6 +19,8 @@
package org.jclouds.vcloud.domain; package org.jclouds.vcloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.ErrorImpl; import org.jclouds.vcloud.domain.internal.ErrorImpl;
@ -31,7 +33,7 @@ import com.google.inject.ImplementedBy;
* @author Adrian Cole * @author Adrian Cole
*/ */
@ImplementedBy(ErrorImpl.class) @ImplementedBy(ErrorImpl.class)
public interface Error { public interface VCloudError {
public static enum MinorCode { public static enum MinorCode {
/** /**
* The request was made by a user who had insufficient rights to the object or operation. * The request was made by a user who had insufficient rights to the object or operation.
@ -75,8 +77,15 @@ public interface Error {
/** /**
* The wrong content type was specified for the request. * The wrong content type was specified for the request.
*/ */
UNSUPPORTED_MEDIA_TYPE; UNSUPPORTED_MEDIA_TYPE, UNRECOGNIZED;
public static MinorCode fromValue(String minorCode) {
try {
return valueOf(checkNotNull(minorCode, "minorCode"));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
} }
/** /**
@ -96,7 +105,7 @@ public interface Error {
* @return error code specific to the failed operation or null if vcloud <0.9 * @return error code specific to the failed operation or null if vcloud <0.9
*/ */
@Nullable @Nullable
String getMinorErrorCode(); MinorCode getMinorErrorCode();
/** /**
* *

View File

@ -21,7 +21,7 @@ package org.jclouds.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.vcloud.domain.Error; import org.jclouds.vcloud.domain.VCloudError;
import com.google.inject.internal.Nullable; import com.google.inject.internal.Nullable;
@ -30,19 +30,19 @@ import com.google.inject.internal.Nullable;
* @author Adrian Cole * @author Adrian Cole
* *
*/ */
public class ErrorImpl implements Error { public class ErrorImpl implements VCloudError {
private final String message; private final String message;
private final int majorErrorCode; private final int majorErrorCode;
private final String minorErrorCode; private final MinorCode minorErrorCode;
@Nullable @Nullable
private final String vendorSpecificErrorCode; private final String vendorSpecificErrorCode;
@Nullable @Nullable
private final String stackTrace; private final String stackTrace;
public ErrorImpl(String message, int majorErrorCode, @Nullable String minorErrorCode, public ErrorImpl(String message, int majorErrorCode, @Nullable MinorCode minorErrorCode,
@Nullable String vendorSpecificErrorCode, @Nullable String stackTrace) { @Nullable String vendorSpecificErrorCode, @Nullable String stackTrace) {
this.message = checkNotNull(message, "message"); this.message = checkNotNull(message, "message");
this.majorErrorCode = checkNotNull(majorErrorCode, "majorErrorCode"); this.majorErrorCode = majorErrorCode;
this.minorErrorCode = minorErrorCode; // check null after 0.8 is gone this.minorErrorCode = minorErrorCode; // check null after 0.8 is gone
this.vendorSpecificErrorCode = vendorSpecificErrorCode; this.vendorSpecificErrorCode = vendorSpecificErrorCode;
this.stackTrace = stackTrace; this.stackTrace = stackTrace;
@ -56,7 +56,7 @@ public class ErrorImpl implements Error {
return majorErrorCode; return majorErrorCode;
} }
public String getMinorErrorCode() { public MinorCode getMinorErrorCode() {
return minorErrorCode; return minorErrorCode;
} }

View File

@ -25,7 +25,7 @@ import java.net.URI;
import java.util.Date; import java.util.Date;
import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Error; import org.jclouds.vcloud.domain.VCloudError;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TaskStatus; import org.jclouds.vcloud.domain.TaskStatus;
@ -48,10 +48,10 @@ public class TaskImpl extends ReferenceTypeImpl implements Task {
private final Date expiryTime; private final Date expiryTime;
private final ReferenceType owner; private final ReferenceType owner;
@Nullable @Nullable
private final Error error; private final VCloudError error;
public TaskImpl(URI id, String operation, TaskStatus status, Date startTime, @Nullable Date endTime, public TaskImpl(URI id, String operation, TaskStatus status, Date startTime, @Nullable Date endTime,
@Nullable Date expiryTime, ReferenceType owner, Error error) { @Nullable Date expiryTime, ReferenceType owner, VCloudError error) {
super(null, VCloudMediaType.TASK_XML, id); super(null, VCloudMediaType.TASK_XML, id);
this.operation = operation; this.operation = operation;
this.status = checkNotNull(status, "status"); this.status = checkNotNull(status, "status");
@ -83,7 +83,7 @@ public class TaskImpl extends ReferenceTypeImpl implements Task {
} }
@Override @Override
public Error getError() { public VCloudError getError() {
return error; return error;
} }

View File

@ -26,16 +26,22 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.VCloudResponseException;
import org.jclouds.vcloud.domain.VCloudError;
import org.jclouds.vcloud.util.VCloudUtils;
/** /**
* This will parse and set an appropriate exception on the command object. * This will parse and set an appropriate exception on the command object.
@ -48,47 +54,60 @@ public class ParseVCloudErrorFromHttpResponse implements HttpErrorHandler {
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
public static final Pattern RESOURCE_PATTERN = Pattern.compile(".*/v[^/]+/([^/]+)/([0-9]+)"); public static final Pattern RESOURCE_PATTERN = Pattern.compile(".*/v[^/]+/([^/]+)/([0-9]+)");
private final VCloudUtils utils;
@Inject
public ParseVCloudErrorFromHttpResponse(VCloudUtils utils) {
this.utils = utils;
}
public void handleError(HttpCommand command, HttpResponse response) { public void handleError(HttpCommand command, HttpResponse response) {
HttpRequest request = command.getRequest();
Exception exception = new HttpResponseException(command, response); Exception exception = new HttpResponseException(command, response);
try { try {
String content = parseErrorFromContentOrNull(command, response); VCloudError error = null;
switch (response.getStatusCode()) { String message = null;
case 401: if (response.getPayload() != null) {
case 403: String contentType = response.getPayload().getContentMetadata().getContentType();
exception = new AuthorizationException(command.getRequest(), content); if (VCloudMediaType.ERROR_XML.equals(contentType)) {
break; error = utils.parseErrorFromContent(request, response);
case 404: if (error != null) {
if (!command.getRequest().getMethod().equals("DELETE")) { message = error.getMessage();
String path = command.getRequest().getEndpoint().getPath(); exception = new VCloudResponseException(command, response, error);
Matcher matcher = RESOURCE_PATTERN.matcher(path); }
String message; } else {
if (matcher.find()) { try {
message = String.format("%s %s not found", matcher.group(1), matcher.group(2)); message = Utils.toStringAndClose(response.getPayload().getInput());
} else { } catch (IOException e) {
message = path;
} }
exception = new ResourceNotFoundException(message);
} }
break; }
default: message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response
exception = new HttpResponseException(command, response, content); .getStatusLine());
switch (response.getStatusCode()) {
case 400:
exception = new IllegalArgumentException(message, exception);
case 401:
case 403:
exception = new AuthorizationException(command.getRequest(), message);
break;
case 404:
if (!command.getRequest().getMethod().equals("DELETE")) {
String path = command.getRequest().getEndpoint().getPath();
Matcher matcher = RESOURCE_PATTERN.matcher(path);
if (matcher.find()) {
message = String.format("%s %s not found", matcher.group(1), matcher.group(2));
} else {
message = path;
}
exception = new ResourceNotFoundException(message);
}
break;
} }
} finally { } finally {
releasePayload(response); releasePayload(response);
command.setException(exception); command.setException(exception);
} }
} }
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
if (response.getPayload() != null) {
try {
return Utils.toStringAndClose(response.getPayload().getInput());
} catch (IOException e) {
logger.warn(e, "exception reading error from response", response);
}
}
return null;
}
} }

View File

@ -22,8 +22,9 @@ package org.jclouds.vcloud.util;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import org.jclouds.vcloud.domain.Error; import org.jclouds.vcloud.domain.VCloudError;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudError.MinorCode;
import org.jclouds.vcloud.domain.internal.ErrorImpl; import org.jclouds.vcloud.domain.internal.ErrorImpl;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
@ -57,12 +58,8 @@ public class Utils {
return newReferenceType(attributes, null); return newReferenceType(attributes, null);
} }
/** public static VCloudError newError(Map<String, String> attributes) {
* note that vCloud 0.9+ the error isn't attributes, it is a nested object. see
* {@link ErrorHandler}
*/
public static Error newError(Map<String, String> attributes) {
String minorErrorCode = attributes.get("minorErrorCode");
String vendorSpecificErrorCode = attributes.get("vendorSpecificErrorCode"); String vendorSpecificErrorCode = attributes.get("vendorSpecificErrorCode");
int errorCode; int errorCode;
// remove this logic when vcloud 0.8 is gone // remove this logic when vcloud 0.8 is gone
@ -72,6 +69,11 @@ public class Utils {
errorCode = 500; errorCode = 500;
vendorSpecificErrorCode = attributes.get("majorErrorCode"); vendorSpecificErrorCode = attributes.get("majorErrorCode");
} }
MinorCode minorErrorCode = MinorCode.fromValue(attributes.get("minorErrorCode"));
if (minorErrorCode == MinorCode.UNRECOGNIZED) {
vendorSpecificErrorCode = attributes.get("minorErrorCode");
}
return new ErrorImpl(attributes.get("message"), errorCode, minorErrorCode, vendorSpecificErrorCode, attributes return new ErrorImpl(attributes.get("message"), errorCode, minorErrorCode, vendorSpecificErrorCode, attributes
.get("stackTrace")); .get("stackTrace"));
} }

View File

@ -0,0 +1,68 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.util;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.VCloudError;
import org.jclouds.vcloud.xml.ErrorHandler;
/**
* Needed to sign and verify requests and responses.
*
* @author Adrian Cole
*/
@Singleton
public class VCloudUtils {
private final ParseSax.Factory factory;
private final Provider<ErrorHandler> errorHandlerProvider;
@Resource
protected Logger logger = Logger.NULL;
@Inject
VCloudUtils(Factory factory, Provider<ErrorHandler> errorHandlerProvider) {
this.factory = factory;
this.errorHandlerProvider = errorHandlerProvider;
}
public VCloudError parseErrorFromContent(HttpRequest request, HttpResponse response) {
// HEAD has no content
if (response.getPayload() == null)
return null;
if (VCloudMediaType.ERROR_XML.equals(response.getPayload().getContentMetadata().getContentType())) {
try {
return (VCloudError) factory.create(errorHandlerProvider.get()).setContext(request).apply(response);
} catch (HttpException e) {
logger.warn(e, "error parsing error");
}
}
return null;
}
}

View File

@ -0,0 +1,49 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.xml;
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
import java.util.Map;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.VCloudError;
import org.jclouds.vcloud.util.Utils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class ErrorHandler extends ParseSax.HandlerWithResult<VCloudError> {
private VCloudError error;
public VCloudError getResult() {
return error;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.equals("Error")) {
error = Utils.newError(attributes);
}
}
}

View File

@ -30,10 +30,10 @@ import javax.inject.Inject;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.Error;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TaskStatus; import org.jclouds.vcloud.domain.TaskStatus;
import org.jclouds.vcloud.domain.VCloudError;
import org.jclouds.vcloud.domain.internal.TaskImpl; import org.jclouds.vcloud.domain.internal.TaskImpl;
import org.jclouds.vcloud.util.Utils; import org.jclouds.vcloud.util.Utils;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
@ -52,7 +52,7 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
private Date endTime; private Date endTime;
private Date expiryTime; private Date expiryTime;
private Task task; private Task task;
private Error error; private VCloudError error;
private boolean inOwner; private boolean inOwner;
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;

View File

@ -75,11 +75,11 @@ public class VCloudLoginLiveTest {
@BeforeClass @BeforeClass
void setupFactory() { void setupFactory() {
String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), "jclouds.test.endpoint") String endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint")
+ "/v0.8/login"; + "/v0.8/login";
String identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity"); String identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential"); String credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider + ".credential");
ContextSpec<VCloudLoginClient, VCloudExpressLoginAsyncClient> contextSpec = contextSpec("test", endpoint, "1", identity, ContextSpec<VCloudLoginClient, VCloudExpressLoginAsyncClient> contextSpec = contextSpec("test", endpoint, "1", identity,
credential, VCloudLoginClient.class, VCloudExpressLoginAsyncClient.class); credential, VCloudLoginClient.class, VCloudExpressLoginAsyncClient.class);

View File

@ -69,9 +69,9 @@ public class VCloudVersionsLiveTest {
@BeforeClass @BeforeClass
void setupFactory() { void setupFactory() {
String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), "jclouds.test.endpoint"); String endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint");
String identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity"); String identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential"); String credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider + ".credential");
ContextSpec<VCloudVersionsClient, VCloudVersionsAsyncClient> contextSpec = contextSpec("test", endpoint, "1", ContextSpec<VCloudVersionsClient, VCloudVersionsAsyncClient> contextSpec = contextSpec("test", endpoint, "1",
identity, credential, VCloudVersionsClient.class, VCloudVersionsAsyncClient.class); identity, credential, VCloudVersionsClient.class, VCloudVersionsAsyncClient.class);

View File

@ -29,6 +29,7 @@ import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TaskStatus; import org.jclouds.vcloud.domain.TaskStatus;
import org.jclouds.vcloud.domain.VCloudError.MinorCode;
import org.jclouds.vcloud.domain.internal.ErrorImpl; import org.jclouds.vcloud.domain.internal.ErrorImpl;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.internal.TaskImpl; import org.jclouds.vcloud.domain.internal.TaskImpl;
@ -121,9 +122,9 @@ public class TaskHandlerTest extends BaseHandlerTest {
Task expects = new TaskImpl(URI.create("http://10.150.4.49/api/v0.8/task/23"), null, TaskStatus.ERROR, Task expects = new TaskImpl(URI.create("http://10.150.4.49/api/v0.8/task/23"), null, TaskStatus.ERROR,
dateService.iso8601SecondsDateParse("2009-12-07T19:05:02Z"), dateService dateService.iso8601SecondsDateParse("2009-12-07T19:05:02Z"), dateService
.iso8601SecondsDateParse("2009-12-10T14:40:32Z"), null, new ReferenceTypeImpl("testapp1", .iso8601SecondsDateParse("2009-12-10T14:40:32Z"), null, new ReferenceTypeImpl("testapp1",
VCloudMediaType.VAPP_XML, URI.create("http://10.150.4.49/api/v0.8/vapp/1")), VCloudMediaType.VAPP_XML, URI.create("http://10.150.4.49/api/v0.8/vapp/1")), new ErrorImpl(
new ErrorImpl("Error processing job", 500, "Error processing job", 500, MinorCode.UNRECOGNIZED,
" Error in runDailySummaries date used:2009-12-09 19:40:30.577326+00:00", null, null)); " Error in runDailySummaries date used:2009-12-09 19:40:30.577326+00:00", null));
assertEquals(result, expects); assertEquals(result, expects);
} }

View File

@ -32,15 +32,15 @@
<description>jclouds Core components to access terremark</description> <description>jclouds Core components to access terremark</description>
<properties> <properties>
<!-- when instances are hung, open a ticket and add here --> <!-- when instances are hung, open a ticket and add here -->
<jclouds.compute.blacklist.nodes>trmkrun-ccc,trmk-924</jclouds.compute.blacklist.nodes> <jclouds.compute.blacklist.nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist.nodes>
<trmk-vcloudexpress.endpoint>https://services.vcloudexpress.terremark.com/api</trmk-vcloudexpress.endpoint> <test.trmk-vcloudexpress.endpoint>https://services.vcloudexpress.terremark.com/api</test.trmk-vcloudexpress.endpoint>
<trmk-vcloudexpress.apiversion>0.8a-ext1.6</trmk-vcloudexpress.apiversion> <test.trmk-vcloudexpress.apiversion>0.8a-ext1.6</test.trmk-vcloudexpress.apiversion>
<trmk-vcloudexpress.identity>FIXME</trmk-vcloudexpress.identity> <test.trmk-vcloudexpress.identity>FIXME</test.trmk-vcloudexpress.identity>
<trmk-vcloudexpress.credential>FIXME</trmk-vcloudexpress.credential> <test.trmk-vcloudexpress.credential>FIXME</test.trmk-vcloudexpress.credential>
<trmk-ecloud.endpoint>https://services.enterprisecloud.terremark.com/api</trmk-ecloud.endpoint> <test.trmk-ecloud.endpoint>https://services.enterprisecloud.terremark.com/api</test.trmk-ecloud.endpoint>
<trmk-ecloud.apiversion>0.8b-ext2.3</trmk-ecloud.apiversion> <test.trmk-ecloud.apiversion>0.8b-ext2.3</test.trmk-ecloud.apiversion>
<trmk-ecloud.identity>FIXME</trmk-ecloud.identity> <test.trmk-ecloud.identity>FIXME</test.trmk-ecloud.identity>
<trmk-ecloud.credential>FIXME</trmk-ecloud.credential> <test.trmk-ecloud.credential>FIXME</test.trmk-ecloud.credential>
</properties> </properties>
<scm> <scm>
@ -82,36 +82,36 @@
<configuration> <configuration>
<systemProperties> <systemProperties>
<property> <property>
<name>trmk-vcloudexpress.endpoint</name> <name>test.trmk-vcloudexpress.endpoint</name>
<value>${trmk-vcloudexpress.endpoint}</value> <value>${test.trmk-vcloudexpress.endpoint}</value>
</property> </property>
<property> <property>
<name>trmk-vcloudexpress.apiversion</name> <name>test.trmk-vcloudexpress.apiversion</name>
<value>${trmk-vcloudexpress.apiversion}</value> <value>${test.trmk-vcloudexpress.apiversion}</value>
</property> </property>
<property> <property>
<name>trmk-vcloudexpress.identity</name> <name>test.trmk-vcloudexpress.identity</name>
<value>${trmk-vcloudexpress.identity}</value> <value>${test.trmk-vcloudexpress.identity}</value>
</property> </property>
<property> <property>
<name>trmk-vcloudexpress.credential</name> <name>test.trmk-vcloudexpress.credential</name>
<value>${trmk-vcloudexpress.credential}</value> <value>${test.trmk-vcloudexpress.credential}</value>
</property> </property>
<property> <property>
<name>trmk-ecloud.endpoint</name> <name>test.trmk-ecloud.endpoint</name>
<value>${trmk-ecloud.endpoint}</value> <value>${test.trmk-ecloud.endpoint}</value>
</property> </property>
<property> <property>
<name>trmk-ecloud.apiversion</name> <name>test.trmk-ecloud.apiversion</name>
<value>${trmk-ecloud.apiversion}</value> <value>${test.trmk-ecloud.apiversion}</value>
</property> </property>
<property> <property>
<name>trmk-ecloud.identity</name> <name>test.trmk-ecloud.identity</name>
<value>${trmk-ecloud.identity}</value> <value>${test.trmk-ecloud.identity}</value>
</property> </property>
<property> <property>
<name>trmk-ecloud.credential</name> <name>test.trmk-ecloud.credential</name>
<value>${trmk-ecloud.credential}</value> <value>${test.trmk-ecloud.credential}</value>
</property> </property>
<property> <property>
<name>jclouds.compute.blacklist.nodes</name> <name>jclouds.compute.blacklist.nodes</name>