mirror of
https://github.com/apache/jclouds.git
synced 2025-03-07 00:39:09 +00:00
Add symbolic error codes for Atmos
This commit is contained in:
parent
5c8bdcdfbb
commit
10262df81c
@ -21,6 +21,7 @@ import javax.inject.Named;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.atmos.domain.AtmosError;
|
||||
import org.jclouds.atmos.reference.AtmosErrorCode;
|
||||
import org.jclouds.atmos.util.AtmosUtils;
|
||||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpException;
|
||||
@ -67,7 +68,7 @@ public class AtmosClientErrorRetryHandler implements HttpRetryHandler {
|
||||
try {
|
||||
AtmosError error = utils.parseAtmosErrorFromContent(command, response,
|
||||
new String(content));
|
||||
if (error.getCode() == 1006) {
|
||||
if (error.getCode() == AtmosErrorCode.CONFLICTING_OPERATION.getCode()) {
|
||||
return backoffHandler.shouldRetryRequest(command, response);
|
||||
}
|
||||
// don't increment count before here, since backoff handler does already
|
||||
|
@ -21,6 +21,7 @@ import javax.inject.Named;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.atmos.domain.AtmosError;
|
||||
import org.jclouds.atmos.reference.AtmosErrorCode;
|
||||
import org.jclouds.atmos.util.AtmosUtils;
|
||||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpException;
|
||||
@ -65,7 +66,7 @@ public class AtmosServerErrorRetryHandler implements HttpRetryHandler {
|
||||
try {
|
||||
AtmosError error = utils.parseAtmosErrorFromContent(command, response,
|
||||
new String(content));
|
||||
if (error.getCode() == 1040) { // The server is busy. Please try again.
|
||||
if (error.getCode() == AtmosErrorCode.SERVER_BUSY.getCode()) {
|
||||
return backoffHandler.shouldRetryRequest(command, response);
|
||||
}
|
||||
// don't increment count before here, since backoff handler does already
|
||||
|
@ -29,6 +29,7 @@ import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.atmos.AtmosResponseException;
|
||||
import org.jclouds.atmos.domain.AtmosError;
|
||||
import org.jclouds.atmos.reference.AtmosErrorCode;
|
||||
import org.jclouds.atmos.util.AtmosUtils;
|
||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||
import org.jclouds.blobstore.KeyAlreadyExistsException;
|
||||
@ -77,7 +78,7 @@ public class ParseAtmosErrorFromXmlContent implements HttpErrorHandler {
|
||||
logger.warn(e, "exception reading error from response", response);
|
||||
}
|
||||
}
|
||||
if (error != null && error.getCode() == 1016) {
|
||||
if (error != null && error.getCode() == AtmosErrorCode.RESOURCE_ALREADY_EXISTS.getCode()) {
|
||||
File file = new File(command.getCurrentRequest().getEndpoint().getPath());
|
||||
exception = new KeyAlreadyExistsException(file.getParentFile().getAbsolutePath(), file.getName());
|
||||
} else {
|
||||
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.atmos.reference;
|
||||
|
||||
/** Atmos error codes. */
|
||||
public enum AtmosErrorCode {
|
||||
/** Operation aborted because of a conflicting operation in progess against the resource. */
|
||||
CONFLICTING_OPERATION(1006),
|
||||
/** The directory you are attempting to delete is not empty. */
|
||||
DIRECTORY_NOT_EMPTY(1023),
|
||||
/** The requested object was not found. */
|
||||
OBJECT_NOT_FOUND(1003),
|
||||
/** The resource you are trying to create already exists. */
|
||||
RESOURCE_ALREADY_EXISTS(1016),
|
||||
/** The server is busy. Please try again. */
|
||||
SERVER_BUSY(1040),
|
||||
/** There was a mismatch between the signature in the request and the signature as computed by the server. */
|
||||
SIGNATURE_MISMATCH(1032);
|
||||
|
||||
private final int code;
|
||||
|
||||
private AtmosErrorCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
@ -30,6 +30,7 @@ import org.jclouds.atmos.domain.AtmosError;
|
||||
import org.jclouds.atmos.domain.AtmosObject;
|
||||
import org.jclouds.atmos.filters.SignRequest;
|
||||
import org.jclouds.atmos.options.PutOptions;
|
||||
import org.jclouds.atmos.reference.AtmosErrorCode;
|
||||
import org.jclouds.atmos.xml.ErrorHandler;
|
||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||
import org.jclouds.blobstore.KeyAlreadyExistsException;
|
||||
@ -60,7 +61,7 @@ public class AtmosUtils {
|
||||
public AtmosError parseAtmosErrorFromContent(HttpCommand command, HttpResponse response, InputStream content)
|
||||
throws HttpException {
|
||||
AtmosError error = factory.create(errorHandlerProvider.get()).parse(content);
|
||||
if (error.getCode() == 1032) {
|
||||
if (error.getCode() == AtmosErrorCode.SIGNATURE_MISMATCH.getCode()) {
|
||||
error.setStringSigned(signer.createStringToSign(command.getCurrentRequest()));
|
||||
}
|
||||
return error;
|
||||
|
@ -21,6 +21,7 @@ import static org.testng.Assert.assertEquals;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.jclouds.atmos.domain.AtmosError;
|
||||
import org.jclouds.atmos.reference.AtmosErrorCode;
|
||||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.testng.annotations.Test;
|
||||
@ -42,6 +43,6 @@ public class ErrorHandlerTest extends BaseHandlerTest {
|
||||
InputStream is = getClass().getResourceAsStream("/error.xml");
|
||||
ParseSax<AtmosError> parser = createParser();
|
||||
AtmosError result = parser.parse(is);
|
||||
assertEquals(result.getCode(), 1003);
|
||||
assertEquals(result.getCode(), AtmosErrorCode.OBJECT_NOT_FOUND.getCode());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user