cleaned Groovy classes * added type information to public methods * removed semicolons * replaced GStrings with Strings
This commit is contained in:
parent
0eaccd483f
commit
5f4c6c75ae
|
@ -24,14 +24,14 @@ package org.elasticsearch.groovy.client
|
|||
*/
|
||||
class GAdminClient {
|
||||
|
||||
private final GClient gClient;
|
||||
private final GClient gClient
|
||||
|
||||
final GIndicesAdminClient indices;
|
||||
final GIndicesAdminClient indices
|
||||
|
||||
final GClusterAdminClient cluster;
|
||||
final GClusterAdminClient cluster
|
||||
|
||||
def GAdminClient(gClient) {
|
||||
this.gClient = gClient;
|
||||
GAdminClient(gClient) {
|
||||
this.gClient = gClient
|
||||
|
||||
this.indices = new GIndicesAdminClient(gClient)
|
||||
this.cluster = new GClusterAdminClient(gClient)
|
||||
|
|
|
@ -54,8 +54,8 @@ class GClient {
|
|||
|
||||
static {
|
||||
BaseRequestBuilder.metaClass.gexecute = {
|
||||
ListenableActionFuture future = delegate.execute();
|
||||
return new GActionFuture(future);
|
||||
ListenableActionFuture future = delegate.execute()
|
||||
return new GActionFuture(future)
|
||||
}
|
||||
|
||||
IndexRequest.metaClass.setSource = {Closure c ->
|
||||
|
@ -148,31 +148,31 @@ class GClient {
|
|||
}
|
||||
}
|
||||
|
||||
public static XContentType contentType = XContentType.SMILE;
|
||||
public static XContentType contentType = XContentType.SMILE
|
||||
|
||||
public static XContentType indexContentType = XContentType.JSON;
|
||||
public static XContentType indexContentType = XContentType.JSON
|
||||
|
||||
final Client client;
|
||||
final Client client
|
||||
|
||||
int resolveStrategy = Closure.DELEGATE_FIRST
|
||||
|
||||
private final InternalClient internalClient
|
||||
|
||||
final GAdminClient admin;
|
||||
final GAdminClient admin
|
||||
|
||||
def GClient(client) {
|
||||
this.client = client;
|
||||
this.internalClient = client;
|
||||
GClient(client) {
|
||||
this.client = client
|
||||
this.internalClient = client
|
||||
|
||||
this.admin = new GAdminClient(this)
|
||||
}
|
||||
|
||||
IndexRequestBuilder prepareIndex(String index, String type) {
|
||||
return client.prepareIndex(index, type);
|
||||
return client.prepareIndex(index, type)
|
||||
}
|
||||
|
||||
IndexRequestBuilder prepareIndex(String index, String type, String id) {
|
||||
return client.prepareIndex(index, type, id);
|
||||
return client.prepareIndex(index, type, id)
|
||||
}
|
||||
|
||||
GActionFuture<IndexResponse> index(Closure c) {
|
||||
|
@ -184,7 +184,7 @@ class GClient {
|
|||
}
|
||||
|
||||
GActionFuture<IndexResponse> index(IndexRequest request) {
|
||||
GActionFuture<IndexResponse> future = new GActionFuture<IndexResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<IndexResponse> future = new GActionFuture<IndexResponse>(internalClient.threadPool(), request)
|
||||
client.index(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ class GClient {
|
|||
}
|
||||
|
||||
GetRequestBuilder prepareGet(String index, String type, String id) {
|
||||
return client.prepareGet(index, type, id);
|
||||
return client.prepareGet(index, type, id)
|
||||
}
|
||||
|
||||
GActionFuture<GetResponse> get(Closure c) {
|
||||
|
@ -206,7 +206,7 @@ class GClient {
|
|||
}
|
||||
|
||||
GActionFuture<GetResponse> get(GetRequest request) {
|
||||
GActionFuture<GetResponse> future = new GActionFuture<GetResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<GetResponse> future = new GActionFuture<GetResponse>(internalClient.threadPool(), request)
|
||||
client.get(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ class GClient {
|
|||
}
|
||||
|
||||
GActionFuture<DeleteResponse> delete(DeleteRequest request) {
|
||||
GActionFuture<DeleteResponse> future = new GActionFuture<DeleteResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<DeleteResponse> future = new GActionFuture<DeleteResponse>(internalClient.threadPool(), request)
|
||||
client.delete(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ class GClient {
|
|||
}
|
||||
|
||||
DeleteByQueryRequestBuilder prepareDeleteByQuery(String... indices) {
|
||||
return client.prepareDeleteByQuery(indices);
|
||||
return client.prepareDeleteByQuery(indices)
|
||||
}
|
||||
|
||||
GActionFuture<DeleteByQueryResponse> deleteByQuery(Closure c) {
|
||||
|
@ -250,7 +250,7 @@ class GClient {
|
|||
}
|
||||
|
||||
GActionFuture<DeleteByQueryResponse> deleteByQuery(DeleteByQueryRequest request) {
|
||||
GActionFuture<DeleteByQueryResponse> future = new GActionFuture<DeleteByQueryResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<DeleteByQueryResponse> future = new GActionFuture<DeleteByQueryResponse>(internalClient.threadPool(), request)
|
||||
client.deleteByQuery(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ class GClient {
|
|||
}
|
||||
|
||||
GActionFuture<CountResponse> count(CountRequest request) {
|
||||
GActionFuture<CountResponse> future = new GActionFuture<CountResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<CountResponse> future = new GActionFuture<CountResponse>(internalClient.threadPool(), request)
|
||||
client.count(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ class GClient {
|
|||
}
|
||||
|
||||
GActionFuture<SearchResponse> search(SearchRequest request) {
|
||||
GActionFuture<SearchResponse> future = new GActionFuture<SearchResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<SearchResponse> future = new GActionFuture<SearchResponse>(internalClient.threadPool(), request)
|
||||
client.search(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -312,7 +312,7 @@ class GClient {
|
|||
}
|
||||
|
||||
GActionFuture<SearchResponse> moreLikeThis(MoreLikeThisRequest request) {
|
||||
GActionFuture<SearchResponse> future = new GActionFuture<SearchResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<SearchResponse> future = new GActionFuture<SearchResponse>(internalClient.threadPool(), request)
|
||||
client.moreLikeThis(request, future)
|
||||
return future
|
||||
}
|
||||
|
|
|
@ -49,14 +49,14 @@ class GClusterAdminClient {
|
|||
|
||||
private final GClient gClient
|
||||
|
||||
private final InternalClient internalClient;
|
||||
private final InternalClient internalClient
|
||||
|
||||
final ClusterAdminClient clusterAdminClient;
|
||||
final ClusterAdminClient clusterAdminClient
|
||||
|
||||
def GClusterAdminClient(gClient) {
|
||||
this.gClient = gClient;
|
||||
this.internalClient = gClient.client;
|
||||
this.clusterAdminClient = internalClient.admin().cluster();
|
||||
this.gClient = gClient
|
||||
this.internalClient = gClient.client
|
||||
this.clusterAdminClient = internalClient.admin().cluster()
|
||||
}
|
||||
|
||||
// HEALTH
|
||||
|
@ -74,7 +74,7 @@ class GClusterAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<ClusterHealthResponse> health(ClusterHealthRequest request) {
|
||||
GActionFuture<ClusterHealthResponse> future = new GActionFuture<ClusterHealthResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<ClusterHealthResponse> future = new GActionFuture<ClusterHealthResponse>(internalClient.threadPool(), request)
|
||||
clusterAdminClient.health(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ class GClusterAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<ClusterStateResponse> state(ClusterStateRequest request) {
|
||||
GActionFuture<ClusterStateResponse> future = new GActionFuture<ClusterStateResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<ClusterStateResponse> future = new GActionFuture<ClusterStateResponse>(internalClient.threadPool(), request)
|
||||
clusterAdminClient.state(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ class GClusterAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<NodesInfoResponse> nodesInfo(NodesInfoRequest request) {
|
||||
GActionFuture<NodesInfoResponse> future = new GActionFuture<NodesInfoResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<NodesInfoResponse> future = new GActionFuture<NodesInfoResponse>(internalClient.threadPool(), request)
|
||||
clusterAdminClient.nodesInfo(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ class GClusterAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<NodesStatsResponse> nodesStats(NodesStatsRequest request) {
|
||||
GActionFuture<NodesStatsResponse> future = new GActionFuture<NodesStatsResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<NodesStatsResponse> future = new GActionFuture<NodesStatsResponse>(internalClient.threadPool(), request)
|
||||
clusterAdminClient.nodesStats(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ class GClusterAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<NodesShutdownResponse> nodesShutdown(NodesShutdownRequest request) {
|
||||
GActionFuture<NodesShutdownResponse> future = new GActionFuture<NodesShutdownResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<NodesShutdownResponse> future = new GActionFuture<NodesShutdownResponse>(internalClient.threadPool(), request)
|
||||
clusterAdminClient.nodesShutdown(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ class GClusterAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<NodesRestartResponse> nodesRestart(NodesRestartRequest request) {
|
||||
GActionFuture<NodesRestartResponse> future = new GActionFuture<NodesRestartResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<NodesRestartResponse> future = new GActionFuture<NodesRestartResponse>(internalClient.threadPool(), request)
|
||||
clusterAdminClient.nodesRestart(request, future)
|
||||
return future
|
||||
}
|
||||
|
|
|
@ -124,14 +124,14 @@ class GIndicesAdminClient {
|
|||
|
||||
private final GClient gClient
|
||||
|
||||
private final InternalClient internalClient;
|
||||
private final InternalClient internalClient
|
||||
|
||||
final IndicesAdminClient indicesAdminClient;
|
||||
final IndicesAdminClient indicesAdminClient
|
||||
|
||||
def GIndicesAdminClient(gClient) {
|
||||
this.gClient = gClient
|
||||
this.internalClient = gClient.client
|
||||
this.indicesAdminClient = internalClient.admin().indices();
|
||||
this.indicesAdminClient = internalClient.admin().indices()
|
||||
}
|
||||
|
||||
// STATUS
|
||||
|
@ -149,7 +149,7 @@ class GIndicesAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<IndicesStatusResponse> status(IndicesStatusRequest request) {
|
||||
GActionFuture<IndicesStatusResponse> future = new GActionFuture<IndicesStatusResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<IndicesStatusResponse> future = new GActionFuture<IndicesStatusResponse>(internalClient.threadPool(), request)
|
||||
indicesAdminClient.status(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ class GIndicesAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<CreateIndexResponse> create(CreateIndexRequest request) {
|
||||
GActionFuture<CreateIndexResponse> future = new GActionFuture<CreateIndexResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<CreateIndexResponse> future = new GActionFuture<CreateIndexResponse>(internalClient.threadPool(), request)
|
||||
indicesAdminClient.create(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ class GIndicesAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<DeleteIndexResponse> delete(DeleteIndexRequest request) {
|
||||
GActionFuture<DeleteIndexResponse> future = new GActionFuture<DeleteIndexResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<DeleteIndexResponse> future = new GActionFuture<DeleteIndexResponse>(internalClient.threadPool(), request)
|
||||
indicesAdminClient.delete(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ class GIndicesAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<RefreshResponse> refresh(RefreshRequest request) {
|
||||
GActionFuture<RefreshResponse> future = new GActionFuture<RefreshResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<RefreshResponse> future = new GActionFuture<RefreshResponse>(internalClient.threadPool(), request)
|
||||
indicesAdminClient.refresh(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ class GIndicesAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<FlushResponse> flush(FlushRequest request) {
|
||||
GActionFuture<FlushResponse> future = new GActionFuture<FlushResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<FlushResponse> future = new GActionFuture<FlushResponse>(internalClient.threadPool(), request)
|
||||
indicesAdminClient.flush(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ class GIndicesAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<OptimizeResponse> optimize(OptimizeRequest request) {
|
||||
GActionFuture<OptimizeResponse> future = new GActionFuture<OptimizeResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<OptimizeResponse> future = new GActionFuture<OptimizeResponse>(internalClient.threadPool(), request)
|
||||
indicesAdminClient.optimize(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ class GIndicesAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<PutMappingResponse> putMapping(PutMappingRequest request) {
|
||||
GActionFuture<PutMappingResponse> future = new GActionFuture<PutMappingResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<PutMappingResponse> future = new GActionFuture<PutMappingResponse>(internalClient.threadPool(), request)
|
||||
indicesAdminClient.putMapping(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ class GIndicesAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<GatewaySnapshotResponse> gatewaySnapshot(GatewaySnapshotRequest request) {
|
||||
GActionFuture<GatewaySnapshotResponse> future = new GActionFuture<GatewaySnapshotResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<GatewaySnapshotResponse> future = new GActionFuture<GatewaySnapshotResponse>(internalClient.threadPool(), request)
|
||||
indicesAdminClient.gatewaySnapshot(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ class GIndicesAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<IndicesAliasesResponse> aliases(IndicesAliasesRequest request) {
|
||||
GActionFuture<IndicesAliasesResponse> future = new GActionFuture<IndicesAliasesResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<IndicesAliasesResponse> future = new GActionFuture<IndicesAliasesResponse>(internalClient.threadPool(), request)
|
||||
indicesAdminClient.aliases(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -369,7 +369,7 @@ class GIndicesAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<ClearIndicesCacheResponse> clearCache(ClearIndicesCacheRequest request) {
|
||||
GActionFuture<ClearIndicesCacheResponse> future = new GActionFuture<ClearIndicesCacheResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<ClearIndicesCacheResponse> future = new GActionFuture<ClearIndicesCacheResponse>(internalClient.threadPool(), request)
|
||||
indicesAdminClient.clearCache(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -389,7 +389,7 @@ class GIndicesAdminClient {
|
|||
}
|
||||
|
||||
GActionFuture<UpdateSettingsResponse> updateSettings(UpdateSettingsRequest request) {
|
||||
GActionFuture<UpdateSettingsResponse> future = new GActionFuture<UpdateSettingsResponse>(internalClient.threadPool(), request);
|
||||
GActionFuture<UpdateSettingsResponse> future = new GActionFuture<UpdateSettingsResponse>(internalClient.threadPool(), request)
|
||||
indicesAdminClient.updateSettings(request, future)
|
||||
return future
|
||||
}
|
||||
|
@ -397,14 +397,14 @@ class GIndicesAdminClient {
|
|||
// ANALYZE
|
||||
|
||||
AnalyzeRequestBuilder prepareAnalyze(String index, String text) {
|
||||
indicesAdminClient.prepareAnalyze(index, text);
|
||||
indicesAdminClient.prepareAnalyze(index, text)
|
||||
}
|
||||
|
||||
GActionFuture<AnalyzeResponse> analyze(Closure c) {
|
||||
AnalyzeRequest request = new AnalyzeRequest()
|
||||
c.setDelegate request
|
||||
c.resolveStrategy = gClient.resolveStrategy;
|
||||
c.call();
|
||||
c.resolveStrategy = gClient.resolveStrategy
|
||||
c.call()
|
||||
analyze(request)
|
||||
}
|
||||
|
||||
|
@ -417,14 +417,14 @@ class GIndicesAdminClient {
|
|||
// PUT INDEX TEMPLATE
|
||||
|
||||
PutIndexTemplateRequestBuilder preparePutTemplate(String name) {
|
||||
indicesAdminClient.preparePutTemplate(name);
|
||||
indicesAdminClient.preparePutTemplate(name)
|
||||
}
|
||||
|
||||
GActionFuture<PutIndexTemplateResponse> putTemplate(Closure c) {
|
||||
PutIndexTemplateRequest request = new PutIndexTemplateRequest()
|
||||
c.setDelegate request
|
||||
c.resolveStrategy = gClient.resolveStrategy;
|
||||
c.call();
|
||||
c.resolveStrategy = gClient.resolveStrategy
|
||||
c.call()
|
||||
putTemplate(request)
|
||||
}
|
||||
|
||||
|
@ -437,14 +437,14 @@ class GIndicesAdminClient {
|
|||
// DELETE INDEX TEMPLATE
|
||||
|
||||
DeleteIndexTemplateRequestBuilder prepareDeleteTemplate(String name) {
|
||||
indicesAdminClient.prepareDeleteTemplate(name);
|
||||
indicesAdminClient.prepareDeleteTemplate(name)
|
||||
}
|
||||
|
||||
GActionFuture<DeleteIndexTemplateResponse> deleteTemplate(Closure c) {
|
||||
DeleteIndexTemplateRequest request = new DeleteIndexTemplateRequest()
|
||||
c.setDelegate request
|
||||
c.resolveStrategy = gClient.resolveStrategy;
|
||||
c.call();
|
||||
c.resolveStrategy = gClient.resolveStrategy
|
||||
c.call()
|
||||
deleteTemplate(request)
|
||||
}
|
||||
|
||||
|
|
|
@ -33,9 +33,9 @@ import org.elasticsearch.common.xcontent.XContentType
|
|||
*/
|
||||
class GXContentBuilder {
|
||||
|
||||
static NODE_ELEMENT = "element"
|
||||
static NODE_ELEMENT = 'element'
|
||||
|
||||
static int rootResolveStrategy = Closure.OWNER_FIRST; // the default in Closure
|
||||
static int rootResolveStrategy = Closure.OWNER_FIRST // the default in Closure
|
||||
|
||||
def root
|
||||
|
||||
|
@ -48,26 +48,26 @@ class GXContentBuilder {
|
|||
}
|
||||
|
||||
String buildAsString(Closure c) {
|
||||
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
|
||||
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)
|
||||
def json = build(c)
|
||||
builder.map(json);
|
||||
return builder.string();
|
||||
builder.map(json)
|
||||
return builder.string()
|
||||
}
|
||||
|
||||
byte[] buildAsBytes(Closure c) {
|
||||
return buildAsBytes(c, XContentType.JSON);
|
||||
return buildAsBytes(c, XContentType.JSON)
|
||||
}
|
||||
|
||||
byte[] buildAsBytes(Closure c, XContentType contentType) {
|
||||
XContentBuilder builder = XContentFactory.contentBuilder(contentType);
|
||||
XContentBuilder builder = XContentFactory.contentBuilder(contentType)
|
||||
def json = build(c)
|
||||
builder.map(json);
|
||||
return builder.copiedBytes();
|
||||
builder.map(json)
|
||||
return builder.copiedBytes()
|
||||
}
|
||||
|
||||
private buildRoot(Closure c) {
|
||||
c.delegate = this
|
||||
c.resolveStrategy = rootResolveStrategy;
|
||||
c.resolveStrategy = rootResolveStrategy
|
||||
root = [:]
|
||||
current = root
|
||||
def returnValue = c.call()
|
||||
|
@ -85,7 +85,6 @@ class GXContentBuilder {
|
|||
def prev = current
|
||||
def list = []
|
||||
try {
|
||||
|
||||
current = list
|
||||
c.call(list)
|
||||
}
|
||||
|
@ -176,7 +175,6 @@ class GXContentBuilder {
|
|||
else {
|
||||
return it
|
||||
}
|
||||
|
||||
}
|
||||
current[propName] = value
|
||||
}
|
||||
|
@ -188,5 +186,4 @@ class GXContentBuilder {
|
|||
def getProperty(String propName) {
|
||||
current[propName]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.groovy.node
|
||||
|
||||
import org.elasticsearch.common.settings.Settings
|
||||
import org.elasticsearch.groovy.client.GClient
|
||||
import org.elasticsearch.node.Node
|
||||
|
||||
|
@ -27,26 +28,26 @@ import org.elasticsearch.node.Node
|
|||
*/
|
||||
class GNode {
|
||||
|
||||
final Node node;
|
||||
final Node node
|
||||
|
||||
final GClient client;
|
||||
final GClient client
|
||||
|
||||
def GNode(Node node) {
|
||||
this.node = node;
|
||||
GNode(Node node) {
|
||||
this.node = node
|
||||
this.client = new GClient(node.client())
|
||||
}
|
||||
|
||||
/**
|
||||
* The settings that were used to create the node.
|
||||
*/
|
||||
def getSettings() {
|
||||
node.settings();
|
||||
Settings getSettings() {
|
||||
node.settings()
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the node. If the node is already started, this method is no-op.
|
||||
*/
|
||||
def start() {
|
||||
GNode start() {
|
||||
node.start()
|
||||
this
|
||||
}
|
||||
|
@ -54,15 +55,15 @@ class GNode {
|
|||
/**
|
||||
* Stops the node. If the node is already started, this method is no-op.
|
||||
*/
|
||||
def stop() {
|
||||
GNode stop() {
|
||||
node.stop()
|
||||
this
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the node (and {@link #stop} s if its running).
|
||||
* Closes the node (and {@link #stop}s if it's running).
|
||||
*/
|
||||
def close() {
|
||||
GNode close() {
|
||||
node.close()
|
||||
this
|
||||
}
|
||||
|
|
|
@ -27,43 +27,43 @@ import org.elasticsearch.node.Node
|
|||
import org.elasticsearch.node.internal.InternalNode
|
||||
|
||||
/**
|
||||
* The node builder allow to build a {@link GNode} instance.
|
||||
* The node builder allow to build a {@link GNode} instance.
|
||||
*
|
||||
* @author kimchy (shay.banon)
|
||||
*/
|
||||
public class GNodeBuilder {
|
||||
class GNodeBuilder {
|
||||
|
||||
private final ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder();
|
||||
private final ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder()
|
||||
|
||||
private boolean loadConfigSettings = true;
|
||||
private boolean loadConfigSettings = true
|
||||
|
||||
public static GNodeBuilder nodeBuilder() {
|
||||
static GNodeBuilder nodeBuilder() {
|
||||
new GNodeBuilder()
|
||||
}
|
||||
|
||||
public ImmutableSettings.Builder getSettings() {
|
||||
return settingsBuilder;
|
||||
ImmutableSettings.Builder getSettings() {
|
||||
settingsBuilder
|
||||
}
|
||||
|
||||
def settings(Settings.Builder settings) {
|
||||
ImmutableSettings.Builder settings(Settings.Builder settings) {
|
||||
settingsBuilder.put(settings.build())
|
||||
}
|
||||
|
||||
def settings(Settings settings) {
|
||||
ImmutableSettings.Builder settings(Settings settings) {
|
||||
settingsBuilder.put(settings)
|
||||
}
|
||||
|
||||
def settings(Closure settings) {
|
||||
ImmutableSettings.Builder settings(Closure settings) {
|
||||
byte[] settingsBytes = new GXContentBuilder().buildAsBytes(settings)
|
||||
settingsBuilder.put(new JsonSettingsLoader().load(settingsBytes))
|
||||
}
|
||||
|
||||
def build() {
|
||||
GNode build() {
|
||||
Node node = new InternalNode(settingsBuilder.build(), loadConfigSettings)
|
||||
new GNode(node)
|
||||
}
|
||||
|
||||
def node() {
|
||||
GNode node() {
|
||||
build().start()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ class GXContentBuilderTests extends GroovyTestCase {
|
|||
def builder = new GXContentBuilder()
|
||||
|
||||
def result = builder.buildAsString {
|
||||
rootprop = "something"
|
||||
rootprop = 'something'
|
||||
}
|
||||
|
||||
assertEquals '{"rootprop":"something"}', result.toString()
|
||||
|
@ -39,7 +39,7 @@ class GXContentBuilderTests extends GroovyTestCase {
|
|||
|
||||
def result = builder.buildAsString {
|
||||
categories = ['a', 'b', 'c']
|
||||
rootprop = "something"
|
||||
rootprop = 'something'
|
||||
}
|
||||
|
||||
assertEquals '{"categories":["a","b","c"],"rootprop":"something"}', result.toString()
|
||||
|
@ -50,7 +50,7 @@ class GXContentBuilderTests extends GroovyTestCase {
|
|||
|
||||
def result = builder.buildAsString {
|
||||
categories = ['a', 'b', 'c']
|
||||
rootprop = "something"
|
||||
rootprop = 'something'
|
||||
test {
|
||||
subprop = 10
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ class GXContentBuilderTests extends GroovyTestCase {
|
|||
|
||||
def result = builder.buildAsString {
|
||||
categories = ['a', 'b', 'c']
|
||||
rootprop = "something"
|
||||
rootprop = 'something'
|
||||
test = {
|
||||
subprop = 10
|
||||
}
|
||||
|
@ -77,9 +77,8 @@ class GXContentBuilderTests extends GroovyTestCase {
|
|||
def builder = new GXContentBuilder()
|
||||
def result = builder.buildAsString {
|
||||
categories = ['a', 'b', 'c']
|
||||
rootprop = "something"
|
||||
rootprop = 'something'
|
||||
test subprop: 10, three: [1, 2, 3]
|
||||
|
||||
}
|
||||
|
||||
assertEquals '{"categories":["a","b","c"],"rootprop":"something","test":{"subprop":10,"three":[1,2,3]}}', result.toString()
|
||||
|
@ -89,7 +88,7 @@ class GXContentBuilderTests extends GroovyTestCase {
|
|||
void testArrayOfClosures() {
|
||||
def builder = new GXContentBuilder()
|
||||
def result = builder.buildAsString {
|
||||
foo = [{ bar = "hello" }]
|
||||
foo = [{ bar = 'hello' }]
|
||||
}
|
||||
|
||||
assertEquals '{"foo":[{"bar":"hello"}]}', result.toString()
|
||||
|
@ -125,7 +124,7 @@ class GXContentBuilderTests extends GroovyTestCase {
|
|||
def results = ['one', 'two', 'three']
|
||||
|
||||
def result = builder.buildAsString {
|
||||
books = array {list ->
|
||||
books = array { list ->
|
||||
for (b in results) {
|
||||
list << [title: b]
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ class BuilderActionsTests {
|
|||
local = true
|
||||
}
|
||||
gateway {
|
||||
type = "none"
|
||||
type = 'none'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,45 +55,43 @@ class BuilderActionsTests {
|
|||
node.close()
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testSimpleOperations() {
|
||||
def indexR = node.client.prepareIndex("test", "type1", "1").setSource({
|
||||
test = "value"
|
||||
def indexR = node.client.prepareIndex('test', 'type1', '1').setSource({
|
||||
test = 'value'
|
||||
complex {
|
||||
value1 = "value1"
|
||||
value2 = "value2"
|
||||
value1 = 'value1'
|
||||
value2 = 'value2'
|
||||
}
|
||||
}).gexecute()
|
||||
|
||||
assertThat indexR.response.index, equalTo("test")
|
||||
assertThat indexR.response.type, equalTo("type1")
|
||||
assertThat indexR.response.id, equalTo("1")
|
||||
assertThat indexR.response.index, equalTo('test')
|
||||
assertThat indexR.response.type, equalTo('type1')
|
||||
assertThat indexR.response.id, equalTo('1')
|
||||
|
||||
node.client.admin.indices.refresh {}.actionGet()
|
||||
|
||||
def countR = node.client.prepareCount("test").setQuery({
|
||||
term(test: "value")
|
||||
}).gexecute();
|
||||
def countR = node.client.prepareCount('test').setQuery({
|
||||
term(test: 'value')
|
||||
}).gexecute()
|
||||
|
||||
assertThat countR.response.count, equalTo(1l)
|
||||
|
||||
def searchR = node.client.prepareSearch("test").setQuery({
|
||||
term(test: "value")
|
||||
}).gexecute();
|
||||
def searchR = node.client.prepareSearch('test').setQuery({
|
||||
term(test: 'value')
|
||||
}).gexecute()
|
||||
|
||||
assertThat searchR.response.hits.totalHits, equalTo(1l)
|
||||
|
||||
def delete = node.client.prepareDelete("test", "type1", "1").gexecute()
|
||||
assertThat delete.response.index, equalTo("test")
|
||||
assertThat delete.response.type, equalTo("type1")
|
||||
assertThat delete.response.id, equalTo("1")
|
||||
def delete = node.client.prepareDelete('test', 'type1', '1').gexecute()
|
||||
assertThat delete.response.index, equalTo('test')
|
||||
assertThat delete.response.type, equalTo('type1')
|
||||
assertThat delete.response.id, equalTo('1')
|
||||
|
||||
def refresh = node.client.admin.indices.refresh {}
|
||||
assertThat refresh.response.failedShards, equalTo(0)
|
||||
|
||||
def get = node.client.prepareGet("test", "type1", "1").gexecute()
|
||||
def get = node.client.prepareGet('test', 'type1', '1').gexecute()
|
||||
assertThat get.response.exists, equalTo(false)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class DifferentApiExecutionTests {
|
|||
local = true
|
||||
}
|
||||
gateway {
|
||||
type = "none"
|
||||
type = 'none'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,93 +61,93 @@ class DifferentApiExecutionTests {
|
|||
@Test
|
||||
void verifyDifferentApiExecutions() {
|
||||
def response = node.client.index(new IndexRequest(
|
||||
index: "test",
|
||||
type: "type1",
|
||||
id: "1",
|
||||
index: 'test',
|
||||
type: 'type1',
|
||||
id: '1',
|
||||
source: {
|
||||
test = "value"
|
||||
test = 'value'
|
||||
complex {
|
||||
value1 = "value1"
|
||||
value2 = "value2"
|
||||
value1 = 'value1'
|
||||
value2 = 'value2'
|
||||
}
|
||||
})).response
|
||||
assertThat response.index, equalTo("test")
|
||||
assertThat response.type, equalTo("type1")
|
||||
assertThat response.id, equalTo("1")
|
||||
assertThat response.index, equalTo('test')
|
||||
assertThat response.type, equalTo('type1')
|
||||
assertThat response.id, equalTo('1')
|
||||
|
||||
def refresh = node.client.admin.indices.refresh {}
|
||||
assertThat 0, equalTo(refresh.response.failedShards)
|
||||
|
||||
def getR = node.client.get {
|
||||
index "test"
|
||||
type "type1"
|
||||
id "1"
|
||||
index 'test'
|
||||
type 'type1'
|
||||
id '1'
|
||||
}
|
||||
assertThat getR.response.exists, equalTo(true)
|
||||
assertThat getR.response.index, equalTo("test")
|
||||
assertThat getR.response.type, equalTo("type1")
|
||||
assertThat getR.response.id, equalTo("1")
|
||||
assertThat getR.response.index, equalTo('test')
|
||||
assertThat getR.response.type, equalTo('type1')
|
||||
assertThat getR.response.id, equalTo('1')
|
||||
assertThat getR.response.sourceAsString(), equalTo('{"test":"value","complex":{"value1":"value1","value2":"value2"}}')
|
||||
assertThat getR.response.source.test, equalTo("value")
|
||||
assertThat getR.response.source.complex.value1, equalTo("value1")
|
||||
assertThat getR.response.source.test, equalTo('value')
|
||||
assertThat getR.response.source.complex.value1, equalTo('value1')
|
||||
|
||||
response = node.client.index({
|
||||
index = "test"
|
||||
type = "type1"
|
||||
id = "1"
|
||||
index = 'test'
|
||||
type = 'type1'
|
||||
id = '1'
|
||||
source = {
|
||||
test = "value"
|
||||
test = 'value'
|
||||
complex {
|
||||
value1 = "value1"
|
||||
value2 = "value2"
|
||||
value1 = 'value1'
|
||||
value2 = 'value2'
|
||||
}
|
||||
}
|
||||
}).response
|
||||
assertThat response.index, equalTo("test")
|
||||
assertThat response.type, equalTo("type1")
|
||||
assertThat response.id, equalTo("1")
|
||||
assertThat response.index, equalTo('test')
|
||||
assertThat response.type, equalTo('type1')
|
||||
assertThat response.id, equalTo('1')
|
||||
|
||||
def indexR = node.client.index(indexRequest().with {
|
||||
index "test"
|
||||
type "type1"
|
||||
id "1"
|
||||
index 'test'
|
||||
type 'type1'
|
||||
id '1'
|
||||
source {
|
||||
test = "value"
|
||||
test = 'value'
|
||||
complex {
|
||||
value1 = "value1"
|
||||
value2 = "value2"
|
||||
value1 = 'value1'
|
||||
value2 = 'value2'
|
||||
}
|
||||
}
|
||||
})
|
||||
CountDownLatch latch = new CountDownLatch(1)
|
||||
indexR.success = {IndexResponse responseX ->
|
||||
assertThat responseX.index, equalTo("test")
|
||||
assertThat indexR.response.index, equalTo("test")
|
||||
assertThat responseX.type, equalTo("type1")
|
||||
assertThat indexR.response.type, equalTo("type1")
|
||||
assertThat response.id, equalTo("1")
|
||||
assertThat indexR.response.id, equalTo("1")
|
||||
indexR.success = { IndexResponse responseX ->
|
||||
assertThat responseX.index, equalTo('test')
|
||||
assertThat indexR.response.index, equalTo('test')
|
||||
assertThat responseX.type, equalTo('type1')
|
||||
assertThat indexR.response.type, equalTo('type1')
|
||||
assertThat response.id, equalTo('1')
|
||||
assertThat indexR.response.id, equalTo('1')
|
||||
latch.countDown()
|
||||
}
|
||||
latch.await()
|
||||
|
||||
indexR = node.client.index {
|
||||
index "test"
|
||||
type "type1"
|
||||
id "1"
|
||||
index 'test'
|
||||
type 'type1'
|
||||
id '1'
|
||||
source {
|
||||
test = "value"
|
||||
test = 'value'
|
||||
complex {
|
||||
value1 = "value1"
|
||||
value2 = "value2"
|
||||
value1 = 'value1'
|
||||
value2 = 'value2'
|
||||
}
|
||||
}
|
||||
}
|
||||
latch = new CountDownLatch(1)
|
||||
indexR.listener = {
|
||||
assertThat indexR.response.index, equalTo("test")
|
||||
assertThat indexR.response.type, equalTo("type1")
|
||||
assertThat indexR.response.id, equalTo("1")
|
||||
assertThat indexR.response.index, equalTo('test')
|
||||
assertThat indexR.response.type, equalTo('type1')
|
||||
assertThat indexR.response.id, equalTo('1')
|
||||
latch.countDown()
|
||||
}
|
||||
latch.await()
|
||||
|
|
|
@ -42,7 +42,7 @@ class SimpleActionsTests {
|
|||
local = true
|
||||
}
|
||||
gateway {
|
||||
type = "none"
|
||||
type = 'none'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,74 +54,73 @@ class SimpleActionsTests {
|
|||
node.close()
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testSimpleOperations() {
|
||||
def value1 = new org.elasticsearch.groovy.common.xcontent.GXContentBuilder().buildAsString {
|
||||
something = "test"
|
||||
something = 'test'
|
||||
}
|
||||
println value1
|
||||
|
||||
def indexR = node.client.index {
|
||||
index "test"
|
||||
type "type1"
|
||||
id "1"
|
||||
index 'test'
|
||||
type 'type1'
|
||||
id '1'
|
||||
source {
|
||||
test = "value"
|
||||
test = 'value'
|
||||
complex {
|
||||
value1 = "value1"
|
||||
value2 = "value2"
|
||||
value1 = 'value1'
|
||||
value2 = 'value2'
|
||||
}
|
||||
}
|
||||
}
|
||||
assertThat indexR.response.index, equalTo("test")
|
||||
assertThat indexR.response.type, equalTo("type1")
|
||||
assertThat indexR.response.id, equalTo("1")
|
||||
assertThat indexR.response.index, equalTo('test')
|
||||
assertThat indexR.response.type, equalTo('type1')
|
||||
assertThat indexR.response.id, equalTo('1')
|
||||
|
||||
def delete = node.client.delete {
|
||||
index "test"
|
||||
type "type1"
|
||||
id "1"
|
||||
index 'test'
|
||||
type 'type1'
|
||||
id '1'
|
||||
}
|
||||
assertThat delete.response.index, equalTo("test")
|
||||
assertThat delete.response.type, equalTo("type1")
|
||||
assertThat delete.response.id, equalTo("1")
|
||||
assertThat delete.response.index, equalTo('test')
|
||||
assertThat delete.response.type, equalTo('type1')
|
||||
assertThat delete.response.id, equalTo('1')
|
||||
|
||||
def refresh = node.client.admin.indices.refresh {}
|
||||
assertThat refresh.response.failedShards, equalTo(0)
|
||||
|
||||
def get = node.client.get {
|
||||
index "test"
|
||||
type "type1"
|
||||
id "1"
|
||||
index 'test'
|
||||
type 'type1'
|
||||
id '1'
|
||||
}
|
||||
assertThat get.response.exists, equalTo(false)
|
||||
|
||||
indexR = node.client.index {
|
||||
index "test"
|
||||
type "type1"
|
||||
id "1"
|
||||
index 'test'
|
||||
type 'type1'
|
||||
id '1'
|
||||
source {
|
||||
test = "value"
|
||||
test = 'value'
|
||||
complex {
|
||||
value1 = "value1"
|
||||
value2 = "value2"
|
||||
value1 = 'value1'
|
||||
value2 = 'value2'
|
||||
}
|
||||
}
|
||||
}
|
||||
assertThat indexR.response.index, equalTo("test")
|
||||
assertThat indexR.response.type, equalTo("type1")
|
||||
assertThat indexR.response.id, equalTo("1")
|
||||
assertThat indexR.response.index, equalTo('test')
|
||||
assertThat indexR.response.type, equalTo('type1')
|
||||
assertThat indexR.response.id, equalTo('1')
|
||||
|
||||
refresh = node.client.admin.indices.refresh {}
|
||||
assertThat refresh.response.failedShards, equalTo(0)
|
||||
|
||||
def count = node.client.count {
|
||||
indices "test"
|
||||
types "type1"
|
||||
indices 'test'
|
||||
types 'type1'
|
||||
query {
|
||||
term {
|
||||
test = "value"
|
||||
test = 'value'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,22 +128,22 @@ class SimpleActionsTests {
|
|||
assertThat count.response.count, equalTo(1l)
|
||||
|
||||
def search = node.client.search {
|
||||
indices "test"
|
||||
types "type1"
|
||||
indices 'test'
|
||||
types 'type1'
|
||||
source {
|
||||
query {
|
||||
term(test: "value")
|
||||
term(test: 'value')
|
||||
}
|
||||
}
|
||||
}
|
||||
assertThat search.response.failedShards, equalTo(0)
|
||||
assertThat search.response.hits.totalHits, equalTo(1l)
|
||||
assertThat search.response.hits[0].source.test, equalTo("value")
|
||||
assertThat search.response.hits[0].source.test, equalTo('value')
|
||||
|
||||
def deleteByQuery = node.client.deleteByQuery {
|
||||
indices "test"
|
||||
indices 'test'
|
||||
query {
|
||||
term("test": "value")
|
||||
term(test: 'value')
|
||||
}
|
||||
}
|
||||
assertThat deleteByQuery.response.indices.test.failedShards, equalTo(0)
|
||||
|
@ -153,9 +152,9 @@ class SimpleActionsTests {
|
|||
assertThat refresh.response.failedShards, equalTo(0)
|
||||
|
||||
get = node.client.get {
|
||||
index "test"
|
||||
type "type1"
|
||||
id "1"
|
||||
index 'test'
|
||||
type 'type1'
|
||||
id '1'
|
||||
}
|
||||
assertThat get.response.exists, equalTo(false)
|
||||
}
|
||||
|
|
|
@ -29,13 +29,13 @@ import static org.elasticsearch.groovy.node.GNodeBuilder.*
|
|||
class GNodeBuilderTests extends GroovyTestCase {
|
||||
|
||||
void testGNodeBuilder() {
|
||||
GNodeBuilder nodeBuilder = nodeBuilder();
|
||||
GNodeBuilder nodeBuilder = nodeBuilder()
|
||||
nodeBuilder.settings {
|
||||
node {
|
||||
local = true
|
||||
}
|
||||
cluster {
|
||||
name = "test"
|
||||
name = 'test'
|
||||
}
|
||||
}
|
||||
GNode node = nodeBuilder.node()
|
||||
|
|
Loading…
Reference in New Issue