From b6f916844595571dcb001ecba3646aec5be32521 Mon Sep 17 00:00:00 2001 From: hansdude Date: Tue, 27 May 2014 16:51:31 -0600 Subject: [PATCH 1/2] Fixed some issues in the recovery helpers. * Updated the recovery helpers to verify the job type when they get it back. * Updated the get recovery helper to get all objects returned by the job request regardless of state. --- Ds3/Ds3.csproj | 1 + Ds3/Helpers/Ds3ClientHelpers.cs | 21 +++++++++++++++-- Ds3/Helpers/JobRecoveryException.cs | 35 +++++++++++++++++++++++++++++ Ds3/Resources.Designer.cs | 9 ++++++++ Ds3/Resources.resx | 3 +++ 5 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 Ds3/Helpers/JobRecoveryException.cs diff --git a/Ds3/Ds3.csproj b/Ds3/Ds3.csproj index 7e948418..d61c93f4 100644 --- a/Ds3/Ds3.csproj +++ b/Ds3/Ds3.csproj @@ -76,6 +76,7 @@ + diff --git a/Ds3/Helpers/Ds3ClientHelpers.cs b/Ds3/Helpers/Ds3ClientHelpers.cs index 0259b29e..c382ff05 100644 --- a/Ds3/Helpers/Ds3ClientHelpers.cs +++ b/Ds3/Helpers/Ds3ClientHelpers.cs @@ -27,6 +27,8 @@ public class Ds3ClientHelpers : IDs3ClientHelpers private const int _defaultMaxKeys = 1000; private readonly IDs3Client _client; + private const string JobTypePut = "PUT"; + private const string JobTypeGet = "GET"; public Ds3ClientHelpers(IDs3Client client) { @@ -108,7 +110,9 @@ public IWriteJob RecoverWriteJob(Guid jobId) { using (var job = this._client.GetJob(new GetJobRequest(jobId))) { - return new WriteJob(new Ds3ClientFactory(this._client), jobId, job.JobInfo.BucketName, job.ObjectLists); + var jobInfo = job.JobInfo; + CheckJobType(JobTypePut, jobInfo.RequestType); + return new WriteJob(new Ds3ClientFactory(this._client), jobInfo.JobId, jobInfo.BucketName, job.ObjectLists); } } @@ -116,7 +120,20 @@ public IReadJob RecoverReadJob(Guid jobId) { using (var job = this._client.GetJob(new GetJobRequest(jobId))) { - return new ReadJob(new Ds3ClientFactory(this._client), jobId, job.JobInfo.BucketName, job.ObjectLists); + var jobInfo = job.JobInfo; + CheckJobType(JobTypeGet, jobInfo.RequestType); + var jobObjectsList = + from jobObjects in job.ObjectLists + select new Ds3ObjectList(jobObjects.ServerId, jobObjects.ObjectsInCache.Concat(jobObjects.Objects)); + return new ReadJob(new Ds3ClientFactory(this._client), jobInfo.JobId, jobInfo.BucketName, jobObjectsList); + } + } + + private static void CheckJobType(string expectedJobType, string actualJobType) + { + if (actualJobType != expectedJobType) + { + throw new JobRecoveryException(expectedJobType, actualJobType); } } } diff --git a/Ds3/Helpers/JobRecoveryException.cs b/Ds3/Helpers/JobRecoveryException.cs new file mode 100644 index 00000000..17d4edaf --- /dev/null +++ b/Ds3/Helpers/JobRecoveryException.cs @@ -0,0 +1,35 @@ +/* + * ****************************************************************************** + * Copyright 2014 Spectra Logic Corporation. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use + * this file except in compliance with the License. A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. + * This file 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. + * **************************************************************************** + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Ds3.Helpers +{ + class JobRecoveryException : Exception + { + public JobRecoveryException(String expectedType, String actualType) + : base(buildMessage(expectedType, actualType)) + { + } + + private static string buildMessage(string expectedType, string actualType) + { + return string.Format(Resources.JobRecoveryException, expectedType, actualType); + } + } +} diff --git a/Ds3/Resources.Designer.cs b/Ds3/Resources.Designer.cs index 998c7ad2..dc9aae16 100644 --- a/Ds3/Resources.Designer.cs +++ b/Ds3/Resources.Designer.cs @@ -105,6 +105,15 @@ internal static string InvalidStreamException { } } + /// + /// Looks up a localized string similar to Expected job type '{0}' but the actual job was of type '{1}'.. + /// + internal static string JobRecoveryException { + get { + return ResourceManager.GetString("JobRecoveryException", resourceCulture); + } + } + /// /// Looks up a localized string similar to Expected an element called "{0}" but didn't find it.. /// diff --git a/Ds3/Resources.resx b/Ds3/Resources.resx index 758a53f3..a205a6ad 100644 --- a/Ds3/Resources.resx +++ b/Ds3/Resources.resx @@ -132,6 +132,9 @@ PUT object streams must be both readable and seekable. + + Expected job type '{0}' but the actual job was of type '{1}'. + Expected an element called "{0}" but didn't find it. From 511ae86525937ef0302d5291e54c260c1515f3a4 Mon Sep 17 00:00:00 2001 From: hansdude Date: Wed, 28 May 2014 09:34:12 -0600 Subject: [PATCH 2/2] Rev'd to 1.4 --- VersionInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VersionInfo.cs b/VersionInfo.cs index 459f0020..04a1ece9 100644 --- a/VersionInfo.cs +++ b/VersionInfo.cs @@ -25,5 +25,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.2.0")] -[assembly: AssemblyFileVersion("1.3.2.0")] +[assembly: AssemblyVersion("1.4.0.0")] +[assembly: AssemblyFileVersion("1.4.0.0")]