Repository: jclouds Updated Branches: refs/heads/master 5c8bdcdfb -> 10262df81
Add symbolic error codes for Atmos Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/10262df8 Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/10262df8 Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/10262df8 Branch: refs/heads/master Commit: 10262df81cd73e0ea6ed26179d4250ba40e87d86 Parents: 5c8bdcd Author: Andrew Gaul <[email protected]> Authored: Thu Jul 24 16:28:30 2014 -0700 Committer: Andrew Gaul <[email protected]> Committed: Thu Jul 24 16:30:42 2014 -0700 ---------------------------------------------------------------------- .../handlers/AtmosClientErrorRetryHandler.java | 3 +- .../handlers/AtmosServerErrorRetryHandler.java | 3 +- .../handlers/ParseAtmosErrorFromXmlContent.java | 3 +- .../jclouds/atmos/reference/AtmosErrorCode.java | 44 ++++++++++++++++++++ .../java/org/jclouds/atmos/util/AtmosUtils.java | 3 +- .../org/jclouds/atmos/xml/ErrorHandlerTest.java | 3 +- 6 files changed, 54 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds/blob/10262df8/apis/atmos/src/main/java/org/jclouds/atmos/handlers/AtmosClientErrorRetryHandler.java ---------------------------------------------------------------------- diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/handlers/AtmosClientErrorRetryHandler.java b/apis/atmos/src/main/java/org/jclouds/atmos/handlers/AtmosClientErrorRetryHandler.java index 986a6e8..dde33aa 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/handlers/AtmosClientErrorRetryHandler.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/handlers/AtmosClientErrorRetryHandler.java @@ -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 http://git-wip-us.apache.org/repos/asf/jclouds/blob/10262df8/apis/atmos/src/main/java/org/jclouds/atmos/handlers/AtmosServerErrorRetryHandler.java ---------------------------------------------------------------------- diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/handlers/AtmosServerErrorRetryHandler.java b/apis/atmos/src/main/java/org/jclouds/atmos/handlers/AtmosServerErrorRetryHandler.java index f32870f..3b8c6a3 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/handlers/AtmosServerErrorRetryHandler.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/handlers/AtmosServerErrorRetryHandler.java @@ -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 http://git-wip-us.apache.org/repos/asf/jclouds/blob/10262df8/apis/atmos/src/main/java/org/jclouds/atmos/handlers/ParseAtmosErrorFromXmlContent.java ---------------------------------------------------------------------- diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/handlers/ParseAtmosErrorFromXmlContent.java b/apis/atmos/src/main/java/org/jclouds/atmos/handlers/ParseAtmosErrorFromXmlContent.java index 768f1fe..2c67a6a 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/handlers/ParseAtmosErrorFromXmlContent.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/handlers/ParseAtmosErrorFromXmlContent.java @@ -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 { http://git-wip-us.apache.org/repos/asf/jclouds/blob/10262df8/apis/atmos/src/main/java/org/jclouds/atmos/reference/AtmosErrorCode.java ---------------------------------------------------------------------- diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/reference/AtmosErrorCode.java b/apis/atmos/src/main/java/org/jclouds/atmos/reference/AtmosErrorCode.java new file mode 100644 index 0000000..1b1d096 --- /dev/null +++ b/apis/atmos/src/main/java/org/jclouds/atmos/reference/AtmosErrorCode.java @@ -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; + } +} http://git-wip-us.apache.org/repos/asf/jclouds/blob/10262df8/apis/atmos/src/main/java/org/jclouds/atmos/util/AtmosUtils.java ---------------------------------------------------------------------- diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/util/AtmosUtils.java b/apis/atmos/src/main/java/org/jclouds/atmos/util/AtmosUtils.java index ed4e499..4534ea2 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/util/AtmosUtils.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/util/AtmosUtils.java @@ -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; http://git-wip-us.apache.org/repos/asf/jclouds/blob/10262df8/apis/atmos/src/test/java/org/jclouds/atmos/xml/ErrorHandlerTest.java ---------------------------------------------------------------------- diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/xml/ErrorHandlerTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/xml/ErrorHandlerTest.java index 3bf57c1..a1b41f2 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/xml/ErrorHandlerTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/xml/ErrorHandlerTest.java @@ -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()); } }
