mirror of https://github.com/apache/jclouds.git
fixed error handling on vcloud and renamed bluelock-vclouddirector to bluelock-vcdirector
This commit is contained in:
parent
af094f6ffe
commit
9aced88ca1
|
@ -35,10 +35,10 @@
|
|||
<properties>
|
||||
<!-- when instances are hung, open a ticket and add their names here -->
|
||||
<jclouds.compute.blacklist.nodes></jclouds.compute.blacklist.nodes>
|
||||
<bluelock-vclouddirector.endpoint>https://vcenterprise.bluelock.com/api</bluelock-vclouddirector.endpoint>
|
||||
<bluelock-vclouddirector.apiversion>1.0</bluelock-vclouddirector.apiversion>
|
||||
<bluelock-vclouddirector.identity>FIXME</bluelock-vclouddirector.identity>
|
||||
<bluelock-vclouddirector.credential>FIXME</bluelock-vclouddirector.credential>
|
||||
<bluelock-vcdirector.endpoint>https://vcenterprise.bluelock.com/api</bluelock-vcdirector.endpoint>
|
||||
<bluelock-vcdirector.apiversion>1.0</bluelock-vcdirector.apiversion>
|
||||
<bluelock-vcdirector.identity>FIXME</bluelock-vcdirector.identity>
|
||||
<bluelock-vcdirector.credential>FIXME</bluelock-vcdirector.credential>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
|
@ -79,20 +79,20 @@
|
|||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>bluelock-vclouddirector.endpoint</name>
|
||||
<value>${bluelock-vclouddirector.endpoint}</value>
|
||||
<name>bluelock-vcdirector.endpoint</name>
|
||||
<value>${bluelock-vcdirector.endpoint}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>bluelock-vclouddirector.apiversion</name>
|
||||
<value>${bluelock-vclouddirector.apiversion}</value>
|
||||
<name>bluelock-vcdirector.apiversion</name>
|
||||
<value>${bluelock-vcdirector.apiversion}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>bluelock-vclouddirector.identity</name>
|
||||
<value>${bluelock-vclouddirector.identity}</value>
|
||||
<name>bluelock-vcdirector.identity</name>
|
||||
<value>${bluelock-vcdirector.identity}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>bluelock-vclouddirector.credential</name>
|
||||
<value>${bluelock-vclouddirector.credential}</value>
|
||||
<name>bluelock-vcdirector.credential</name>
|
||||
<value>${bluelock-vcdirector.credential}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.compute.blacklist.nodes</name>
|
||||
|
|
|
@ -43,11 +43,11 @@ public class BlueLockVCloudDirectorClientLiveTest extends VCloudClientLiveTest {
|
|||
@BeforeGroups(groups = { "live" })
|
||||
@Override
|
||||
public void setupClient() {
|
||||
identity = checkNotNull(System.getProperty("bluelock-vclouddirector.identity"),
|
||||
"bluelock-vclouddirector.identity");
|
||||
String credential = checkNotNull(System.getProperty("bluelock-vclouddirector.credential"),
|
||||
"bluelock-vclouddirector.credential");
|
||||
context = new ComputeServiceContextFactory().createContext("bluelock-vclouddirector", identity, credential, ImmutableSet
|
||||
identity = checkNotNull(System.getProperty("bluelock-vcdirector.identity"),
|
||||
"bluelock-vcdirector.identity");
|
||||
String credential = checkNotNull(System.getProperty("bluelock-vcdirector.credential"),
|
||||
"bluelock-vcdirector.credential");
|
||||
context = new ComputeServiceContextFactory().createContext("bluelock-vcdirector", identity, credential, ImmutableSet
|
||||
.<Module> of(new Log4JLoggingModule()), new Properties()).getProviderSpecificContext();
|
||||
connection = context.getApi();
|
||||
}
|
||||
|
|
|
@ -34,11 +34,11 @@ public class BlueLockVCloudDirectorGuestCustomizationLiveTest extends VCloudGues
|
|||
|
||||
@Override
|
||||
protected void setupCredentials() {
|
||||
provider = "bluelock-vclouddirector";
|
||||
identity = checkNotNull(System.getProperty("bluelock-vclouddirector.identity"),
|
||||
"bluelock-vclouddirector.identity");
|
||||
credential = checkNotNull(System.getProperty("bluelock-vclouddirector.credential"),
|
||||
"bluelock-vclouddirector.credential");
|
||||
provider = "bluelock-vcdirector";
|
||||
identity = checkNotNull(System.getProperty("bluelock-vcdirector.identity"),
|
||||
"bluelock-vcdirector.identity");
|
||||
credential = checkNotNull(System.getProperty("bluelock-vcdirector.credential"),
|
||||
"bluelock-vcdirector.credential");
|
||||
}
|
||||
|
||||
}
|
|
@ -36,14 +36,14 @@ public class ProvidersInPropertiesTest {
|
|||
@Test
|
||||
public void testSupportedProviders() {
|
||||
Iterable<String> providers = Utils.getSupportedProviders();
|
||||
assert Iterables.contains(providers, "bluelock-vclouddirector") : providers;
|
||||
assert Iterables.contains(providers, "bluelock-vcdirector") : providers;
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportedComputeServiceProviders() {
|
||||
Iterable<String> providers = ComputeServiceUtils.getSupportedProviders();
|
||||
assert Iterables.contains(providers, "bluelock-vclouddirector") : providers;
|
||||
assert Iterables.contains(providers, "bluelock-vcdirector") : providers;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -60,14 +60,14 @@ public class VCloudSessionRefreshLiveTest {
|
|||
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() throws IOException {
|
||||
identity = checkNotNull(System.getProperty("bluelock-vclouddirector.identity"), "bluelock-vclouddirector.identity");
|
||||
String credential = checkNotNull(System.getProperty("bluelock-vclouddirector.credential"),
|
||||
"bluelock-vclouddirector.credential");
|
||||
identity = checkNotNull(System.getProperty("bluelock-vcdirector.identity"), "bluelock-vcdirector.identity");
|
||||
String credential = checkNotNull(System.getProperty("bluelock-vcdirector.credential"),
|
||||
"bluelock-vcdirector.credential");
|
||||
|
||||
Properties props = new Properties();
|
||||
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);
|
||||
|
||||
connection = VCloudClient.class.cast(context.getProviderSpecificContext().getApi());
|
||||
|
|
|
@ -40,16 +40,16 @@ import org.testng.annotations.Test;
|
|||
public class BlueLockVCloudDirectorComputeServiceLiveTest extends VCloudComputeServiceLiveTest {
|
||||
@Override
|
||||
public void setServiceDefaults() {
|
||||
provider = "bluelock-vclouddirector";
|
||||
provider = "bluelock-vcdirector";
|
||||
tag = "director";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupCredentials() {
|
||||
identity = checkNotNull(System.getProperty("bluelock-vclouddirector.identity"),
|
||||
"bluelock-vclouddirector.identity");
|
||||
credential = checkNotNull(System.getProperty("bluelock-vclouddirector.credential"),
|
||||
"bluelock-vclouddirector.credential");
|
||||
identity = checkNotNull(System.getProperty("bluelock-vcdirector.identity"),
|
||||
"bluelock-vcdirector.identity");
|
||||
credential = checkNotNull(System.getProperty("bluelock-vcdirector.credential"),
|
||||
"bluelock-vcdirector.credential");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -31,9 +31,9 @@
|
|||
<name>jclouds vcloud Components Core</name>
|
||||
<description>jclouds Core components to access vcloud</description>
|
||||
<properties>
|
||||
<jclouds.test.identity>${jclouds.vcloud.user}</jclouds.test.identity>
|
||||
<jclouds.test.credential>${jclouds.vcloud.password}</jclouds.test.credential>
|
||||
<jclouds.test.endpoint>${jclouds.vcloud.endpoint}</jclouds.test.endpoint>
|
||||
<test.identity>${jclouds.vcloud.user}</test.identity>
|
||||
<test.credential>${jclouds.vcloud.password}</test.credential>
|
||||
<test.endpoint>${jclouds.vcloud.endpoint}</test.endpoint>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
|
|
|
@ -27,6 +27,16 @@ import javax.ws.rs.core.MediaType;
|
|||
* @see MediaType
|
||||
*/
|
||||
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"
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -71,6 +71,6 @@ public interface Task extends ReferenceType {
|
|||
* error message or related information returned by the task
|
||||
*/
|
||||
@Nullable
|
||||
Error getError();
|
||||
VCloudError getError();
|
||||
|
||||
}
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.jclouds.vcloud.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.vcloud.domain.internal.ErrorImpl;
|
||||
|
@ -31,7 +33,7 @@ import com.google.inject.ImplementedBy;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@ImplementedBy(ErrorImpl.class)
|
||||
public interface Error {
|
||||
public interface VCloudError {
|
||||
public static enum MinorCode {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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
|
||||
*/
|
||||
@Nullable
|
||||
String getMinorErrorCode();
|
||||
MinorCode getMinorErrorCode();
|
||||
|
||||
/**
|
||||
*
|
|
@ -21,7 +21,7 @@ package org.jclouds.vcloud.domain.internal;
|
|||
|
||||
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;
|
||||
|
||||
|
@ -30,19 +30,19 @@ import com.google.inject.internal.Nullable;
|
|||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class ErrorImpl implements Error {
|
||||
public class ErrorImpl implements VCloudError {
|
||||
private final String message;
|
||||
private final int majorErrorCode;
|
||||
private final String minorErrorCode;
|
||||
private final MinorCode minorErrorCode;
|
||||
@Nullable
|
||||
private final String vendorSpecificErrorCode;
|
||||
@Nullable
|
||||
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) {
|
||||
this.message = checkNotNull(message, "message");
|
||||
this.majorErrorCode = checkNotNull(majorErrorCode, "majorErrorCode");
|
||||
this.majorErrorCode = majorErrorCode;
|
||||
this.minorErrorCode = minorErrorCode; // check null after 0.8 is gone
|
||||
this.vendorSpecificErrorCode = vendorSpecificErrorCode;
|
||||
this.stackTrace = stackTrace;
|
||||
|
@ -56,7 +56,7 @@ public class ErrorImpl implements Error {
|
|||
return majorErrorCode;
|
||||
}
|
||||
|
||||
public String getMinorErrorCode() {
|
||||
public MinorCode getMinorErrorCode() {
|
||||
return minorErrorCode;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.net.URI;
|
|||
import java.util.Date;
|
||||
|
||||
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.Task;
|
||||
import org.jclouds.vcloud.domain.TaskStatus;
|
||||
|
@ -48,10 +48,10 @@ public class TaskImpl extends ReferenceTypeImpl implements Task {
|
|||
private final Date expiryTime;
|
||||
private final ReferenceType owner;
|
||||
@Nullable
|
||||
private final Error error;
|
||||
private final VCloudError error;
|
||||
|
||||
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);
|
||||
this.operation = operation;
|
||||
this.status = checkNotNull(status, "status");
|
||||
|
@ -83,7 +83,7 @@ public class TaskImpl extends ReferenceTypeImpl implements Task {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Error getError() {
|
||||
public VCloudError getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,16 +26,22 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpErrorHandler;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
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.
|
||||
|
@ -48,47 +54,60 @@ public class ParseVCloudErrorFromHttpResponse implements HttpErrorHandler {
|
|||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
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) {
|
||||
HttpRequest request = command.getRequest();
|
||||
Exception exception = new HttpResponseException(command, response);
|
||||
|
||||
try {
|
||||
String content = parseErrorFromContentOrNull(command, response);
|
||||
switch (response.getStatusCode()) {
|
||||
case 401:
|
||||
case 403:
|
||||
exception = new AuthorizationException(command.getRequest(), content);
|
||||
break;
|
||||
case 404:
|
||||
if (!command.getRequest().getMethod().equals("DELETE")) {
|
||||
String path = command.getRequest().getEndpoint().getPath();
|
||||
Matcher matcher = RESOURCE_PATTERN.matcher(path);
|
||||
String message;
|
||||
if (matcher.find()) {
|
||||
message = String.format("%s %s not found", matcher.group(1), matcher.group(2));
|
||||
} else {
|
||||
message = path;
|
||||
VCloudError error = null;
|
||||
String message = null;
|
||||
if (response.getPayload() != null) {
|
||||
String contentType = response.getPayload().getContentMetadata().getContentType();
|
||||
if (VCloudMediaType.ERROR_XML.equals(contentType)) {
|
||||
error = utils.parseErrorFromContent(request, response);
|
||||
if (error != null) {
|
||||
message = error.getMessage();
|
||||
exception = new VCloudResponseException(command, response, error);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
message = Utils.toStringAndClose(response.getPayload().getInput());
|
||||
} catch (IOException e) {
|
||||
}
|
||||
exception = new ResourceNotFoundException(message);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
exception = new HttpResponseException(command, response, content);
|
||||
}
|
||||
message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response
|
||||
.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 {
|
||||
releasePayload(response);
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -22,8 +22,9 @@ package org.jclouds.vcloud.util;
|
|||
import java.net.URI;
|
||||
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.VCloudError.MinorCode;
|
||||
import org.jclouds.vcloud.domain.internal.ErrorImpl;
|
||||
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
|
||||
import org.xml.sax.Attributes;
|
||||
|
@ -57,12 +58,8 @@ public class Utils {
|
|||
return newReferenceType(attributes, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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");
|
||||
public static VCloudError newError(Map<String, String> attributes) {
|
||||
|
||||
String vendorSpecificErrorCode = attributes.get("vendorSpecificErrorCode");
|
||||
int errorCode;
|
||||
// remove this logic when vcloud 0.8 is gone
|
||||
|
@ -72,6 +69,11 @@ public class Utils {
|
|||
errorCode = 500;
|
||||
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
|
||||
.get("stackTrace"));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,10 +30,10 @@ import javax.inject.Inject;
|
|||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.vcloud.domain.Error;
|
||||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.TaskStatus;
|
||||
import org.jclouds.vcloud.domain.VCloudError;
|
||||
import org.jclouds.vcloud.domain.internal.TaskImpl;
|
||||
import org.jclouds.vcloud.util.Utils;
|
||||
import org.xml.sax.Attributes;
|
||||
|
@ -52,7 +52,7 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
|
|||
private Date endTime;
|
||||
private Date expiryTime;
|
||||
private Task task;
|
||||
private Error error;
|
||||
private VCloudError error;
|
||||
private boolean inOwner;
|
||||
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
|
|
@ -75,11 +75,11 @@ public class VCloudLoginLiveTest {
|
|||
|
||||
@BeforeClass
|
||||
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";
|
||||
|
||||
String identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity");
|
||||
String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential");
|
||||
String identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
|
||||
String credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider + ".credential");
|
||||
|
||||
ContextSpec<VCloudLoginClient, VCloudExpressLoginAsyncClient> contextSpec = contextSpec("test", endpoint, "1", identity,
|
||||
credential, VCloudLoginClient.class, VCloudExpressLoginAsyncClient.class);
|
||||
|
|
|
@ -69,9 +69,9 @@ public class VCloudVersionsLiveTest {
|
|||
|
||||
@BeforeClass
|
||||
void setupFactory() {
|
||||
String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), "jclouds.test.endpoint");
|
||||
String identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity");
|
||||
String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential");
|
||||
String endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint");
|
||||
String identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
|
||||
String credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider + ".credential");
|
||||
|
||||
ContextSpec<VCloudVersionsClient, VCloudVersionsAsyncClient> contextSpec = contextSpec("test", endpoint, "1",
|
||||
identity, credential, VCloudVersionsClient.class, VCloudVersionsAsyncClient.class);
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.jclouds.http.functions.BaseHandlerTest;
|
|||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
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.ReferenceTypeImpl;
|
||||
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,
|
||||
dateService.iso8601SecondsDateParse("2009-12-07T19:05:02Z"), dateService
|
||||
.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")),
|
||||
new ErrorImpl("Error processing job", 500,
|
||||
" Error in runDailySummaries date used:2009-12-09 19:40:30.577326+00:00", null, null));
|
||||
VCloudMediaType.VAPP_XML, URI.create("http://10.150.4.49/api/v0.8/vapp/1")), new ErrorImpl(
|
||||
"Error processing job", 500, MinorCode.UNRECOGNIZED,
|
||||
" Error in runDailySummaries date used:2009-12-09 19:40:30.577326+00:00", null));
|
||||
assertEquals(result, expects);
|
||||
|
||||
}
|
||||
|
|
|
@ -32,15 +32,15 @@
|
|||
<description>jclouds Core components to access terremark</description>
|
||||
<properties>
|
||||
<!-- when instances are hung, open a ticket and add here -->
|
||||
<jclouds.compute.blacklist.nodes>trmkrun-ccc,trmk-924</jclouds.compute.blacklist.nodes>
|
||||
<trmk-vcloudexpress.endpoint>https://services.vcloudexpress.terremark.com/api</trmk-vcloudexpress.endpoint>
|
||||
<trmk-vcloudexpress.apiversion>0.8a-ext1.6</trmk-vcloudexpress.apiversion>
|
||||
<trmk-vcloudexpress.identity>FIXME</trmk-vcloudexpress.identity>
|
||||
<trmk-vcloudexpress.credential>FIXME</trmk-vcloudexpress.credential>
|
||||
<trmk-ecloud.endpoint>https://services.enterprisecloud.terremark.com/api</trmk-ecloud.endpoint>
|
||||
<trmk-ecloud.apiversion>0.8b-ext2.3</trmk-ecloud.apiversion>
|
||||
<trmk-ecloud.identity>FIXME</trmk-ecloud.identity>
|
||||
<trmk-ecloud.credential>FIXME</trmk-ecloud.credential>
|
||||
<jclouds.compute.blacklist.nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist.nodes>
|
||||
<test.trmk-vcloudexpress.endpoint>https://services.vcloudexpress.terremark.com/api</test.trmk-vcloudexpress.endpoint>
|
||||
<test.trmk-vcloudexpress.apiversion>0.8a-ext1.6</test.trmk-vcloudexpress.apiversion>
|
||||
<test.trmk-vcloudexpress.identity>FIXME</test.trmk-vcloudexpress.identity>
|
||||
<test.trmk-vcloudexpress.credential>FIXME</test.trmk-vcloudexpress.credential>
|
||||
<test.trmk-ecloud.endpoint>https://services.enterprisecloud.terremark.com/api</test.trmk-ecloud.endpoint>
|
||||
<test.trmk-ecloud.apiversion>0.8b-ext2.3</test.trmk-ecloud.apiversion>
|
||||
<test.trmk-ecloud.identity>FIXME</test.trmk-ecloud.identity>
|
||||
<test.trmk-ecloud.credential>FIXME</test.trmk-ecloud.credential>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
|
@ -82,36 +82,36 @@
|
|||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>trmk-vcloudexpress.endpoint</name>
|
||||
<value>${trmk-vcloudexpress.endpoint}</value>
|
||||
<name>test.trmk-vcloudexpress.endpoint</name>
|
||||
<value>${test.trmk-vcloudexpress.endpoint}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>trmk-vcloudexpress.apiversion</name>
|
||||
<value>${trmk-vcloudexpress.apiversion}</value>
|
||||
<name>test.trmk-vcloudexpress.apiversion</name>
|
||||
<value>${test.trmk-vcloudexpress.apiversion}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>trmk-vcloudexpress.identity</name>
|
||||
<value>${trmk-vcloudexpress.identity}</value>
|
||||
<name>test.trmk-vcloudexpress.identity</name>
|
||||
<value>${test.trmk-vcloudexpress.identity}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>trmk-vcloudexpress.credential</name>
|
||||
<value>${trmk-vcloudexpress.credential}</value>
|
||||
<name>test.trmk-vcloudexpress.credential</name>
|
||||
<value>${test.trmk-vcloudexpress.credential}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>trmk-ecloud.endpoint</name>
|
||||
<value>${trmk-ecloud.endpoint}</value>
|
||||
<name>test.trmk-ecloud.endpoint</name>
|
||||
<value>${test.trmk-ecloud.endpoint}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>trmk-ecloud.apiversion</name>
|
||||
<value>${trmk-ecloud.apiversion}</value>
|
||||
<name>test.trmk-ecloud.apiversion</name>
|
||||
<value>${test.trmk-ecloud.apiversion}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>trmk-ecloud.identity</name>
|
||||
<value>${trmk-ecloud.identity}</value>
|
||||
<name>test.trmk-ecloud.identity</name>
|
||||
<value>${test.trmk-ecloud.identity}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>trmk-ecloud.credential</name>
|
||||
<value>${trmk-ecloud.credential}</value>
|
||||
<name>test.trmk-ecloud.credential</name>
|
||||
<value>${test.trmk-ecloud.credential}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.compute.blacklist.nodes</name>
|
||||
|
|
Loading…
Reference in New Issue