Merge pull request #887 from andreisavu/issue-973

Issue 973. Performance problems with Synaptic's Atmos service
This commit is contained in:
Adrian Cole 2012-10-08 12:50:42 -07:00
commit a02c79c7f4
5 changed files with 20 additions and 4 deletions

View File

@ -58,6 +58,7 @@ import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;

View File

@ -37,6 +37,7 @@ import com.google.inject.Inject;
/**
* Handles Retryable responses with error codes in the 4xx range
*
* @see Error codes section at <a href="https://www.synaptic.att.com/assets/us/en/home/Atmos_Programmers_Guide_1.3.4A.pdf" />
* @author Adrian Cole
*/
public class AtmosClientErrorRetryHandler implements HttpRetryHandler {
@ -62,14 +63,14 @@ public class AtmosClientErrorRetryHandler implements HttpRetryHandler {
if (response.getStatusCode() == 404 && command.getCurrentRequest().getMethod().equals("DELETE")) {
command.incrementFailureCount();
return true;
} else if (response.getStatusCode() == 409 || response.getStatusCode() == 400) {
} else if (response.getStatusCode() == 409) {
byte[] content = HttpUtils.closeClientButKeepContentStream(response);
// Content can be null in the case of HEAD requests
if (content != null) {
try {
AtmosError error = utils.parseAtmosErrorFromContent(command, response,
new String(content));
if (error.getCode() == 1016) {
if (error.getCode() == 1006) {
return backoffHandler.shouldRetryRequest(command, response);
}
// don't increment count before here, since backoff handler does already

View File

@ -27,9 +27,11 @@ import javax.inject.Provider;
import org.jclouds.atmos.AtmosClient;
import org.jclouds.atmos.blobstore.functions.BlobToObject;
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.xml.ErrorHandler;
import org.jclouds.blobstore.KeyAlreadyExistsException;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.crypto.Crypto;
import org.jclouds.http.HttpCommand;
@ -70,8 +72,15 @@ public class AtmosUtils {
public static String putBlob(final AtmosClient sync, Crypto crypto, BlobToObject blob2Object, String container,
Blob blob, PutOptions options) {
final String path = container + "/" + blob.getMetadata().getName();
deleteAndEnsureGone(sync, path);
sync.createFile(container, blob2Object.apply(blob), options);
final AtmosObject object = blob2Object.apply(blob);
try {
sync.createFile(container, object, options);
} catch(KeyAlreadyExistsException e) {
deleteAndEnsureGone(sync, path);
sync.createFile(container, object, options);
}
return path;
}

View File

@ -32,6 +32,8 @@ public class AtmosLiveTest extends BaseBlobLiveTest {
public AtmosLiveTest() {
provider = "atmos";
}
@Override
protected void checkMD5(String container, String name, byte[] md5) {
// atmos does not support content-md5 yet
assertEquals(view.getBlobStore().blobMetadata(container, name).getContentMetadata().getContentMD5(), null);

View File

@ -29,4 +29,7 @@ import org.testng.annotations.Test;
@Test(groups = "live", sequential = true, testName = "SynapticStorageClientLiveTest")
public class SynapticStorageClientLiveTest extends AtmosClientLiveTest {
public SynapticStorageClientLiveTest() {
provider = "synaptic-storage";
}
}