Skip to content

Commit

Permalink
Merge pull request #18 from hansdude/master
Browse files Browse the repository at this point in the history
Fixed some job recovery issues and version-ed.
  • Loading branch information
rpmoore committed May 28, 2014
2 parents 7042aac + 5779813 commit 9587e97
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
1 change: 1 addition & 0 deletions Ds3/Ds3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<Compile Include="Helpers\IDs3ClientHelpers.cs" />
<Compile Include="Helpers\Job.cs" />
<Compile Include="Helpers\JobApi.cs" />
<Compile Include="Helpers\JobRecoveryException.cs" />
<Compile Include="Helpers\WriteJob.cs" />
<Compile Include="Helpers\ReadJob.cs" />
<Compile Include="IDs3Client.cs" />
Expand Down
21 changes: 19 additions & 2 deletions Ds3/Helpers/Ds3ClientHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -108,15 +110,30 @@ 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);
}
}

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);
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions Ds3/Helpers/JobRecoveryException.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
9 changes: 9 additions & 0 deletions Ds3/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Ds3/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
<data name="InvalidStreamException" xml:space="preserve">
<value>PUT object streams must be both readable and seekable.</value>
</data>
<data name="JobRecoveryException" xml:space="preserve">
<value>Expected job type '{0}' but the actual job was of type '{1}'.</value>
</data>
<data name="MissingElementException" xml:space="preserve">
<value>Expected an element called "{0}" but didn't find it.</value>
</data>
Expand Down
4 changes: 2 additions & 2 deletions VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

0 comments on commit 9587e97

Please sign in to comment.