Navigation Menu

Skip to content

Commit

Permalink
Add Transformers tab to the studio
Browse files Browse the repository at this point in the history
expose Get, Set and Delete commands for transformers
  • Loading branch information
DanielDar committed Feb 27, 2013
1 parent 9c714ee commit af2ead8
Show file tree
Hide file tree
Showing 34 changed files with 940 additions and 51 deletions.
10 changes: 5 additions & 5 deletions Raven.Abstractions/Data/IndexStats.cs
Expand Up @@ -37,15 +37,15 @@ public override string ToString()
[Flags]
public enum IndexingPriority
{
Normal = 0,
Normal = 1,

Disabled = 1,
Disabled = 2,

Idle = 2,
Idle = 4,

Abandoned = 4,
Abandoned = 8,

Forced = 256,
Forced = 512,
}

public class IndexingPerformanceStats
Expand Down
16 changes: 16 additions & 0 deletions Raven.Client.Embedded/EmbeddedAsyncServerClient.cs
Expand Up @@ -171,6 +171,11 @@ public Task<IndexDefinition[]> GetIndexesAsync(int start, int pageSize)
return new CompletedTask<IndexDefinition[]>(databaseCommands.GetIndexes(start, pageSize));
}

public Task<TransformerDefinition[]> GetTransformersAsync(int start, int pageSize)
{
return new CompletedTask<TransformerDefinition[]>(databaseCommands.GetTransformers(start, pageSize));
}

public Task ResetIndexAsync(string name)
{
databaseCommands.ResetIndex(name);
Expand All @@ -182,6 +187,11 @@ public Task<IndexDefinition> GetIndexAsync(string name)
return new CompletedTask<IndexDefinition>(databaseCommands.GetIndex(name));
}

public Task<TransformerDefinition> GetTransformerAsync(string name)
{
return new CompletedTask<TransformerDefinition>(databaseCommands.GetTransformer(name));
}

public Task<string> PutIndexAsync(string name, IndexDefinition indexDef, bool overwrite)
{
return new CompletedTask<string>(databaseCommands.PutIndex(name, indexDef, overwrite));
Expand All @@ -204,6 +214,12 @@ public Task DeleteByIndexAsync(string indexName, IndexQuery queryToDelete, bool
return new CompletedTask();
}

public Task DeleteTransformerAsync(string name)
{
databaseCommands.DeleteTransformer(name);
return new CompletedTask();
}

public Task DeleteDocumentAsync(string id)
{
databaseCommands.Delete(id, null);
Expand Down
33 changes: 33 additions & 0 deletions Raven.Client.Embedded/EmbeddedDatabaseCommands.cs
Expand Up @@ -307,6 +307,39 @@ public IndexDefinition[] GetIndexes(int start, int pageSize)
.ToArray();
}

/// <summary>
/// Gets the transformers from the server
/// </summary>
/// <param name="start">Paging start</param>
/// <param name="pageSize">Size of the page.</param>
public TransformerDefinition[] GetTransformers(int start, int pageSize)
{
return database.GetTransformers(start, pageSize)
.Select(x =>JsonConvert.DeserializeObject<TransformerDefinition>(((RavenJObject) x)["definition"].ToString(),new JsonToJsonConverter()))
.ToArray();

}

/// <summary>
/// Gets the transformer definition for the specified name
/// </summary>
/// <param name="name">The name.</param>
public TransformerDefinition GetTransformer(string name)
{
CurrentOperationContext.Headers.Value = OperationsHeaders;
return database.GetTransformerDefinition(name);
}

/// <summary>
/// Deletes the transformer.
/// </summary>
/// <param name="name">The name.</param>
public void DeleteTransformer(string name)
{
CurrentOperationContext.Headers.Value = OperationsHeaders;
database.DeleteTransfom(name);
}

/// <summary>
/// Resets the specified index
/// </summary>
Expand Down
53 changes: 53 additions & 0 deletions Raven.Client.Lightweight/Connection/Async/AsyncServerClient.cs
Expand Up @@ -152,6 +152,29 @@ public Task<IndexDefinition[]> GetIndexesAsync(int start, int pageSize)
});
}

/// <summary>
/// Gets the transformers from the server asynchronously
/// </summary>
public Task<TransformerDefinition[]> GetTransformersAsync(int start, int pageSize)
{
return ExecuteWithReplication("GET", operationUrl =>
{
var url2 = (operationUrl + "/transformers?start=" + start + "&pageSize=" + pageSize).NoCache();
var request = jsonRequestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(this, url2, "GET", credentials, convention));
request.AddReplicationStatusHeaders(url, operationUrl, replicationInformer, convention.FailoverBehavior, HandleReplicationStatusChanges);
return request.ReadResponseJsonAsync()
.ContinueWith(task =>
{
var json = ((RavenJArray)task.Result);
//NOTE: To review, I'm not confidence this is the correct way to deserialize the transformer definition
return json
.Select(x => JsonConvert.DeserializeObject<TransformerDefinition>(((RavenJObject)x)["definition"].ToString(), new JsonToJsonConverter()))
.ToArray();
});
});
}

/// <summary>
/// Resets the specified index asynchronously
/// </summary>
Expand Down Expand Up @@ -190,6 +213,28 @@ public Task<IndexDefinition> GetIndexAsync(string name)
});
}

/// <summary>
/// Gets the transformer definition for the specified name asynchronously
/// </summary>
/// <param name="name">The name.</param>
public Task<TransformerDefinition> GetTransformerAsync(string name)
{
return ExecuteWithReplication("GET", operationUrl =>
{
return operationUrl.Transformer(name)
.NoCache()
.ToJsonRequest(this, credentials, convention)
.AddReplicationStatusHeaders(url, operationUrl, replicationInformer, convention.FailoverBehavior, HandleReplicationStatusChanges)
.ReadResponseJsonAsync()
.ContinueWith(task =>
{
var json = (RavenJObject)task.Result;
//NOTE: To review, I'm not confidence this is the correct way to deserialize the index definition
return convention.CreateSerializer().Deserialize<TransformerDefinition>(new RavenJTokenReader(json));
});
});
}

/// <summary>
/// Puts the index definition for the specified name asynchronously
/// </summary>
Expand Down Expand Up @@ -314,6 +359,14 @@ public Task DeleteByIndexAsync(string indexName, IndexQuery queryToDelete, bool
});
}

public Task DeleteTransformerAsync(string name)
{
return ExecuteWithReplication("DELETE", operationUrl => operationUrl.Transformer(name)
.ToJsonRequest(this, credentials, convention, OperationsHeaders, "DELETE")
.AddReplicationStatusHeaders(url, operationUrl, replicationInformer, convention.FailoverBehavior, HandleReplicationStatusChanges)
.ExecuteRequestAsync());
}

/// <summary>
/// Deletes the document for the specified id asynchronously
/// </summary>
Expand Down
Expand Up @@ -87,6 +87,11 @@ public interface IAsyncDatabaseCommands : IDisposable, IHoldProfilingInformation
/// <param name="pageSize">Size of the page.</param>
Task<IndexDefinition[]> GetIndexesAsync(int start, int pageSize);

/// <summary>
/// Gets the transformers from the server asynchronously
/// </summary>
Task<TransformerDefinition[]> GetTransformersAsync(int start, int pageSize);

/// <summary>
/// Resets the specified index asynchronously
/// </summary>
Expand All @@ -99,6 +104,12 @@ public interface IAsyncDatabaseCommands : IDisposable, IHoldProfilingInformation
/// <param name="name">The name.</param>
Task<IndexDefinition> GetIndexAsync(string name);

/// <summary>
/// Gets the transformer definition for the specified name asynchronously
/// </summary>
/// <param name="name">The name.</param>
Task<TransformerDefinition> GetTransformerAsync(string name);

/// <summary>
/// Puts the index definition for the specified name asynchronously
/// </summary>
Expand All @@ -108,7 +119,7 @@ public interface IAsyncDatabaseCommands : IDisposable, IHoldProfilingInformation
Task<string> PutIndexAsync(string name, IndexDefinition indexDef, bool overwrite);

/// <summary>
/// Puts the transfomer definition for the specified name asynchronously
/// Puts the transformer definition for the specified name asynchronously
/// </summary>
Task<string> PutTransfomerAsync(string name, TransformerDefinition transformerDefinition);

Expand All @@ -126,6 +137,12 @@ public interface IAsyncDatabaseCommands : IDisposable, IHoldProfilingInformation
/// <param name="allowStale">if set to <c>true</c> allow the operation while the index is stale.</param>
Task DeleteByIndexAsync(string indexName, IndexQuery queryToDelete, bool allowStale);

/// <summary>
/// Deletes the transformer definition for the specified name asynchronously
/// </summary>
/// <param name="name">The name.</param>
Task DeleteTransformerAsync(string name);

/// <summary>
/// Deletes the document for the specified id asynchronously
/// </summary>
Expand Down
17 changes: 17 additions & 0 deletions Raven.Client.Lightweight/Connection/IDatabaseCommands.cs
Expand Up @@ -450,7 +450,24 @@ public interface IDatabaseCommands : IHoldProfilingInformation
/// </summary>
ILowLevelBulkInsertOperation GetBulkInsertOperation(BulkInsertOptions options);
#endif
/// <summary>
/// Gets the transformers from the server
/// </summary>
/// <param name="start">Paging start</param>
/// <param name="pageSize">Size of the page.</param>
TransformerDefinition[] GetTransformers(int start, int pageSize);

/// <summary>
/// Gets the transformer definition for the specified name
/// </summary>
/// <param name="name">The name.</param>
TransformerDefinition GetTransformer(string name);

/// <summary>
/// Deletes the specified transformer
/// </summary>
/// <param name="name">The name.</param>
void DeleteTransformer(string name);
}
}
#endif
5 changes: 5 additions & 0 deletions Raven.Client.Lightweight/Connection/RavenUrlExtensions.cs
Expand Up @@ -26,6 +26,11 @@ public static string IndexDefinition(this string url, string index)
return url + "/indexes/" + index + "?definition=yes";
}

public static string Transformer(this string url, string transformer)
{
return url + "/transformers/" + transformer;
}

public static string IndexNames(this string url, int start, int pageSize)
{
return url + "/indexes/?namesOnly=true&start=" + start + "&pageSize=" + pageSize;
Expand Down
68 changes: 64 additions & 4 deletions Raven.Client.Lightweight/Connection/ServerClient.cs
Expand Up @@ -702,6 +702,70 @@ public IndexDefinition[] GetIndexes(int start, int pageSize)
});
}

public TransformerDefinition[] GetTransformers(int start, int pageSize)
{
return ExecuteWithReplication("GET", operationUrl =>
{
var url2 = (operationUrl + "/transformers?start=" + start + "&pageSize=" + pageSize).NoCache();
var request = jsonRequestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(this, url2, "GET", credentials, convention));
request.AddReplicationStatusHeaders(url, operationUrl, replicationInformer, convention.FailoverBehavior, HandleReplicationStatusChanges);
var result = request.ReadResponseJson();
var json = ((RavenJArray)result);
//NOTE: To review, I'm not confidence this is the correct way to deserialize the transformer definition
return json
.Select(x => JsonConvert.DeserializeObject<TransformerDefinition>(((RavenJObject)x)["definition"].ToString(), new JsonToJsonConverter()))
.ToArray();
});
}

public TransformerDefinition GetTransformer(string name)
{
EnsureIsNotNullOrEmpty(name, "name");
return ExecuteWithReplication("GET", u => DirectGetTransformer(name, u));
}

public void DeleteTransformer(string name)
{
EnsureIsNotNullOrEmpty(name, "name");
ExecuteWithReplication("DELETE", operationUrl => DirectDeleteTransformer(name, operationUrl));
}

private void DirectDeleteTransformer(string name, string operationUrl)
{
var request = jsonRequestFactory.CreateHttpJsonRequest(
new CreateHttpJsonRequestParams(this, operationUrl + "/transformers/" + name, "DELETE", credentials, convention)
.AddOperationHeaders(OperationsHeaders))
.AddReplicationStatusHeaders(Url, operationUrl, replicationInformer, convention.FailoverBehavior, HandleReplicationStatusChanges);

request.ExecuteRequest();
}

private TransformerDefinition DirectGetTransformer(string transformerName, string operationUrl)
{
var httpJsonRequest = jsonRequestFactory.CreateHttpJsonRequest(
new CreateHttpJsonRequestParams(this, operationUrl + "/transformers/" + transformerName, "GET", credentials, convention)
.AddOperationHeaders(OperationsHeaders))
.AddReplicationStatusHeaders(Url, operationUrl, replicationInformer, convention.FailoverBehavior, HandleReplicationStatusChanges);

RavenJToken transformerDef;
try
{
transformerDef = httpJsonRequest.ReadResponseJson();
}
catch (WebException e)
{
var httpWebResponse = e.Response as HttpWebResponse;
if (httpWebResponse != null &&
httpWebResponse.StatusCode == HttpStatusCode.NotFound)
return null;
throw;
}

var value = transformerDef.Value<RavenJObject>("Transformer");
return convention.CreateSerializer().Deserialize<TransformerDefinition>(new RavenJTokenReader(value));
}

/// <summary>
/// Resets the specified index
/// </summary>
Expand Down Expand Up @@ -753,8 +817,6 @@ private IndexDefinition DirectGetIndex(string indexName, string operationUrl)
.AddOperationHeaders(OperationsHeaders))
.AddReplicationStatusHeaders(Url, operationUrl, replicationInformer, convention.FailoverBehavior, HandleReplicationStatusChanges);



RavenJToken indexDef;
try
{
Expand Down Expand Up @@ -1066,8 +1128,6 @@ private QueryResult DirectQuery(string index, IndexQuery query, string operation
convention.FailoverBehavior,
HandleReplicationStatusChanges);



RavenJObject json;
try
{
Expand Down
5 changes: 5 additions & 0 deletions Raven.Database/DocumentDatabase.cs
Expand Up @@ -2305,5 +2305,10 @@ public JsonDocument GetWithTransformer(string key, string transformer, Transacti
});
return result;
}

public TransformerDefinition GetTransformerDefinition(string name)
{
return IndexDefinitionStorage.GetTransformerDefinition(name);
}
}
}
2 changes: 1 addition & 1 deletion Raven.Database/Raven.Database.csproj
Expand Up @@ -699,7 +699,7 @@
<Compile Include="Storage\Esent\StorageActionsAccessor.cs" />
<Compile Include="Storage\Esent\StorageActions\Documents.cs" />
<Compile Include="Storage\Esent\StorageActions\DocumentStorageActions.cs" />
<Compile Include="Storage\Esent\StorageActions\EsentUtil.cs" />
<Compile Include="Storage\Esent\Debug\EsentUtil.cs" />
<Compile Include="Storage\Esent\StorageActions\General.cs" />
<Compile Include="Storage\Esent\StorageActions\Indexing.cs" />
<Compile Include="Storage\Esent\StorageActions\Lists.cs" />
Expand Down

0 comments on commit af2ead8

Please sign in to comment.