Skip to content

Commit

Permalink
Merge pull request Azure#192 from joeg/dev
Browse files Browse the repository at this point in the history
Dev: Fixed issue in storage convenience libraries with download resume etag lock, check for nulls on extended error parsing.
  • Loading branch information
toddysm committed Dec 20, 2011
2 parents 88ba14d + 65c6504 commit 151e943
Show file tree
Hide file tree
Showing 3 changed files with 369 additions and 428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* Copyright 2011 Microsoft Corporation
*
* 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
* 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.
* 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 com.microsoft.windowsazure.services.blob.client;

Expand All @@ -37,6 +37,7 @@
import com.microsoft.windowsazure.services.core.storage.StorageCredentialsSharedAccessSignature;
import com.microsoft.windowsazure.services.core.storage.StorageErrorCodeStrings;
import com.microsoft.windowsazure.services.core.storage.StorageException;
import com.microsoft.windowsazure.services.core.storage.StorageExtendedErrorInformation;
import com.microsoft.windowsazure.services.core.storage.utils.Base64;
import com.microsoft.windowsazure.services.core.storage.utils.PathUtility;
import com.microsoft.windowsazure.services.core.storage.utils.StreamMd5AndLength;
Expand Down Expand Up @@ -807,6 +808,8 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op
final String contentLength = request.getHeaderField(Constants.HeaderConstants.CONTENT_LENGTH);
final long expectedLength = Long.parseLong(contentLength);

blob.updatePropertiesFromResponse(request);

final StreamMd5AndLength descriptor = Utility.writeToOutputStream(streamRef, outStream, -1, false,
validateMD5, this.getResult(), opContext);

Expand All @@ -817,8 +820,6 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op
return null;
}

blob.updatePropertiesFromResponse(request);

if (descriptor.getLength() != expectedLength) {
throw new StorageException(
StorageErrorCodeStrings.OUT_OF_RANGE_INPUT,
Expand Down Expand Up @@ -855,8 +856,15 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op
// be outside the operation above as it would get retried resulting
// in a nested retry

// Copy access condition, and update etag. This will potentially replace the if match value, but not on the
// users object.

AccessCondition etagLockCondition = new AccessCondition();
etagLockCondition.setIfMatch(this.getProperties().getEtag());
etagLockCondition.setLeaseID(accessCondition.getLeaseID());

// 1. Open Read Stream
final BlobInputStream streamRef = this.openInputStream(accessCondition, options, opContext);
final BlobInputStream streamRef = this.openInputStream(etagLockCondition, options, opContext);

// Cache value indicating if we need
final boolean validateMd5 = streamRef.getValidateBlobMd5();
Expand Down Expand Up @@ -2029,8 +2037,15 @@ public Long execute(final CloudBlobClient client, final CloudBlob blob, final Op
final StorageException potentialConflictException = StorageException.translateException(request,
null, opContext);

if (!potentialConflictException.getExtendedErrorInformation().getErrorCode()
.equals(StorageErrorCodeStrings.LEASE_ALREADY_BROKEN)) {
StorageExtendedErrorInformation extendedInfo = potentialConflictException
.getExtendedErrorInformation();

if (extendedInfo == null) {
// If we cant validate the error then the error must be surfaced to the user.
throw potentialConflictException;
}

if (!extendedInfo.getErrorCode().equals(StorageErrorCodeStrings.LEASE_ALREADY_BROKEN)) {
this.setException(potentialConflictException);
this.setNonExceptionedRetryableFailure(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* Copyright 2011 Microsoft Corporation
*
* 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
* 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.
* 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 com.microsoft.windowsazure.services.blob.client;

Expand All @@ -37,6 +37,7 @@
import com.microsoft.windowsazure.services.core.storage.StorageCredentialsSharedAccessSignature;
import com.microsoft.windowsazure.services.core.storage.StorageErrorCodeStrings;
import com.microsoft.windowsazure.services.core.storage.StorageException;
import com.microsoft.windowsazure.services.core.storage.StorageExtendedErrorInformation;
import com.microsoft.windowsazure.services.core.storage.utils.PathUtility;
import com.microsoft.windowsazure.services.core.storage.utils.UriQueryBuilder;
import com.microsoft.windowsazure.services.core.storage.utils.Utility;
Expand Down Expand Up @@ -309,8 +310,14 @@ else if (this.getResult().getStatusCode() == HttpURLConnection.HTTP_CONFLICT) {
final StorageException potentialConflictException = StorageException.translateException(request,
null, opContext);

if (!potentialConflictException.getExtendedErrorInformation().getErrorCode()
.equals(StorageErrorCodeStrings.CONTAINER_ALREADY_EXISTS)) {
StorageExtendedErrorInformation extendedInfo = potentialConflictException
.getExtendedErrorInformation();
if (extendedInfo == null) {
// If we can't validate the error then the error must be surfaced to the user.
throw potentialConflictException;
}

if (!extendedInfo.getErrorCode().equals(StorageErrorCodeStrings.CONTAINER_ALREADY_EXISTS)) {
this.setException(potentialConflictException);
this.setNonExceptionedRetryableFailure(true);

Expand Down
Loading

0 comments on commit 151e943

Please sign in to comment.